emberjs / babel-plugin-ember-template-compilation

Babel implementation of Ember's low-level template-compilation API
9 stars 11 forks source link

Remove extraneous import from `@ember/template-compiler` #51

Closed NullVoxPopuli closed 6 months ago

NullVoxPopuli commented 6 months ago

First commit:

demonstrates a failing test where @ember/template-compiler is left in the output code. This manifests itself in the default blueprint when two components exist in the same file:

reproduction is simple Input code: ```gjs import Component from '@glimmer/component'; export default class Test extends Component { foo = 1; } const Icon = ; ``` Which is intermediately (still correct): ```js import { template } from "@ember/template-compiler"; import Component from '@glimmer/component'; export default class Test extends Component { foo = 1; static{ template("", { component: this, eval () { return eval(arguments[0]); } }); } } const Icon = template("Icon", { eval () { return eval(arguments[0]); } }); ``` Output code: ```js import '@ember/template-compiler'; import Component from '@glimmer/component'; import { precompileTemplate } from '@ember/template-compilation'; import { setComponentTemplate } from '@ember/component'; import templateOnly from '@ember/component/template-only'; class Test extends Component { foo = 1; static { setComponentTemplate(precompileTemplate("", { strictMode: true, scope: () => ({ Icon }) }), this); } } const Icon = setComponentTemplate(precompileTemplate("Icon", { strictMode: true }), templateOnly()); export { Test as default }; //# sourceMappingURL=test.js.map ```

Rollup detects that { template } is unused, but then leaves a side-effecting import for @ember/template-compiler

ef4 commented 6 months ago

Thanks, the test was helpful in narrowing this down.