From b9d104495729ad0fb054295540e3b3496eea1fe1 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 13 Jun 2018 12:58:28 -0400 Subject: [PATCH] fix annotateWithScopes and move test --- src/compile/Compiler.ts | 4 ++- src/utils/annotateWithScopes.ts | 6 ++++- test/js/samples/script-object-rest/input.html | 13 ---------- test/runtime/samples/object-rest/_config.js | 25 +++++++++++++++++++ test/runtime/samples/object-rest/main.html | 18 +++++++++++++ 5 files changed, 51 insertions(+), 15 deletions(-) delete mode 100644 test/js/samples/script-object-rest/input.html create mode 100644 test/runtime/samples/object-rest/_config.js create mode 100644 test/runtime/samples/object-rest/main.html diff --git a/src/compile/Compiler.ts b/src/compile/Compiler.ts index 4a4239bbae..4f7f18d07b 100644 --- a/src/compile/Compiler.ts +++ b/src/compile/Compiler.ts @@ -587,7 +587,9 @@ export default class Compiler { const param = value.params[0]; if (param.type === 'ObjectPattern') { - const deps = param.properties.map(prop => prop.key.name); + const deps = param.properties.map(prop => { + return (prop.type === 'RestElement' ? prop.argument : prop.key).name; + }); deps.forEach(dep => { this.expectedProperties.add(dep); diff --git a/src/utils/annotateWithScopes.ts b/src/utils/annotateWithScopes.ts index 408de776b2..08ac93387c 100644 --- a/src/utils/annotateWithScopes.ts +++ b/src/utils/annotateWithScopes.ts @@ -137,7 +137,11 @@ const extractors = { ObjectPattern(names: string[], param: Node) { param.properties.forEach((prop: Node) => { - extractors[prop.value.type](names, prop.value); + if (prop.type === 'RestElement') { + names.push(prop.argument.name); + } else { + extractors[prop.value.type](names, prop.value); + } }); }, diff --git a/test/js/samples/script-object-rest/input.html b/test/js/samples/script-object-rest/input.html deleted file mode 100644 index 2150a0427c..0000000000 --- a/test/js/samples/script-object-rest/input.html +++ /dev/null @@ -1,13 +0,0 @@ -

Hello {name}!

- - diff --git a/test/runtime/samples/object-rest/_config.js b/test/runtime/samples/object-rest/_config.js new file mode 100644 index 0000000000..a93a863493 --- /dev/null +++ b/test/runtime/samples/object-rest/_config.js @@ -0,0 +1,25 @@ +export default { + html: ` +
{"wanted":2}
+ `, + + test(assert, component, target) { + component.set({ + unwanted: 3, + wanted: 4 + }); + + // assert.htmlEqual(target.innerHTML, ` + //
{"wanted":4}
+ // `); + + component.set({ + unwanted: 5, + wanted: 6 + }); + + assert.htmlEqual(target.innerHTML, ` +
{"wanted":6}
+ `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/object-rest/main.html b/test/runtime/samples/object-rest/main.html new file mode 100644 index 0000000000..3777f4bb4f --- /dev/null +++ b/test/runtime/samples/object-rest/main.html @@ -0,0 +1,18 @@ +
{JSON.stringify(props)}
+ +