babel-plugin-htmlbars-inline-precompile
Advanced tools
Comparing version 0.2.1 to 0.2.2
19
index.js
@@ -8,13 +8,2 @@ 'use strict'; | ||
visitor: { | ||
Program: { | ||
enter: function(path, state) { | ||
state.hbsImports = []; | ||
}, | ||
exit: function(path, state) { | ||
state.hbsImports.forEach(function(path) { | ||
path.remove(); | ||
}); | ||
}, | ||
}, | ||
ImportDeclaration: function(path, state) { | ||
@@ -31,3 +20,5 @@ let node = path.node; | ||
state.hbsImports.push(path); | ||
state.importId = state.importId || path.scope.generateUidIdentifierBasedOnNode(path.node.id); | ||
path.scope.rename(first.local.name, state.importId.name); | ||
path.remove(); | ||
} | ||
@@ -38,3 +29,3 @@ }, | ||
let tagPath = path.get('tag'); | ||
if (!tagPath.referencesImport('htmlbars-inline-precompile', 'default')) { | ||
if (tagPath.node.name !== state.importId.name) { | ||
return; | ||
@@ -55,3 +46,3 @@ } | ||
let calleePath = path.get('callee'); | ||
if (!calleePath.referencesImport('htmlbars-inline-precompile', 'default')) { | ||
if (calleePath.node.name !== state.importId.name) { | ||
return; | ||
@@ -58,0 +49,0 @@ } |
{ | ||
"name": "babel-plugin-htmlbars-inline-precompile", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Babel plugin to replace tagged template strings with precompiled HTMLBars templates", | ||
@@ -16,2 +16,3 @@ "scripts": { | ||
"babel-core": "^6.7.4", | ||
"babel-plugin-transform-es2015-modules-amd": "^6.24.0", | ||
"babel-plugin-transform-es2015-template-literals": "^6.22.0", | ||
@@ -18,0 +19,0 @@ "mocha": "^3.0.2" |
@@ -9,2 +9,3 @@ 'use strict'; | ||
const TransformTemplateLiterals = require('babel-plugin-transform-es2015-template-literals'); | ||
const TransformModules = require('babel-plugin-transform-es2015-modules-amd'); | ||
@@ -57,2 +58,29 @@ describe("htmlbars-inline-precompile", function() { | ||
it("works with multiple imports", function() { | ||
let transformed = transform(` | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import otherHbs from 'htmlbars-inline-precompile'; | ||
let a = hbs\`hello\`; | ||
let b = otherHbs\`hello\`; | ||
`); | ||
let expected = `let a = Ember.HTMLBars.template(HELLO);\nlet b = Ember.HTMLBars.template(HELLO);`; | ||
assert.equal(transformed, expected, "tagged template is replaced"); | ||
}); | ||
it("works properly when used along with modules transform", function() { | ||
plugins.push([TransformModules]); | ||
let transformed = transform("import hbs from 'htmlbars-inline-precompile';\nvar compiled = hbs`hello`;"); | ||
assert.equal(transformed, `define([], function () {\n 'use strict';\n\n var compiled = Ember.HTMLBars.template(HELLO);\n});`, "tagged template is replaced"); | ||
}); | ||
it("works properly when used after modules transform", function() { | ||
plugins.unshift([TransformModules]); | ||
let transformed = transform("import hbs from 'htmlbars-inline-precompile';\nvar compiled = hbs`hello`;"); | ||
assert.equal(transformed, `define([], function () {\n 'use strict';\n\n var compiled = Ember.HTMLBars.template(HELLO);\n});`, "tagged template is replaced"); | ||
}); | ||
it("replaces tagged template expressions when before babel-plugin-transform-es2015-template-literals", function() { | ||
@@ -59,0 +87,0 @@ plugins.push([TransformTemplateLiterals]); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29095
157
4