ember-cli-htmlbars
Advanced tools
Comparing version 5.6.5 to 5.7.0
# Changelog | ||
## v5.7.0 (2021-03-18) | ||
#### :rocket: Enhancement | ||
* [#683](https://github.com/ember-cli/ember-cli-htmlbars/pull/683) Disable the modules API polyfill on Ember 3.27+ ([@pzuraq](https://github.com/pzuraq)) | ||
#### :house: Internal | ||
* [#684](https://github.com/ember-cli/ember-cli-htmlbars/pull/684) Update babel-plugin-htmlbars-inline-precompile to 4.4.6. ([@rwjblue](https://github.com/rwjblue)) | ||
#### Committers: 2 | ||
- Chris Garrett ([@pzuraq](https://github.com/pzuraq)) | ||
- Robert Jackson ([@rwjblue](https://github.com/rwjblue)) | ||
## v5.6.5 (2021-03-12) | ||
@@ -4,0 +17,0 @@ |
@@ -6,3 +6,7 @@ // For ease of debuggin / tweaking: | ||
function makeSetComponentTemplateMemberExpression() { | ||
function makeSetComponentTemplateExpression(state) { | ||
if (!state.opts.requiresModuleApiPolyfill) { | ||
return state._colocationEnsureImport('setComponentTemplate', '@ember/component'); | ||
} | ||
return t.memberExpression(t.identifier('Ember'), t.identifier('_setComponentTemplate')); | ||
@@ -19,2 +23,49 @@ } | ||
visitor: { | ||
Program(path, state) { | ||
let allAddedImports = {}; | ||
state._colocationEnsureImport = (exportName, moduleName) => { | ||
let addedImports = (allAddedImports[moduleName] = allAddedImports[moduleName] || {}); | ||
if (addedImports[exportName]) return t.identifier(addedImports[exportName].name); | ||
let importDeclarations = path.get('body').filter((n) => n.type === 'ImportDeclaration'); | ||
let preexistingImportDeclaration = importDeclarations.find( | ||
(n) => n.get('source').get('value').node === moduleName | ||
); | ||
if (preexistingImportDeclaration) { | ||
let importSpecifier = preexistingImportDeclaration | ||
.get('specifiers') | ||
.find(({ node }) => { | ||
return exportName === 'default' | ||
? t.isImportDefaultSpecifier(node) | ||
: node.imported && node.imported.name === exportName; | ||
}); | ||
if (importSpecifier) { | ||
addedImports[exportName] = importSpecifier.node.local; | ||
} | ||
} | ||
if (!addedImports[exportName]) { | ||
let uid = path.scope.generateUidIdentifier( | ||
exportName === 'default' ? moduleName : exportName | ||
); | ||
addedImports[exportName] = uid; | ||
let newImportSpecifier = | ||
exportName === 'default' | ||
? t.importDefaultSpecifier(uid) | ||
: t.importSpecifier(uid, t.identifier(exportName)); | ||
let newImport = t.importDeclaration([newImportSpecifier], t.stringLiteral(moduleName)); | ||
path.unshiftContainer('body', newImport); | ||
} | ||
return t.identifier(addedImports[exportName].name); | ||
}; | ||
}, | ||
VariableDeclarator(path, state) { | ||
@@ -43,3 +94,3 @@ if (path.node.id.name === '__COLOCATED_TEMPLATE__') { | ||
let defaultExportDeclaration = path.node.declaration; | ||
let setComponentTemplateMemberExpression = makeSetComponentTemplateMemberExpression(); | ||
let setComponentTemplateMemberExpression = makeSetComponentTemplateExpression(state); | ||
let colocatedTemplateIdentifier = makeColocatedTemplateIdentifier(); | ||
@@ -91,3 +142,3 @@ | ||
t.expressionStatement( | ||
t.callExpression(makeSetComponentTemplateMemberExpression(), [ | ||
t.callExpression(makeSetComponentTemplateExpression(state), [ | ||
makeColocatedTemplateIdentifier(), | ||
@@ -94,0 +145,0 @@ defaultSpecifier.local, |
@@ -6,2 +6,3 @@ 'use strict'; | ||
const utils = require('./utils'); | ||
const VersionChecker = require('ember-cli-version-checker'); | ||
@@ -66,3 +67,3 @@ let registryInvocationCounter = 0; | ||
return new TemplateCompiler(inputTree, htmlbarsOptions); | ||
return new TemplateCompiler(inputTree, htmlbarsOptions, this._requiresModuleApiPolyfill); | ||
}, | ||
@@ -174,2 +175,5 @@ | ||
let checker = new VersionChecker(this.parent).for('ember-source', 'npm'); | ||
this._requiresModuleApiPolyfill = checker.exists() && checker.lt('3.27.0-alpha.1'); | ||
// This is an option intended to be used only be `ember-template-imports`. | ||
@@ -196,3 +200,4 @@ // DO NOT USE THIS | ||
isProduction, | ||
customModules | ||
customModules, | ||
this._requiresModuleApiPolyfill | ||
); | ||
@@ -212,2 +217,3 @@ | ||
modules: customModules, | ||
requiresModuleApiPolyfill: this._requiresModuleApiPolyfill, | ||
}); | ||
@@ -220,3 +226,6 @@ | ||
if (this._shouldColocateTemplates() && !utils.isColocatedBabelPluginRegistered(babelPlugins)) { | ||
babelPlugins.push(require.resolve('./colocated-babel-plugin')); | ||
babelPlugins.push([ | ||
require.resolve('./colocated-babel-plugin'), | ||
{ requiresModuleApiPolyfill: this._requiresModuleApiPolyfill }, | ||
]); | ||
} | ||
@@ -223,0 +232,0 @@ }, |
@@ -27,3 +27,3 @@ 'use strict'; | ||
class TemplateCompiler extends Filter { | ||
constructor(inputTree, _options) { | ||
constructor(inputTree, _options, requiresModuleApiPolyfill = true) { | ||
let options = _options || {}; | ||
@@ -39,2 +39,3 @@ | ||
this.inputTree = inputTree; | ||
this.requiresModuleApiPolyfill = requiresModuleApiPolyfill; | ||
@@ -56,2 +57,3 @@ // TODO: do we need this? | ||
let srcName = path.join(srcDir, relativePath); | ||
try { | ||
@@ -69,21 +71,19 @@ // we have to reverse these for reasons that are a bit bonkers. the initial | ||
let result = | ||
'export default ' + | ||
utils.template(this.options.templateCompiler, stripBom(string), { | ||
contents: string, | ||
isProduction: this.options.isProduction, | ||
moduleName: relativePath, | ||
parseOptions: { | ||
srcName: srcName, | ||
}, | ||
let precompiled = this.options.templateCompiler.precompile(stripBom(string), { | ||
contents: string, | ||
isProduction: this.options.isProduction, | ||
moduleName: relativePath, | ||
parseOptions: { | ||
srcName: srcName, | ||
}, | ||
// intentionally not using `plugins: this.options.plugins` here | ||
// because if we do, Ember will mutate the shared plugins object (adding | ||
// all of the built in AST transforms into plugins.ast, which breaks | ||
// persistent caching) | ||
plugins: { | ||
ast: astPlugins, | ||
}, | ||
}) + | ||
';'; | ||
// intentionally not using `plugins: this.options.plugins` here | ||
// because if we do, Ember will mutate the shared plugins object (adding | ||
// all of the built in AST transforms into plugins.ast, which breaks | ||
// persistent caching) | ||
plugins: { | ||
ast: astPlugins, | ||
}, | ||
}); | ||
if (this.options.dependencyInvalidation) { | ||
@@ -98,3 +98,8 @@ let plugins = pluginsWithDependencies(this.options.plugins.ast); | ||
} | ||
return result; | ||
if (this.requiresModuleApiPolyfill) { | ||
return `export default Ember.HTMLBars.template(${precompiled});`; | ||
} else { | ||
return `import { createTemplateFactory } from '@ember/template-factory';\n\nexport default createTemplateFactory(${precompiled});`; | ||
} | ||
} catch (error) { | ||
@@ -114,2 +119,4 @@ rethrowBuildError(error); | ||
strippedOptions._requiresModuleApiPolyfill = this.requiresModuleApiPolyfill; | ||
return strippedOptions; | ||
@@ -116,0 +123,0 @@ } |
@@ -53,5 +53,7 @@ 'use strict'; | ||
function isColocatedBabelPluginRegistered(plugins) { | ||
return plugins.some( | ||
(plugin) => typeof plugin === 'string' && plugin === require.resolve('./colocated-babel-plugin') | ||
); | ||
return plugins.some((plugin) => { | ||
let path = Array.isArray(plugin) ? plugin[0] : plugin; | ||
return typeof path === 'string' && path === require.resolve('./colocated-babel-plugin'); | ||
}); | ||
} | ||
@@ -64,3 +66,4 @@ | ||
isProduction, | ||
customModules | ||
customModules, | ||
requiresModuleApiPolyfill | ||
) { | ||
@@ -76,2 +79,3 @@ let parallelBabelInfo = { | ||
modules: Object.assign({}, customModules, INLINE_PRECOMPILE_MODULES), | ||
requiresModuleApiPolyfill, | ||
}, | ||
@@ -205,8 +209,2 @@ }; | ||
function template(templateCompiler, string, options) { | ||
let precompiled = templateCompiler.precompile(string, options); | ||
return 'Ember.HTMLBars.template(' + precompiled + ')'; | ||
} | ||
function setup(pluginInfo, options) { | ||
@@ -237,15 +235,6 @@ let projectConfig = options.projectConfig || {}; | ||
}, | ||
..._options, | ||
}; | ||
for (let option in _options) { | ||
if (option === 'scope') { | ||
// The template compiler expects this option to be named `locals`, but | ||
// we want users to pass it in as `scope`. In the future, we should update | ||
// the template compiler to accept scope as well and remove this. | ||
options.locals = _options.scope; | ||
} else { | ||
options[option] = _options[option]; | ||
} | ||
} | ||
return templatePrecompile(template, options); | ||
@@ -269,3 +258,3 @@ }; | ||
isProduction: options.isProduction, | ||
ensureModuleApiPolyfill: true, | ||
ensureModuleApiPolyfill: options.requiresModuleApiPolyfill, | ||
modules: Object.assign({}, options.modules, INLINE_PRECOMPILE_MODULES), | ||
@@ -364,3 +353,2 @@ }, | ||
initializeEmberENV, | ||
template, | ||
setup, | ||
@@ -367,0 +355,0 @@ makeCacheKey, |
{ | ||
"name": "ember-cli-htmlbars", | ||
"version": "5.6.5", | ||
"version": "5.7.0", | ||
"description": "A library for adding htmlbars to ember CLI", | ||
@@ -36,3 +36,3 @@ "keywords": [ | ||
"@ember/edition-utils": "^1.2.0", | ||
"babel-plugin-htmlbars-inline-precompile": "^4.4.5", | ||
"babel-plugin-htmlbars-inline-precompile": "^5.0.0", | ||
"broccoli-debug": "^0.6.5", | ||
@@ -43,2 +43,3 @@ "broccoli-persistent-filter": "^3.1.2", | ||
"ember-cli-babel-plugin-helpers": "^1.1.1", | ||
"ember-cli-version-checker": "^5.1.2", | ||
"fs-tree-diff": "^2.0.1", | ||
@@ -71,6 +72,5 @@ "hash-for-dep": "^1.5.1", | ||
"ember-cli-app-version": "^4.0.0", | ||
"ember-cli-babel": "^7.23.1", | ||
"ember-cli-babel": "^7.25.0", | ||
"ember-cli-dependency-checker": "^3.2.0", | ||
"ember-cli-inject-live-reload": "^2.0.2", | ||
"ember-cli-version-checker": "^5.1.1", | ||
"ember-compatibility-helpers": "^1.2.2", | ||
@@ -77,0 +77,0 @@ "ember-export-application-global": "^2.0.1", |
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
70136
44
1091
16
+ Addedarray-buffer-byte-length@1.0.1(transitive)
+ Addedarraybuffer.prototype.slice@1.0.3(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedbabel-plugin-htmlbars-inline-precompile@5.3.1(transitive)
+ Addeddata-view-buffer@1.0.1(transitive)
+ Addeddata-view-byte-length@1.0.1(transitive)
+ Addeddata-view-byte-offset@1.0.0(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedember-cli-version-checker@5.1.2(transitive)
+ Addedes-abstract@1.23.3(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedes-set-tostringtag@2.0.3(transitive)
+ Addedes-to-primitive@1.2.1(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction.prototype.name@1.1.6(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-symbol-description@1.0.2(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedhas-bigints@1.0.2(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedinternal-slot@1.0.7(transitive)
+ Addedis-array-buffer@3.0.4(transitive)
+ Addedis-bigint@1.0.4(transitive)
+ Addedis-boolean-object@1.1.2(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-data-view@1.0.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-negative-zero@2.0.3(transitive)
+ Addedis-number-object@1.0.7(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedis-shared-array-buffer@1.0.3(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedis-weakref@1.0.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.0(transitive)
+ Addedline-column@1.0.2(transitive)
+ Addedmagic-string@0.25.9(transitive)
+ Addedobject-inspect@1.13.2(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedparse-static-imports@1.1.0(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedregexp.prototype.flags@1.5.2(transitive)
+ Addedresolve-package-path@3.1.0(transitive)
+ Addedsafe-array-concat@1.1.2(transitive)
+ Addedsafe-regex-test@1.0.3(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedsourcemap-codec@1.4.8(transitive)
+ Addedstring.prototype.matchall@4.0.11(transitive)
+ Addedstring.prototype.trim@1.2.9(transitive)
+ Addedstring.prototype.trimend@1.0.8(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedtyped-array-buffer@1.0.2(transitive)
+ Addedtyped-array-byte-length@1.0.1(transitive)
+ Addedtyped-array-byte-offset@1.0.2(transitive)
+ Addedtyped-array-length@1.0.6(transitive)
+ Addedunbox-primitive@1.0.2(transitive)
+ Addedwhich-boxed-primitive@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)
- Removedbabel-plugin-htmlbars-inline-precompile@4.4.6(transitive)