Skip to content
This repository was archived by the owner on Dec 8, 2024. It is now read-only.
Merged
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
24 changes: 24 additions & 0 deletions __tests__/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,30 @@ describe('htmlbars-inline-precompile', function () {
`);
});

it('works properly when used along with modules transform multiple times', function () {
plugins.push([TransformModules]);
let transformed = transform(
"import hbs from 'htmlbars-inline-precompile';\nvar compiled = hbs`hello`;\nvar otherCompiled = hbs`hello`;"
);

expect(transformed).toMatchInlineSnapshot(`
"define([\\"@ember/template-factory\\"], function (_templateFactory) {
\\"use strict\\";

var compiled = (0, _templateFactory.createTemplateFactory)(
/*
hello
*/
\\"precompiled(hello)\\");
var otherCompiled = (0, _templateFactory.createTemplateFactory)(
/*
hello
*/
\\"precompiled(hello)\\");
});"
`);
});

it('works properly when used after modules transform', function () {
plugins.unshift([TransformModules]);
let transformed = transform(
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ module.exports = function (babel) {
let addedImports = (state.allAddedImports[moduleName] =
state.allAddedImports[moduleName] || {});

if (addedImports[exportName]) return addedImports[exportName].id;
if (addedImports[exportName]) return t.identifier(addedImports[exportName].id.name);

if (moduleOverrides) {
let glimmerModule = moduleOverrides[moduleName];
Expand All @@ -205,6 +205,7 @@ module.exports = function (babel) {

if (exportName === 'default' && moduleName === 'ember' && !useEmberModule) {
addedImports[exportName] = { id: t.identifier('Ember') };

return addedImports[exportName].id;
}

Expand All @@ -218,7 +219,7 @@ module.exports = function (babel) {
let importSpecifier = preexistingImportDeclaration.get('specifiers').find(({ node }) => {
return exportName === 'default'
? t.isImportDefaultSpecifier(node)
: node.imported.name === exportName;
: node.imported && node.imported.name === exportName;
});

if (importSpecifier) {
Expand Down Expand Up @@ -246,7 +247,7 @@ module.exports = function (babel) {
};
}

return addedImports[exportName].id;
return t.identifier(addedImports[exportName].id.name);
};

// Setup other module options and create cache for values
Expand Down