Skip to content

check if template is in heritage clause #748

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

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/core/__tests__/transform/rewrite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,29 @@ describe('Transform: rewriteModule', () => {
});

describe('ember-template-imports', () => {
test('in class extends', () => {
let customEnv = GlintEnvironment.load(['ember-loose', 'ember-template-imports']);
let script = {
filename: 'test.gts',
contents: stripIndent`
import Component, { hbs } from 'special/component';
export default class MyComponent extends Component(<template></template>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a goofy test, but the real-world use case is ember-route-template, yea?

https://github.com/discourse/ember-route-template

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


}
`,
};

let transformedModule = rewriteModule(ts, { script }, customEnv);

expect(transformedModule?.transformedContents).toMatchInlineSnapshot(`
"import Component, { hbs } from 'special/component';
export default class MyComponent extends Component(({} as typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")).templateExpression(function(𝚪, χ: typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")) {
𝚪; χ;
})) {

}"
`);
});
test('embedded gts templates', () => {
let customEnv = GlintEnvironment.load(['ember-loose', 'ember-template-imports']);
let script = {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/transform/template/inlining/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export function isEmbeddedInClass(ts: TSLib, node: ts.Node): boolean {
// TODO: this should likely actually filter on whether the template appears in a
// static block or property definition, but just "am I in a class body" is the
// current status quo and has been ok so far.
if (ts.isHeritageClause(current)) {
return false;
}
if (ts.isClassLike(current)) {
return true;
}
Expand Down
Loading