more tidying up

pull/1839/head
Rich Harris 7 years ago
parent f33c5ee8d2
commit ad653c5834

@ -62,8 +62,6 @@ export default class Component {
namespace: string;
tag: string;
properties: Map<string, Node>;
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<string> = new Set();
initialised_declarations: Set<string> = new Set();
node_for_declaration: Map<string, Node> = 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<string> = new Set();
templateVars: Map<string, string> = new Map();
aliases: Map<string, string> = new Map();
usedNames: Set<string> = 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);
}

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

@ -38,12 +38,6 @@ export default class EventHandler extends Node {
`);
this.handler_name = name;
Object.defineProperty(this, 'snippet', {
get: () => {
throw new Error('here');
}
});
}
}

@ -17,7 +17,6 @@ export default class Renderer {
block: Block;
fragment: FragmentWrapper;
usedNames: Set<string>;
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 <svelte:window> meta tag

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

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

Loading…
Cancel
Save