Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix gts in v1 addons #2120

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from

Conversation

patricklx
Copy link
Contributor

@patricklx patricklx commented Sep 20, 2024

fixes #2119

@patricklx patricklx changed the base branch from main to stable September 20, 2024 14:55
@patricklx patricklx force-pushed the fix-gts-in-v1-addons branch 2 times, most recently from 8cd0ee8 to 0714d84 Compare September 20, 2024 15:41
@ef4
Copy link
Contributor

ef4 commented Sep 23, 2024

This shouldn't be necessary. ember-template-imports pushes a babel plugin, which should mean that this.plugins.length > 0 is already true.

@patricklx
Copy link
Contributor Author

ah, but that was only merged yesterday :)

@ef4
Copy link
Contributor

ef4 commented Sep 23, 2024

It took me a little while to understand this, because while I think your fix is correct the explanation for it is more subtle.

Stage1 will always run custom broccoli preprocessors. So that's enough to convert:

import Thing from './thing';
<template><Thing/></template>

to

import Thing from './thing';
import { template } from '@ember/template-compiler';
export default template("Thing", {
  eval: function() { return eval(arguments[0]) } })
});

This is really all we need to do at stage1, since this is now valid Javascript that could appear in a v2 addon.

But if the addon is also using TS, we also need to run the typescript transform before it will be valid JS. And if the typescript transform was being truly correct it would not try to delete the import because the eval can see the imported binding. That's why we have an eval. It's a standards-compliant want of gaining access to everything in scope.

Unfortunately the typescript transform is a jerk and will drop the binding anyway, assuming with no evidence that it must have been "type only".

Normally we only use babel-plugin-ember-template-compilation in stage1 to run custom AST transforms. Since there are none in the addon, we don't add it. The fix here is helping because there is a new reason to add it. It will further convert the above example to:

import Thing from './thing';
import { template } from '@ember/template-compiler';
export default template("Thing", {
  scope: () => ({ Thing })
});

which typescript then respects.

@ef4
Copy link
Contributor

ef4 commented Sep 23, 2024

This could really use a test.

@ef4
Copy link
Contributor

ef4 commented Sep 23, 2024

Also, if you can update the comments in the code to align with my explanation above it will help us in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v1 addon with gts + ember-template-imports failing under Embroider
2 participants