From ef23c5d04a3ff05a334ad5fe7654f052dc75504e Mon Sep 17 00:00:00 2001 From: simonihmig Date: Mon, 24 Jun 2019 17:50:30 +0200 Subject: [PATCH] Add dirty workaround for AST plugins in wrong order --- index.js | 19 +++++++++++++++++-- package.json | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b7b9d8f..e1b0f43 100644 --- a/index.js +++ b/index.js @@ -6,12 +6,27 @@ module.exports = { name: require('./package').name, setupPreprocessorRegistry(type, registry) { - registry.add('htmlbars-ast-plugin', { + let plugins = registry.load('htmlbars-ast-plugin'); + let inElementPlugin = plugins.find((plugin) => plugin.name === 'ember-in-element-polyfill'); + let maybePlugin = { name: 'ember-maybe-in-element-transform', plugin: EmberMaybeInElementAstTransform, baseDir() { return __dirname; } - }); + }; + + // Yes, this a bit ugly, but it seems for some reason AST plugins are applied in a different order (reversed?) than + // the order they are added to the registry. + // With this dirty hack we make sure there is always a "polyfill" transform running after the "maybe" transform, to make + // sure the AST returned from "maybe" containing `{{in-element}}` gets further transformed by the polyfill! + if (inElementPlugin) { + registry.remove('htmlbars-ast-plugin', inElementPlugin); + registry.add('htmlbars-ast-plugin', inElementPlugin); + registry.add('htmlbars-ast-plugin', maybePlugin); + registry.add('htmlbars-ast-plugin', inElementPlugin); + } else { + registry.add('htmlbars-ast-plugin', maybePlugin); + } }, }; diff --git a/package.json b/package.json index 85b5b55..a557cc3 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,6 @@ }, "ember-addon": { "configPath": "tests/dummy/config", - "before": "ember-in-element-polyfill" + "after": "ember-in-element-polyfill" } }