emberjs / babel-plugin-ember-template-compilation

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

Preserve used imports when interoperating with transform-typescript #32

Closed ef4 closed 1 year ago

ef4 commented 1 year ago

Builds off https://github.com/emberjs/babel-plugin-ember-template-compilation/pull/31 to fix https://github.com/emberjs/babel-plugin-ember-template-compilation/pull/30.

Instead of keeping everything as in https://github.com/emberjs/babel-plugin-ember-template-compilation/pull/31 (which is not safe in general), we use the pre to take a snapshot of available imports and then only when we discover that a template wants to use a name that is not in scope do we check if it was in the original set of available imports and reintroduce an import for it.

ef4 commented 1 year ago

I confirmed locally that this PR fixes https://github.com/ember-template-imports/ember-template-imports/pull/211

patricklx commented 1 year ago

Does this also work with amd transform? Would be good to have a test for it too .

Btw, thanks for basing this on my pr. Much appreciated. if this works well, also with AMD transform, then this is better

ef4 commented 1 year ago

This PR didn't change anything about the timing of when we add imports. We were already adding imports in a bunch of places within the expression-level visitors.

patricklx commented 1 year ago

I also saw now that amd transform runs an program:exit