Skip to content

Commit d8e5dda

Browse files
committed
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.
1 parent d7698a1 commit d8e5dda

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-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 ? [...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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,20 @@ function setup(pluginInfo, options) {
208208
let templatePrecompile = templateCompiler.precompile;
209209

210210
let precompile = (template, _options) => {
211+
// we have to reverse these for reasons that are a bit bonkers. the initial
212+
// version of this system used `registeredPlugin` from
213+
// `ember-template-compiler.js` to set up these plugins (because Ember ~ 1.13
214+
// only had `registerPlugin`, and there was no way to pass plugins directly
215+
// to the call to `compile`/`precompile`). calling `registerPlugin`
216+
// unfortunately **inverted** the order of plugins (it essentially did
217+
// `PLUGINS = [plugin, ...PLUGINS]`).
218+
//
219+
// sooooooo...... we are forced to maintain that **absolutely bonkers** ordering
220+
let astPlugins = [...pluginInfo.plugins].reverse();
221+
211222
let options = {
212223
plugins: {
213-
ast: pluginInfo.plugins,
224+
ast: astPlugins,
214225
},
215226
};
216227

0 commit comments

Comments
 (0)