Skip to content

Commit 59379a3

Browse files
author
Robert Jackson
authored
Merge pull request #762 from dfreeman/babel-plugin-ember-template-compilation-v2
2 parents 9f1882d + 386e54f commit 59379a3

File tree

4 files changed

+52
-54
lines changed

4 files changed

+52
-54
lines changed

lib/utils.js

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -196,45 +196,43 @@ function setup(pluginInfo, options) {
196196

197197
let htmlbarsOptions = buildOptions(projectConfig, templateCompilerPath, pluginInfo);
198198
let { templateCompiler } = htmlbarsOptions;
199-
200-
let templatePrecompile = templateCompiler.precompile;
201-
202-
let precompile = (template, _options) => {
203-
// we have to reverse these for reasons that are a bit bonkers. the initial
204-
// version of this system used `registeredPlugin` from
205-
// `ember-template-compiler.js` to set up these plugins (because Ember ~ 1.13
206-
// only had `registerPlugin`, and there was no way to pass plugins directly
207-
// to the call to `compile`/`precompile`). calling `registerPlugin`
208-
// unfortunately **inverted** the order of plugins (it essentially did
209-
// `PLUGINS = [plugin, ...PLUGINS]`).
210-
//
211-
// sooooooo...... we are forced to maintain that **absolutely bonkers** ordering
212-
let astPlugins = [...pluginInfo.plugins].reverse();
213-
214-
let options = {
215-
plugins: {
216-
ast: astPlugins,
217-
},
218-
219-
..._options,
199+
if (options.requiresModuleApiPolyfill) {
200+
let templatePrecompile = templateCompiler.precompile;
201+
202+
let precompile = (template, _options) => {
203+
// we have to reverse these for reasons that are a bit bonkers. the initial
204+
// version of this system used `registeredPlugin` from
205+
// `ember-template-compiler.js` to set up these plugins (because Ember ~ 1.13
206+
// only had `registerPlugin`, and there was no way to pass plugins directly
207+
// to the call to `compile`/`precompile`). calling `registerPlugin`
208+
// unfortunately **inverted** the order of plugins (it essentially did
209+
// `PLUGINS = [plugin, ...PLUGINS]`).
210+
//
211+
// sooooooo...... we are forced to maintain that **absolutely bonkers** ordering
212+
let astPlugins = [...pluginInfo.plugins].reverse();
213+
214+
let options = {
215+
plugins: {
216+
ast: astPlugins,
217+
},
218+
219+
..._options,
220+
};
221+
222+
return templatePrecompile(template, options);
220223
};
221224

222-
return templatePrecompile(template, options);
223-
};
224-
225-
precompile.baseDir = () => path.resolve(__dirname, '..');
225+
precompile.baseDir = () => path.resolve(__dirname, '..');
226226

227-
let cacheKey;
228-
precompile.cacheKey = () => {
229-
if (cacheKey === undefined) {
230-
cacheKey = makeCacheKey(templateCompilerPath, pluginInfo);
231-
}
232-
cacheKey;
233-
};
227+
let cacheKey;
228+
precompile.cacheKey = () => {
229+
if (cacheKey === undefined) {
230+
cacheKey = makeCacheKey(templateCompilerPath, pluginInfo);
231+
}
232+
cacheKey;
233+
};
234234

235-
let plugin;
236-
if (options.requiresModuleApiPolyfill) {
237-
plugin = [
235+
return [
238236
require.resolve('babel-plugin-htmlbars-inline-precompile'),
239237
{
240238
precompile,
@@ -245,10 +243,12 @@ function setup(pluginInfo, options) {
245243
'ember-cli-htmlbars:inline-precompile',
246244
];
247245
} else {
248-
plugin = [
246+
return [
249247
require.resolve('babel-plugin-ember-template-compilation'),
250248
{
251-
precompile,
249+
// As above, we present the AST transforms in reverse order
250+
transforms: [...pluginInfo.plugins].reverse(),
251+
compilerPath: require.resolve(templateCompilerPath),
252252
enableLegacyModules: [
253253
'ember-cli-htmlbars',
254254
'ember-cli-htmlbars-inline-precompile',
@@ -258,8 +258,6 @@ function setup(pluginInfo, options) {
258258
'ember-cli-htmlbars:inline-precompile',
259259
];
260260
}
261-
262-
return plugin;
263261
}
264262

265263
function getTemplateCompilerCacheKey(templateCompilerPath) {

node-tests/utils_test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ describe('utils', function () {
153153

154154
it('detects when the ember-template-compilation plugin exists', function () {
155155
let plugins = [
156-
utils.setup({}, { requiresModuleApiPolyfill: false, templateCompilerPath: '.' }),
156+
utils.setup(
157+
{ plugins: [] },
158+
{ requiresModuleApiPolyfill: false, templateCompilerPath: '.' }
159+
),
157160
];
158161

159162
assert.strictEqual(utils.isInlinePrecompileBabelPluginRegistered(plugins), true);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"dependencies": {
3535
"@ember/edition-utils": "^1.2.0",
36-
"babel-plugin-ember-template-compilation": "^1.0.0",
36+
"babel-plugin-ember-template-compilation": "^2.0.0",
3737
"babel-plugin-htmlbars-inline-precompile": "^5.3.0",
3838
"broccoli-debug": "^0.6.5",
3939
"broccoli-persistent-filter": "^3.1.2",

yarn.lock

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,10 +3441,10 @@ babel-helpers@^6.24.1:
34413441
babel-runtime "^6.22.0"
34423442
babel-template "^6.24.1"
34433443

3444-
babel-import-util@^0.2.0:
3445-
version "0.2.0"
3446-
resolved "https://registry.yarnpkg.com/babel-import-util/-/babel-import-util-0.2.0.tgz#b468bb679919601a3570f9e317536c54f2862e23"
3447-
integrity sha512-CtWYYHU/MgK88rxMrLfkD356dApswtR/kWZ/c6JifG1m10e7tBBrs/366dFzWMAoqYmG5/JSh+94tUSpIwh+ag==
3444+
babel-import-util@^1.3.0:
3445+
version "1.3.0"
3446+
resolved "https://registry.yarnpkg.com/babel-import-util/-/babel-import-util-1.3.0.tgz#dc9251ea39a7747bd586c1c13b8d785a42797f8e"
3447+
integrity sha512-PPzUT17eAI18zn6ek1R3sB4Krc/MbnmT1MkZQFmyhjoaEGBVwNABhfVU9+EKcDSKrrOm9OIpGhjxukx1GCiy1g==
34483448

34493449
babel-loader@^8.0.6:
34503450
version "8.2.2"
@@ -3512,15 +3512,12 @@ babel-plugin-ember-modules-api-polyfill@^3.5.0:
35123512
dependencies:
35133513
ember-rfc176-data "^0.3.17"
35143514

3515-
babel-plugin-ember-template-compilation@^1.0.0:
3516-
version "1.0.0"
3517-
resolved "https://registry.yarnpkg.com/babel-plugin-ember-template-compilation/-/babel-plugin-ember-template-compilation-1.0.0.tgz#984bc2ceb0bb864e878e25a9ca5c2a6153c96881"
3518-
integrity sha512-SvDQ+DbimZEq7XZztxiCKPNO3/HEwAOKBdJ9r4qtMpgmSuuhzO1elkixJTrnwnkLv1titAYAXNqLVD1fkE4Vgg==
3515+
babel-plugin-ember-template-compilation@^2.0.0:
3516+
version "2.0.0"
3517+
resolved "https://registry.yarnpkg.com/babel-plugin-ember-template-compilation/-/babel-plugin-ember-template-compilation-2.0.0.tgz#41d895874ba6119dd461f61993c16d1154bf8a57"
3518+
integrity sha512-d+4jaB2ik0rt9TH0K9kOlKJeRBHEb373FgFMcU9ZaJL2zYuVXe19bqy+cWlLpLf1tpOBcBG9QTlFBCoImlOt1g==
35193519
dependencies:
3520-
babel-import-util "^0.2.0"
3521-
line-column "^1.0.2"
3522-
magic-string "^0.25.7"
3523-
string.prototype.matchall "^4.0.5"
3520+
babel-import-util "^1.3.0"
35243521

35253522
babel-plugin-filter-imports@^4.0.0:
35263523
version "4.0.0"
@@ -13583,7 +13580,7 @@ string-width@^3.0.0, string-width@^3.1.0:
1358313580
is-fullwidth-code-point "^2.0.0"
1358413581
strip-ansi "^5.1.0"
1358513582

13586-
string.prototype.matchall@^4.0.4, string.prototype.matchall@^4.0.5:
13583+
string.prototype.matchall@^4.0.4:
1358713584
version "4.0.6"
1358813585
resolved "https://registry.yarnpkg.com/string.prototype.matchall/-/string.prototype.matchall-4.0.6.tgz#5abb5dabc94c7b0ea2380f65ba610b3a544b15fa"
1358913586
integrity sha512-6WgDX8HmQqvEd7J+G6VtAahhsQIssiZ8zl7zKh1VDMFyL3hRTJP4FTNA3RbIp2TOQ9AYNDcc7e3fH0Qbup+DBg==

0 commit comments

Comments
 (0)