Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[legacy-data-mixin] Ensure wildcard arguments get undefined treatment. Fixes #5428. #5522

Merged
merged 2 commits into from
Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/legacy/legacy-data-mixin.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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