pull/3539/head
Richard Harris 6 years ago
parent bc066d3562
commit 7efcca82cc

@ -22,14 +22,7 @@ module.exports = {
'arrow-spacing': 2, 'arrow-spacing': 2,
'no-inner-declarations': 0, 'no-inner-declarations': 0,
'require-atomic-updates': 'off', 'require-atomic-updates': 'off',
'@typescript-eslint/indent': [ '@typescript-eslint/indent': 'off',
'error',
'tab',
{
SwitchCase: 1,
ignoredNodes: ['TemplateLiteral']
}
],
'@typescript-eslint/camelcase': 'off', '@typescript-eslint/camelcase': 'off',
'@typescript-eslint/no-use-before-define': 'off', '@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/array-type': ['error', 'array-simple'], '@typescript-eslint/array-type': ['error', 'array-simple'],

@ -71,8 +71,8 @@ export default class Component {
hoistable_nodes: Set<Node> = new Set(); hoistable_nodes: Set<Node> = new Set();
node_for_declaration: Map<string, Node> = new Map(); node_for_declaration: Map<string, Node> = new Map();
partly_hoisted: (Node | Node[])[] = []; partly_hoisted: Array<(Node | Node[])> = [];
fully_hoisted: (Node | Node[])[] = []; fully_hoisted: Array<(Node | Node[])> = [];
reactive_declarations: Array<{ reactive_declarations: Array<{
assignees: Set<string>; assignees: Set<string>;
dependencies: Set<string>; dependencies: Set<string>;

@ -62,7 +62,7 @@ function esm(
imported: { type: 'Identifier', name: h.name } imported: { type: 'Identifier', name: h.name }
})), })),
source: { type: 'Literal', value: internal_path } source: { type: 'Literal', value: internal_path }
} };
const internal_globals = globals.length > 0 && { const internal_globals = globals.length > 0 && {
type: 'VariableDeclaration', type: 'VariableDeclaration',

@ -1,4 +1,4 @@
export type CssNode = { export interface CssNode {
type: string; type: string;
start: number; start: number;
end: number; end: number;

@ -37,7 +37,7 @@ function unpack_destructuring(contexts: Context[], node: Node, modifier: (node:
const replacement: RestElement = { const replacement: RestElement = {
type: 'RestElement', type: 'RestElement',
argument: property.key as Identifier argument: property.key as Identifier
} };
node.properties[i] = replacement; node.properties[i] = replacement;

@ -32,7 +32,7 @@ export default class Expression {
// TODO apparently unnecessary? // TODO apparently unnecessary?
// is_synthetic: boolean; // is_synthetic: boolean;
declarations: (Node | Node[])[] = []; declarations: Array<(Node | Node[])> = [];
uses_context = false; uses_context = false;
manipulated: Node; manipulated: Node;

@ -44,18 +44,18 @@ export default class Block {
}>; }>;
chunks: { chunks: {
init: (Node | Node[])[]; init: Array<Node | Node[]>;
create: (Node | Node[])[]; create: Array<Node | Node[]>;
claim: (Node | Node[])[]; claim: Array<Node | Node[]>;
hydrate: (Node | Node[])[]; hydrate: Array<Node | Node[]>;
mount: (Node | Node[])[]; mount: Array<Node | Node[]>;
measure: (Node | Node[])[]; measure: Array<Node | Node[]>;
fix: (Node | Node[])[]; fix: Array<Node | Node[]>;
animate: (Node | Node[])[]; animate: Array<Node | Node[]>;
intro: (Node | Node[])[]; intro: Array<Node | Node[]>;
update: (Node | Node[])[]; update: Array<Node | Node[]>;
outro: (Node | Node[])[]; outro: Array<Node | Node[]>;
destroy: (Node | Node[])[]; destroy: Array<Node | Node[]>;
}; };
event_listeners: Node[] = []; event_listeners: Node[] = [];
@ -69,7 +69,7 @@ export default class Block {
outros: number; outros: number;
aliases: Map<string, Identifier>; aliases: Map<string, Identifier>;
variables: Map<string, { id: Identifier, init?: Node }> = new Map(); variables: Map<string, { id: Identifier; init?: Node }> = new Map();
get_unique_name: (name: string) => Identifier; get_unique_name: (name: string) => Identifier;
has_update_method = false; has_update_method = false;
@ -249,7 +249,7 @@ export default class Block {
const noop = x`@noop`; const noop = x`@noop`;
properties.key = key properties.key = key;
if (this.first) { if (this.first) {
properties.first = x`null`; properties.first = x`null`;

@ -11,7 +11,7 @@ export default class Renderer {
blocks: Array<Block | Node | Node[]> = []; blocks: Array<Block | Node | Node[]> = [];
readonly: Set<string> = new Set(); readonly: Set<string> = new Set();
meta_bindings: (Node | Node[])[] = []; // initial values for e.g. window.innerWidth, if there's a <svelte:window> meta tag meta_bindings: Array<Node | Node[]> = []; // initial values for e.g. window.innerWidth, if there's a <svelte:window> meta tag
binding_groups: string[] = []; binding_groups: string[] = [];
block: Block; block: Block;

@ -475,7 +475,7 @@ export default function dom(
value: x`function() { value: x`function() {
return [${props.map(prop => x`"${prop.export_name}"`)}]; return [${props.map(prop => x`"${prop.export_name}"`)}];
}` as FunctionExpression }` as FunctionExpression
}) });
} }
declaration.body.body.push(...accessors); declaration.body.body.push(...accessors);

@ -188,7 +188,7 @@ export default class AwaitBlockWrapper extends Wrapper {
const dependencies = this.node.expression.dynamic_dependencies(); const dependencies = this.node.expression.dynamic_dependencies();
if (dependencies.length > 0) { if (dependencies.length > 0) {
let condition = x` const condition = x`
${changed(dependencies)} && ${changed(dependencies)} &&
${promise} !== (${promise} = ${snippet}) && ${promise} !== (${promise} = ${snippet}) &&
@handle_promise(${promise}, ${info})`; @handle_promise(${promise}, ${info})`;

@ -61,7 +61,7 @@ export default class EachBlockWrapper extends Wrapper {
view_length: string; view_length: string;
} }
context_props: (Node | Node[])[]; context_props: Array<Node | Node[]>;
index_name: Identifier; index_name: Identifier;
var: Identifier = { type: 'Identifier', name: 'each' }; var: Identifier = { type: 'Identifier', name: 'each' };

@ -84,7 +84,7 @@ export default class AttributeWrapper {
} else { } else {
value = this.node.name === 'class' value = this.node.name === 'class'
? this.get_class_name_text() ? this.get_class_name_text()
: this.render_chunks().reduce((lhs, rhs) => x`${lhs} + ${rhs}`) : this.render_chunks().reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
// '{foo} {bar}' — treat as string concatenation // '{foo} {bar}' — treat as string concatenation
if (this.node.chunks[0].type !== 'Text') { if (this.node.chunks[0].type !== 'Text') {

@ -267,7 +267,7 @@ function get_event_handler(
} }
} }
let mutation = b` const mutation = b`
${lhs} = ${value}; ${lhs} = ${value};
${set_store} ${set_store}
`; `;

@ -38,7 +38,7 @@ export default class StyleAttributeWrapper extends AttributeWrapper {
return chunk.manipulate(block); return chunk.manipulate(block);
} }
}) })
.reduce((lhs, rhs) => x`${lhs} + ${rhs}`) .reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
// TODO is this necessary? style.setProperty always treats value as string, no? // TODO is this necessary? style.setProperty always treats value as string, no?
// if (prop.value.length === 1 || prop.value[0].type !== 'Text') { // if (prop.value.length === 1 || prop.value[0].type !== 'Text') {

@ -310,7 +310,7 @@ export default class ElementWrapper extends Wrapper {
quasis: [] quasis: []
}; };
to_html((this.fragment.nodes as unknown as (ElementWrapper | TextWrapper)[]), block, literal, state); to_html((this.fragment.nodes as unknown as Array<ElementWrapper | TextWrapper>), block, literal, state);
literal.quasis.push(state.quasi); literal.quasis.push(state.quasi);
block.chunks.create.push( block.chunks.create.push(
@ -832,7 +832,7 @@ export default class ElementWrapper extends Wrapper {
} }
} }
function to_html(wrappers: (ElementWrapper | TextWrapper)[], block: Block, literal: any, state: any) { function to_html(wrappers: Array<ElementWrapper | TextWrapper>, block: Block, literal: any, state: any) {
wrappers.forEach(wrapper => { wrappers.forEach(wrapper => {
if (wrapper.node.type === 'Text') { if (wrapper.node.type === 'Text') {
if ((wrapper as TextWrapper).use_space()) state.quasi.value.raw += ' '; if ((wrapper as TextWrapper).use_space()) state.quasi.value.raw += ' ';
@ -866,7 +866,7 @@ function to_html(wrappers: (ElementWrapper | TextWrapper)[], block: Block, liter
state.quasi.value.raw += chunk.data; state.quasi.value.raw += chunk.data;
} else { } else {
literal.quasis.push(state.quasi); literal.quasis.push(state.quasi);
literal.expressions.push(chunk.manipulate(block)) literal.expressions.push(chunk.manipulate(block));
state.quasi = { state.quasi = {
type: 'TemplateElement', type: 'TemplateElement',
@ -881,7 +881,7 @@ function to_html(wrappers: (ElementWrapper | TextWrapper)[], block: Block, liter
state.quasi.value.raw += '>'; state.quasi.value.raw += '>';
if (!is_void(wrapper.node.name)) { if (!is_void(wrapper.node.name)) {
to_html((wrapper as ElementWrapper).fragment.nodes as (ElementWrapper | TextWrapper)[], block, literal, state); to_html((wrapper as ElementWrapper).fragment.nodes as Array<ElementWrapper | TextWrapper>, block, literal, state);
state.quasi.value.raw += `</${wrapper.node.name}>`; state.quasi.value.raw += `</${wrapper.node.name}>`;
} }

@ -261,7 +261,7 @@ export default class IfBlockWrapper extends Wrapper {
const current_block_type = block.get_unique_name(`current_block_type`); const current_block_type = block.get_unique_name(`current_block_type`);
const get_block = has_else const get_block = has_else
? x`${current_block_type}(#ctx)` ? x`${current_block_type}(#ctx)`
: x`${current_block_type} && ${current_block_type}(#ctx)` : x`${current_block_type} && ${current_block_type}(#ctx)`;
/* eslint-disable @typescript-eslint/indent,indent */ /* eslint-disable @typescript-eslint/indent,indent */
if (this.needs_update) { if (this.needs_update) {

@ -116,8 +116,8 @@ export default class InlineComponentWrapper extends Wrapper {
const component_opts = x`{}` as ObjectExpression; const component_opts = x`{}` as ObjectExpression;
const statements: (Node | Node[])[] = []; const statements: Array<Node | Node[]> = [];
const updates: (Node | Node[])[] = []; const updates: Array<Node | Node[]> = [];
let props; let props;
const name_changes = block.get_unique_name(`${name.name}_changes`); const name_changes = block.get_unique_name(`${name.name}_changes`);

@ -1,8 +1,7 @@
import { b } from 'code-red'; import { b, x } from 'code-red';
import Block from '../../Block'; import Block from '../../Block';
import Action from '../../../nodes/Action'; import Action from '../../../nodes/Action';
import Component from '../../../Component'; import Component from '../../../Component';
import { x } from 'code-red';
export default function add_actions( export default function add_actions(
component: Component, component: Component,

@ -48,7 +48,7 @@ export default class Renderer {
name: Identifier; name: Identifier;
stack: { current: { value: string }, literal: TemplateLiteral }[] = []; stack: Array<{ current: { value: string }; literal: TemplateLiteral }> = [];
current: { value: string }; // TODO can it just be `current: string`? current: { value: string }; // TODO can it just be `current: string`?
literal: TemplateLiteral; literal: TemplateLiteral;
@ -59,17 +59,6 @@ export default class Renderer {
this.push(); this.push();
} }
append() {
throw new Error('no more append');
// if (this.targets.length) {
// const target = this.targets[this.targets.length - 1];
// const slot_name = target.slot_stack[target.slot_stack.length - 1];
// target.slots[slot_name] += code;
// } else {
// this.code += code;
// }
}
add_string(str: string) { add_string(str: string) {
this.current.value += escape_template(str); this.current.value += escape_template(str);
} }
@ -94,7 +83,7 @@ export default class Renderer {
quasis: [] quasis: []
}; };
this.stack.push({ current, literal }) this.stack.push({ current, literal });
} }
pop() { pop() {

@ -11,7 +11,7 @@ export default function get_slot_data(values: Map<string, Attribute>, is_ssr: bo
const value = get_value(attribute); const value = get_value(attribute);
return p`${attribute.name}: ${value}`; return p`${attribute.name}: ${value}`;
}) })
} };
} }
// TODO fairly sure this is duplicated at least once // TODO fairly sure this is duplicated at least once

@ -67,7 +67,7 @@ export interface Parser {
} }
export interface Script extends BaseNode { export interface Script extends BaseNode {
type: 'Script', type: 'Script';
context: string; context: string;
content: Program; content: Program;
} }
@ -80,7 +80,7 @@ export interface Style extends BaseNode {
start: number; start: number;
end: number; end: number;
styles: string; styles: string;
} };
} }
export interface Ast { export interface Ast {

@ -37,8 +37,8 @@ const specials = new Map([
], ],
]); ]);
const SELF = /^svelte:self(?=[\s\/>])/; const SELF = /^svelte:self(?=[\s/>])/;
const COMPONENT = /^svelte:component(?=[\s\/>])/; const COMPONENT = /^svelte:component(?=[\s/>])/;
function parent_is_head(stack) { function parent_is_head(stack) {
let i = stack.length; let i = stack.length;

Loading…
Cancel
Save