Skip to content

Commit

Permalink
Merge pull request #748 from patricklx/patch-4
Browse files Browse the repository at this point in the history
check if template is in heritage clause
  • Loading branch information
ef4 authored Jul 9, 2024
2 parents 49eda95 + 1a1a150 commit 6e6c9d7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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>) {
}
`,
};

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

0 comments on commit 6e6c9d7

Please sign in to comment.