remove writable_declarations

pull/2011/head
Richard Harris 7 years ago
parent 238dcc3f88
commit 4d6eabf228

@ -64,7 +64,6 @@ export default class Component {
javascript: string;
declarations: string[] = [];
writable_declarations: Set<string> = new Set();
initialised_declarations: Set<string> = new Set();
imported_declarations: Set<string> = new Set();
hoistable_names: Set<string> = 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
});
});

@ -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} });

@ -89,4 +89,5 @@ export interface Var {
module: boolean;
mutated: boolean;
referenced: boolean;
writable: boolean;
}

@ -60,7 +60,6 @@ export class Scope {
block: boolean;
declarations: Map<string, Node> = new Map();
writable_declarations: Set<string> = new Set();
initialised_declarations: Set<string> = 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);
});
});

Loading…
Cancel
Save