remove initialised_declarations

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

@ -64,7 +64,6 @@ export default class Component {
javascript: string; javascript: string;
declarations: string[] = []; declarations: string[] = [];
initialised_declarations: Set<string> = new Set();
imported_declarations: Set<string> = new Set(); imported_declarations: Set<string> = new Set();
hoistable_names: Set<string> = new Set(); hoistable_names: Set<string> = new Set();
hoistable_nodes: Set<Node> = new Set(); hoistable_nodes: Set<Node> = new Set();
@ -153,13 +152,9 @@ export default class Component {
this.add_var({ this.add_var({
name, name,
kind: 'injected', kind: 'injected',
import_type: null,
imported_as: null,
exported_as: name, exported_as: name,
source: null,
mutated: true, // TODO kind of a misnomer... it's *mutable* but not necessarily *mutated*. is that a problem? mutated: true, // TODO kind of a misnomer... it's *mutable* but not necessarily *mutated*. is that a problem?
referenced: true, referenced: true,
module: false,
writable: true writable: true
}); });
}); });
@ -180,11 +175,6 @@ export default class Component {
this.add_var({ this.add_var({
name, name,
kind: 'injected', kind: 'injected',
import_type: null,
imported_as: null,
source: null,
exported_as: null,
module: false,
mutated: true, mutated: true,
referenced: true, referenced: true,
writable: name[0] !== '$' writable: name[0] !== '$'
@ -442,11 +432,7 @@ export default class Component {
imported_as, imported_as,
import_type, import_type,
source: node.source.value, source: node.source.value,
exported_as: null,
module: is_module, module: is_module,
mutated: false,
referenced: false,
writable: false
}); });
this.imported_declarations.add(specifier.local.name); this.imported_declarations.add(specifier.local.name);
@ -476,14 +462,11 @@ export default class Component {
this.add_var({ this.add_var({
name, name,
kind, kind,
import_type: null,
imported_as: null,
exported_as: name, exported_as: name,
source: null,
module: is_module, module: is_module,
mutated: !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({ this.add_var({
name, name,
kind, kind,
import_type: null,
imported_as: null,
exported_as: name, exported_as: name,
source: null,
module: is_module, module: is_module,
mutated: !is_module, mutated: !is_module,
referenced: false, initialised: true
writable: false
}); });
} }
@ -598,15 +577,7 @@ export default class Component {
this.add_var({ this.add_var({
name, name,
kind, kind
import_type: null,
imported_as: null,
exported_as: null,
source: null,
module: false,
mutated: false,
referenced: false,
writable: false
}); });
this.declarations.push(name); this.declarations.push(name);
@ -652,14 +623,7 @@ export default class Component {
this.add_var({ this.add_var({
name, name,
kind, kind,
import_type: null, initialised: instance_scope.initialised_declarations.has(name)
imported_as: null,
exported_as: null,
source: null,
module: false,
mutated: false,
referenced: false,
writable: false
}); });
this.declarations.push(name); this.declarations.push(name);
@ -668,20 +632,10 @@ export default class Component {
this.node_for_declaration.set(name, node); this.node_for_declaration.set(name, node);
}); });
this.initialised_declarations = instance_scope.initialised_declarations;
globals.forEach(name => { globals.forEach(name => {
this.add_var({ this.add_var({
name, name,
kind: 'global', kind: 'global'
import_type: null,
imported_as: null,
source: null,
exported_as: null,
module: false,
mutated: false,
referenced: false,
writable: false
}); });
}); });

@ -130,17 +130,15 @@ export default function dom(
if (component.options.dev) { if (component.options.dev) {
// TODO check no uunexpected props were passed, as well as // TODO check no uunexpected props were passed, as well as
// checking that expected ones were passed // checking that expected ones were passed
const expected = props const expected = props.filter(prop => !prop.initialised);
.map(x => x.name)
.filter(name => !component.initialised_declarations.has(name));
if (expected.length) { if (expected.length) {
dev_props_check = deindent` dev_props_check = deindent`
const { ctx } = this.$$; const { ctx } = this.$$;
const props = ${options.customElement ? `this.attributes` : `options.props || {}`}; const props = ${options.customElement ? `this.attributes` : `options.props || {}`};
${expected.map(name => deindent` ${expected.map(prop => deindent`
if (ctx.${name} === undefined && !('${name}' in props)) { if (ctx.${prop.name} === undefined && !('${prop.exported_as}' in props)) {
console.warn("<${component.tag}> was created without expected prop '${name}'"); console.warn("<${component.tag}> was created without expected prop '${prop.exported_as}'");
}`)} }`)}
`; `;
} }

@ -82,12 +82,13 @@ export interface AppendTarget {
export interface Var { export interface Var {
name: string; name: string;
kind: 'let' | 'var' | 'const' | 'class' | 'function' | 'import' | 'injected' | 'global'; kind: 'let' | 'var' | 'const' | 'class' | 'function' | 'import' | 'injected' | 'global';
import_type: 'default' | 'named' | 'namespace'; import_type?: 'default' | 'named' | 'namespace';
imported_as: string; // the `foo` in `import { foo as bar }` imported_as?: string; // the `foo` in `import { foo as bar }`
exported_as: string; // the `bar` in `export { foo as bar }` exported_as?: string; // the `bar` in `export { foo as bar }`
source: string; source?: string;
module: boolean; module?: boolean;
mutated: boolean; mutated?: boolean;
referenced: boolean; referenced?: boolean;
writable: boolean; writable?: boolean;
initialised?: boolean;
} }
Loading…
Cancel
Save