Skip to content

Commit

Permalink
Ensure wildcard arguments get undefined treatment. Fixes #5428.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Apr 11, 2019
1 parent b7c73bd commit f5a45eb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/legacy/legacy-data-mixin.js
Expand Up @@ -94,7 +94,8 @@ export const LegacyDataMixin = dedupingMixin(superClass => {
// undefined or not. Multi-property observers must have all arguments defined
if (this._legacyUndefinedCheck && vals.length > 1) {
for (let i=0; i<vals.length; i++) {
if (vals[i] === undefined) {
if (vals[i] === undefined ||
(args[i].wildcard && vals[i].base === undefined)) {
// Break out of effect's control flow; will be caught in
// wrapped property effect function below
const name = args[i].name;
Expand Down
48 changes: 46 additions & 2 deletions test/unit/legacy-data.html
Expand Up @@ -51,20 +51,24 @@
},
computedMulti: {
computed: 'computeMulti(computedMultiDep1, computedMultiDep2)'
}
},
wildcardProp: String,
wildcardObj: Object
},
observers: [
'staticObserver("staticObserver")',
'singlePropObserver(singleProp)',
'multiPropObserver(multiProp1, multiProp2)',
'throws(throwProp)'
'throws(throwProp)',
'wildcardObserver(wildcardProp, wildcardObj.*)'
],
created() {
this.singlePropObserver = sinon.spy();
this.multiPropObserver = sinon.spy();
this.staticObserver = sinon.spy();
this.computeSingle = sinon.spy((inlineSingleDep) => `[${inlineSingleDep}]`);
this.computeMulti = sinon.spy((inlineMultiDep1, inlineMultiDep2) => `[${inlineMultiDep1},${inlineMultiDep2}]`);
this.wildcardObserver = sinon.spy();
},
throws() {
throw new Error('real error');
Expand Down Expand Up @@ -145,6 +149,18 @@
</template>
</test-fixture>

<test-fixture id="declarative-wildcard-one">
<template>
<x-data wildcard-prop='prop'></x-data>
</template>
</test-fixture>

<test-fixture id="declarative-wildcard-all">
<template>
<x-data wildcard-prop="prop" wildcard-obj='{"prop": "wildcardObj"}'></x-data>
</template>
</test-fixture>

<script type="module">
import {flush} from '../../lib/utils/flush.js';

Expand Down Expand Up @@ -192,6 +208,8 @@
const inlineMultiDep2 = 'inlineMultiDep2';
const inlineMultiIfDep1 = 'inlineMultiIfDep1';
const inlineMultiIfDep2 = 'inlineMultiIfDep2';
const wildcardProp = 'wildcardProp';
const wildcardObj = {prop: 'wildcardObj'};

suite('check disabled', () => {
test('no arguments defined', () => {
Expand Down Expand Up @@ -270,6 +288,14 @@
assertEffects({computeMulti: 1});
assert.equal(el.$$('#ifChild').computedMulti, '[inlineMultiIfDep1,inlineMultiIfDep2]');
});
test('one wildcard argument defined', () => {
setupElement(false, {wildcardProp});
assertEffects({wildcardObserver: 1});
});
test('all wildcard arguments defined', () => {
setupElement(false, {wildcardProp, wildcardObj});
assertEffects({wildcardObserver: 1});
});
});

suite('warn', () => {
Expand Down Expand Up @@ -349,6 +375,14 @@
assertEffects({computeMulti: 1});
assert.equal(el.$$('#ifChild').computedMulti, '[inlineMultiIfDep1,inlineMultiIfDep2]');
});
test('one wildcard argument defined', () => {
setupElement(true, {wildcardProp});
assertEffects({warn: 1});
});
test('all wildcard arguments defined', () => {
setupElement(true, {wildcardProp, wildcardObj});
assertEffects({wildcardObserver: 1});
});
});
});

Expand Down Expand Up @@ -416,6 +450,16 @@
assertEffects({computeMulti: 1});
assert.equal(el.$$('#ifChild').computedMulti, '[b,c]');
});
test.only('one wildcard argument defined', () => {
el = fixture('declarative-wildcard-one');
flush();
assertEffects({warn: 1});
});
test.only('all wildcard arguments defined', () => {
el = fixture('declarative-wildcard-all');
flush();
assertEffects({wildcardObserver: 1});
});
});
});

Expand Down

0 comments on commit f5a45eb

Please sign in to comment.