From 261aac8953c4a9e9bb0cfd2f7cad0e3aaedbb73b Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sun, 3 Jun 2018 11:09:56 -0400 Subject: [PATCH] Prevent implicit `this.` in dynamically invoked paths. --- lib/angle-bracket-invocation-polyfill.js | 4 +-- .../angle-bracket-invocation-test.js | 35 ++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/angle-bracket-invocation-polyfill.js b/lib/angle-bracket-invocation-polyfill.js index 8ca8c9f..a249aa2 100644 --- a/lib/angle-bracket-invocation-polyfill.js +++ b/lib/angle-bracket-invocation-polyfill.js @@ -111,14 +111,14 @@ class AngleBracketPolyfill { let tag = getTag(element); let invocationFirstChar = tag[0]; let isNamedArgument = invocationFirstChar === '@'; - let isPath = tag.indexOf('.') > -1; + let isThisPath = tag.indexOf('this.') === 0; let [maybeLocal] = tag.split('.'); let isLocal = locals.indexOf(maybeLocal) !== -1; let isUpperCase = invocationFirstChar === invocationFirstChar.toUpperCase() && invocationFirstChar !== invocationFirstChar.toLowerCase(); let selfClosing = getSelfClosing(element); - if (isLocal || isNamedArgument || isPath) { + if (isLocal || isNamedArgument || isThisPath) { return { kind: 'DynamicComponent', path: b.path(tag), diff --git a/tests/integration/components/angle-bracket-invocation-test.js b/tests/integration/components/angle-bracket-invocation-test.js index 0397090..9bfafb8 100644 --- a/tests/integration/components/angle-bracket-invocation-test.js +++ b/tests/integration/components/angle-bracket-invocation-test.js @@ -82,6 +82,18 @@ module('Integration | Component | angle-bracket-invocation', function (hooks) { assert.dom().hasText("hi rwjblue!"); }); + test('invoke dynamic - local path', async function (assert) { + this.owner.register('template:components/foo-bar', hbs`hi rwjblue!`); + + await render(hbs` + {{#with (hash here=(component 'foo-bar')) as |stuff|}} + + {{/with}} + `); + + assert.dom().hasText("hi rwjblue!"); + }); + test('invoke dynamic - local, block', async function (assert) { this.owner.register('template:components/foo-bar', hbs`{{yield}}!`); @@ -130,13 +142,34 @@ module('Integration | Component | angle-bracket-invocation', function (hooks) { elsewhere.set('curriedThing', this.curriedThing); } })); - this.owner.register('template:components/x-invoker', hbs``); + this.owner.register('template:components/x-invoker', hbs``); 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 - path no implicit this', async function (assert) { + this.owner.register('service:elsewhere', Service.extend()); + this.owner.register('component:x-invoker', Component.extend({ + elsewhere: injectService(), + + init() { + this._super(...arguments); + + let elsewhere = this.get('elsewhere'); + elsewhere.set('curriedThing', this.curriedThing); + } + })); + this.owner.register('template:components/x-invoker', hbs``); + this.owner.register('template:components/foo-bar', hbs`hi rwjblue!`); + + await render(hbs`{{x-invoker curriedThing=(component 'foo-bar')}}`); + + // should not have rendered anything (no implicit `this`) + assert.dom().hasText(""); + }); }); module('has-block', function (hooks) {