From 3c5a721ccb1e4205060170c23db5f52a1f498144 Mon Sep 17 00:00:00 2001 From: Luke Melia Date: Mon, 18 Sep 2023 23:06:35 -0400 Subject: [PATCH] Support import paths with .gts extensions Fixes #618 --- .../core/__tests__/transform/debug.test.ts | 348 +++++++++--------- .../core/__tests__/transform/rewrite.test.ts | 244 ++++++------ packages/core/src/common/document-cache.ts | 9 +- packages/core/src/config/types.cts | 6 +- .../template/import-declaration-span.ts | 53 +++ .../src/transform/template/mapping-tree.ts | 29 +- .../src/transform/template/rewrite-module.ts | 8 +- .../-private/environment/transform.ts | 7 + .../{src => app/components}/Greeting.gts | 11 +- .../{src => app/components}/Playground.gts | 0 .../components/WorldGreeting.gts} | 2 +- .../app/helpers/repeat.ts | 9 + .../app/templates/application.hbs | 3 + .../ts-template-imports-app/package.json | 9 +- .../ts-template-imports-app/tsconfig.json | 6 +- yarn.lock | 139 +++++++ 16 files changed, 581 insertions(+), 302 deletions(-) create mode 100644 packages/core/src/transform/template/import-declaration-span.ts rename test-packages/ts-template-imports-app/{src => app/components}/Greeting.gts (72%) rename test-packages/ts-template-imports-app/{src => app/components}/Playground.gts (100%) rename test-packages/ts-template-imports-app/{src/index.gts => app/components/WorldGreeting.gts} (64%) create mode 100644 test-packages/ts-template-imports-app/app/helpers/repeat.ts create mode 100644 test-packages/ts-template-imports-app/app/templates/application.hbs diff --git a/packages/core/__tests__/transform/debug.test.ts b/packages/core/__tests__/transform/debug.test.ts index 03429e192..b59b19e89 100644 --- a/packages/core/__tests__/transform/debug.test.ts +++ b/packages/core/__tests__/transform/debug.test.ts @@ -37,129 +37,129 @@ describe('Transform: Debug utilities', () => { "TransformedModule | Mapping: TemplateEmbedding - | hbs(0:123): {{#each (array \\"world\\" \\"planet\\" \\"universe\\") as |target index|}}\\\\n #{{add index 1}}: {{this.message}}, {{target}}!\\\\n{{/each}} - | ts(131:685): ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"each\\"])([\\"world\\", \\"planet\\", \\"universe\\"]));\\\\n {\\\\n const [target, index] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolve(χ.Globals[\\"add\\"])(index, 1));\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.this.message)());\\\\n χ.emitContent(χ.resolveOrReturn(target)());\\\\n }\\\\n χ.Globals[\\"each\\"];\\\\n }\\\\n 𝚪; χ;\\\\n}) + | in: hbs(0:123): {{#each (array \\"world\\" \\"planet\\" \\"universe\\") as |target index|}}\\\\n #{{add index 1}}: {{this.message}}, {{target}}!\\\\n{{/each}} + | out: ts(131:685): ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"each\\"])([\\"world\\", \\"planet\\", \\"universe\\"]));\\\\n {\\\\n const [target, index] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolve(χ.Globals[\\"add\\"])(index, 1));\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.this.message)());\\\\n χ.emitContent(χ.resolveOrReturn(target)());\\\\n }\\\\n χ.Globals[\\"each\\"];\\\\n }\\\\n 𝚪; χ;\\\\n}) | | | Mapping: Template - | | hbs(0:123): {{#each (array \\"world\\" \\"planet\\" \\"universe\\") as |target index|}}\\\\n #{{add index 1}}: {{this.message}}, {{target}}!\\\\n{{/each}} - | | ts(310:674): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"each\\"])([\\"world\\", \\"planet\\", \\"universe\\"]));\\\\n {\\\\n const [target, index] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolve(χ.Globals[\\"add\\"])(index, 1));\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.this.message)());\\\\n χ.emitContent(χ.resolveOrReturn(target)());\\\\n }\\\\n χ.Globals[\\"each\\"];\\\\n } + | | in: hbs(0:123): {{#each (array \\"world\\" \\"planet\\" \\"universe\\") as |target index|}}\\\\n #{{add index 1}}: {{this.message}}, {{target}}!\\\\n{{/each}} + | | out: ts(310:674): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"each\\"])([\\"world\\", \\"planet\\", \\"universe\\"]));\\\\n {\\\\n const [target, index] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolve(χ.Globals[\\"add\\"])(index, 1));\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.this.message)());\\\\n χ.emitContent(χ.resolveOrReturn(target)());\\\\n }\\\\n χ.Globals[\\"each\\"];\\\\n } | | | | | Mapping: BlockStatement - | | | hbs(0:123): {{#each (array \\"world\\" \\"planet\\" \\"universe\\") as |target index|}}\\\\n #{{add index 1}}: {{this.message}}, {{target}}!\\\\n{{/each}} - | | | ts(310:673): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"each\\"])([\\"world\\", \\"planet\\", \\"universe\\"]));\\\\n {\\\\n const [target, index] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolve(χ.Globals[\\"add\\"])(index, 1));\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.this.message)());\\\\n χ.emitContent(χ.resolveOrReturn(target)());\\\\n }\\\\n χ.Globals[\\"each\\"];\\\\n } + | | | in: hbs(0:123): {{#each (array \\"world\\" \\"planet\\" \\"universe\\") as |target index|}}\\\\n #{{add index 1}}: {{this.message}}, {{target}}!\\\\n{{/each}} + | | | out: ts(310:673): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"each\\"])([\\"world\\", \\"planet\\", \\"universe\\"]));\\\\n {\\\\n const [target, index] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolve(χ.Globals[\\"add\\"])(index, 1));\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.this.message)());\\\\n χ.emitContent(χ.resolveOrReturn(target)());\\\\n }\\\\n χ.Globals[\\"each\\"];\\\\n } | | | | | | | Mapping: PathExpression - | | | | hbs(3:7): each - | | | | ts(355:372): χ.Globals[\\"each\\"] + | | | | in: hbs(3:7): each + | | | | out: ts(355:372): χ.Globals[\\"each\\"] | | | | | | | | | Mapping: Identifier - | | | | | hbs(3:7): each - | | | | | ts(366:370): each + | | | | | in: hbs(3:7): each + | | | | | out: ts(366:370): each | | | | | | | | | | | | | Mapping: SubExpression - | | | | hbs(8:43): (array \\"world\\" \\"planet\\" \\"universe\\") - | | | | ts(374:405): [\\"world\\", \\"planet\\", \\"universe\\"] + | | | | in: hbs(8:43): (array \\"world\\" \\"planet\\" \\"universe\\") + | | | | out: ts(374:405): [\\"world\\", \\"planet\\", \\"universe\\"] | | | | | | | | | Mapping: StringLiteral - | | | | | hbs(15:22): \\"world\\" - | | | | | ts(375:382): \\"world\\" + | | | | | in: hbs(15:22): \\"world\\" + | | | | | out: ts(375:382): \\"world\\" | | | | | | | | | | Mapping: StringLiteral - | | | | | hbs(23:31): \\"planet\\" - | | | | | ts(384:392): \\"planet\\" + | | | | | in: hbs(23:31): \\"planet\\" + | | | | | out: ts(384:392): \\"planet\\" | | | | | | | | | | Mapping: StringLiteral - | | | | | hbs(32:42): \\"universe\\" - | | | | | ts(394:404): \\"universe\\" + | | | | | in: hbs(32:42): \\"universe\\" + | | | | | out: ts(394:404): \\"universe\\" | | | | | | | | | | | | | Mapping: Identifier - | | | | hbs(48:54): target - | | | | ts(428:434): target + | | | | in: hbs(48:54): target + | | | | out: ts(428:434): target | | | | | | | | Mapping: Identifier - | | | | hbs(55:60): index - | | | | ts(436:441): index + | | | | in: hbs(55:60): index + | | | | out: ts(436:441): index | | | | | | | | Mapping: TextContent - | | | | hbs(66:67): # - | | | | ts(472:472): + | | | | in: hbs(66:67): # + | | | | out: ts(472:472): | | | | | | | | Mapping: MustacheStatement - | | | | hbs(67:82): {{add index 1}} - | | | | ts(472:530): χ.emitContent(χ.resolve(χ.Globals[\\"add\\"])(index, 1)) + | | | | in: hbs(67:82): {{add index 1}} + | | | | out: ts(472:530): χ.emitContent(χ.resolve(χ.Globals[\\"add\\"])(index, 1)) | | | | | | | | | Mapping: PathExpression - | | | | | hbs(69:72): add - | | | | | ts(502:518): χ.Globals[\\"add\\"] + | | | | | in: hbs(69:72): add + | | | | | out: ts(502:518): χ.Globals[\\"add\\"] | | | | | | | | | | | Mapping: Identifier - | | | | | | hbs(69:72): add - | | | | | | ts(513:516): add + | | | | | | in: hbs(69:72): add + | | | | | | out: ts(513:516): add | | | | | | | | | | | | | | | | Mapping: PathExpression - | | | | | hbs(73:78): index - | | | | | ts(520:525): index + | | | | | in: hbs(73:78): index + | | | | | out: ts(520:525): index | | | | | | | | | | | Mapping: Identifier - | | | | | | hbs(73:78): index - | | | | | | ts(520:525): index + | | | | | | in: hbs(73:78): index + | | | | | | out: ts(520:525): index | | | | | | | | | | | | | | | | Mapping: NumberLiteral - | | | | | hbs(79:80): 1 - | | | | | ts(527:528): 1 + | | | | | in: hbs(79:80): 1 + | | | | | out: ts(527:528): 1 | | | | | | | | | | | | | Mapping: TextContent - | | | | hbs(82:83): : - | | | | ts(532:532): + | | | | in: hbs(82:83): : + | | | | out: ts(532:532): | | | | | | | | Mapping: MustacheStatement - | | | | hbs(84:100): {{this.message}} - | | | | ts(532:589): χ.emitContent(χ.resolveOrReturn(𝚪.this.message)()) + | | | | in: hbs(84:100): {{this.message}} + | | | | out: ts(532:589): χ.emitContent(χ.resolveOrReturn(𝚪.this.message)()) | | | | | | | | | Mapping: PathExpression - | | | | | hbs(86:98): this.message - | | | | | ts(570:585): 𝚪.this.message + | | | | | in: hbs(86:98): this.message + | | | | | out: ts(570:585): 𝚪.this.message | | | | | | | | | | | Mapping: Identifier - | | | | | | hbs(86:90): this - | | | | | | ts(573:577): this + | | | | | | in: hbs(86:90): this + | | | | | | out: ts(573:577): this | | | | | | | | | | | | Mapping: Identifier - | | | | | | hbs(91:98): message - | | | | | | ts(578:585): message + | | | | | | in: hbs(91:98): message + | | | | | | out: ts(578:585): message | | | | | | | | | | | | | | | | | | | Mapping: TextContent - | | | | hbs(100:101): , - | | | | ts(591:591): + | | | | in: hbs(100:101): , + | | | | out: ts(591:591): | | | | | | | | Mapping: MustacheStatement - | | | | hbs(102:112): {{target}} - | | | | ts(591:639): χ.emitContent(χ.resolveOrReturn(target)()) + | | | | in: hbs(102:112): {{target}} + | | | | out: ts(591:639): χ.emitContent(χ.resolveOrReturn(target)()) | | | | | | | | | Mapping: PathExpression - | | | | | hbs(104:110): target - | | | | | ts(629:635): target + | | | | | in: hbs(104:110): target + | | | | | out: ts(629:635): target | | | | | | | | | | | Mapping: Identifier - | | | | | | hbs(104:110): target - | | | | | | ts(629:635): target + | | | | | | in: hbs(104:110): target + | | | | | | out: ts(629:635): target | | | | | | | | | | | | | | | | | | | Mapping: TextContent - | | | | hbs(112:113): ! - | | | | ts(641:641): + | | | | in: hbs(112:113): ! + | | | | out: ts(641:641): | | | | | | | | Mapping: Identifier - | | | | hbs(117:121): each - | | | | ts(662:666): each + | | | | in: hbs(117:121): each + | | | | out: ts(662:666): each | | | | | | | | | @@ -200,132 +200,132 @@ describe('Transform: Debug utilities', () => { "TransformedModule | Mapping: TemplateEmbedding - | hbs(151:201): hbs\`\\\\n \\\\n \` - | ts(151:462): ({} as typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")) {\\\\n hbs;\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n }\\\\n 𝚪; χ;\\\\n}) + | in: hbs(151:201): hbs\`\\\\n \\\\n \` + | out: ts(151:462): ({} as typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")) {\\\\n hbs;\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n }\\\\n 𝚪; χ;\\\\n}) | | | Mapping: Template - | | hbs(155:200): - | | ts(331:451): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n } + | | in: hbs(155:200): + | | out: ts(331:451): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n } | | | | | Mapping: TextContent - | | | hbs(155:160): - | | | ts(331:331): + | | | in: hbs(155:160): + | | | out: ts(331:331): | | | | | | Mapping: ElementNode - | | | hbs(160:197): - | | | ts(331:451): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n } + | | | in: hbs(160:197): + | | | out: ts(331:451): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n } | | | | | | | Mapping: Identifier - | | | | hbs(161:176): HelperComponent - | | | | ts(376:391): HelperComponent + | | | | in: hbs(161:176): HelperComponent + | | | | out: ts(376:391): HelperComponent | | | | | | | | Mapping: AttrNode - | | | | hbs(177:194): @foo={{this.bar}} - | | | | ts(395:411): foo: 𝚪.this.bar + | | | | in: hbs(177:194): @foo={{this.bar}} + | | | | out: ts(395:411): foo: 𝚪.this.bar | | | | | | | | | Mapping: Identifier - | | | | | hbs(178:181): foo - | | | | | ts(395:398): foo + | | | | | in: hbs(178:181): foo + | | | | | out: ts(395:398): foo | | | | | | | | | | Mapping: MustacheStatement - | | | | | hbs(182:194): {{this.bar}} - | | | | | ts(400:411): 𝚪.this.bar + | | | | | in: hbs(182:194): {{this.bar}} + | | | | | out: ts(400:411): 𝚪.this.bar | | | | | | | | | | | Mapping: PathExpression - | | | | | | hbs(184:192): this.bar - | | | | | | ts(400:411): 𝚪.this.bar + | | | | | | in: hbs(184:192): this.bar + | | | | | | out: ts(400:411): 𝚪.this.bar | | | | | | | | | | | | | Mapping: Identifier - | | | | | | | hbs(184:188): this - | | | | | | | ts(403:407): this + | | | | | | | in: hbs(184:188): this + | | | | | | | out: ts(403:407): this | | | | | | | | | | | | | | Mapping: Identifier - | | | | | | | hbs(189:192): bar - | | | | | | | ts(408:411): bar + | | | | | | | in: hbs(189:192): bar + | | | | | | | out: ts(408:411): bar | | | | | | | | | | | | | | | | | | | | | | | | | | | | Mapping: TextContent - | | | hbs(197:200): - | | | ts(451:451): + | | | in: hbs(197:200): + | | | out: ts(451:451): | | | | | | | Mapping: TemplateEmbedding - | hbs(295:419): hbs\`\\\\n

