delete some junk

pull/3539/head
Richard Harris 6 years ago
parent 7cbb65878b
commit 0982fea5ac

@ -260,18 +260,8 @@ export default class Component {
walk(program, { walk(program, {
enter: (node, parent, key) => { 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.type === 'Identifier') {
if (node.name[0] === '@') { if (node.name[0] === '@') {
// TODO temp
if (!/@\w+$/.test(node.name)) {
throw new Error(`wut "${node.name}"`);
}
if (node.name[1] === '_') { if (node.name[1] === '_') {
const alias = this.global(node.name.slice(2)); const alias = this.global(node.name.slice(2));
node.name = alias.name; node.name = alias.name;
@ -303,11 +293,6 @@ export default class Component {
parent.property = literal; parent.property = literal;
parent.computed = true; 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.type === 'VariableDeclaration') {
if (node.kind === 'var' || scope === instance_scope) { if (node.kind === 'var' || scope === instance_scope) {
node.declarations.forEach(declarator => { node.declarations.forEach(declarator => {
// const next = node.declarations[i + 1];
if (declarator.id.type !== 'Identifier') { if (declarator.id.type !== 'Identifier') {
const inserts = []; const inserts = [];

@ -23,10 +23,8 @@ export default function create_module(
) { ) {
const internal_path = `${sveltePath}/internal`; const internal_path = `${sveltePath}/internal`;
helpers.sort((a, b) => { helpers.sort((a, b) => (a.name < b.name) ? -1 : 1);
if (a.name < b.name) return -1; globals.sort((a, b) => (a.name < b.name) ? -1 : 1);
return 1;
});
if (format === 'esm') { if (format === 'esm') {
return esm(program, name, banner, sveltePath, internal_path, helpers, globals, imports, module_exports); return esm(program, name, banner, sveltePath, internal_path, helpers, globals, imports, module_exports);
@ -71,7 +69,7 @@ function esm(
type: 'VariableDeclarator', type: 'VariableDeclarator',
id: { id: {
type: 'ObjectPattern', type: 'ObjectPattern',
properties: globals.sort((a, b) => a.name < b.name ? -1 : 1).map(g => ({ properties: globals.map(g => ({
type: 'Property', type: 'Property',
method: false, method: false,
shorthand: false, shorthand: false,
@ -129,7 +127,7 @@ function cjs(
type: 'VariableDeclarator', type: 'VariableDeclarator',
id: { id: {
type: 'ObjectPattern', type: 'ObjectPattern',
properties: helpers.sort((a, b) => a.name < b.name ? -1 : 1).map(h => ({ properties: helpers.map(h => ({
type: 'Property', type: 'Property',
method: false, method: false,
shorthand: false, shorthand: false,
@ -150,7 +148,7 @@ function cjs(
type: 'VariableDeclarator', type: 'VariableDeclarator',
id: { id: {
type: 'ObjectPattern', type: 'ObjectPattern',
properties: globals.sort((a, b) => a.name < b.name ? -1 : 1).map(g => ({ properties: globals.map(g => ({
type: 'Property', type: 'Property',
method: false, method: false,
shorthand: false, shorthand: false,

@ -20,8 +20,6 @@ export default class Attribute extends Node {
is_spread: boolean; is_spread: boolean;
is_true: boolean; is_true: boolean;
is_static: boolean; is_static: boolean;
// TODO apparently unnecessary?
// is_synthetic: boolean;
expression?: Expression; expression?: Expression;
chunks: Array<Text | Expression>; chunks: Array<Text | Expression>;
dependencies: Set<string>; dependencies: Set<string>;
@ -34,7 +32,6 @@ export default class Attribute extends Node {
this.name = null; this.name = null;
this.is_spread = true; this.is_spread = true;
this.is_true = false; this.is_true = false;
// this.is_synthetic = false;
this.expression = new Expression(component, this, scope, info.expression); this.expression = new Expression(component, this, scope, info.expression);
this.dependencies = this.expression.dependencies; this.dependencies = this.expression.dependencies;
@ -47,7 +44,6 @@ export default class Attribute extends Node {
this.name = info.name; this.name = info.name;
this.is_true = info.value === true; this.is_true = info.value === true;
this.is_static = true; this.is_static = true;
// this.is_synthetic = info.synthetic;
this.dependencies = new Set(); this.dependencies = new Set();

@ -5,7 +5,6 @@ import Component from '../Component';
import TemplateScope from './shared/TemplateScope'; import TemplateScope from './shared/TemplateScope';
import {dimensions} from "../../utils/patterns"; import {dimensions} from "../../utils/patterns";
import { Node as ESTreeNode } from 'estree'; import { Node as ESTreeNode } from 'estree';
import { x } from 'code-red';
// TODO this should live in a specific binding // TODO this should live in a specific binding
const read_only_media_attributes = new Set([ const read_only_media_attributes = new Set([
@ -21,8 +20,6 @@ export default class Binding extends Node {
expression: Expression; expression: Expression;
raw_expression: ESTreeNode; // TODO exists only for bind:this — is there a more elegant solution? raw_expression: ESTreeNode; // TODO exists only for bind:this — is there a more elegant solution?
is_contextual: boolean; is_contextual: boolean;
obj: string;
prop: string;
is_readonly: boolean; is_readonly: boolean;
constructor(component: Component, parent, scope: TemplateScope, info) { 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.expression = new Expression(component, this, scope, info.expression);
this.raw_expression = JSON.parse(JSON.stringify(info.expression)); this.raw_expression = JSON.parse(JSON.stringify(info.expression));
let obj;
let prop;
const { name } = get_object(this.expression.node); const { name } = get_object(this.expression.node);
this.is_contextual = scope.names.has(name); 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; 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'); const type = parent.get_static_attribute_value('type');
this.is_readonly = ( this.is_readonly = (

@ -9,7 +9,7 @@ import TemplateScope from './TemplateScope';
import get_object from '../../utils/get_object'; import get_object from '../../utils/get_object';
import Block from '../../render_dom/Block'; import Block from '../../render_dom/Block';
import is_dynamic from '../../render_dom/wrappers/shared/is_dynamic'; 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 { invalidate } from '../../utils/invalidate';
import { Node, FunctionExpression } from 'estree'; import { Node, FunctionExpression } from 'estree';
import { TemplateNode } from '../../../interfaces'; import { TemplateNode } from '../../../interfaces';
@ -29,9 +29,6 @@ export default class Expression {
scope: Scope; scope: Scope;
scope_map: WeakMap<Node, Scope>; scope_map: WeakMap<Node, Scope>;
// TODO apparently unnecessary?
// is_synthetic: boolean;
declarations: Array<(Node | Node[])> = []; declarations: Array<(Node | Node[])> = [];
uses_context = false; uses_context = false;
@ -49,8 +46,6 @@ export default class Expression {
this.node = info; this.node = info;
this.template_scope = template_scope; this.template_scope = template_scope;
this.owner = owner; this.owner = owner;
// @ts-ignore
// this.is_synthetic = owner.is_synthetic;
const { dependencies, contextual_dependencies } = this; const { dependencies, contextual_dependencies } = this;
@ -253,7 +248,6 @@ export default class Expression {
if (dependencies.size === 0 && contextual_dependencies.size === 0) { if (dependencies.size === 0 && contextual_dependencies.size === 0) {
// we can hoist this out of the component completely // we can hoist this out of the component completely
component.fully_hoisted.push(declaration); component.fully_hoisted.push(declaration);
// node.name = id;
this.replace(id as any); this.replace(id as any);
@ -268,7 +262,6 @@ export default class Expression {
else if (contextual_dependencies.size === 0) { else if (contextual_dependencies.size === 0) {
// function can be hoisted inside the component init // function can be hoisted inside the component init
component.partly_hoisted.push(declaration); component.partly_hoisted.push(declaration);
// node.name = id;
this.replace(x`#ctx.${id}` as any); this.replace(x`#ctx.${id}` as any);
@ -283,19 +276,10 @@ export default class Expression {
// we need a combo block/init recipe // we need a combo block/init recipe
(node as FunctionExpression).params.unshift({ (node as FunctionExpression).params.unshift({
type: 'ObjectPattern', type: 'ObjectPattern',
properties: Array.from(contextual_dependencies).map(name => ({ properties: Array.from(contextual_dependencies).map(name => p`${name}` as any)
type: 'Property',
kind: 'init',
method: false,
shorthand: false,
computed: false,
key: { type: 'Identifier', name },
value: { type: 'Identifier', name }
}))
}); });
component.partly_hoisted.push(declaration); component.partly_hoisted.push(declaration);
// node.name = id;
this.replace(id as any); this.replace(id as any);

@ -46,9 +46,6 @@ export default function ssr(
}) })
.filter(Boolean); .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 }) => { component.rewrite_props(({ name }) => {
const value = `$${name}`; const value = `$${name}`;
@ -67,9 +64,11 @@ export default function ssr(
// TODO only do this for props with a default value // TODO only do this for props with a default value
const parent_bindings = instance_javascript const parent_bindings = instance_javascript
? props.map(prop => { ? component.vars
return b`if ($$props.${prop.export_name} === void 0 && $$bindings.${prop.export_name} && ${prop.name} !== void 0) $$bindings.${prop.export_name}(${prop.name});`; .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 => { const reactive_declarations = component.reactive_declarations.map(d => {

@ -1,11 +1,6 @@
import { Node, Identifier } from 'estree'; import { Node, Identifier } from 'estree';
export default function flatten_reference(node: Node) { 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 nodes = [];
const parts = []; const parts = [];

@ -65,7 +65,6 @@ describe("runtime", () => {
unhandled_rejection = null; unhandled_rejection = null;
config.preserveIdentifiers = true; // TODO remove later
compile = (config.preserveIdentifiers ? svelte : svelte$).compile; compile = (config.preserveIdentifiers ? svelte : svelte$).compile;
const cwd = path.resolve(`test/runtime/samples/${dir}`); const cwd = path.resolve(`test/runtime/samples/${dir}`);

Loading…
Cancel
Save