pull/1864/head
Rich Harris 7 years ago
parent 6fd8fbf40b
commit b33f2d8660

@ -60,6 +60,9 @@ export default class Component {
properties: Map<string, Node>; properties: Map<string, Node>;
instance_script: Node;
module_script: Node;
imports: Node[] = []; imports: Node[] = [];
namespace: string; namespace: string;
hasComponents: boolean; hasComponents: boolean;
@ -69,6 +72,7 @@ export default class Component {
declarations: string[] = []; declarations: string[] = [];
writable_declarations: Set<string> = new Set(); writable_declarations: Set<string> = new Set();
initialised_declarations: Set<string> = new Set(); initialised_declarations: Set<string> = new Set();
node_for_declaration: Map<string, Node> = new Map();
exports: Array<{ name: string, as: string }> = []; exports: Array<{ name: string, as: string }> = [];
module_exports: Array<{ name: string, as: string }> = []; module_exports: Array<{ name: string, as: string }> = [];
partly_hoisted: string[] = []; partly_hoisted: string[] = [];
@ -122,6 +126,9 @@ export default class Component {
this.properties = new Map(); this.properties = new Map();
this.module_script = ast.js.find(script => get_context(script) === 'module');
this.instance_script = ast.js.find(script => get_context(script) === 'default');
this.walk_module_js(); this.walk_module_js();
this.walk_instance_js(); this.walk_instance_js();
this.name = this.alias(name); this.name = this.alias(name);
@ -147,7 +154,7 @@ export default class Component {
this.stylesheet.warnOnUnusedSelectors(options.onwarn); this.stylesheet.warnOnUnusedSelectors(options.onwarn);
if (!this.ast.js.find(script => get_context(script) === 'default')) { if (!this.instance_script) {
const props = [...this.expectedProperties]; const props = [...this.expectedProperties];
this.declarations.push(...props); this.declarations.push(...props);
addToSet(this.writable_declarations, this.expectedProperties); addToSet(this.writable_declarations, this.expectedProperties);
@ -425,8 +432,18 @@ export default class Component {
}); });
} }
extract_javascript(script) {
let a = script.content.start;
while (/\s/.test(this.source[a])) a += 1;
let b = script.content.end;
while (/\s/.test(this.source[b - 1])) b -= 1;
return a !== b ? `[✂${a}-${b}✂]` : null;
}
walk_module_js() { walk_module_js() {
const script = this.ast.js.find(script => get_context(script) === 'module'); const script = this.module_script;
if (!script) return; if (!script) return;
this.addSourcemapLocations(script.content); this.addSourcemapLocations(script.content);
@ -434,18 +451,11 @@ export default class Component {
// TODO unindent // TODO unindent
this.extract_imports_and_exports(script.content, this.imports, this.module_exports); this.extract_imports_and_exports(script.content, this.imports, this.module_exports);
this.module_javascript = this.extract_javascript(script);
let a = script.content.start;
while (/\s/.test(this.source[a])) a += 1;
let b = script.content.end;
while (/\s/.test(this.source[b - 1])) b -= 1;
this.module_javascript = a !== b ? `[✂${a}-${b}✂]` : null;
} }
walk_instance_js() { walk_instance_js() {
const script = this.ast.js.find(script => get_context(script) === 'default'); const script = this.instance_script;
if (!script) return; if (!script) return;
this.addSourcemapLocations(script.content); this.addSourcemapLocations(script.content);
@ -501,13 +511,7 @@ export default class Component {
} }
}); });
let a = script.content.start; this.javascript = this.extract_javascript(script);
while (/\s/.test(source[a])) a += 1;
let b = script.content.end;
while (/\s/.test(source[b - 1])) b -= 1;
this.javascript = a !== b ? `[✂${a}-${b}✂]` : '';
} }
instrument(node, parent, name, is_event_handler) { instrument(node, parent, name, is_event_handler) {

Loading…
Cancel
Save