Skip to content

Commit

Permalink
Ensure AST plugins have the same ordering as < [email protected].
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rwjblue committed Feb 27, 2021
1 parent d7698a1 commit d8e5dda
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/template-compiler-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ class TemplateCompiler extends Filter {
let srcDir = this.inputPaths[0];
let srcName = path.join(srcDir, relativePath);
try {
// 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
let astPlugins = this.options.plugins ? [...this.options.plugins.ast].reverse() : [];

let result =
'export default ' +
utils.template(this.options.templateCompiler, stripBom(string), {
Expand All @@ -67,7 +78,7 @@ class TemplateCompiler extends Filter {
// all of the built in AST transforms into plugins.ast, which breaks
// persistent caching)
plugins: {
ast: this.options.plugins ? this.options.plugins.ast : [],
ast: astPlugins,
},
}) +
';';
Expand Down
13 changes: 12 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,20 @@ function setup(pluginInfo, options) {
let templatePrecompile = templateCompiler.precompile;

let precompile = (template, _options) => {
// 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
let astPlugins = [...pluginInfo.plugins].reverse();

let options = {
plugins: {
ast: pluginInfo.plugins,
ast: astPlugins,
},
};

Expand Down

0 comments on commit d8e5dda

Please sign in to comment.