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
4
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 4.4.0 to 4.4.1

37

__tests__/template-literal-tests.js

@@ -5,2 +5,3 @@ 'use strict';

const HTMLBarsInlinePrecompile = require('../index');
const TransformModules = require('@babel/plugin-transform-modules-amd');

@@ -412,3 +413,39 @@ describe('htmlbars-inline-precompile: useTemplateLiteralProposalSemantics', function () {

});
it('works when used alongside modules transform', function () {
plugins[0][1].ensureModuleApiPolyfill = true;
plugins.push([TransformModules]);
let transpiled = transform(
`
import { hbs } from 'ember-template-imports';
const Foo = hbs\`hello\`;
const Bar = hbs\`hello\`;
`
);
expect(transpiled).toMatchInlineSnapshot(`
"define([], function () {
\\"use strict\\";
const Foo = Ember._templateOnlyComponent(\\"foo-bar\\", \\"Foo\\");
Ember._setComponentTemplate(Ember.HTMLBars.template(
/*
hello
*/
\\"precompiled(hello)\\"), Foo);
const Bar = Ember._templateOnlyComponent(\\"foo-bar\\", \\"Bar\\");
Ember._setComponentTemplate(Ember.HTMLBars.template(
/*
hello
*/
\\"precompiled(hello)\\"), Bar);
});"
`);
});
});
});

@@ -5,2 +5,3 @@ 'use strict';

const HTMLBarsInlinePrecompile = require('../index');
const TransformModules = require('@babel/plugin-transform-modules-amd');

@@ -507,3 +508,37 @@ describe('htmlbars-inline-precompile: useTemplateTagProposalSemantics', function () {

});
it('works when used alongside modules transform', function () {
plugins[0][1].ensureModuleApiPolyfill = true;
plugins.push([TransformModules]);
let transpiled = transform(
`
const Foo = [GLIMMER_TEMPLATE(\`hello\`)];
const Bar = [GLIMMER_TEMPLATE(\`hello\`)];
`
);
expect(transpiled).toMatchInlineSnapshot(`
"define([], function () {
\\"use strict\\";
const Foo = Ember._templateOnlyComponent(\\"foo-bar\\", \\"Foo\\");
Ember._setComponentTemplate(Ember.HTMLBars.template(
/*
hello
*/
\\"precompiled(hello)\\"), Foo);
const Bar = Ember._templateOnlyComponent(\\"foo-bar\\", \\"Bar\\");
Ember._setComponentTemplate(Ember.HTMLBars.template(
/*
hello
*/
\\"precompiled(hello)\\"), Bar);
});"
`);
});
});
});

@@ -686,2 +686,24 @@ 'use strict';

});
it('works with ensureModuleApiPolyfill', function () {
plugins[0][1].ensureModuleApiPolyfill = true;
precompile = (template) => {
return `function() { return "${template}"; }`;
};
let transpiled = transform(
"import hbs from 'htmlbars-inline-precompile';\nvar compiled = hbs`hello`;"
);
expect(transpiled).toMatchInlineSnapshot(`
"var compiled = Ember.HTMLBars.template(
/*
hello
*/
function () {
return \\"hello\\";
});"
`);
});
});

@@ -688,0 +710,0 @@

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

## v4.4.1 (2021-02-24)
#### :bug: Bug Fix
* [#346](https://github.com/ember-cli/babel-plugin-htmlbars-inline-precompile/pull/346) Ensure proposal syntaxes work with Ember module API polyfill ([@pzuraq](https://github.com/pzuraq))
#### Committers: 1
- Chris Garrett ([@pzuraq](https://github.com/pzuraq))
## v4.4.0 (2021-02-23)

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

48

index.js

@@ -5,2 +5,3 @@ 'use strict';

const { registerRefs } = require('./src/util');
const { setupState, processImportDeclaration } = require('babel-plugin-ember-modules-api-polyfill');

@@ -148,6 +149,35 @@ module.exports = function (babel) {

}
if (state.opts.ensureModuleApiPolyfill) {
processModuleApiPolyfill(state);
}
}
let allAddedImports = Object.create(null);
function processModuleApiPolyfill(state) {
for (let module in allAddedImports) {
let addedImports = allAddedImports[module];
for (let addedImport in addedImports) {
let { path } = addedImports[addedImport];
if (path && path.node) {
processImportDeclaration(t, path, state);
if (path.removed) {
delete addedImports[addedImport];
}
}
}
}
}
let visitor = {
Program(path, state) {
if (state.opts.ensureModuleApiPolyfill) {
// Setup state for the module API polyfill
setupState(t, path, state);
}
let options = state.opts || {};

@@ -159,8 +189,6 @@

let allAddedImports = {};
state.ensureImport = (exportName, moduleName) => {
let addedImports = (allAddedImports[moduleName] = allAddedImports[moduleName] || {});
if (addedImports[exportName]) return addedImports[exportName];
if (addedImports[exportName]) return addedImports[exportName].id;

@@ -178,4 +206,4 @@ if (moduleOverrides) {

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

@@ -197,3 +225,3 @@

if (importSpecifier) {
addedImports[exportName] = importSpecifier.node.local;
addedImports[exportName] = [importSpecifier.node.local];
}

@@ -206,3 +234,2 @@ }

);
addedImports[exportName] = uid;

@@ -217,5 +244,10 @@ let newImportSpecifier =

path.scope.registerBinding('module', path.get('body.0.specifiers.0'));
addedImports[exportName] = {
id: uid,
path: path.get('body.0'),
};
}
return addedImports[exportName];
return addedImports[exportName].id;
};

@@ -222,0 +254,0 @@

16

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

@@ -12,9 +12,11 @@ "repository": "https://github.com/ember-cli/babel-plugin-htmlbars-inline-precompile",

},
"dependencies": {
"babel-plugin-ember-modules-api-polyfill": "^3.4.0"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/plugin-proposal-class-properties": "^7.12.13",
"@babel/plugin-transform-modules-amd": "^7.12.13",
"@babel/plugin-transform-template-literals": "^7.12.13",
"@babel/core": "^7.13.1",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-transform-modules-amd": "^7.13.0",
"@babel/plugin-transform-template-literals": "^7.13.0",
"@babel/plugin-transform-unicode-escapes": "^7.12.13",
"babel-plugin-ember-modules-api-polyfill": "^3.3.0",
"common-tags": "^1.8.0",

@@ -28,3 +30,3 @@ "ember-source": "^3.25.1",

"prettier": "^2.2.1",
"release-it": "^14.4.0",
"release-it": "^14.4.1",
"release-it-lerna-changelog": "^3.1.0"

@@ -31,0 +33,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