diff --git a/__tests__/tests.ts b/__tests__/tests.ts
index 86ed1fe..df4fa99 100644
--- a/__tests__/tests.ts
+++ b/__tests__/tests.ts
@@ -1468,7 +1468,7 @@ describe('htmlbars-inline-precompile', function () {
import { precompileTemplate } from "@ember/template-compilation";
import { setComponentTemplate } from "@ember/component";
import templateOnly from "@ember/component/template-only";
- export default setComponentTemplate(precompileTemplate('', { scope: () => ({ HelloWorld }), strictMode: true }), templateOnly());
+ export default setComponentTemplate(precompileTemplate('', { scope: () => ({ HelloWorld }), strictMode: true }), templateOnly(undefined, "foo-bar"));
`);
});
@@ -1599,7 +1599,7 @@ describe('htmlbars-inline-precompile', function () {
precompileTemplate("Icon", {
strictMode: true,
}),
- templateOnly()
+ templateOnly(undefined, "foo-bar:Icon")
);
`);
});
@@ -1626,7 +1626,7 @@ describe('htmlbars-inline-precompile', function () {
import { precompileTemplate } from "@ember/template-compilation";
import { setComponentTemplate } from "@ember/component";
import templateOnly from "@ember/component/template-only";
- export default setComponentTemplate(precompileTemplate('', { strictMode: false, scope: () => ({ HelloWorld }) }), templateOnly());
+ export default setComponentTemplate(precompileTemplate('', { strictMode: false, scope: () => ({ HelloWorld }) }), templateOnly(undefined, "foo-bar"));
`);
});
});
@@ -1698,7 +1698,7 @@ describe('htmlbars-inline-precompile', function () {
scope: () => [HelloWorld],
isStrictMode: true,
}
- ), templateOnly());
+ ), templateOnly(undefined, "foo-bar"));
`);
});
@@ -1897,7 +1897,7 @@ describe('htmlbars-inline-precompile', function () {
import { precompileTemplate } from "@ember/template-compilation";
import { setComponentTemplate } from "@ember/component";
import templateOnly from "@ember/component/template-only";
- export default setComponentTemplate(precompileTemplate('', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly());
+ export default setComponentTemplate(precompileTemplate('', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly(undefined, "foo-bar"));
`);
});
@@ -1928,7 +1928,7 @@ describe('htmlbars-inline-precompile', function () {
import { setComponentTemplate } from "@ember/component";
import templateOnly from "@ember/component/template-only";
let div = 1;
- export default setComponentTemplate(precompileTemplate('
', { strictMode: true, scope: () => ({ div })}), templateOnly());
+ export default setComponentTemplate(precompileTemplate('', { strictMode: true, scope: () => ({ div })}), templateOnly(undefined, "foo-bar"));
`);
});
@@ -1955,7 +1955,7 @@ describe('htmlbars-inline-precompile', function () {
import { setComponentTemplate } from "@ember/component";
import templateOnly from "@ember/component/template-only";
let hasBlock = 1;
- export default setComponentTemplate(precompileTemplate('{{hasBlock "thing"}}', { strictMode: true, scope: () => ({ hasBlock }) }), templateOnly());
+ export default setComponentTemplate(precompileTemplate('{{hasBlock "thing"}}', { strictMode: true, scope: () => ({ hasBlock }) }), templateOnly(undefined, "foo-bar"));
`);
});
@@ -1980,7 +1980,7 @@ describe('htmlbars-inline-precompile', function () {
import { precompileTemplate } from "@ember/template-compilation";
import { setComponentTemplate } from "@ember/component";
import templateOnly from "@ember/component/template-only";
- export default setComponentTemplate(precompileTemplate('{{hasBlock "thing"}}', { strictMode: true }), templateOnly());
+ export default setComponentTemplate(precompileTemplate('{{hasBlock "thing"}}', { strictMode: true }), templateOnly(undefined, "foo-bar"));
`);
});
@@ -2020,7 +2020,7 @@ describe('htmlbars-inline-precompile', function () {
isStrictMode: true,
}
),
- templateOnly()
+ templateOnly(undefined, "foo-bar")
);
`);
});
@@ -2049,7 +2049,7 @@ describe('htmlbars-inline-precompile', function () {
import { precompileTemplate } from "@ember/template-compilation";
import { setComponentTemplate } from "@ember/component";
import templateOnly from "@ember/component/template-only";
- export default setComponentTemplate(precompileTemplate('', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly());
+ export default setComponentTemplate(precompileTemplate('', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly(undefined, "foo-bar"));
`);
});
@@ -2081,7 +2081,7 @@ describe('htmlbars-inline-precompile', function () {
import templateOnly from "@ember/component/template-only";
export default function() {
let { HelloWorld } = globalThis;
- return setComponentTemplate(precompileTemplate('', { strictMode: true, scope: () => ({ HelloWorld })}), templateOnly());
+ return setComponentTemplate(precompileTemplate('', { strictMode: true, scope: () => ({ HelloWorld })}), templateOnly(undefined, undefined));
}
`);
});
@@ -2133,7 +2133,7 @@ describe('htmlbars-inline-precompile', function () {
isStrictMode: true,
}
),
- templateOnly()
+ templateOnly(undefined, "foo-bar")
);
`);
});
@@ -2166,7 +2166,7 @@ describe('htmlbars-inline-precompile', function () {
import { precompileTemplate } from "@ember/template-compilation";
import { setComponentTemplate } from "@ember/component";
import templateOnly from "@ember/component/template-only";
- const MyComponent = setComponentTemplate(precompileTemplate('', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly());
+ const MyComponent = setComponentTemplate(precompileTemplate('', { strictMode: true, scope: () => ({ HelloWorld }) }), templateOnly(undefined, "foo-bar:MyComponent"));
`);
});
diff --git a/src/plugin.ts b/src/plugin.ts
index 50bd5a8..fb341f8 100644
--- a/src/plugin.ts
+++ b/src/plugin.ts
@@ -8,6 +8,7 @@ import type { EmberTemplateCompiler, PreprocessOptions } from './ember-template-
import { LegacyModuleName } from './public-types';
import { ScopeLocals } from './scope-locals';
import { ASTPluginBuilder, preprocess, print } from '@glimmer/syntax';
+import { basename, extname } from 'path';
export * from './public-types';
@@ -496,13 +497,31 @@ function insertCompiledTemplate(
let expression = t.callExpression(templateFactoryIdentifier, [templateExpression]);
+ let params = [];
+ let assignment = target.parent;
+ let rootName = basename(state.filename).slice(0, -extname(state.filename).length);
+ let assignmentName: t.StringLiteral | t.Identifier = t.identifier('undefined');
+ if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') {
+ assignmentName = t.stringLiteral(rootName + ':' + assignment.left.name);
+ }
+ if (assignment.type === 'VariableDeclarator' && assignment.id.type === 'Identifier') {
+ assignmentName = t.stringLiteral(rootName + ':' + assignment.id.name);
+ }
+ if (assignment.type === 'ExportDefaultDeclaration') {
+ assignmentName = t.stringLiteral(rootName);
+ }
+
+ if (process.env.EMBER_ENV !== 'production') {
+ params.push(t.identifier('undefined'), assignmentName);
+ }
+
if (config.rfc931Support) {
expression = t.callExpression(i.import('@ember/component', 'setComponentTemplate'), [
expression,
backingClass?.node ??
t.callExpression(
i.import('@ember/component/template-only', 'default', 'templateOnly'),
- []
+ params
),
]);
}
@@ -606,6 +625,27 @@ function updateCallForm(
convertStrictMode(babel, target);
removeEvalAndScope(target);
target.node.arguments = target.node.arguments.slice(0, 2);
+
+ let params: (Babel.types.Identifier | Babel.types.StringLiteral)[] = [];
+ let assignment = target.parent;
+ let rootName = basename(state.filename).slice(0, -extname(state.filename).length);
+ let assignmentName: Babel.types.Identifier | Babel.types.StringLiteral =
+ babel.types.identifier('undefined');
+ if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') {
+ assignmentName = babel.types.stringLiteral(rootName + ':' + assignment.left.name);
+ }
+ if (assignment.type === 'VariableDeclarator' && assignment.id.type === 'Identifier') {
+ assignmentName = babel.types.stringLiteral(rootName + ':' + assignment.id.name);
+ }
+ if (assignment.type === 'ExportDefaultDeclaration') {
+ const name = basename(state.filename).slice(0, -extname(state.filename).length);
+ assignmentName = babel.types.stringLiteral(name);
+ }
+
+ if (process.env.EMBER_ENV !== 'production') {
+ params.push(babel.types.identifier('undefined'), assignmentName);
+ }
+
state.recursionGuard.add(target.node);
state.util.replaceWith(target, (i) =>
babel.types.callExpression(i.import('@ember/component', 'setComponentTemplate'), [
@@ -613,7 +653,7 @@ function updateCallForm(
backingClass?.node ??
babel.types.callExpression(
i.import('@ember/component/template-only', 'default', 'templateOnly'),
- []
+ params
),
])
);