Skip to content

Commit

Permalink
Use new inline babel plugin when we don't need modules api polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Jul 14, 2021
1 parent 6b69fef commit 33f0134
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 69 deletions.
17 changes: 0 additions & 17 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,6 @@ module.exports = function (defaults) {
],
],
},

'ember-cli-htmlbars': {
// This is an option intended to be used only be `ember-template-imports`.
// DO NOT USE THIS
_customInlineModules: {
'ember-template-imports': {
export: 'hbs',
useTemplateLiteralProposalSemantics: 1,
},

'TEMPLATE-TAG-MODULE': {
export: 'GLIMMER_TEMPLATE',
debugName: '<template>',
useTemplateTagProposalSemantics: 1,
},
},
},
});

/*
Expand Down
7 changes: 0 additions & 7 deletions lib/ember-addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ module.exports = {
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`.
// DO NOT USE THIS
let customModules =
addonOptions['ember-cli-htmlbars'] && addonOptions['ember-cli-htmlbars']._customInlineModules;

// add the babel-plugin-htmlbars-inline-precompile to the list of plugins
// used by `ember-cli-babel` addon
if (!utils.isInlinePrecompileBabelPluginRegistered(babelPlugins)) {
Expand All @@ -194,7 +189,6 @@ module.exports = {
this.projectConfig(),
templateCompilerPath,
isProduction,
customModules,
this._requiresModuleApiPolyfill
);

Expand All @@ -209,7 +203,6 @@ module.exports = {
isProduction,
projectConfig: this.projectConfig(),
templateCompilerPath,
modules: customModules,
requiresModuleApiPolyfill: this._requiresModuleApiPolyfill,
});

Expand Down
38 changes: 26 additions & 12 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function buildParalleizedBabelPlugin(
projectConfig,
templateCompilerPath,
isProduction,
customModules,
requiresModuleApiPolyfill
) {
let parallelBabelInfo = {
Expand All @@ -73,7 +72,6 @@ function buildParalleizedBabelPlugin(
isProduction,
projectConfig,
parallelConfigs: pluginInfo.parallelConfigs,
modules: Object.assign({}, customModules, INLINE_PRECOMPILE_MODULES),
requiresModuleApiPolyfill,
},
};
Expand Down Expand Up @@ -262,16 +260,32 @@ function setup(pluginInfo, options) {
cacheKey;
};

let plugin = [
require.resolve('babel-plugin-htmlbars-inline-precompile'),
{
precompile,
isProduction: options.isProduction,
ensureModuleApiPolyfill: options.requiresModuleApiPolyfill,
modules: Object.assign({}, options.modules, INLINE_PRECOMPILE_MODULES),
},
'ember-cli-htmlbars:inline-precompile',
];
let plugin;
if (options.requiresModuleApiPolyfill) {
plugin = [
require.resolve('babel-plugin-htmlbars-inline-precompile'),
{
precompile,
isProduction: options.isProduction,
ensureModuleApiPolyfill: options.requiresModuleApiPolyfill,
modules: INLINE_PRECOMPILE_MODULES,
},
'ember-cli-htmlbars:inline-precompile',
];
} else {
plugin = [
require.resolve('@ef4/babel-plugin-htmlbars-inline-precompile'),
{
precompile,
enableLegacyModules: [
'ember-cli-htmlbars',
'ember-cli-htmlbars-inline-precompile',
'htmlbars-inline-precompile',
],
},
'ember-cli-htmlbars:inline-precompile',
];
}

return plugin;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"test:node:debug": "mocha debug node-tests/*.js"
},
"dependencies": {
"@ef4/babel-plugin-htmlbars-inline-precompile": "^6.0.0-alpha.3",
"@ember/edition-utils": "^1.2.0",
"babel-plugin-htmlbars-inline-precompile": "^5.3.0",
"broccoli-debug": "^0.6.5",
Expand Down Expand Up @@ -70,7 +71,6 @@
"ember-cli-babel": "^7.25.0",
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-inject-live-reload": "^2.1.0",
"ember-compatibility-helpers": "^1.2.2",
"ember-export-application-global": "^2.0.1",
"ember-load-initializers": "^2.1.1",
"ember-maybe-import-regenerator": "^0.1.6",
Expand Down
20 changes: 0 additions & 20 deletions tests/integration/components/test-inline-precompile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import hbsOne from 'htmlbars-inline-precompile';
import hbsTwo from 'ember-cli-htmlbars-inline-precompile';
import { hbs as hbsThree } from 'ember-cli-htmlbars';
import { precompileTemplate } from '@ember/template-compilation';
import { hbs } from 'ember-template-imports';
import { gte } from 'ember-compatibility-helpers';

module('tests/integration/components/test-inline-precompile', function (hooks) {
setupRenderingTest(hooks);
Expand Down Expand Up @@ -35,24 +33,6 @@ module('tests/integration/components/test-inline-precompile', function (hooks) {
assert.equal(this.element.textContent.trim(), 'Wheeeee');
});

if (gte('3.25.0')) {
test('template literal proposal works', async function (assert) {
// eslint-disable-next-line no-undef
const Bar = [GLIMMER_TEMPLATE('world')];

const Foo = hbs`Hello`;

await render(
precompileTemplate(`<Foo/>, <Bar/>!`, {
strictMode: true,
scope: { Foo, Bar },
})
);

assert.equal(this.element.textContent.trim(), 'Hello, world!');
});
}

test('inline templates have "legacy" AST plugins ran', async function (assert) {
await render(hbsThree('{{module-name-reverser}}', { moduleName: 'hello-template.hbs' }));

Expand Down
85 changes: 73 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,16 @@
exec-sh "^0.3.2"
minimist "^1.2.0"

"@ef4/babel-plugin-htmlbars-inline-precompile@^6.0.0-alpha.3":
version "6.0.0-alpha.3"
resolved "https://registry.yarnpkg.com/@ef4/babel-plugin-htmlbars-inline-precompile/-/babel-plugin-htmlbars-inline-precompile-6.0.0-alpha.3.tgz#9a1301f16bd0c4943ec36812b88434b86d188d74"
integrity sha512-PosYrbpYyEszLXKOAKbMbPOL7K/F9weut/VDAPWxjWJV/3i7wNx3E1bNVCAa24hb3IUKvj8dR8K0o+fJwJxaUA==
dependencies:
babel-import-util "^0.2.0"
line-column "^1.0.2"
magic-string "^0.25.7"
string.prototype.matchall "^4.0.5"

"@ember-data/rfc395-data@^0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@ember-data/rfc395-data/-/rfc395-data-0.0.4.tgz#ecb86efdf5d7733a76ff14ea651a1b0ed1f8a843"
Expand Down Expand Up @@ -2001,6 +2011,11 @@ babel-helpers@^6.24.1:
babel-runtime "^6.22.0"
babel-template "^6.24.1"

babel-import-util@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/babel-import-util/-/babel-import-util-0.2.0.tgz#b468bb679919601a3570f9e317536c54f2862e23"
integrity sha512-CtWYYHU/MgK88rxMrLfkD356dApswtR/kWZ/c6JifG1m10e7tBBrs/366dFzWMAoqYmG5/JSh+94tUSpIwh+ag==

babel-messages@^6.23.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e"
Expand All @@ -2015,7 +2030,7 @@ babel-plugin-check-es2015-constants@^6.22.0:
dependencies:
babel-runtime "^6.22.0"

babel-plugin-debug-macros@^0.2.0, babel-plugin-debug-macros@^0.2.0-beta.6:
babel-plugin-debug-macros@^0.2.0-beta.6:
version "0.2.0"
resolved "https://registry.yarnpkg.com/babel-plugin-debug-macros/-/babel-plugin-debug-macros-0.2.0.tgz#0120ac20ce06ccc57bf493b667cf24b85c28da7a"
integrity sha512-Wpmw4TbhR3Eq2t3W51eBAQSdKlr+uAyF0GI4GtPfMCD12Y4cIdpKC9l0RjNTH/P9isFypSqqewMPm7//fnZlNA==
Expand Down Expand Up @@ -4495,15 +4510,6 @@ ember-cli@~3.25.2:
workerpool "^6.0.3"
yam "^1.0.0"

ember-compatibility-helpers@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/ember-compatibility-helpers/-/ember-compatibility-helpers-1.2.2.tgz#839e0c24190b7a2ec8c39b80e030811b1a95b6d3"
integrity sha512-EKyCGOGBvKkBsk6wKfg3GhjTvTTkcEwzl/cv4VYvZM18cihmjGNpliR4BymWsKRWrv4VJLyq15Vhk3NHkSNBag==
dependencies:
babel-plugin-debug-macros "^0.2.0"
ember-cli-version-checker "^5.1.1"
semver "^5.4.1"

ember-export-application-global@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/ember-export-application-global/-/ember-export-application-global-2.0.1.tgz#b120a70e322ab208defc9e2daebe8d0dfc2dcd46"
Expand Down Expand Up @@ -4843,6 +4849,28 @@ es-abstract@^1.18.0-next.2:
string.prototype.trimstart "^1.0.4"
unbox-primitive "^1.0.0"

es-abstract@^1.18.2:
version "1.18.3"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.18.3.tgz#25c4c3380a27aa203c44b2b685bba94da31b63e0"
integrity sha512-nQIr12dxV7SSxE6r6f1l3DtAeEYdsGpps13dR0TwJg1S8gyp4ZPgy3FZcHBgbiQqnoqSTb+oC+kO4UQ0C/J8vw==
dependencies:
call-bind "^1.0.2"
es-to-primitive "^1.2.1"
function-bind "^1.1.1"
get-intrinsic "^1.1.1"
has "^1.0.3"
has-symbols "^1.0.2"
is-callable "^1.2.3"
is-negative-zero "^2.0.1"
is-regex "^1.1.3"
is-string "^1.0.6"
object-inspect "^1.10.3"
object-keys "^1.1.1"
object.assign "^4.1.2"
string.prototype.trimend "^1.0.4"
string.prototype.trimstart "^1.0.4"
unbox-primitive "^1.0.1"

es-to-primitive@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.1.tgz#e55cd4c9cdc188bcefb03b366c736323fc5c898a"
Expand Down Expand Up @@ -6830,6 +6858,14 @@ is-regex@^1.1.2:
call-bind "^1.0.2"
has-symbols "^1.0.1"

is-regex@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.3.tgz#d029f9aff6448b93ebbe3f33dac71511fdcbef9f"
integrity sha512-qSVXFz28HM7y+IWX6vLCsexdlvzT1PJNFSBuaQLQ5o0IEw8UDYW6/2+eCMVyIsbM8CNLX2a/QWmSpyxYEHY7CQ==
dependencies:
call-bind "^1.0.2"
has-symbols "^1.0.2"

is-retry-allowed@^1.0.0, is-retry-allowed@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-1.2.0.tgz#d778488bd0a4666a3be8a1482b9f2baafedea8b4"
Expand Down Expand Up @@ -6857,6 +6893,11 @@ is-string@^1.0.5:
resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.5.tgz#40493ed198ef3ff477b8c7f92f644ec82a5cd3a6"
integrity sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ==

is-string@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.6.tgz#3fe5d5992fb0d93404f32584d4b0179a71b54a5f"
integrity sha512-2gdzbKUuqtQ3lYNrUTQYoClPhm7oQu4UdpSZMp1/DGgkHBT8E2Z1l0yMdb6D4zNAxwDiMv8MdulKROJGNl0Q0w==

is-symbol@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.2.tgz#a055f6ae57192caee329e7a860118b497a950f38"
Expand Down Expand Up @@ -7910,7 +7951,8 @@ mocha@^8.4.0:
yargs-unparser "2.0.0"

"module-name-inliner@link:./tests/dummy/lib/module-name-inliner":
version "0.1.0"
version "0.0.0"
uid ""

morgan@^1.10.0:
version "1.10.0"
Expand Down Expand Up @@ -8175,6 +8217,11 @@ object-hash@^1.3.1:
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-1.3.1.tgz#fde452098a951cb145f039bb7d455449ddc126df"
integrity sha512-OSuu/pU4ENM9kmREg0BdNrUDIl1heYa4mBZacJc+vVWz4GtAwu7jO8s4AIt2aGRUTqxykpWzI3Oqnsm13tTMDA==

object-inspect@^1.10.3:
version "1.11.0"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.11.0.tgz#9dceb146cedd4148a0d9e51ab88d34cf509922b1"
integrity sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg==

object-inspect@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.7.0.tgz#f4f6bd181ad77f006b5ece60bd0b6f398ff74a67"
Expand Down Expand Up @@ -9923,6 +9970,20 @@ string.prototype.matchall@^4.0.4:
regexp.prototype.flags "^1.3.1"
side-channel "^1.0.4"

string.prototype.matchall@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/string.prototype.matchall/-/string.prototype.matchall-4.0.5.tgz#59370644e1db7e4c0c045277690cf7b01203c4da"
integrity sha512-Z5ZaXO0svs0M2xd/6By3qpeKpLKd9mO4v4q3oMEQrk8Ck4xOD5d5XeBOOjGrmVZZ/AHB1S0CgG4N5r1G9N3E2Q==
dependencies:
call-bind "^1.0.2"
define-properties "^1.1.3"
es-abstract "^1.18.2"
get-intrinsic "^1.1.1"
has-symbols "^1.0.2"
internal-slot "^1.0.3"
regexp.prototype.flags "^1.3.1"
side-channel "^1.0.4"

string.prototype.trimend@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.4.tgz#e75ae90c2942c63504686c18b287b4a0b1a45f80"
Expand Down Expand Up @@ -10413,7 +10474,7 @@ uglify-js@^3.1.4:
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.13.5.tgz#5d71d6dbba64cf441f32929b1efce7365bb4f113"
integrity sha512-xtB8yEqIkn7zmOyS2zUNBsYCBRhDkvlNxMMY2smuJ/qA8NCHeQvKCF3i9Z4k8FJH4+PJvZRtMrPynfZ75+CSZw==

unbox-primitive@^1.0.0:
unbox-primitive@^1.0.0, unbox-primitive@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471"
integrity sha512-tZU/3NqK3dA5gpE1KtyiJUrEB0lxnGkMFHptJ7q6ewdZ8s12QrODwNbhIJStmJkd1QDXa1NRA8aF2A1zk/Ypyw==
Expand Down

0 comments on commit 33f0134

Please sign in to comment.