From fad5ccdf59a40725fc8ef40b076eb87981dfff87 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 7 Mar 2018 09:53:46 -0500 Subject: [PATCH] prevent context variables being called component or state - fixes #1213 --- src/generators/dom/Block.ts | 8 ++++++-- .../deconflict-component-refs/_config.js | 17 +++++++++++++++++ .../samples/deconflict-component-refs/main.html | 11 +++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 test/runtime/samples/deconflict-component-refs/_config.js create mode 100644 test/runtime/samples/deconflict-component-refs/main.html diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index 49f4f81d86..089817a637 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -112,9 +112,13 @@ export default class Block { this.hasOutroMethod = false; this.outros = 0; - this.aliases = new Map(); - this.variables = new Map(); this.getUniqueName = this.generator.getUniqueNameMaker(); + this.variables = new Map(); + + this.aliases = new Map() + .set('component', this.getUniqueName('component')) + .set('state', this.getUniqueName('state')); + if (this.key) this.aliases.set('key', this.getUniqueName('key')); this.hasUpdateMethod = false; // determined later } diff --git a/test/runtime/samples/deconflict-component-refs/_config.js b/test/runtime/samples/deconflict-component-refs/_config.js new file mode 100644 index 0000000000..213abd245c --- /dev/null +++ b/test/runtime/samples/deconflict-component-refs/_config.js @@ -0,0 +1,17 @@ +export default { + html: ` + + `, + + data: { + components: [ + { name: 'foo', edit: true }, + { name: 'bar', edit: false }, + { name: 'baz', edit: false } + ] + } +}; \ No newline at end of file diff --git a/test/runtime/samples/deconflict-component-refs/main.html b/test/runtime/samples/deconflict-component-refs/main.html new file mode 100644 index 0000000000..78f0c26661 --- /dev/null +++ b/test/runtime/samples/deconflict-component-refs/main.html @@ -0,0 +1,11 @@ + \ No newline at end of file