Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

babel-plugin-htmlbars-inline-precompile

Package Overview
Dependencies
Maintainers
5
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-htmlbars-inline-precompile - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

28

__tests__/tests.js

@@ -114,2 +114,18 @@ 'use strict';

it('throws error when import statement is not using custom specifier', function() {
plugins[0][1].modules = {
'foo-bar': 'baz',
};
expect(() => transform("import hbs from 'foo-bar'")).toThrow(
/Only `import { baz } from 'foo-bar'` is supported/,
'needed import syntax is present'
);
expect(() => transform("import hbs from 'foo-bar'")).toThrow(
/You used: `import hbs from 'foo-bar'`/,
'used import syntax is present'
);
});
it('replaces tagged template expressions with precompiled version', function() {

@@ -126,2 +142,14 @@ let transformed = transform(

it('replaces tagged template expressions with precompiled version for custom import paths with named exports', function() {
plugins[0][1].modules = {
'foo-bar': 'baz',
};
let transformed = transform("import { baz } from 'foo-bar';\nvar compiled = baz`hello`;");
expect(transformed).toEqual(
'var compiled = Ember.HTMLBars.template(\n/*\n hello\n*/\n"precompiled(hello)");'
);
});
it('replaces tagged template expressions with precompiled version for custom import paths', function() {

@@ -128,0 +156,0 @@ plugins[0][1].modulePaths = ['ember-cli-htmlbars-inline-precompile'];

@@ -0,1 +1,10 @@

## v2.1.0 (2019-09-09)
#### :rocket: Enhancement
* [#92](https://github.com/ember-cli/babel-plugin-htmlbars-inline-precompile/pull/92) Allow named exports to be replaced. ([@rwjblue](https://github.com/rwjblue))
#### Committers: 2
- Robert Jackson ([@rwjblue](https://github.com/rwjblue))
- [@dependabot-preview[bot]](https://github.com/apps/dependabot-preview)
## v2.0.0 (2019-08-30)

@@ -2,0 +11,0 @@

39

index.js

@@ -109,12 +109,35 @@ 'use strict';

let modulePaths = state.opts.modulePaths || ['htmlbars-inline-precompile'];
let modules = state.opts.modules || {
'htmlbars-inline-precompile': 'default',
};
if (state.opts.modulePaths) {
let modulePaths = state.opts.modulePaths;
modulePaths.forEach(path => (modules[path] = 'default'));
}
let modulePaths = Object.keys(modules);
let matchingModulePath = modulePaths.find(value => t.isLiteral(node.source, { value }));
let modulePathExport = modules[matchingModulePath];
if (matchingModulePath) {
let first = node.specifiers && node.specifiers[0];
if (!t.isImportDefaultSpecifier(first)) {
let input = state.file.code;
let usedImportStatement = input.slice(node.start, node.end);
let msg = `Only \`import hbs from '${matchingModulePath}'\` is supported. You used: \`${usedImportStatement}\``;
throw path.buildCodeFrameError(msg);
let localName = first.local.name;
if (modulePathExport === 'default') {
if (!t.isImportDefaultSpecifier(first)) {
let input = state.file.code;
let usedImportStatement = input.slice(node.start, node.end);
let msg = `Only \`import hbs from '${matchingModulePath}'\` is supported. You used: \`${usedImportStatement}\``;
throw path.buildCodeFrameError(msg);
}
} else {
if (!t.isImportSpecifier(first) || modulePathExport !== first.imported.name) {
let input = state.file.code;
let usedImportStatement = input.slice(node.start, node.end);
let msg = `Only \`import { ${modulePathExport} } from '${matchingModulePath}'\` is supported. You used: \`${usedImportStatement}\``;
throw path.buildCodeFrameError(msg);
}
}

@@ -124,3 +147,5 @@

state.importId || path.scope.generateUidIdentifierBasedOnNode(path.node.id);
path.scope.rename(first.local.name, state.importId.name);
path.scope.rename(localName, state.importId.name);
path.remove();

@@ -127,0 +152,0 @@ }

6

package.json
{
"name": "babel-plugin-htmlbars-inline-precompile",
"version": "2.0.0",
"version": "2.1.0",
"description": "Babel plugin to replace tagged template strings with precompiled HTMLBars templates",

@@ -24,4 +24,4 @@ "repository": "https://github.com/ember-cli/babel-plugin-htmlbars-inline-precompile",

"eslint": "^6.3.0",
"eslint-config-prettier": "^6.1.0",
"eslint-plugin-node": "^9.2.0",
"eslint-config-prettier": "^6.2.0",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-prettier": "^3.1.0",

@@ -28,0 +28,0 @@ "jest": "^24.9.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc