diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 032358b151..6e4b09c773 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -260,18 +260,8 @@ export default class Component { walk(program, { enter: (node, parent, key) => { - if (node.type === 'Identifier' && !('name' in node)) { - console.log(node); - throw new Error('this should never happen'); // TODO remove once satisfied - } - if (node.type === 'Identifier') { if (node.name[0] === '@') { - // TODO temp - if (!/@\w+$/.test(node.name)) { - throw new Error(`wut "${node.name}"`); - } - if (node.name[1] === '_') { const alias = this.global(node.name.slice(2)); node.name = alias.name; @@ -303,11 +293,6 @@ export default class Component { parent.property = literal; parent.computed = true; } - - else { - console.log(node); - throw new Error('this should never happen'); // TODO remove once satisfied - } } } } @@ -853,8 +838,6 @@ export default class Component { if (node.type === 'VariableDeclaration') { if (node.kind === 'var' || scope === instance_scope) { node.declarations.forEach(declarator => { - // const next = node.declarations[i + 1]; - if (declarator.id.type !== 'Identifier') { const inserts = []; diff --git a/src/compiler/compile/create_module.ts b/src/compiler/compile/create_module.ts index df85c276ea..76e68e758f 100644 --- a/src/compiler/compile/create_module.ts +++ b/src/compiler/compile/create_module.ts @@ -23,10 +23,8 @@ export default function create_module( ) { const internal_path = `${sveltePath}/internal`; - helpers.sort((a, b) => { - if (a.name < b.name) return -1; - return 1; - }); + helpers.sort((a, b) => (a.name < b.name) ? -1 : 1); + globals.sort((a, b) => (a.name < b.name) ? -1 : 1); if (format === 'esm') { return esm(program, name, banner, sveltePath, internal_path, helpers, globals, imports, module_exports); @@ -71,7 +69,7 @@ function esm( type: 'VariableDeclarator', id: { type: 'ObjectPattern', - properties: globals.sort((a, b) => a.name < b.name ? -1 : 1).map(g => ({ + properties: globals.map(g => ({ type: 'Property', method: false, shorthand: false, @@ -129,7 +127,7 @@ function cjs( type: 'VariableDeclarator', id: { type: 'ObjectPattern', - properties: helpers.sort((a, b) => a.name < b.name ? -1 : 1).map(h => ({ + properties: helpers.map(h => ({ type: 'Property', method: false, shorthand: false, @@ -150,7 +148,7 @@ function cjs( type: 'VariableDeclarator', id: { type: 'ObjectPattern', - properties: globals.sort((a, b) => a.name < b.name ? -1 : 1).map(g => ({ + properties: globals.map(g => ({ type: 'Property', method: false, shorthand: false, diff --git a/src/compiler/compile/nodes/Attribute.ts b/src/compiler/compile/nodes/Attribute.ts index 5bedc21838..c09f9c3074 100644 --- a/src/compiler/compile/nodes/Attribute.ts +++ b/src/compiler/compile/nodes/Attribute.ts @@ -20,8 +20,6 @@ export default class Attribute extends Node { is_spread: boolean; is_true: boolean; is_static: boolean; - // TODO apparently unnecessary? - // is_synthetic: boolean; expression?: Expression; chunks: Array; dependencies: Set; @@ -34,7 +32,6 @@ export default class Attribute extends Node { this.name = null; this.is_spread = true; this.is_true = false; - // this.is_synthetic = false; this.expression = new Expression(component, this, scope, info.expression); this.dependencies = this.expression.dependencies; @@ -47,7 +44,6 @@ export default class Attribute extends Node { this.name = info.name; this.is_true = info.value === true; this.is_static = true; - // this.is_synthetic = info.synthetic; this.dependencies = new Set(); diff --git a/src/compiler/compile/nodes/Binding.ts b/src/compiler/compile/nodes/Binding.ts index 8fc983254b..969232a17c 100644 --- a/src/compiler/compile/nodes/Binding.ts +++ b/src/compiler/compile/nodes/Binding.ts @@ -5,7 +5,6 @@ import Component from '../Component'; import TemplateScope from './shared/TemplateScope'; import {dimensions} from "../../utils/patterns"; import { Node as ESTreeNode } from 'estree'; -import { x } from 'code-red'; // TODO this should live in a specific binding const read_only_media_attributes = new Set([ @@ -21,8 +20,6 @@ export default class Binding extends Node { expression: Expression; raw_expression: ESTreeNode; // TODO exists only for bind:this — is there a more elegant solution? is_contextual: boolean; - obj: string; - prop: string; is_readonly: boolean; constructor(component: Component, parent, scope: TemplateScope, info) { @@ -39,9 +36,6 @@ export default class Binding extends Node { this.expression = new Expression(component, this, scope, info.expression); this.raw_expression = JSON.parse(JSON.stringify(info.expression)); - let obj; - let prop; - const { name } = get_object(this.expression.node); this.is_contextual = scope.names.has(name); @@ -67,18 +61,6 @@ export default class Binding extends Node { variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true; } - if (this.expression.node.type === 'MemberExpression') { - prop = `[✂${this.expression.node.property.start}-${this.expression.node.property.end}✂]`; - if (!this.expression.node.computed) prop = `'${prop}'`; - obj = `[✂${this.expression.node.object.start}-${this.expression.node.object.end}✂]`; - } else { - obj = x`#ctx`; - prop = x`'${name}'`; - } - - this.obj = obj; - this.prop = prop; - const type = parent.get_static_attribute_value('type'); this.is_readonly = ( diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts index 99d063a98d..f69ff07410 100644 --- a/src/compiler/compile/nodes/shared/Expression.ts +++ b/src/compiler/compile/nodes/shared/Expression.ts @@ -9,7 +9,7 @@ import TemplateScope from './TemplateScope'; import get_object from '../../utils/get_object'; import Block from '../../render_dom/Block'; import is_dynamic from '../../render_dom/wrappers/shared/is_dynamic'; -import { x, b } from 'code-red'; +import { x, b, p } from 'code-red'; import { invalidate } from '../../utils/invalidate'; import { Node, FunctionExpression } from 'estree'; import { TemplateNode } from '../../../interfaces'; @@ -29,9 +29,6 @@ export default class Expression { scope: Scope; scope_map: WeakMap; - // TODO apparently unnecessary? - // is_synthetic: boolean; - declarations: Array<(Node | Node[])> = []; uses_context = false; @@ -49,8 +46,6 @@ export default class Expression { this.node = info; this.template_scope = template_scope; this.owner = owner; - // @ts-ignore - // this.is_synthetic = owner.is_synthetic; const { dependencies, contextual_dependencies } = this; @@ -253,7 +248,6 @@ export default class Expression { if (dependencies.size === 0 && contextual_dependencies.size === 0) { // we can hoist this out of the component completely component.fully_hoisted.push(declaration); - // node.name = id; this.replace(id as any); @@ -268,7 +262,6 @@ export default class Expression { else if (contextual_dependencies.size === 0) { // function can be hoisted inside the component init component.partly_hoisted.push(declaration); - // node.name = id; this.replace(x`#ctx.${id}` as any); @@ -283,19 +276,10 @@ export default class Expression { // we need a combo block/init recipe (node as FunctionExpression).params.unshift({ type: 'ObjectPattern', - properties: Array.from(contextual_dependencies).map(name => ({ - type: 'Property', - kind: 'init', - method: false, - shorthand: false, - computed: false, - key: { type: 'Identifier', name }, - value: { type: 'Identifier', name } - })) + properties: Array.from(contextual_dependencies).map(name => p`${name}` as any) }); component.partly_hoisted.push(declaration); - // node.name = id; this.replace(id as any); diff --git a/src/compiler/compile/render_ssr/index.ts b/src/compiler/compile/render_ssr/index.ts index f63b73d564..e20e95dbd4 100644 --- a/src/compiler/compile/render_ssr/index.ts +++ b/src/compiler/compile/render_ssr/index.ts @@ -46,9 +46,6 @@ export default function ssr( }) .filter(Boolean); - // TODO remove this, just use component.vars everywhere - const props = component.vars.filter(variable => !variable.module && variable.export_name); - component.rewrite_props(({ name }) => { const value = `$${name}`; @@ -67,9 +64,11 @@ export default function ssr( // TODO only do this for props with a default value const parent_bindings = instance_javascript - ? props.map(prop => { - return b`if ($$props.${prop.export_name} === void 0 && $$bindings.${prop.export_name} && ${prop.name} !== void 0) $$bindings.${prop.export_name}(${prop.name});`; - }) + ? component.vars + .filter(variable => !variable.module && variable.export_name) + .map(prop => { + return b`if ($$props.${prop.export_name} === void 0 && $$bindings.${prop.export_name} && ${prop.name} !== void 0) $$bindings.${prop.export_name}(${prop.name});`; + }) : []; const reactive_declarations = component.reactive_declarations.map(d => { diff --git a/src/compiler/compile/utils/flatten_reference.ts b/src/compiler/compile/utils/flatten_reference.ts index 9ea42fd00a..e0d05ee7c4 100644 --- a/src/compiler/compile/utils/flatten_reference.ts +++ b/src/compiler/compile/utils/flatten_reference.ts @@ -1,11 +1,6 @@ import { Node, Identifier } from 'estree'; export default function flatten_reference(node: Node) { - // TODO temporary (#3539) - if ((node as any).type === 'Expression') { - throw new Error('flatten_reference bad'); - } - const nodes = []; const parts = []; diff --git a/test/runtime/index.js b/test/runtime/index.js index 22ffcc36b3..646eeb99b6 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -65,7 +65,6 @@ describe("runtime", () => { unhandled_rejection = null; - config.preserveIdentifiers = true; // TODO remove later compile = (config.preserveIdentifiers ? svelte : svelte$).compile; const cwd = path.resolve(`test/runtime/samples/${dir}`);