\\\\n Hello, {{@foo}}!\\\\n\\\\n {{! @glint-expect-error: no @bar arg }}\\\\n {{@bar}}\\\\n

\\\\n \` - | ts(556:973): ({} as typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")) {\\\\n hbs;\\\\n {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n }\\\\n 𝚪; χ;\\\\n}) + | in: hbs(295:419): hbs\`\\\\n

\\\\n Hello, {{@foo}}!\\\\n\\\\n {{! @glint-expect-error: no @bar arg }}\\\\n {{@bar}}\\\\n

\\\\n \` + | out: ts(556:973): ({} as typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")) {\\\\n hbs;\\\\n {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n }\\\\n 𝚪; χ;\\\\n}) | | | Mapping: Template - | | hbs(299:418):

\\\\n Hello, {{@foo}}!\\\\n\\\\n {{! @glint-expect-error: no @bar arg }}\\\\n {{@bar}}\\\\n

- | | ts(736:962): {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n } + | | in: hbs(299:418):

\\\\n Hello, {{@foo}}!\\\\n\\\\n {{! @glint-expect-error: no @bar arg }}\\\\n {{@bar}}\\\\n

+ | | out: ts(736:962): {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n } | | | | | Mapping: TextContent - | | | hbs(299:304): - | | | ts(736:736): + | | | in: hbs(299:304): + | | | out: ts(736:736): | | | | | | Mapping: ElementNode - | | | hbs(304:415):

\\\\n Hello, {{@foo}}!\\\\n\\\\n {{! @glint-expect-error: no @bar arg }}\\\\n {{@bar}}\\\\n

- | | | ts(736:962): {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n } + | | | in: hbs(304:415):

\\\\n Hello, {{@foo}}!\\\\n\\\\n {{! @glint-expect-error: no @bar arg }}\\\\n {{@bar}}\\\\n

+ | | | out: ts(736:962): {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n } | | | | | | | Mapping: AttrNode - | | | | hbs(307:320): ...attributes - | | | | ts(775:824): χ.applySplattributes(𝚪.element, 𝛄.element); + | | | | in: hbs(307:320): ...attributes + | | | | out: ts(775:824): χ.applySplattributes(𝚪.element, 𝛄.element); | | | | | | | | Mapping: TextContent - | | | | hbs(328:334): Hello, - | | | | ts(825:825): + | | | | in: hbs(328:334): Hello, + | | | | out: ts(825:825): | | | | | | | | Mapping: MustacheStatement - | | | | hbs(335:343): {{@foo}} - | | | | ts(825:876): χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)()) + | | | | in: hbs(335:343): {{@foo}} + | | | | out: ts(825:876): χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)()) | | | | | | | | | Mapping: PathExpression - | | | | | hbs(337:341): @foo - | | | | | ts(861:872): 𝚪.args.foo + | | | | | in: hbs(337:341): @foo + | | | | | out: ts(861:872): 𝚪.args.foo | | | | | | | | | | | Mapping: Identifier - | | | | | | hbs(338:341): foo - | | | | | | ts(869:872): foo + | | | | | | in: hbs(338:341): foo + | | | | | | out: ts(869:872): foo | | | | | | | | | | | | | | | | | | | Mapping: TextContent - | | | | hbs(343:344): ! - | | | | ts(878:878): + | | | | in: hbs(343:344): ! + | | | | out: ts(878:878): | | | | | | | | Mapping: MustacheCommentStatement - | | | | hbs(352:391): {{! @glint-expect-error: no @bar arg }} - | | | | ts(878:905): // @glint-expect-error + | | | | in: hbs(352:391): {{! @glint-expect-error: no @bar arg }} + | | | | out: ts(878:905): // @glint-expect-error | | | | | | | | Mapping: TextContent - | | | | hbs(392:398): - | | | | ts(905:905): + | | | | in: hbs(392:398): + | | | | out: ts(905:905): | | | | | | | | Mapping: MustacheStatement - | | | | hbs(398:406): {{@bar}} - | | | | ts(905:956): χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)()) + | | | | in: hbs(398:406): {{@bar}} + | | | | out: ts(905:956): χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)()) | | | | | | | | | Mapping: PathExpression - | | | | | hbs(400:404): @bar - | | | | | ts(941:952): 𝚪.args.bar + | | | | | in: hbs(400:404): @bar + | | | | | out: ts(941:952): 𝚪.args.bar | | | | | | | | | | | Mapping: Identifier - | | | | | | hbs(401:404): bar - | | | | | | ts(949:952): bar + | | | | | | in: hbs(401:404): bar + | | | | | | out: ts(949:952): bar | | | | | | | | | | | | | | | | | | | Mapping: TextContent - | | | | hbs(406:411): - | | | | ts(958:958): + | | | | in: hbs(406:411): + | | | | out: ts(958:958): | | | | | | | | | | Mapping: TextContent - | | | hbs(415:418): - | | | ts(962:962): + | | | in: hbs(415:418): + | | | out: ts(962:962): | | | | | |" @@ -365,132 +365,132 @@ describe('Transform: Debug utilities', () => { "TransformedModule | Mapping: TemplateEmbedding - | hbs(156:208): hbs\`\\\\r\\\\n \\\\r\\\\n \` - | ts(156:467): ({} as typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")) {\\\\n hbs;\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n }\\\\n 𝚪; χ;\\\\n}) + | in: hbs(156:208): hbs\`\\\\r\\\\n \\\\r\\\\n \` + | out: ts(156:467): ({} as typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")) {\\\\n hbs;\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n }\\\\n 𝚪; χ;\\\\n}) | | | Mapping: Template - | | hbs(160:207): - | | ts(336:456): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n } + | | in: hbs(160:207): + | | out: ts(336:456): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n } | | | | | Mapping: TextContent - | | | hbs(160:166): - | | | ts(336:336): + | | | in: hbs(160:166): + | | | out: ts(336:336): | | | | | | Mapping: ElementNode - | | | hbs(166:203): - | | | ts(336:456): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n } + | | | in: hbs(166:203): + | | | out: ts(336:456): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(HelperComponent)({ foo: 𝚪.this.bar, ...χ.NamedArgsMarker }));\\\\n 𝛄;\\\\n } | | | | | | | Mapping: Identifier - | | | | hbs(167:182): HelperComponent - | | | | ts(381:396): HelperComponent + | | | | in: hbs(167:182): HelperComponent + | | | | out: ts(381:396): HelperComponent | | | | | | | | Mapping: AttrNode - | | | | hbs(183:200): @foo={{this.bar}} - | | | | ts(400:416): foo: 𝚪.this.bar + | | | | in: hbs(183:200): @foo={{this.bar}} + | | | | out: ts(400:416): foo: 𝚪.this.bar | | | | | | | | | Mapping: Identifier - | | | | | hbs(184:187): foo - | | | | | ts(400:403): foo + | | | | | in: hbs(184:187): foo + | | | | | out: ts(400:403): foo | | | | | | | | | | Mapping: MustacheStatement - | | | | | hbs(188:200): {{this.bar}} - | | | | | ts(405:416): 𝚪.this.bar + | | | | | in: hbs(188:200): {{this.bar}} + | | | | | out: ts(405:416): 𝚪.this.bar | | | | | | | | | | | Mapping: PathExpression - | | | | | | hbs(190:198): this.bar - | | | | | | ts(405:416): 𝚪.this.bar + | | | | | | in: hbs(190:198): this.bar + | | | | | | out: ts(405:416): 𝚪.this.bar | | | | | | | | | | | | | Mapping: Identifier - | | | | | | | hbs(190:194): this - | | | | | | | ts(408:412): this + | | | | | | | in: hbs(190:194): this + | | | | | | | out: ts(408:412): this | | | | | | | | | | | | | | Mapping: Identifier - | | | | | | | hbs(195:198): bar - | | | | | | | ts(413:416): bar + | | | | | | | in: hbs(195:198): bar + | | | | | | | out: ts(413:416): bar | | | | | | | | | | | | | | | | | | | | | | | | | | | | Mapping: TextContent - | | | hbs(203:207): - | | | ts(456:456): + | | | in: hbs(203:207): + | | | out: ts(456:456): | | | | | | | Mapping: TemplateEmbedding - | hbs(306:437): hbs\`\\\\r\\\\n

\\\\r\\\\n Hello, {{@foo}}!\\\\r\\\\n\\\\r\\\\n {{! @glint-expect-error: no @bar arg }}\\\\r\\\\n {{@bar}}\\\\r\\\\n

\\\\r\\\\n \` - | ts(565:982): ({} as typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")) {\\\\n hbs;\\\\n {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n }\\\\n 𝚪; χ;\\\\n}) + | in: hbs(306:437): hbs\`\\\\r\\\\n

\\\\r\\\\n Hello, {{@foo}}!\\\\r\\\\n\\\\r\\\\n {{! @glint-expect-error: no @bar arg }}\\\\r\\\\n {{@bar}}\\\\r\\\\n

\\\\r\\\\n \` + | out: ts(565:982): ({} as typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-glimmerx/-private/dsl\\")) {\\\\n hbs;\\\\n {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n }\\\\n 𝚪; χ;\\\\n}) | | | Mapping: Template - | | hbs(310:436):

\\\\r\\\\n Hello, {{@foo}}!\\\\r\\\\n\\\\r\\\\n {{! @glint-expect-error: no @bar arg }}\\\\r\\\\n {{@bar}}\\\\r\\\\n

- | | ts(745:971): {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n } + | | in: hbs(310:436):

\\\\r\\\\n Hello, {{@foo}}!\\\\r\\\\n\\\\r\\\\n {{! @glint-expect-error: no @bar arg }}\\\\r\\\\n {{@bar}}\\\\r\\\\n

+ | | out: ts(745:971): {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n } | | | | | Mapping: TextContent - | | | hbs(310:316): - | | | ts(745:745): + | | | in: hbs(310:316): + | | | out: ts(745:745): | | | | | | Mapping: ElementNode - | | | hbs(316:432):

\\\\r\\\\n Hello, {{@foo}}!\\\\r\\\\n\\\\r\\\\n {{! @glint-expect-error: no @bar arg }}\\\\r\\\\n {{@bar}}\\\\r\\\\n

- | | | ts(745:971): {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n } + | | | in: hbs(316:432):

\\\\r\\\\n Hello, {{@foo}}!\\\\r\\\\n\\\\r\\\\n {{! @glint-expect-error: no @bar arg }}\\\\r\\\\n {{@bar}}\\\\r\\\\n

+ | | | out: ts(745:971): {\\\\n const 𝛄 = χ.emitElement(\\"p\\");\\\\n χ.applySplattributes(𝚪.element, 𝛄.element);\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)());\\\\n // @glint-expect-error\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)());\\\\n } | | | | | | | Mapping: AttrNode - | | | | hbs(319:332): ...attributes - | | | | ts(784:833): χ.applySplattributes(𝚪.element, 𝛄.element); + | | | | in: hbs(319:332): ...attributes + | | | | out: ts(784:833): χ.applySplattributes(𝚪.element, 𝛄.element); | | | | | | | | Mapping: TextContent - | | | | hbs(340:347): Hello, - | | | | ts(834:834): + | | | | in: hbs(340:347): Hello, + | | | | out: ts(834:834): | | | | | | | | Mapping: MustacheStatement - | | | | hbs(348:356): {{@foo}} - | | | | ts(834:885): χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)()) + | | | | in: hbs(348:356): {{@foo}} + | | | | out: ts(834:885): χ.emitContent(χ.resolveOrReturn(𝚪.args.foo)()) | | | | | | | | | Mapping: PathExpression - | | | | | hbs(350:354): @foo - | | | | | ts(870:881): 𝚪.args.foo + | | | | | in: hbs(350:354): @foo + | | | | | out: ts(870:881): 𝚪.args.foo | | | | | | | | | | | Mapping: Identifier - | | | | | | hbs(351:354): foo - | | | | | | ts(878:881): foo + | | | | | | in: hbs(351:354): foo + | | | | | | out: ts(878:881): foo | | | | | | | | | | | | | | | | | | | Mapping: TextContent - | | | | hbs(356:359): ! - | | | | ts(887:887): + | | | | in: hbs(356:359): ! + | | | | out: ts(887:887): | | | | | | | | Mapping: MustacheCommentStatement - | | | | hbs(367:406): {{! @glint-expect-error: no @bar arg }} - | | | | ts(887:914): // @glint-expect-error + | | | | in: hbs(367:406): {{! @glint-expect-error: no @bar arg }} + | | | | out: ts(887:914): // @glint-expect-error | | | | | | | | Mapping: TextContent - | | | | hbs(408:414): - | | | | ts(914:914): + | | | | in: hbs(408:414): + | | | | out: ts(914:914): | | | | | | | | Mapping: MustacheStatement - | | | | hbs(414:422): {{@bar}} - | | | | ts(914:965): χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)()) + | | | | in: hbs(414:422): {{@bar}} + | | | | out: ts(914:965): χ.emitContent(χ.resolveOrReturn(𝚪.args.bar)()) | | | | | | | | | Mapping: PathExpression - | | | | | hbs(416:420): @bar - | | | | | ts(950:961): 𝚪.args.bar + | | | | | in: hbs(416:420): @bar + | | | | | out: ts(950:961): 𝚪.args.bar | | | | | | | | | | | Mapping: Identifier - | | | | | | hbs(417:420): bar - | | | | | | ts(958:961): bar + | | | | | | in: hbs(417:420): bar + | | | | | | out: ts(958:961): bar | | | | | | | | | | | | | | | | | | | Mapping: TextContent - | | | | hbs(422:428): - | | | | ts(967:967): + | | | | in: hbs(422:428): + | | | | out: ts(967:967): | | | | | | | | | | Mapping: TextContent - | | | hbs(432:436): - | | | ts(971:971): + | | | in: hbs(432:436): + | | | out: ts(971:971): | | | | | |" diff --git a/packages/core/__tests__/transform/rewrite.test.ts b/packages/core/__tests__/transform/rewrite.test.ts index 986d7b6b4..5d8eaa6d8 100644 --- a/packages/core/__tests__/transform/rewrite.test.ts +++ b/packages/core/__tests__/transform/rewrite.test.ts @@ -499,38 +499,38 @@ describe('Transform: rewriteModule', () => { "TransformedModule | Mapping: TemplateEmbedding - | hbs(22:74): - | ts(22:299): static { ({} as typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")) {\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.this.target)());\\\\n 𝚪; χ;\\\\n}) } + | in: hbs(22:74): + | out: ts(22:299): static { ({} as typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")) {\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.this.target)());\\\\n 𝚪; χ;\\\\n}) } | | | Mapping: Template - | | hbs(32:63): Hello, {{this.target}}! - | | ts(232:286): χ.emitContent(χ.resolveOrReturn(𝚪.this.target)()); + | | in: hbs(32:63): Hello, {{this.target}}! + | | out: ts(232:286): χ.emitContent(χ.resolveOrReturn(𝚪.this.target)()); | | | | | Mapping: TextContent - | | | hbs(37:43): Hello, - | | | ts(232:232): + | | | in: hbs(37:43): Hello, + | | | out: ts(232:232): | | | | | | Mapping: MustacheStatement - | | | hbs(44:59): {{this.target}} - | | | ts(232:284): χ.emitContent(χ.resolveOrReturn(𝚪.this.target)()) + | | | in: hbs(44:59): {{this.target}} + | | | out: ts(232:284): χ.emitContent(χ.resolveOrReturn(𝚪.this.target)()) | | | | | | | Mapping: PathExpression - | | | | hbs(46:57): this.target - | | | | ts(266:280): 𝚪.this.target + | | | | in: hbs(46:57): this.target + | | | | out: ts(266:280): 𝚪.this.target | | | | | | | | | Mapping: Identifier - | | | | | hbs(46:50): this - | | | | | ts(269:273): this + | | | | | in: hbs(46:50): this + | | | | | out: ts(269:273): this | | | | | | | | | | Mapping: Identifier - | | | | | hbs(51:57): target - | | | | | ts(274:280): target + | | | | | in: hbs(51:57): target + | | | | | out: ts(274:280): target | | | | | | | | | | | | | | | Mapping: TextContent - | | | hbs(59:60): ! - | | | ts(286:286): + | | | in: hbs(59:60): ! + | | | out: ts(286:286): | | | | | |" @@ -552,34 +552,34 @@ describe('Transform: rewriteModule', () => { "TransformedModule | Mapping: TemplateEmbedding - | hbs(0:44): - | ts(0:270): export default ({} as typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")).templateExpression(function(𝚪, χ: typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")) {\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.target)());\\\\n 𝚪; χ;\\\\n}) + | in: hbs(0:44): + | out: ts(0:270): export default ({} as typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")).templateExpression(function(𝚪, χ: typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")) {\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.target)());\\\\n 𝚪; χ;\\\\n}) | | | Mapping: Template - | | hbs(10:33): Hello, {{@target}}! - | | ts(205:259): χ.emitContent(χ.resolveOrReturn(𝚪.args.target)()); + | | in: hbs(10:33): Hello, {{@target}}! + | | out: ts(205:259): χ.emitContent(χ.resolveOrReturn(𝚪.args.target)()); | | | | | Mapping: TextContent - | | | hbs(13:19): Hello, - | | | ts(205:205): + | | | in: hbs(13:19): Hello, + | | | out: ts(205:205): | | | | | | Mapping: MustacheStatement - | | | hbs(20:31): {{@target}} - | | | ts(205:257): χ.emitContent(χ.resolveOrReturn(𝚪.args.target)()) + | | | in: hbs(20:31): {{@target}} + | | | out: ts(205:257): χ.emitContent(χ.resolveOrReturn(𝚪.args.target)()) | | | | | | | Mapping: PathExpression - | | | | hbs(22:29): @target - | | | | ts(239:253): 𝚪.args.target + | | | | in: hbs(22:29): @target + | | | | out: ts(239:253): 𝚪.args.target | | | | | | | | | Mapping: Identifier - | | | | | hbs(23:29): target - | | | | | ts(247:253): target + | | | | | in: hbs(23:29): target + | | | | | out: ts(247:253): target | | | | | | | | | | | | | | | Mapping: TextContent - | | | hbs(31:32): ! - | | | ts(259:259): + | | | in: hbs(31:32): ! + | | | out: ts(259:259): | | | | | |" @@ -616,24 +616,24 @@ describe('Transform: rewriteModule', () => { "TransformedModule | Mapping: TemplateEmbedding - | hbs(56:89): - | ts(56:312): ({} as typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")).templateExpression(function(𝚪, χ: typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")) {\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.message)());\\\\n 𝚪; χ;\\\\n}) + | in: hbs(56:89): + | out: ts(56:312): ({} as typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")).templateExpression(function(𝚪, χ: typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")) {\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.args.message)());\\\\n 𝚪; χ;\\\\n}) | | | Mapping: Template - | | hbs(66:78): {{@message}} - | | ts(246:301): χ.emitContent(χ.resolveOrReturn(𝚪.args.message)()); + | | in: hbs(66:78): {{@message}} + | | out: ts(246:301): χ.emitContent(χ.resolveOrReturn(𝚪.args.message)()); | | | | | Mapping: MustacheStatement - | | | hbs(66:78): {{@message}} - | | | ts(246:299): χ.emitContent(χ.resolveOrReturn(𝚪.args.message)()) + | | | in: hbs(66:78): {{@message}} + | | | out: ts(246:299): χ.emitContent(χ.resolveOrReturn(𝚪.args.message)()) | | | | | | | Mapping: PathExpression - | | | | hbs(68:76): @message - | | | | ts(280:295): 𝚪.args.message + | | | | in: hbs(68:76): @message + | | | | out: ts(280:295): 𝚪.args.message | | | | | | | | | Mapping: Identifier - | | | | | hbs(69:76): message - | | | | | ts(288:295): message + | | | | | in: hbs(69:76): message + | | | | | out: ts(288:295): message | | | | | | | | | | | | @@ -641,28 +641,28 @@ describe('Transform: rewriteModule', () => { | | Mapping: TemplateEmbedding - | hbs(139:174): - | ts(362:638): static { ({} as typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")) {\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.this.title)());\\\\n 𝚪; χ;\\\\n}) } + | in: hbs(139:174): + | out: ts(362:638): static { ({} as typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")).templateForBackingValue(this, function(𝚪, χ: typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")) {\\\\n χ.emitContent(χ.resolveOrReturn(𝚪.this.title)());\\\\n 𝚪; χ;\\\\n}) } | | | Mapping: Template - | | hbs(149:163): {{this.title}} - | | ts(572:625): χ.emitContent(χ.resolveOrReturn(𝚪.this.title)()); + | | in: hbs(149:163): {{this.title}} + | | out: ts(572:625): χ.emitContent(χ.resolveOrReturn(𝚪.this.title)()); | | | | | Mapping: MustacheStatement - | | | hbs(149:163): {{this.title}} - | | | ts(572:623): χ.emitContent(χ.resolveOrReturn(𝚪.this.title)()) + | | | in: hbs(149:163): {{this.title}} + | | | out: ts(572:623): χ.emitContent(χ.resolveOrReturn(𝚪.this.title)()) | | | | | | | Mapping: PathExpression - | | | | hbs(151:161): this.title - | | | | ts(606:619): 𝚪.this.title + | | | | in: hbs(151:161): this.title + | | | | out: ts(606:619): 𝚪.this.title | | | | | | | | | Mapping: Identifier - | | | | | hbs(151:155): this - | | | | | ts(609:613): this + | | | | | in: hbs(151:155): this + | | | | | out: ts(609:613): this | | | | | | | | | | Mapping: Identifier - | | | | | hbs(156:161): title - | | | | | ts(614:619): title + | | | | | in: hbs(156:161): title + | | | | | out: ts(614:619): title | | | | | | | | | | | | @@ -677,6 +677,7 @@ describe('Transform: rewriteModule', () => { filename: 'foo.gts', contents: stripIndent` import { array as arr, hash as h } from '@ember/helper'; + import AnotherComponent from './another.gts'; `, }; @@ -691,132 +693,154 @@ describe('Transform: rewriteModule', () => { expect(rewriteModule(ts, { script }, env)?.toDebugString()).toMatchInlineSnapshot(` "TransformedModule + | Mapping: GtsImport + | in: ts(57:102): import AnotherComponent from './another.gts'; + | out: ts(57:101): import AnotherComponent from \\"./another.ts\\"; + | + | Mapping: TemplateEmbedding - | hbs(58:210): - | ts(58:585): export default ({} as typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")).templateExpression(function(𝚪, χ: typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")) {\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"let\\"])((χ.noop(arr), [1, 2]), (χ.noop(h), ({\\\\n red: \\"blue\\",\\\\n }))));\\\\n {\\\\n const [arr, h] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolveOrReturn(arr)());\\\\n χ.emitContent(χ.resolveOrReturn(h)());\\\\n }\\\\n χ.Globals[\\"let\\"];\\\\n }\\\\n 𝚪; χ;\\\\n}) + | in: hbs(104:270): + | out: ts(103:700): export default ({} as typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")).templateExpression(function(𝚪, χ: typeof import(\\"@glint/environment-ember-template-imports/-private/dsl\\")) {\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"let\\"])((χ.noop(arr), [1, 2]), (χ.noop(h), ({\\\\n red: \\"blue\\",\\\\n }))));\\\\n {\\\\n const [arr, h] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolveOrReturn(arr)());\\\\n χ.emitContent(χ.resolveOrReturn(h)());\\\\n }\\\\n χ.Globals[\\"let\\"];\\\\n }\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(Another)());\\\\n 𝛄;\\\\n }\\\\n 𝚪; χ;\\\\n}) | | | Mapping: Template - | | hbs(68:199): {{! Intentionally shadowing }}\\\\n {{#let (arr 1 2) (h red=\\"blue\\") as |arr h|}}\\\\n Array is {{arr}}\\\\n Hash is {{h}}\\\\n {{/let}} - | | ts(263:574): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"let\\"])((χ.noop(arr), [1, 2]), (χ.noop(h), ({\\\\n red: \\"blue\\",\\\\n }))));\\\\n {\\\\n const [arr, h] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolveOrReturn(arr)());\\\\n χ.emitContent(χ.resolveOrReturn(h)());\\\\n }\\\\n χ.Globals[\\"let\\"];\\\\n } + | | in: hbs(114:259): {{! Intentionally shadowing }}\\\\n {{#let (arr 1 2) (h red=\\"blue\\") as |arr h|}}\\\\n Array is {{arr}}\\\\n Hash is {{h}}\\\\n {{/let}}\\\\n + | | out: ts(308:689): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"let\\"])((χ.noop(arr), [1, 2]), (χ.noop(h), ({\\\\n red: \\"blue\\",\\\\n }))));\\\\n {\\\\n const [arr, h] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolveOrReturn(arr)());\\\\n χ.emitContent(χ.resolveOrReturn(h)());\\\\n }\\\\n χ.Globals[\\"let\\"];\\\\n }\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(Another)());\\\\n 𝛄;\\\\n } | | | | | Mapping: TextContent - | | | hbs(68:69): - | | | ts(263:263): + | | | in: hbs(114:115): + | | | out: ts(308:308): | | | | | | Mapping: MustacheCommentStatement - | | | hbs(71:101): {{! Intentionally shadowing }} - | | | ts(263:263): + | | | in: hbs(117:147): {{! Intentionally shadowing }} + | | | out: ts(308:308): | | | | | | Mapping: BlockStatement - | | | hbs(104:198): {{#let (arr 1 2) (h red=\\"blue\\") as |arr h|}}\\\\n Array is {{arr}}\\\\n Hash is {{h}}\\\\n {{/let}} - | | | ts(263:573): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"let\\"])((χ.noop(arr), [1, 2]), (χ.noop(h), ({\\\\n red: \\"blue\\",\\\\n }))));\\\\n {\\\\n const [arr, h] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolveOrReturn(arr)());\\\\n χ.emitContent(χ.resolveOrReturn(h)());\\\\n }\\\\n χ.Globals[\\"let\\"];\\\\n } + | | | in: hbs(150:244): {{#let (arr 1 2) (h red=\\"blue\\") as |arr h|}}\\\\n Array is {{arr}}\\\\n Hash is {{h}}\\\\n {{/let}} + | | | out: ts(308:618): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"let\\"])((χ.noop(arr), [1, 2]), (χ.noop(h), ({\\\\n red: \\"blue\\",\\\\n }))));\\\\n {\\\\n const [arr, h] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitContent(χ.resolveOrReturn(arr)());\\\\n χ.emitContent(χ.resolveOrReturn(h)());\\\\n }\\\\n χ.Globals[\\"let\\"];\\\\n } | | | | | | | Mapping: PathExpression - | | | | hbs(107:110): let - | | | | ts(308:324): χ.Globals[\\"let\\"] + | | | | in: hbs(153:156): let + | | | | out: ts(353:369): χ.Globals[\\"let\\"] | | | | | | | | | Mapping: Identifier - | | | | | hbs(107:110): let - | | | | | ts(319:322): let + | | | | | in: hbs(153:156): let + | | | | | out: ts(364:367): let | | | | | | | | | | | | | Mapping: PathExpression - | | | | hbs(112:115): arr - | | | | ts(334:337): arr + | | | | in: hbs(158:161): arr + | | | | out: ts(379:382): arr | | | | | | | | | Mapping: Identifier - | | | | | hbs(112:115): arr - | | | | | ts(334:337): arr + | | | | | in: hbs(158:161): arr + | | | | | out: ts(379:382): arr | | | | | | | | | | | | | Mapping: SubExpression - | | | | hbs(111:120): (arr 1 2) - | | | | ts(340:346): [1, 2] + | | | | in: hbs(157:166): (arr 1 2) + | | | | out: ts(385:391): [1, 2] | | | | | | | | | Mapping: NumberLiteral - | | | | | hbs(116:117): 1 - | | | | | ts(341:342): 1 + | | | | | in: hbs(162:163): 1 + | | | | | out: ts(386:387): 1 | | | | | | | | | | Mapping: NumberLiteral - | | | | | hbs(118:119): 2 - | | | | | ts(344:345): 2 + | | | | | in: hbs(164:165): 2 + | | | | | out: ts(389:390): 2 | | | | | | | | | | | | | Mapping: PathExpression - | | | | hbs(122:123): h - | | | | ts(357:358): h + | | | | in: hbs(168:169): h + | | | | out: ts(402:403): h | | | | | | | | | Mapping: Identifier - | | | | | hbs(122:123): h - | | | | | ts(357:358): h + | | | | | in: hbs(168:169): h + | | | | | out: ts(402:403): h | | | | | | | | | | | | | Mapping: SubExpression - | | | | hbs(121:135): (h red=\\"blue\\") - | | | | ts(361:389): ({\\\\n red: \\"blue\\",\\\\n }) + | | | | in: hbs(167:181): (h red=\\"blue\\") + | | | | out: ts(406:434): ({\\\\n red: \\"blue\\",\\\\n }) | | | | | | | | | Mapping: Identifier - | | | | | hbs(124:127): red - | | | | | ts(370:373): red + | | | | | in: hbs(170:173): red + | | | | | out: ts(415:418): red | | | | | | | | | | Mapping: StringLiteral - | | | | | hbs(128:134): \\"blue\\" - | | | | | ts(375:381): \\"blue\\" + | | | | | in: hbs(174:180): \\"blue\\" + | | | | | out: ts(420:426): \\"blue\\" | | | | | | | | | | | | | Mapping: Identifier - | | | | hbs(140:143): arr - | | | | ts(413:416): arr + | | | | in: hbs(186:189): arr + | | | | out: ts(458:461): arr | | | | | | | | Mapping: Identifier - | | | | hbs(144:145): h - | | | | ts(418:419): h + | | | | in: hbs(190:191): h + | | | | out: ts(463:464): h | | | | | | | | Mapping: TextContent - | | | | hbs(153:161): Array is - | | | | ts(450:450): + | | | | in: hbs(199:207): Array is + | | | | out: ts(495:495): | | | | | | | | Mapping: MustacheStatement - | | | | hbs(162:169): {{arr}} - | | | | ts(450:495): χ.emitContent(χ.resolveOrReturn(arr)()) + | | | | in: hbs(208:215): {{arr}} + | | | | out: ts(495:540): χ.emitContent(χ.resolveOrReturn(arr)()) | | | | | | | | | Mapping: PathExpression - | | | | | hbs(164:167): arr - | | | | | ts(488:491): arr + | | | | | in: hbs(210:213): arr + | | | | | out: ts(533:536): arr | | | | | | | | | | | Mapping: Identifier - | | | | | | hbs(164:167): arr - | | | | | | ts(488:491): arr + | | | | | | in: hbs(210:213): arr + | | | | | | out: ts(533:536): arr | | | | | | | | | | | | | | | | | | | Mapping: TextContent - | | | | hbs(174:181): Hash is - | | | | ts(497:497): + | | | | in: hbs(220:227): Hash is + | | | | out: ts(542:542): | | | | | | | | Mapping: MustacheStatement - | | | | hbs(182:187): {{h}} - | | | | ts(497:540): χ.emitContent(χ.resolveOrReturn(h)()) + | | | | in: hbs(228:233): {{h}} + | | | | out: ts(542:585): χ.emitContent(χ.resolveOrReturn(h)()) | | | | | | | | | Mapping: PathExpression - | | | | | hbs(184:185): h - | | | | | ts(535:536): h + | | | | | in: hbs(230:231): h + | | | | | out: ts(580:581): h | | | | | | | | | | | Mapping: Identifier - | | | | | | hbs(184:185): h - | | | | | | ts(535:536): h + | | | | | | in: hbs(230:231): h + | | | | | | out: ts(580:581): h | | | | | | | | | | | | | | | | | | | Mapping: TextContent - | | | | hbs(187:188): - | | | | ts(542:542): + | | | | in: hbs(233:234): + | | | | out: ts(587:587): | | | | | | | | Mapping: Identifier - | | | | hbs(193:196): let - | | | | ts(563:566): let + | | | | in: hbs(239:242): let + | | | | out: ts(608:611): let + | | | | + | | | + | | | Mapping: TextContent + | | | in: hbs(245:247): + | | | out: ts(619:619): + | | | + | | | Mapping: ElementNode + | | | in: hbs(247:258): + | | | out: ts(619:689): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(Another)());\\\\n 𝛄;\\\\n } + | | | + | | | | Mapping: Identifier + | | | | in: hbs(248:255): Another + | | | | out: ts(664:671): Another | | | | | | | + | | | Mapping: TextContent + | | | in: hbs(258:259): + | | | out: ts(689:689): + | | | | | |" `); diff --git a/packages/core/src/common/document-cache.ts b/packages/core/src/common/document-cache.ts index 94ece4a18..7876329c9 100644 --- a/packages/core/src/common/document-cache.ts +++ b/packages/core/src/common/document-cache.ts @@ -58,8 +58,15 @@ export default class DocumentCache { ); } + private gtsAwareExtName(filename: string): string { + if (filename.endsWith('.gts.ts')) { + return '.gts.ts'; + } + return path.extname(filename); + } + public getCandidateDocumentPaths(filename: string): Array { - let extension = path.extname(filename); + let extension = this.gtsAwareExtName(filename); let filenameWithoutExtension = filename.slice(0, filename.lastIndexOf(extension)); return this.getCandidateExtensions(filename).map((ext) => `${filenameWithoutExtension}${ext}`); diff --git a/packages/core/src/config/types.cts b/packages/core/src/config/types.cts index a0beabe09..6c3bfef31 100644 --- a/packages/core/src/config/types.cts +++ b/packages/core/src/config/types.cts @@ -24,6 +24,7 @@ export type GlintExtensionPreprocess = ( export type GlintEmitMetadata = { prepend?: string; append?: string; + replaceExtension?: string; templateLocation?: { start: number; end: number; @@ -37,7 +38,10 @@ export type GlintExtensionTransform = ( state: { ts: TSLib; context: ts.TransformationContext; - setEmitMetadata: (node: ts.TaggedTemplateExpression, meta: GlintEmitMetadata) => void; + setEmitMetadata: ( + node: ts.TaggedTemplateExpression | ts.ImportDeclaration, + meta: GlintEmitMetadata + ) => void; } ) => ts.Transformer; diff --git a/packages/core/src/transform/template/import-declaration-span.ts b/packages/core/src/transform/template/import-declaration-span.ts new file mode 100644 index 000000000..5163602dc --- /dev/null +++ b/packages/core/src/transform/template/import-declaration-span.ts @@ -0,0 +1,53 @@ +import * as ts from 'typescript'; +import { TSLib } from '../util.js'; +import { CorrelatedSpansResult, PartialCorrelatedSpan } from './inlining/index.js'; +import { Directive, SourceFile, TransformError } from './transformed-module.js'; +import { GlintEmitMetadata } from '@glint/core/config-types'; +import MappingTree, { GtsImport } from './mapping-tree.js'; + +export function calculateImportSpan( + ts: TSLib, + node: ts.ImportDeclaration, + meta: GlintEmitMetadata | undefined, + script: SourceFile +): CorrelatedSpansResult { + let directives: Array = []; + let errors: Array = []; + let partialSpans: Array = []; + let moduleSpecifierText = (node.moduleSpecifier as ts.StringLiteral).text; + if (meta?.replaceExtension) { + let newModuleSpecifier = ts.factory.createStringLiteral( + moduleSpecifierText.replace(/\.gts$/, '.' + meta.replaceExtension) + ); + let updatedNode = ts.factory.updateImportDeclaration( + node, + node.modifiers, + node.importClause, + newModuleSpecifier, + node.assertClause + ); + let originalStart = node.getStart(); + let originalLength = node.getEnd() - originalStart; + const printer = ts.createPrinter(); + let transformedSource = printer.printNode( + ts.EmitHint.Unspecified, + updatedNode, + node.getSourceFile() + ); + partialSpans.push({ + originalFile: script, + originalStart, + originalLength, + insertionPoint: originalStart, + transformedSource, + mapping: new MappingTree( + { start: 0, end: transformedSource.length }, + { start: 0, end: originalLength }, + [], + new GtsImport() + ), + }); + } + + return { errors, directives, partialSpans }; +} diff --git a/packages/core/src/transform/template/mapping-tree.ts b/packages/core/src/transform/template/mapping-tree.ts index fe6abf674..6a5e8322d 100644 --- a/packages/core/src/transform/template/mapping-tree.ts +++ b/packages/core/src/transform/template/mapping-tree.ts @@ -2,7 +2,13 @@ import { AST } from '@glimmer/syntax'; import { Range } from './transformed-module.js'; import { Identifier } from './map-template-contents.js'; -export type MappingSource = AST.Node | TemplateEmbedding | TextContent | Identifier | ParseError; +export type MappingSource = + | AST.Node + | TemplateEmbedding + | TextContent + | Identifier + | GtsImport + | ParseError; /** * In cases where we're unable to parse a template, we still want to @@ -34,6 +40,13 @@ export class TemplateEmbedding { public readonly type = 'TemplateEmbedding'; } +/** + * This node represents an import declaration of a .gts file. + */ +export class GtsImport { + public readonly type = 'GtsImport'; +} + /** * A `MappingTree` maintains a hierarchy of mappings between ranges of * locations in original and transformed source strings. These mappings @@ -109,23 +122,23 @@ export default class MappingTree { }): string { let { originalSource, transformedSource, indent = '| ' } = options; let { sourceNode, originalRange, transformedRange, children } = this; - let hbsStart = options.originalStart + originalRange.start; - let hbsEnd = options.originalStart + originalRange.end; + let sourceStart = options.originalStart + originalRange.start; + let sourceEnd = options.originalStart + originalRange.end; let tsStart = options.transformedStart + transformedRange.start; let tsEnd = options.transformedStart + transformedRange.end; let lines = []; lines.push(`${indent}Mapping: ${sourceNode.type}`); + let sourceDesc = sourceNode.type === 'GtsImport' ? 'ts' : 'hbs'; lines.push( - `${indent}${` hbs(${hbsStart}:${hbsEnd}):`.padEnd(15)}${this.getSourceRange( - originalSource, - originalRange - )}` + `${indent}${` in: ${sourceDesc}(${sourceStart}:${sourceEnd}):`.padEnd( + 20 + )}${this.getSourceRange(originalSource, originalRange)}` ); lines.push( - `${indent}${` ts(${tsStart}:${tsEnd}):`.padEnd(15)}${this.getSourceRange( + `${indent}${` out: ts(${tsStart}:${tsEnd}):`.padEnd(20)}${this.getSourceRange( transformedSource, transformedRange )}` diff --git a/packages/core/src/transform/template/rewrite-module.ts b/packages/core/src/transform/template/rewrite-module.ts index 7ae8a9662..5e20947c4 100644 --- a/packages/core/src/transform/template/rewrite-module.ts +++ b/packages/core/src/transform/template/rewrite-module.ts @@ -12,6 +12,7 @@ import TransformedModule, { } from './transformed-module.js'; import { calculateTaggedTemplateSpans } from './inlining/tagged-strings.js'; import { calculateCompanionTemplateSpans } from './inlining/companion-file.js'; +import { calculateImportSpan } from './import-declaration-span.js'; /** * Input to the process of rewriting a template, containing one or both of: @@ -86,8 +87,13 @@ function calculateCorrelatedSpans( } else if (ts.isModuleDeclaration(node)) { // don't traverse into declare module return node; + } else if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) { + let meta = emitMetadata.get(node); + let result = calculateImportSpan(ts, node, meta, script); + directives.push(...result.directives); + errors.push(...result.errors); + partialSpans.push(...result.partialSpans); } - return ts.visitEachChild(node, visit, context); }, ]); diff --git a/packages/environment-ember-template-imports/-private/environment/transform.ts b/packages/environment-ember-template-imports/-private/environment/transform.ts index b4bc6ede2..0a503c078 100644 --- a/packages/environment-ember-template-imports/-private/environment/transform.ts +++ b/packages/environment-ember-template-imports/-private/environment/transform.ts @@ -22,6 +22,13 @@ export const transform: GlintExtensionTransform = ( if (ts.isSourceFile(node)) { // Add `import { hbs as __T } from 'ember-template-imports'` to the file return addTagImport(f, node); + } else if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) { + if (node.moduleSpecifier.text.endsWith('.gts')) { + setEmitMetadata(node, { + replaceExtension: 'ts', + }); + } + return node; } else if (isETIDefaultTemplate(ts, node)) { // Annotate that this template is a default export setEmitMetadata(node.expression, { prepend: 'export default ' }); diff --git a/test-packages/ts-template-imports-app/src/Greeting.gts b/test-packages/ts-template-imports-app/app/components/Greeting.gts similarity index 72% rename from test-packages/ts-template-imports-app/src/Greeting.gts rename to test-packages/ts-template-imports-app/app/components/Greeting.gts index 0fbbf1152..0732294ed 100644 --- a/test-packages/ts-template-imports-app/src/Greeting.gts +++ b/test-packages/ts-template-imports-app/app/components/Greeting.gts @@ -1,5 +1,6 @@ import Component from '@glimmer/component'; import { TOC } from '@ember/component/template-only'; +import repeat from '../helpers/repeat'; export interface GreetingSignature { Args: { target: string }; @@ -13,10 +14,12 @@ export default class Greeting extends Component { } -function repeat(value: string, times: number): string { - return Array(times).fill(value).join(''); -} - const Bang: TOC<{ Args: { times: number } }> = + +declare module '@glint/environment-ember-loose/registry' { + export default interface Registry { + Greeting: typeof Greeting; + } +} diff --git a/test-packages/ts-template-imports-app/src/Playground.gts b/test-packages/ts-template-imports-app/app/components/Playground.gts similarity index 100% rename from test-packages/ts-template-imports-app/src/Playground.gts rename to test-packages/ts-template-imports-app/app/components/Playground.gts diff --git a/test-packages/ts-template-imports-app/src/index.gts b/test-packages/ts-template-imports-app/app/components/WorldGreeting.gts similarity index 64% rename from test-packages/ts-template-imports-app/src/index.gts rename to test-packages/ts-template-imports-app/app/components/WorldGreeting.gts index f479dee5f..f35bc8209 100644 --- a/test-packages/ts-template-imports-app/src/index.gts +++ b/test-packages/ts-template-imports-app/app/components/WorldGreeting.gts @@ -1,4 +1,4 @@ -import Greeting from './Greeting'; +import Greeting from './Greeting.gts'; export default