diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 7a98eec6cb..ed030a055e 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -62,8 +62,6 @@ export default class Component { namespace: string; tag: string; - properties: Map; - instance_script: Node; module_script: Node; @@ -72,10 +70,10 @@ export default class Component { javascript: string; declarations: string[] = []; + props: Array<{ name: string, as: string }> = []; writable_declarations: Set = new Set(); initialised_declarations: Set = new Set(); node_for_declaration: Map = new Map(); - exports: Array<{ name: string, as: string }> = []; module_exports: Array<{ name: string, as: string }> = []; partly_hoisted: string[] = []; fully_hoisted: string[] = []; @@ -98,7 +96,6 @@ export default class Component { stylesheet: Stylesheet; userVars: Set = new Set(); - templateVars: Map = new Map(); aliases: Map = new Map(); usedNames: Set = new Set(); @@ -126,8 +123,6 @@ export default class Component { this.stylesheet = new Stylesheet(source, ast, options.filename, options.dev); this.stylesheet.validate(this); - 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'); @@ -158,7 +153,7 @@ export default class Component { this.declarations.push(...props); addToSet(this.writable_declarations, this.template_references); - this.exports = props.map(name => ({ + this.props = props.map(name => ({ name, as: name })); @@ -182,12 +177,11 @@ export default class Component { return this.aliases.get(name); } - generate(result: string, options: CompileOptions, { - banner = '', - name, - format - }) { - const pattern = /\[✂(\d+)-(\d+)$/; + generate(result: string) { + const { options, name } = this; + const { format = 'esm' } = options; + + const banner = `/* ${this.file ? `${this.file} ` : ``}generated by Svelte v${"__VERSION__"} */`; const helpers = new Set(); @@ -248,6 +242,8 @@ export default class Component { }); } + const pattern = /\[✂(\d+)-(\d+)$/; + parts.forEach((str: string) => { const chunk = str.replace(pattern, ''); if (chunk) addString(chunk); @@ -528,7 +524,7 @@ export default class Component { this.userVars.add(name); }); - this.extract_imports_and_exports(script.content, this.imports, this.exports); + this.extract_imports_and_exports(script.content, this.imports, this.props); this.javascript = this.extract_javascript(script); } diff --git a/src/compile/index.ts b/src/compile/index.ts index ec1243b10d..1802d56df4 100644 --- a/src/compile/index.ts +++ b/src/compile/index.ts @@ -77,9 +77,5 @@ export default function compile(source: string, options: CompileOptions = {}) { ? renderSSR(component, options) : renderDOM(component, options); - return component.generate(`${js}`, options, { - banner: `/* ${component.file ? `${component.file} ` : ``}generated by Svelte v${"__VERSION__"} */`, - name: component.name, - format: options.format || 'esm' - }); + return component.generate(js); } \ No newline at end of file diff --git a/src/compile/nodes/EventHandler.ts b/src/compile/nodes/EventHandler.ts index 923f0e5f41..d98dd9859c 100644 --- a/src/compile/nodes/EventHandler.ts +++ b/src/compile/nodes/EventHandler.ts @@ -38,12 +38,6 @@ export default class EventHandler extends Node { `); this.handler_name = name; - - Object.defineProperty(this, 'snippet', { - get: () => { - throw new Error('here'); - } - }); } } diff --git a/src/compile/render-dom/Renderer.ts b/src/compile/render-dom/Renderer.ts index d83e415f3b..28a8a90dfb 100644 --- a/src/compile/render-dom/Renderer.ts +++ b/src/compile/render-dom/Renderer.ts @@ -17,7 +17,6 @@ export default class Renderer { block: Block; fragment: FragmentWrapper; - usedNames: Set; fileVar: string; hasIntroTransitions: boolean; @@ -31,7 +30,6 @@ export default class Renderer { this.readonly = new Set(); this.slots = new Set(); - this.usedNames = new Set(); this.fileVar = options.dev && this.component.getUniqueName('file'); // initial values for e.g. window.innerWidth, if there's a meta tag diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 09564f0a84..319b3b4b0b 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -69,7 +69,7 @@ export default function dom( options.css !== false ); - const props = component.exports.filter(x => component.writable_declarations.has(x.name)); + const props = component.props.filter(x => component.writable_declarations.has(x.name)); const set = component.meta.props || props.length > 0 ? deindent` @@ -98,7 +98,7 @@ export default function dom( const not_equal = component.options.immutable ? `@not_equal` : `@safe_not_equal`; let dev_props_check; - component.exports.forEach(x => { + component.props.forEach(x => { body.push(deindent` get ${x.as}() { return this.$$.get().${x.name}; @@ -124,7 +124,7 @@ 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 = component.exports + const expected = component.props .map(x => x.name) .filter(name => !component.initialised_declarations.has(name)); @@ -181,7 +181,7 @@ export default function dom( ${should_add_css && `if (!document.getElementById("${component.stylesheet.id}-style")) @add_css();`} - ${component.javascript || component.exports.map(x => `let ${x.name};`)} + ${component.javascript || component.props.map(x => `let ${x.name};`)} ${component.partly_hoisted.length > 0 && component.partly_hoisted.join('\n\n')} @@ -219,7 +219,7 @@ export default function dom( } static get observedAttributes() { - return ${JSON.stringify(component.exports.map(x => x.as))}; + return ${JSON.stringify(component.props.map(x => x.as))}; } ${body.join('\n\n')} diff --git a/src/compile/render-dom/wrappers/InlineComponent/index.ts b/src/compile/render-dom/wrappers/InlineComponent/index.ts index c7111873c4..c74ad0a571 100644 --- a/src/compile/render-dom/wrappers/InlineComponent/index.ts +++ b/src/compile/render-dom/wrappers/InlineComponent/index.ts @@ -96,7 +96,7 @@ export default class InlineComponentWrapper extends Wrapper { const updates: string[] = []; const postupdates: string[] = []; - const name_initial_data = block.getUniqueName(`${name}_initial_data`); + const props = block.getUniqueName(`${name}_props`); const name_changes = block.getUniqueName(`${name}_changes`); const usesSpread = !!this.node.attributes.find(a => a.isSpread); @@ -108,7 +108,7 @@ export default class InlineComponentWrapper extends Wrapper { ); if (this.node.attributes.length || this.node.bindings.length) { - componentInitProperties.push(`props: ${name_initial_data}`); + componentInitProperties.push(`props: ${props}`); } if (component.options.dev) { @@ -166,7 +166,7 @@ export default class InlineComponentWrapper extends Wrapper { statements.push(deindent` for (var #i = 0; #i < ${levels}.length; #i += 1) { - ${name_initial_data} = @assign(${name_initial_data}, ${levels}[#i]); + ${props} = @assign(${props}, ${levels}[#i]); } `); @@ -203,7 +203,7 @@ export default class InlineComponentWrapper extends Wrapper { statements.push(deindent` if (${snippet} !== void 0) { - ${name_initial_data}${quotePropIfNecessary(binding.name)} = ${snippet}; + ${props}${quotePropIfNecessary(binding.name)} = ${snippet}; }` ); @@ -286,7 +286,7 @@ export default class InlineComponentWrapper extends Wrapper { function ${switch_props}(ctx) { ${(this.node.attributes.length || this.node.bindings.length) && deindent` - var ${name_initial_data} = ${attributeObject};`} + var ${props} = ${attributeObject};`} ${statements} return { ${componentInitProperties.join(',\n')} @@ -380,7 +380,7 @@ export default class InlineComponentWrapper extends Wrapper { block.builders.init.addBlock(deindent` ${(this.node.attributes.length || this.node.bindings.length) && deindent` - var ${name_initial_data} = ${attributeObject};`} + var ${props} = ${attributeObject};`} ${statements} var ${name} = new ${expression}({ ${componentInitProperties.join(',\n')}