From 54344bae898ede74b59011b66ac5e8617ce5f3db Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Mon, 18 Mar 2024 12:06:39 +0100 Subject: [PATCH 1/3] check if is in heritage clause class A extends X() { } --- packages/core/src/transform/template/inlining/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/core/src/transform/template/inlining/index.ts b/packages/core/src/transform/template/inlining/index.ts index affed1f2e..ac7a72eb6 100644 --- a/packages/core/src/transform/template/inlining/index.ts +++ b/packages/core/src/transform/template/inlining/index.ts @@ -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; } From 674122121270ad6184c4c7449a14e016a94460df Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Tue, 19 Mar 2024 16:02:22 +0100 Subject: [PATCH 2/3] add test --- .../core/__tests__/transform/rewrite.test.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/core/__tests__/transform/rewrite.test.ts b/packages/core/__tests__/transform/rewrite.test.ts index 986d7b6b4..39f81c878 100644 --- a/packages/core/__tests__/transform/rewrite.test.ts +++ b/packages/core/__tests__/transform/rewrite.test.ts @@ -467,6 +467,30 @@ 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() { + + } + `, + }; + + 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 = { From 1a1a15075a922c4818f40f12f376b65fcb60f036 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Thu, 21 Mar 2024 14:29:52 +0100 Subject: [PATCH 3/3] fix lint --- packages/core/__tests__/transform/rewrite.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/__tests__/transform/rewrite.test.ts b/packages/core/__tests__/transform/rewrite.test.ts index 39f81c878..0676df9cf 100644 --- a/packages/core/__tests__/transform/rewrite.test.ts +++ b/packages/core/__tests__/transform/rewrite.test.ts @@ -481,7 +481,6 @@ describe('Transform: rewriteModule', () => { 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\\")) {