From d92e0130ea4e2552ae4e67950fb87f33b786cec9 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 27 Jan 2019 22:09:26 -0500 Subject: [PATCH] remove initialised_declarations --- src/compile/Component.ts | 58 ++++----------------------------- src/compile/render-dom/index.ts | 10 +++--- src/interfaces.ts | 17 +++++----- 3 files changed, 19 insertions(+), 66 deletions(-) diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 409d30b137..3bf60fbc46 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -64,7 +64,6 @@ export default class Component { javascript: string; declarations: string[] = []; - initialised_declarations: Set = new Set(); imported_declarations: Set = new Set(); hoistable_names: Set = new Set(); hoistable_nodes: Set = new Set(); @@ -153,13 +152,9 @@ export default class Component { this.add_var({ name, kind: 'injected', - import_type: null, - imported_as: null, exported_as: name, - source: null, mutated: true, // TODO kind of a misnomer... it's *mutable* but not necessarily *mutated*. is that a problem? referenced: true, - module: false, writable: true }); }); @@ -180,11 +175,6 @@ export default class Component { this.add_var({ name, kind: 'injected', - import_type: null, - imported_as: null, - source: null, - exported_as: null, - module: false, mutated: true, referenced: true, writable: name[0] !== '$' @@ -442,11 +432,7 @@ export default class Component { imported_as, import_type, source: node.source.value, - exported_as: null, module: is_module, - mutated: false, - referenced: false, - writable: false }); this.imported_declarations.add(specifier.local.name); @@ -476,14 +462,11 @@ export default class Component { this.add_var({ name, kind, - import_type: null, - imported_as: null, exported_as: name, - source: null, module: is_module, mutated: !is_module, - referenced: false, - writable: kind === 'let' || kind === 'var' + writable: kind === 'let' || kind === 'var', + initialised: !!declarator.init }); }); }); @@ -502,14 +485,10 @@ export default class Component { this.add_var({ name, kind, - import_type: null, - imported_as: null, exported_as: name, - source: null, module: is_module, mutated: !is_module, - referenced: false, - writable: false + initialised: true }); } @@ -598,15 +577,7 @@ export default class Component { this.add_var({ name, - kind, - import_type: null, - imported_as: null, - exported_as: null, - source: null, - module: false, - mutated: false, - referenced: false, - writable: false + kind }); this.declarations.push(name); @@ -652,14 +623,7 @@ export default class Component { this.add_var({ name, kind, - import_type: null, - imported_as: null, - exported_as: null, - source: null, - module: false, - mutated: false, - referenced: false, - writable: false + initialised: instance_scope.initialised_declarations.has(name) }); this.declarations.push(name); @@ -668,20 +632,10 @@ export default class Component { this.node_for_declaration.set(name, node); }); - this.initialised_declarations = instance_scope.initialised_declarations; - globals.forEach(name => { this.add_var({ name, - kind: 'global', - import_type: null, - imported_as: null, - source: null, - exported_as: null, - module: false, - mutated: false, - referenced: false, - writable: false + kind: 'global' }); }); diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 31f42706d4..4f5312bf76 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -130,17 +130,15 @@ export default function dom( if (component.options.dev) { // TODO check no uunexpected props were passed, as well as // checking that expected ones were passed - const expected = props - .map(x => x.name) - .filter(name => !component.initialised_declarations.has(name)); + const expected = props.filter(prop => !prop.initialised); if (expected.length) { dev_props_check = deindent` const { ctx } = this.$$; const props = ${options.customElement ? `this.attributes` : `options.props || {}`}; - ${expected.map(name => deindent` - if (ctx.${name} === undefined && !('${name}' in props)) { - console.warn("<${component.tag}> was created without expected prop '${name}'"); + ${expected.map(prop => deindent` + if (ctx.${prop.name} === undefined && !('${prop.exported_as}' in props)) { + console.warn("<${component.tag}> was created without expected prop '${prop.exported_as}'"); }`)} `; } diff --git a/src/interfaces.ts b/src/interfaces.ts index 7ea66c362c..e511b754d0 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -82,12 +82,13 @@ export interface AppendTarget { export interface Var { name: string; kind: 'let' | 'var' | 'const' | 'class' | 'function' | 'import' | 'injected' | 'global'; - import_type: 'default' | 'named' | 'namespace'; - imported_as: string; // the `foo` in `import { foo as bar }` - exported_as: string; // the `bar` in `export { foo as bar }` - source: string; - module: boolean; - mutated: boolean; - referenced: boolean; - writable: boolean; + import_type?: 'default' | 'named' | 'namespace'; + imported_as?: string; // the `foo` in `import { foo as bar }` + exported_as?: string; // the `bar` in `export { foo as bar }` + source?: string; + module?: boolean; + mutated?: boolean; + referenced?: boolean; + writable?: boolean; + initialised?: boolean; } \ No newline at end of file