diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 6e4b09c773..aad7cfe69e 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -233,12 +233,6 @@ export default class Component { return this.aliases.get(name); } - helper(name: string) { - const alias = this.alias(name); - this.helpers.set(name, alias); - return alias; - } - global(name: string) { const alias = this.alias(name); this.globals.set(name, alias); @@ -276,7 +270,8 @@ export default class Component { } } - const alias = this.helper(name); + const alias = this.alias(name); + this.helpers.set(name, alias); node.name = alias.name; } } @@ -303,7 +298,7 @@ export default class Component { ([name, alias]) => name !== alias.name && { name, alias } ).filter(Boolean); if (referenced_globals.length) { - this.helper('globals'); + this.helpers.set('globals', this.alias('globals')); } const imported_helpers = Array.from(this.helpers, ([name, alias]) => ({ name, diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 7e6aa2804b..2981741fa0 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -676,7 +676,6 @@ export default class Element extends Node { if (modifier === 'passive') { if (passive_events.has(handler.name)) { - console.log('here', handler.name, handler.can_make_passive); if (handler.can_make_passive) { component.warn(handler, { code: 'redundant-event-modifier', diff --git a/src/compiler/compile/render_dom/Block.ts b/src/compiler/compile/render_dom/Block.ts index fc501143d1..f73212f3ba 100644 --- a/src/compiler/compile/render_dom/Block.ts +++ b/src/compiler/compile/render_dom/Block.ts @@ -130,7 +130,6 @@ export default class Block { const wrapper = this.wrappers[i]; if (!wrapper.var) continue; - // if (wrapper.parent && wrapper.parent.can_use_innerhtml) continue; if (seen.has(wrapper.var.name)) { dupes.add(wrapper.var.name); @@ -375,9 +374,6 @@ export default class Block { d: ${properties.destroy} }`; - // TODO should code-red do this automatically? probably - return_value.properties = return_value.properties.filter(prop => prop.value); - const body = b` ${Array.from(this.variables.values()).map(({ id, init }) => { return init @@ -447,15 +443,4 @@ export default class Block { } } } - - // toString() { - // const local_key = this.key && this.get_unique_name('key'); - - // return deindent` - // ${this.comment && `// ${escape(this.comment, { only_escape_at_symbol: true })}`} - // function ${this.name}(${this.key ? `${local_key}, ` : ''}ctx) { - // ${this.get_contents(local_key)} - // } - // `; - // } } \ No newline at end of file diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index a972baf5c8..1186f1b483 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -228,13 +228,11 @@ export default function dom( return b`${`$$subscribe_${name}`}()`; } - const component_subscribe = component.helper('component_subscribe'); - const callback = x`$$value => { ${value} = $$value; $$invalidate('${value}', ${value}) }`; + const callback = x`$$value => { $$invalidate('${value}', ${value} = $$value) }`; - let insert = b`${component_subscribe}($$self, ${name}, $${callback})`; + let insert = b`@component_subscribe($$self, ${name}, $${callback})`; if (component.compile_options.dev) { - const validate_store = component.helper('validate_store'); - insert = b`${validate_store}(${name}, '${name}'); ${insert}`; + insert = b`@validate_store(${name}, '${name}'); ${insert}`; } return insert; @@ -260,7 +258,7 @@ export default function dom( .filter(v => ((v.referenced || v.export_name) && !v.hoistable)) .map(v => p`${v.name}`); - if (uses_props) filtered_declarations.push(p`$$props: $$props = ${component.helper('exclude_internal_props')}($$props)`); + if (uses_props) filtered_declarations.push(p`$$props: $$props = @exclude_internal_props($$props)`); const filtered_props = props.filter(prop => { const variable = component.var_lookup.get(prop.name); diff --git a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts index 0497ca5d56..aa3e775d72 100644 --- a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts @@ -149,9 +149,6 @@ export default class AwaitBlockWrapper extends Wrapper { blocks: ${this.pending.block.has_outro_method && x`[,,,]`} }`; - // TODO move this into code-red - info_props.properties = info_props.properties.filter(prop => prop.value); - block.chunks.init.push(b` let ${info} = ${info_props}; `); diff --git a/src/compiler/compile/render_ssr/handlers/Element.ts b/src/compiler/compile/render_ssr/handlers/Element.ts index 2e24b0e471..762152f4d5 100644 --- a/src/compiler/compile/render_ssr/handlers/Element.ts +++ b/src/compiler/compile/render_ssr/handlers/Element.ts @@ -70,20 +70,6 @@ export default function(node: Element, renderer: Renderer, options: RenderOption renderer.add_string(`<${node.name}`); - // if (slot && nearest_inline_component) { - // const slot = node.attributes.find((attribute) => attribute.name === 'slot'); - // const slot_name = (slot.chunks[0] as Text).data; - - // const lets = node.lets; - // const seen = new Set(lets.map(l => l.name.name)); - - // nearest_inline_component.lets.forEach(l => { - // if (!seen.has(l.name.name)) lets.push(l); - // }); - - // options.slot_scopes.set(slot_name, get_slot_scope(node.lets)); - // } - const class_expression = node.classes.length > 0 && node.classes .map((class_directive: Class) => { const { expression, name } = class_directive; diff --git a/src/compiler/compile/render_ssr/index.ts b/src/compiler/compile/render_ssr/index.ts index e20e95dbd4..d193508a89 100644 --- a/src/compiler/compile/render_ssr/index.ts +++ b/src/compiler/compile/render_ssr/index.ts @@ -49,12 +49,9 @@ export default function ssr( component.rewrite_props(({ name }) => { const value = `$${name}`; - const get_store_value = component.helper('get_store_value'); - - let insert = b`${value} = ${get_store_value}(${name})`; + let insert = b`${value} = @get_store_value(${name})`; if (component.compile_options.dev) { - const validate_store = component.helper('validate_store'); - insert = b`${validate_store}(${name}, '${name}'); ${insert}`; + insert = b`@validate_store(${name}, '${name}'); ${insert}`; } return insert; @@ -135,8 +132,7 @@ export default function ssr( const store_name = name.slice(1); const store = component.var_lookup.get(store_name); if (store && store.hoistable) { - const get_store_value = component.helper('get_store_value'); - return b`let ${name} = ${get_store_value}(${store_name});`; + return b`let ${name} = @get_store_value(${store_name});`; } return b`let ${name};`; }), diff --git a/src/compiler/compile/utils/deindent.ts b/src/compiler/compile/utils/deindent.ts deleted file mode 100644 index f9fd49ca47..0000000000 --- a/src/compiler/compile/utils/deindent.ts +++ /dev/null @@ -1,53 +0,0 @@ -const start = /\n(\t+)/; - -export default function deindent( - strings: TemplateStringsArray, - ...values: any[] -) { - const indentation = start.exec(strings[0])[1]; - const pattern = new RegExp(`^${indentation}`, 'gm'); - - let result = strings[0].replace(start, '').replace(pattern, ''); - - let current_indentation = get_current_indentation(result); - - for (let i = 1; i < strings.length; i += 1) { - let expression = values[i - 1]; - const string = strings[i].replace(pattern, ''); - - if (Array.isArray(expression)) { - expression = expression.length ? expression.join('\n') : null; - } - - // discard empty codebuilders - if (expression && expression.is_empty && expression.is_empty()) { - expression = null; - } - - if (expression || expression === '') { - const value = String(expression).replace( - /\n/g, - `\n${current_indentation}` - ); - result += value + string; - } else { - let c = result.length; - while (/\s/.test(result[c - 1])) c -= 1; - result = result.slice(0, c) + string; - } - - current_indentation = get_current_indentation(result); - } - - return result.trim().replace(/\t+$/gm, '').replace(/{\n\n/gm, '{\n'); -} - -function get_current_indentation(str: string) { - let a = str.length; - while (a > 0 && str[a - 1] !== '\n') a -= 1; - - let b = a; - while (b < str.length && /\s/.test(str[b])) b += 1; - - return str.slice(a, b); -} diff --git a/test/helpers.js b/test/helpers.js index 480b28948b..6ac20eed8b 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -199,47 +199,6 @@ export function showOutput(cwd, options = {}, compile = svelte.compile) { }); } -const start = /\n(\t+)/; -export function deindent(strings, ...values) { - const indentation = start.exec(strings[0])[1]; - const pattern = new RegExp(`^${indentation}`, 'gm'); - - let result = strings[0].replace(start, '').replace(pattern, ''); - - let trailingIndentation = getTrailingIndentation(result); - - for (let i = 1; i < strings.length; i += 1) { - let expression = values[i - 1]; - const string = strings[i].replace(pattern, ''); - - if (Array.isArray(expression)) { - expression = expression.length ? expression.join('\n') : null; - } - - if (expression || expression === '') { - const value = String(expression).replace( - /\n/g, - `\n${trailingIndentation}` - ); - result += value + string; - } else { - let c = result.length; - while (/\s/.test(result[c - 1])) c -= 1; - result = result.slice(0, c) + string; - } - - trailingIndentation = getTrailingIndentation(result); - } - - return result.trim().replace(/\t+$/gm, ''); -} - -function getTrailingIndentation(str) { - let i = str.length; - while (str[i - 1] === ' ' || str[i - 1] === '\t') i -= 1; - return str.slice(i, str.length); -} - export function spaces(i) { let result = ''; while (i--) result += ' ';