diff --git a/lib/ast-transform.js b/lib/ast-transform.js index 9d533ca..fc45ba7 100644 --- a/lib/ast-transform.js +++ b/lib/ast-transform.js @@ -139,9 +139,17 @@ class AngleBracketPolyfill { let hasAttrSplat = element.attributes.find(n => n.name === '...attributes'); if (isLocal || isNamedArgument || isThisPath) { + let path = b.path(tag); + + if (isNamedArgument) { + path = b.path(tag.slice(1)); + path.original = tag; + path.data = true; + } + return { kind: 'DynamicComponent', - path: b.path(tag), + path, selfClosing, hasAttrSplat, }; diff --git a/lib/sample-compile-script.js b/lib/sample-compile-script.js index e1caeba..8c827bd 100644 --- a/lib/sample-compile-script.js +++ b/lib/sample-compile-script.js @@ -9,8 +9,9 @@ */ const compiler = require('ember-source/dist/ember-template-compiler'); +//compiler.registerPlugin('ast', require('ember-named-arguments-polyfill/lib/ast-transform')); compiler.registerPlugin('ast', require('./ast-transform')); -let template = '<@nav.item />'; +let template = '<@curriedThing />'; let output = compiler.precompile(template, { contents: template }); console.log(output); // eslint-disable-line no-console diff --git a/package.json b/package.json index 31c2c99..6ba0deb 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "ember-export-application-global": "^2.0.0", "ember-load-initializers": "^1.1.0", "ember-maybe-import-regenerator": "^0.1.6", + "ember-named-arguments-polyfill": "^1.0.0", "ember-resolver": "^4.0.0", "ember-source": "~3.2.0-beta.2", "ember-source-channel-url": "^1.0.1", @@ -57,6 +58,7 @@ "node": "6.* || 8.* || 9.* || >= 10.*" }, "ember-addon": { - "configPath": "tests/dummy/config" + "configPath": "tests/dummy/config", + "after": "ember-named-arguments-polyfill" } } diff --git a/tests/integration/components/angle-bracket-invocation-test.js b/tests/integration/components/angle-bracket-invocation-test.js index 85301bc..c83c9a0 100644 --- a/tests/integration/components/angle-bracket-invocation-test.js +++ b/tests/integration/components/angle-bracket-invocation-test.js @@ -153,6 +153,24 @@ module('Integration | Component | angle-bracket-invocation', function(hooks) { assert.dom().hasText('hi rwjblue!'); }); + test('invoke dynamic - named arguments', async function(assert) { + this.owner.register('template:components/x-invoker', hbs`<@curriedThing />`); + this.owner.register('template:components/foo-bar', hbs`hi rwjblue!`); + + await render(hbs`{{x-invoker curriedThing=(component 'foo-bar')}}`); + + assert.dom().hasText('hi rwjblue!'); + }); + + test('invoke dynamic - named argument paths', async function(assert) { + this.owner.register('template:components/x-invoker', hbs`<@stuff.curriedThing />`); + this.owner.register('template:components/foo-bar', hbs`hi rwjblue!`); + + await render(hbs`{{x-invoker stuff=(hash curriedThing=(component 'foo-bar'))}}`); + + assert.dom().hasText('hi rwjblue!'); + }); + test('invoke dynamic - path no implicit this', async function(assert) { this.owner.register('service:elsewhere', Service.extend()); this.owner.register( diff --git a/yarn.lock b/yarn.lock index d29bf75..5485480 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2153,6 +2153,13 @@ ember-maybe-import-regenerator@^0.1.6: ember-cli-babel "^6.0.0-beta.4" regenerator-runtime "^0.9.5" +ember-named-arguments-polyfill@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/ember-named-arguments-polyfill/-/ember-named-arguments-polyfill-1.0.0.tgz#0b81fb81a7cef2c89e9e1d0278b579e708bf4ded" + dependencies: + ember-cli-babel "^6.6.0" + ember-cli-version-checker "^2.1.2" + ember-qunit@^3.3.2: version "3.4.1" resolved "https://registry.yarnpkg.com/ember-qunit/-/ember-qunit-3.4.1.tgz#204a2d39a5d44d494c56bf17cf3fd12f06210359"