Skip to content

Duplicate decorator helper in each compile Typescript file #1850

Open
@motss

Description

⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.

  • Read the docs.
  • Use Vite >=2.0. (1.x is no longer supported)
  • If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

Describe the bug

The following code is embedded in each compiled TypeScript file when decorator is used.

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorate = (decorators,target,key,kind)=>{
    var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
    for (var i = decorators.length - 1, decorator; i >= 0; i--)
        if (decorator = decorators[i])
            result = (kind ? decorator(target, key, result) : decorator(result)) || result;
    if (kind && result)
        __defProp(target, key, result);
    return result;
}
;

While the code above is not going to increase the overall file size, it is good to be able to dedupe such code in a separate bundle and import when needed in each and every compiled TS file that requires it.

Reproduction

  1. Run npm init @vitejs/app and select lit-element-ts to scaffold a project
  2. Ensure vite is always the latest version
  3. Create a simple my-app using lit-element and render my-app inside my-element
  4. Run npm run dev to start the dev server
  5. Access the local dev server and inspect the compiled scripts in the Network tab in Chrome DevTool or equivalent
  6. The said generated code will be inside each and every compiled TS file

System Info

  • vite version: 2.0.0-beta.61
  • Operating System: Windows 10 x64
  • Node version: 15.7.0
  • Package manager (npm/yarn/pnpm) and version: npm@7.4.3

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.

Metadata

Assignees

No one assigned

    Labels

    bug: upstreamBug in a dependency of ViteenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions