Skip to content

Commit c99903e

Browse files
committed
fix tests
1 parent 1fade50 commit c99903e

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

__tests__/tests.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ describe('htmlbars-inline-precompile', function () {
14681468
import { precompileTemplate } from "@ember/template-compilation";
14691469
import { setComponentTemplate } from "@ember/component";
14701470
import templateOnly from "@ember/component/template-only";
1471-
export default setComponentTemplate(precompileTemplate('<HelloWorld @color={{"#ff0000"}} />', { scope: () => ({ HelloWorld }), strictMode: true }), templateOnly());
1471+
export default setComponentTemplate(precompileTemplate('<HelloWorld @color={{"#ff0000"}} />', { scope: () => ({ HelloWorld }), strictMode: true }), templateOnly(undefined, "foo-bar"));
14721472
`);
14731473
});
14741474

@@ -1599,7 +1599,7 @@ describe('htmlbars-inline-precompile', function () {
15991599
precompileTemplate("Icon", {
16001600
strictMode: true,
16011601
}),
1602-
templateOnly()
1602+
templateOnly(undefined, "Icon")
16031603
);
16041604
`);
16051605
});
@@ -1626,7 +1626,7 @@ describe('htmlbars-inline-precompile', function () {
16261626
import { precompileTemplate } from "@ember/template-compilation";
16271627
import { setComponentTemplate } from "@ember/component";
16281628
import templateOnly from "@ember/component/template-only";
1629-
export default setComponentTemplate(precompileTemplate('<HelloWorld />', { strictMode: false, scope: () => ({ HelloWorld }) }), templateOnly());
1629+
export default setComponentTemplate(precompileTemplate('<HelloWorld />', { strictMode: false, scope: () => ({ HelloWorld }) }), templateOnly(undefined, "foo-bar"));
16301630
`);
16311631
});
16321632
});
@@ -1698,7 +1698,7 @@ describe('htmlbars-inline-precompile', function () {
16981698
scope: () => [HelloWorld],
16991699
isStrictMode: true,
17001700
}
1701-
), templateOnly());
1701+
), templateOnly(undefined, "foo-bar"));
17021702
`);
17031703
});
17041704

@@ -1897,7 +1897,7 @@ describe('htmlbars-inline-precompile', function () {
18971897
import { precompileTemplate } from "@ember/template-compilation";
18981898
import { setComponentTemplate } from "@ember/component";
18991899
import templateOnly from "@ember/component/template-only";
1900-
export default setComponentTemplate(precompileTemplate('<HelloWorld />', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly());
1900+
export default setComponentTemplate(precompileTemplate('<HelloWorld />', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly(undefined, "foo-bar"));
19011901
`);
19021902
});
19031903

@@ -1928,7 +1928,7 @@ describe('htmlbars-inline-precompile', function () {
19281928
import { setComponentTemplate } from "@ember/component";
19291929
import templateOnly from "@ember/component/template-only";
19301930
let div = 1;
1931-
export default setComponentTemplate(precompileTemplate('<div></div>', { strictMode: true, scope: () => ({ div })}), templateOnly());
1931+
export default setComponentTemplate(precompileTemplate('<div></div>', { strictMode: true, scope: () => ({ div })}), templateOnly(undefined, "foo-bar"));
19321932
`);
19331933
});
19341934

@@ -1955,7 +1955,7 @@ describe('htmlbars-inline-precompile', function () {
19551955
import { setComponentTemplate } from "@ember/component";
19561956
import templateOnly from "@ember/component/template-only";
19571957
let hasBlock = 1;
1958-
export default setComponentTemplate(precompileTemplate('{{hasBlock "thing"}}', { strictMode: true, scope: () => ({ hasBlock }) }), templateOnly());
1958+
export default setComponentTemplate(precompileTemplate('{{hasBlock "thing"}}', { strictMode: true, scope: () => ({ hasBlock }) }), templateOnly(undefined, "foo-bar"));
19591959
`);
19601960
});
19611961

@@ -1980,7 +1980,7 @@ describe('htmlbars-inline-precompile', function () {
19801980
import { precompileTemplate } from "@ember/template-compilation";
19811981
import { setComponentTemplate } from "@ember/component";
19821982
import templateOnly from "@ember/component/template-only";
1983-
export default setComponentTemplate(precompileTemplate('{{hasBlock "thing"}}', { strictMode: true }), templateOnly());
1983+
export default setComponentTemplate(precompileTemplate('{{hasBlock "thing"}}', { strictMode: true }), templateOnly(undefined, "foo-bar"));
19841984
`);
19851985
});
19861986

@@ -2020,7 +2020,7 @@ describe('htmlbars-inline-precompile', function () {
20202020
isStrictMode: true,
20212021
}
20222022
),
2023-
templateOnly()
2023+
templateOnly(undefined, "foo-bar")
20242024
);
20252025
`);
20262026
});
@@ -2049,7 +2049,7 @@ describe('htmlbars-inline-precompile', function () {
20492049
import { precompileTemplate } from "@ember/template-compilation";
20502050
import { setComponentTemplate } from "@ember/component";
20512051
import templateOnly from "@ember/component/template-only";
2052-
export default setComponentTemplate(precompileTemplate('<HelloWorld />', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly());
2052+
export default setComponentTemplate(precompileTemplate('<HelloWorld />', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly(undefined, "foo-bar"));
20532053
`);
20542054
});
20552055

@@ -2081,7 +2081,7 @@ describe('htmlbars-inline-precompile', function () {
20812081
import templateOnly from "@ember/component/template-only";
20822082
export default function() {
20832083
let { HelloWorld } = globalThis;
2084-
return setComponentTemplate(precompileTemplate('<HelloWorld />', { strictMode: true, scope: () => ({ HelloWorld })}), templateOnly());
2084+
return setComponentTemplate(precompileTemplate('<HelloWorld />', { strictMode: true, scope: () => ({ HelloWorld })}), templateOnly(undefined, undefined));
20852085
}
20862086
`);
20872087
});
@@ -2133,7 +2133,7 @@ describe('htmlbars-inline-precompile', function () {
21332133
isStrictMode: true,
21342134
}
21352135
),
2136-
templateOnly()
2136+
templateOnly(undefined, "foo-bar")
21372137
);
21382138
`);
21392139
});
@@ -2166,7 +2166,7 @@ describe('htmlbars-inline-precompile', function () {
21662166
import { precompileTemplate } from "@ember/template-compilation";
21672167
import { setComponentTemplate } from "@ember/component";
21682168
import templateOnly from "@ember/component/template-only";
2169-
const MyComponent = setComponentTemplate(precompileTemplate('<HelloWorld />', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly());
2169+
const MyComponent = setComponentTemplate(precompileTemplate('<HelloWorld />', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly(undefined, "MyComponent"));
21702170
`);
21712171
});
21722172

src/plugin.ts

+22-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { EmberTemplateCompiler, PreprocessOptions } from './ember-template-
88
import { LegacyModuleName } from './public-types';
99
import { ScopeLocals } from './scope-locals';
1010
import { ASTPluginBuilder, preprocess, print } from '@glimmer/syntax';
11+
import { basename, extname } from 'path';
1112

1213
export * from './public-types';
1314

@@ -497,23 +498,26 @@ function insertCompiledTemplate<EnvSpecificOptions>(
497498
let expression = t.callExpression(templateFactoryIdentifier, [templateExpression]);
498499

499500
let assignment = target.parent;
500-
let assignmentName: string | null = null;
501+
let assignmentName: t.StringLiteral = t.stringLiteral(state.filename);
501502
if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') {
502-
assignmentName = assignment.left.name;
503+
assignmentName = t.stringLiteral(assignment.left.name);
503504
}
504-
505505
if (assignment.type === 'VariableDeclarator' && assignment.id.type === 'Identifier') {
506-
assignmentName = assignment.id.name;
506+
assignmentName = t.stringLiteral(assignment.id.name);
507+
}
508+
if (assignment.type === 'ExportDefaultDeclaration') {
509+
const name = basename(state.filename).slice(0, -extname(state.filename).length);
510+
assignmentName = t.stringLiteral(name);
507511
}
508512

509513
if (config.rfc931Support) {
510514
expression = t.callExpression(i.import('@ember/component', 'setComponentTemplate'), [
511515
expression,
512516
backingClass?.node ??
513-
t.callExpression(
514-
i.import('@ember/component/template-only', 'default', 'templateOnly'),
515-
['@ember/component/template-only', assignmentName]
516-
),
517+
t.callExpression(i.import('@ember/component/template-only', 'default', 'templateOnly'), [
518+
t.identifier('undefined'),
519+
assignmentName,
520+
]),
517521
]);
518522
}
519523
return expression;
@@ -616,14 +620,19 @@ function updateCallForm<EnvSpecificOptions>(
616620
convertStrictMode(babel, target);
617621
removeEvalAndScope(target);
618622
target.node.arguments = target.node.arguments.slice(0, 2);
623+
619624
let assignment = target.parent;
620-
let assignmentName: string | null = null;
625+
let assignmentName: Babel.types.Identifier | Babel.types.StringLiteral =
626+
babel.types.identifier('undefined');
621627
if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') {
622-
assignmentName = assignment.left.name;
628+
assignmentName = babel.types.stringLiteral(assignment.left.name);
623629
}
624-
625630
if (assignment.type === 'VariableDeclarator' && assignment.id.type === 'Identifier') {
626-
assignmentName = assignment.id.name;
631+
assignmentName = babel.types.stringLiteral(assignment.id.name);
632+
}
633+
if (assignment.type === 'ExportDefaultDeclaration') {
634+
const name = basename(state.filename).slice(0, -extname(state.filename).length);
635+
assignmentName = babel.types.stringLiteral(name);
627636
}
628637

629638
state.recursionGuard.add(target.node);
@@ -633,7 +642,7 @@ function updateCallForm<EnvSpecificOptions>(
633642
backingClass?.node ??
634643
babel.types.callExpression(
635644
i.import('@ember/component/template-only', 'default', 'templateOnly'),
636-
['@ember/component/template-only', assignmentName]
645+
[babel.types.identifier('undefined'), assignmentName]
637646
),
638647
])
639648
);

0 commit comments

Comments
 (0)