Skip to content

Commit c1f98b1

Browse files
rwjblueRobert Jackson
authored andcommitted
Ensure AST plugins have the same ordering as < [email protected].
We have to reverse these for reasons that are a bit bonkers. The initial version of this system used `registeredPlugin` from `ember-template-compiler.js` to set up these plugins (because Ember ~ 1.13 only had `registerPlugin`, and there was no way to pass plugins directly to the call to `compile`/`precompile`). Calling `registerPlugin` unfortunately **inverted** the order of plugins (it essentially did `PLUGINS = [plugin, ...PLUGINS]`). Sooooooo...... we are forced to maintain that **absolutely bonkers** ordering. (cherry picked from commit d8e5dda)
1 parent 336d4d8 commit c1f98b1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/template-compiler-plugin.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ class TemplateCompiler extends Filter {
5252
let srcDir = this.inputPaths[0];
5353
let srcName = path.join(srcDir, relativePath);
5454
try {
55+
// we have to reverse these for reasons that are a bit bonkers. the initial
56+
// version of this system used `registeredPlugin` from
57+
// `ember-template-compiler.js` to set up these plugins (because Ember ~ 1.13
58+
// only had `registerPlugin`, and there was no way to pass plugins directly
59+
// to the call to `compile`/`precompile`). calling `registerPlugin`
60+
// unfortunately **inverted** the order of plugins (it essentially did
61+
// `PLUGINS = [plugin, ...PLUGINS]`).
62+
//
63+
// sooooooo...... we are forced to maintain that **absolutely bonkers** ordering
64+
let astPlugins = this.options.plugins ? [].concat(this.options.plugins.ast).reverse() : [];
65+
5566
let result =
5667
'export default ' +
5768
utils.template(this.options.templateCompiler, stripBom(string), {
@@ -67,7 +78,7 @@ class TemplateCompiler extends Filter {
6778
// all of the built in AST transforms into plugins.ast, which breaks
6879
// persistent caching)
6980
plugins: {
70-
ast: this.options.plugins ? this.options.plugins.ast : [],
81+
ast: astPlugins,
7182
},
7283
}) +
7384
';';

lib/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,14 @@ function setup(pluginInfo, options) {
195195
let templatePrecompile = templateCompiler.precompile;
196196

197197
let precompile = (template, options) => {
198+
let plugins = pluginInfo.plugins || [];
199+
// concat so we ensure we don't mutate the original plugins
200+
// reverse to ensure that original AST plugin ordering is preserved
201+
let astPlugins = [].concat(plugins).reverse();
202+
198203
options = options || {};
199204
options.plugins = {
200-
ast: pluginInfo.plugins,
205+
ast: astPlugins,
201206
};
202207

203208
return templatePrecompile(template, options);

0 commit comments

Comments
 (0)