Skip to content
Closed
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
13 changes: 7 additions & 6 deletions __tests__/preprocess-embedded-templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('preprocessEmbeddedTemplates', function () {
});

const expected = {
output: '[__GLIMMER_TEMPLATE(`Hello!`, { strictMode: true })]',
output:
"[__GLIMMER_TEMPLATE(`Hello!`, { strictMode: true, moduleName: 'foo.gjs' })]",
replacements: [
{
type: 'start',
Expand All @@ -29,7 +30,7 @@ describe('preprocessEmbeddedTemplates', function () {
type: 'end',
index: 16,
oldLength: 11,
newLength: 25,
newLength: 48,
originalCol: 17,
originalLine: 1,
},
Expand All @@ -52,7 +53,7 @@ describe('preprocessEmbeddedTemplates', function () {

const expected = {
output:
'[__GLIMMER_TEMPLATE(`Hello \\`world\\`!`, { strictMode: true })]',
"[__GLIMMER_TEMPLATE(`Hello \\`world\\`!`, { strictMode: true, moduleName: 'foo.gjs' })]",
replacements: [
{
type: 'start',
Expand All @@ -66,7 +67,7 @@ describe('preprocessEmbeddedTemplates', function () {
type: 'end',
index: 24,
oldLength: 11,
newLength: 25,
newLength: 48,
originalCol: 25,
originalLine: 1,
},
Expand Down Expand Up @@ -135,7 +136,7 @@ describe('preprocessEmbeddedTemplates', function () {

const expected = {
output:
"import { hbs } from 'ember-template-imports'\nconst Greeting = hbs(`Hello!`, { strictMode: true })\n",
"import { hbs } from 'ember-template-imports'\nconst Greeting = hbs(`Hello!`, { strictMode: true, moduleName: 'foo.gjs' })\n",
replacements: [
{
type: 'start',
Expand All @@ -149,7 +150,7 @@ describe('preprocessEmbeddedTemplates', function () {
type: 'end',
index: 72,
oldLength: 1,
newLength: 24,
newLength: 47,
originalCol: 28,
originalLine: 2,
},
Expand Down
11 changes: 7 additions & 4 deletions src/preprocess-embedded-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ function replaceMatch(
endReplacement: string,
template: string,
getTemplateLocals: GetTemplateLocals,
includeTemplateTokens: boolean
includeTemplateTokens: boolean,
relativePath: string
): Replacement[] {
const { start: openStart, end: openEnd } = getMatchStartAndEnd(match.start);
const { start: closeStart, end: closeEnd } = getMatchStartAndEnd(match.end);
Expand All @@ -130,7 +131,7 @@ function replaceMatch(
}

const newStart = `${startReplacement}\``;
const newEnd = `\`, { strictMode: true${options} }${endReplacement}`;
const newEnd = `\`, { strictMode: true, moduleName: '${relativePath}'${options} }${endReplacement}`;

s.overwrite(openStart, openEnd, newStart);
s.overwrite(closeStart, closeEnd, newEnd);
Expand Down Expand Up @@ -234,7 +235,8 @@ export function preprocessEmbeddedTemplates(
')',
template,
getTemplateLocals,
includeTemplateTokens
includeTemplateTokens,
relativePath
)
);
} else if (match.type === 'template-tag') {
Expand All @@ -246,7 +248,8 @@ export function preprocessEmbeddedTemplates(
')]',
template,
getTemplateLocals,
includeTemplateTokens
includeTemplateTokens,
relativePath
)
);
}
Expand Down
1 change: 1 addition & 0 deletions tests/integration/gjs-test.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module('tests/integration/components/gjs', function (hooks) {
})
);

assert.equal(Foo.moduleName, 'gjs-test');
assert.equal(this.element.textContent.trim(), 'Hello, world!');
});

Expand Down