babel-plugin-htmlbars-inline-precompile
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -51,2 +51,25 @@ 'use strict'; | ||
it('allows a template string literal when used as a call expression', function () { | ||
let source = 'hello'; | ||
transform(`import hbs from 'htmlbars-inline-precompile';\nvar compiled = hbs(\`${source}\`);`); | ||
expect(optionsReceived).toEqual({ | ||
contents: source, | ||
}); | ||
}); | ||
it('errors when the template string contains placeholders', function () { | ||
expect(() => | ||
transform( | ||
"import hbs from 'htmlbars-inline-precompile';\nvar compiled = hbs(`string ${value}`)" | ||
) | ||
).toThrow(/placeholders inside a template string are not supported/); | ||
}); | ||
it('errors when the template string is tagged', function () { | ||
expect(() => | ||
transform("import hbs from 'htmlbars-inline-precompile';\nvar compiled = hbs(hbs`string`)") | ||
).toThrow(/tagged template strings inside hbs are not supported/); | ||
}); | ||
it('allows static userland options when used as a call expression', function () { | ||
@@ -53,0 +76,0 @@ let source = 'hello'; |
@@ -0,1 +1,10 @@ | ||
## v4.0.1 (2020-05-06) | ||
#### :bug: Bug Fix | ||
* [#215](https://github.com/ember-cli/babel-plugin-htmlbars-inline-precompile/pull/215) Add support for hbs(`...`) ([@chancancode](https://github.com/chancancode)) | ||
#### Committers: 1 | ||
- Godfrey Chan ([@chancancode](https://github.com/chancancode)) | ||
## v4.0.0 (2020-05-06) | ||
@@ -2,0 +11,0 @@ |
39
index.js
@@ -207,21 +207,34 @@ 'use strict'; | ||
let options; | ||
let args = path.node.arguments; | ||
let template = path.node.arguments[0]; | ||
if (template === undefined || typeof template.value !== 'string') { | ||
throw path.buildCodeFrameError( | ||
'hbs should be invoked with at least a single argument: the template string' | ||
); | ||
} | ||
let template; | ||
switch (path.node.arguments.length) { | ||
case 0: | ||
switch (args[0] && args[0].type) { | ||
case 'StringLiteral': | ||
template = args[0].value; | ||
break; | ||
case 'TemplateLiteral': | ||
if (args[0].expressions.length) { | ||
throw path.buildCodeFrameError( | ||
'placeholders inside a template string are not supported' | ||
); | ||
} else { | ||
template = args[0].quasis.map((quasi) => quasi.value.cooked).join(''); | ||
} | ||
break; | ||
case 'TaggedTemplateExpression': | ||
throw path.buildCodeFrameError('tagged template strings inside hbs are not supported'); | ||
default: | ||
throw path.buildCodeFrameError( | ||
'hbs should be invoked with at least a single argument: the template string' | ||
); | ||
} | ||
let options; | ||
switch (args.length) { | ||
case 1: | ||
break; | ||
case 2: { | ||
let astOptions = path.node.arguments[1]; | ||
if (astOptions.type !== 'ObjectExpression') { | ||
if (args[1].type !== 'ObjectExpression') { | ||
throw path.buildCodeFrameError( | ||
@@ -232,3 +245,3 @@ 'hbs can only be invoked with 2 arguments: the template string, and any static options' | ||
options = parseObjectExpression(path.buildCodeFrameError.bind(path), astOptions); | ||
options = parseObjectExpression(path.buildCodeFrameError.bind(path), args[1]); | ||
@@ -245,3 +258,3 @@ break; | ||
path.replaceWith(compileTemplate(precompile, template.value, options)); | ||
path.replaceWith(compileTemplate(precompile, template, options)); | ||
}, | ||
@@ -248,0 +261,0 @@ }, |
{ | ||
"name": "babel-plugin-htmlbars-inline-precompile", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Babel plugin to replace tagged template strings with precompiled HTMLBars templates", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/ember-cli/babel-plugin-htmlbars-inline-precompile", |
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
40956
545