Skip to content

Commit

Permalink
Merge pull request #34 from DockYard/make-it-work-with-ember-312
Browse files Browse the repository at this point in the history
Make it work in ember 3.12
  • Loading branch information
cibernox authored Aug 12, 2020
2 parents b19a41f + 727ec86 commit 35232e8
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- env: EMBER_TRY_SCENARIO=ember-lts-3.16
- env: EMBER_TRY_SCENARIO=ember-3.13
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
Expand Down
4 changes: 2 additions & 2 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module.exports = async function() {
return {
scenarios: [
{
name: 'ember-lts-3.16',
name: 'ember-3.13',
npm: {
devDependencies: {
'ember-source': '~3.16.0'
'ember-source': '~3.13.0'
}
}
},
Expand Down
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
'use strict';

const EmberMaybeInElementAstTransform = require('./lib/ast-transform')
const VersionChecker = require('ember-cli-version-checker');
const buildAstTransform = require('./lib/ast-transform')

module.exports = {
name: require('./package').name,

setupPreprocessorRegistry(type, registry) {
let plugins = registry.load('htmlbars-ast-plugin');
let inElementPlugin = plugins.find((plugin) => plugin.name === 'ember-in-element-polyfill');
let checker = new VersionChecker(this.project);
let dep = checker.for('ember-source');
let maybePlugin = {
name: 'ember-maybe-in-element-transform',
plugin: EmberMaybeInElementAstTransform,
plugin: buildAstTransform(dep.gte('3.17.0')),
baseDir() {
return __dirname;
}
},
};
registry.add("htmlbars-ast-plugin", maybePlugin);
registry.add('htmlbars-ast-plugin', maybePlugin);
},
};
66 changes: 44 additions & 22 deletions lib/ast-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,53 @@
*
* It also thrown an error if called with less than two arguments.
*/
module.exports = function ({ syntax }) {
const b = syntax.builders;
module.exports = function(is317OrGreater) {
return function ({ syntax }) {
const b = syntax.builders;

return {
name: "ember-maybe-in-element-transform",
let buildMaybeInElement;
if (is317OrGreater) {
buildMaybeInElement = function (destinationElement, renderInPlace, children) {
return b.element("MaybeInElement", {
attrs: [
b.attr("@destinationElement", b.mustache(destinationElement)),
b.attr("@renderInPlace", b.mustache(renderInPlace)),
],
children
});
};
} else {
buildMaybeInElement = function (destinationElement, renderInPlace, children) {
return b.element("MaybeInElement",
[b.attr("@destinationElement", b.mustache(destinationElement)),b.attr("@renderInPlace", b.mustache(renderInPlace))],
[],
children,
);
};
}

visitor: {
BlockStatement(node) {
if (node.path.original === "maybe-in-element") {
if (node.params.length < 2) {
throw new Error(
"{{#maybe-in-element}} requires two arguments. The first is the destination element and the second is the `renderInPlace` boolean flag"
return {
name: "ember-maybe-in-element-transform",

visitor: {
BlockStatement(node) {
if (node.path.original === "maybe-in-element") {
if (node.params.length < 2) {
throw new Error(
"{{#maybe-in-element}} requires two arguments. The first is the destination element and the second is the `renderInPlace` boolean flag"
);
}
let destinationElement = node.params[0];
let renderInPlace = node.params[1];
let newNode = buildMaybeInElement(
destinationElement,
renderInPlace,
node.program.body
);
return newNode;
}
let destinationElement = node.params[0];
let renderInPlace = node.params[1];
return b.element("MaybeInElement", {
attrs: [
b.attr("@destinationElement", b.mustache(destinationElement)),
b.attr("@renderInPlace", b.mustache(renderInPlace)),
],
children: node.program.body,
});
}
},
},
},
};
};
}
};
79 changes: 39 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"ember-cli-babel": "^7.21.0",
"ember-cli-htmlbars": "^5.2.0",
"ember-cli-version-checker": "^5.1.1",
"ember-in-element-polyfill": "^1.0.0"
},
"devDependencies": {
Expand All @@ -48,7 +49,7 @@
"ember-maybe-import-regenerator": "^0.1.6",
"ember-maybe-import-regenerator-for-testing": "^1.0.0",
"ember-resolver": "^8.0.0",
"ember-source": "~3.20.2",
"ember-source": "~3.20.0",
"ember-source-channel-url": "^2.0.1",
"ember-template-lint": "^2.9.1",
"ember-try": "^1.4.0",
Expand Down

0 comments on commit 35232e8

Please sign in to comment.