From 4d6eabf228793d0ba61c8c1cdacbe4a920119075 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 27 Jan 2019 21:52:17 -0500 Subject: [PATCH] remove writable_declarations --- src/compile/Component.ts | 31 +++++++++++++++++++------------ src/compile/render-dom/index.ts | 6 ++++-- src/interfaces.ts | 1 + src/utils/annotateWithScopes.ts | 3 --- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/compile/Component.ts b/src/compile/Component.ts index ec9ea43929..409d30b137 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -64,7 +64,6 @@ export default class Component { javascript: string; declarations: string[] = []; - writable_declarations: Set = new Set(); initialised_declarations: Set = new Set(); imported_declarations: Set = new Set(); hoistable_names: Set = new Set(); @@ -149,7 +148,6 @@ export default class Component { if (!ast.instance && !ast.module) { const props = [...this.template_references]; this.declarations.push(...props); - addToSet(this.writable_declarations, this.template_references); props.forEach(name => { this.add_var({ @@ -161,7 +159,8 @@ export default class Component { source: null, mutated: true, // TODO kind of a misnomer... it's *mutable* but not necessarily *mutated*. is that a problem? referenced: true, - module: false + module: false, + writable: true }); }); } @@ -187,7 +186,8 @@ export default class Component { exported_as: null, module: false, mutated: true, - referenced: true + referenced: true, + writable: name[0] !== '$' }); } @@ -445,7 +445,8 @@ export default class Component { exported_as: null, module: is_module, mutated: false, - referenced: false + referenced: false, + writable: false }); this.imported_declarations.add(specifier.local.name); @@ -467,19 +468,22 @@ export default class Component { if (node.type === 'ExportNamedDeclaration') { if (node.declaration) { + const { kind } = node.declaration; + if (node.declaration.type === 'VariableDeclaration') { node.declaration.declarations.forEach(declarator => { extractNames(declarator.id).forEach(name => { this.add_var({ name, - kind: node.declaration.kind, + kind, import_type: null, imported_as: null, exported_as: name, source: null, module: is_module, mutated: !is_module, - referenced: false + referenced: false, + writable: kind === 'let' || kind === 'var' }); }); }); @@ -504,7 +508,8 @@ export default class Component { source: null, module: is_module, mutated: !is_module, - referenced: false + referenced: false, + writable: false }); } @@ -600,7 +605,8 @@ export default class Component { source: null, module: false, mutated: false, - referenced: false + referenced: false, + writable: false }); this.declarations.push(name); @@ -652,7 +658,8 @@ export default class Component { source: null, module: false, mutated: false, - referenced: false + referenced: false, + writable: false }); this.declarations.push(name); @@ -661,7 +668,6 @@ export default class Component { this.node_for_declaration.set(name, node); }); - this.writable_declarations = instance_scope.writable_declarations; this.initialised_declarations = instance_scope.initialised_declarations; globals.forEach(name => { @@ -674,7 +680,8 @@ export default class Component { exported_as: null, module: false, mutated: false, - referenced: false + referenced: false, + writable: false }); }); diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 5808302912..31f42706d4 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -71,7 +71,7 @@ export default function dom( ); const props = component.vars.filter(variable => !variable.module && variable.exported_as); - const writable_props = props.filter(x => component.writable_declarations.has(x.name)); + const writable_props = props.filter(variable => variable.writable); const set = (component.meta.props || writable_props.length > 0 || renderer.slots.size > 0) ? deindent` @@ -95,6 +95,8 @@ export default function dom( let dev_props_check; props.forEach(x => { + const variable = component.var_lookup.get(x.name); + if (component.imported_declarations.has(x.name) || component.hoistable_names.has(x.name)) { body.push(deindent` get ${x.exported_as}() { @@ -109,7 +111,7 @@ export default function dom( `); } - if (component.writable_declarations.has(x.exported_as) && !renderer.readonly.has(x.exported_as)) { + if (variable.writable && !renderer.readonly.has(x.exported_as)) { body.push(deindent` set ${x.exported_as}(${x.name}) { this.$set({ ${x.name} }); diff --git a/src/interfaces.ts b/src/interfaces.ts index cc4bd33a6d..7ea66c362c 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -89,4 +89,5 @@ export interface Var { module: boolean; mutated: boolean; referenced: boolean; + writable: boolean; } \ No newline at end of file diff --git a/src/utils/annotateWithScopes.ts b/src/utils/annotateWithScopes.ts index 96459e1ede..bedab0cbce 100644 --- a/src/utils/annotateWithScopes.ts +++ b/src/utils/annotateWithScopes.ts @@ -60,7 +60,6 @@ export class Scope { block: boolean; declarations: Map = new Map(); - writable_declarations: Set = new Set(); initialised_declarations: Set = new Set(); constructor(parent: Scope, block: boolean) { @@ -72,13 +71,11 @@ export class Scope { if (node.kind === 'var' && this.block && this.parent) { this.parent.addDeclaration(node); } else if (node.type === 'VariableDeclaration') { - const writable = node.kind !== 'const'; const initialised = !!node.init; node.declarations.forEach((declarator: Node) => { extractNames(declarator.id).forEach(name => { this.declarations.set(name, node); - if (writable) this.writable_declarations.add(name); if (initialised) this.initialised_declarations.add(name); }); });