From b1a24c853b571a3ee1f1ec78afa6baee9a299f93 Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Tue, 21 May 2019 17:51:36 +0200 Subject: [PATCH 01/21] ignore .idea folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7aa75b29f4..3d1322c33e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea .DS_Store .nyc_output node_modules From 6fdaa803c77a6bb1d0eb5c20906cc2783da430da Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Tue, 21 May 2019 17:54:06 +0200 Subject: [PATCH 02/21] improve parser typings --- src/interfaces.ts | 45 ++++++++++++++++++++++++++++++++++-- src/parse/read/expression.ts | 9 ++++---- src/parse/state/tag.ts | 14 +++++------ 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/interfaces.ts b/src/interfaces.ts index 68fef7472e..90ee60d1be 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,10 +1,51 @@ -export interface Node { +interface BaseNode { start: number; end: number; type: string; + children?: Node[]; [prop_name: string]: any; } +export interface Text extends BaseNode { + type: 'Text', + data: string; +} + +export interface MustacheTag extends BaseNode { + type: 'MustacheTag', + expresion: Node; +} + +export type DirectiveType = 'Action' + | 'Animation' + | 'Binding' + | 'Class' + | 'EventHandler' + | 'Let' + | 'Ref' + | 'Transition'; + +interface BaseDirective extends BaseNode { + type: DirectiveType; + expression: null|Node; + name: string; + modifiers: string[] +} + +export interface Transition extends BaseDirective{ + type: 'Transition', + intro: boolean; + outro: boolean; +} + +export type Directive = BaseDirective | Transition; + +export type Node = Text + | MustacheTag + | BaseNode + | Directive + | Transition; + export interface Parser { readonly template: string; readonly filename?: string; @@ -92,4 +133,4 @@ export interface Var { initialised?: boolean; hoistable?: boolean; subscribable?: boolean; -} \ No newline at end of file +} diff --git a/src/parse/read/expression.ts b/src/parse/read/expression.ts index 4d1de89fe7..615f270112 100644 --- a/src/parse/read/expression.ts +++ b/src/parse/read/expression.ts @@ -1,9 +1,10 @@ import { parse_expression_at } from '../acorn'; import { Parser } from '../index'; +import { Identifier, Node, SimpleLiteral } from 'estree'; const literals = new Map([['true', true], ['false', false], ['null', null]]); -export default function read_expression(parser: Parser) { +export default function read_expression(parser: Parser): Node { const start = parser.index; const name = parser.read_until(/\s*}/); @@ -17,7 +18,7 @@ export default function read_expression(parser: Parser) { end, value: literals.get(name), raw: name, - }; + } as SimpleLiteral; } return { @@ -25,7 +26,7 @@ export default function read_expression(parser: Parser) { start, end: start + name.length, name, - }; + } as Identifier; } parser.index = start; @@ -34,7 +35,7 @@ export default function read_expression(parser: Parser) { const node = parse_expression_at(parser.template, parser.index); parser.index = node.end; - return node; + return node as Node; } catch (err) { parser.acorn_error(err); } diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index 56195549d8..f7f5a93574 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -4,7 +4,7 @@ import read_style from '../read/style'; import { decode_character_references } from '../utils/html'; import { is_void } from '../../utils/names'; import { Parser } from '../index'; -import { Node } from '../../interfaces'; +import { Directive, DirectiveType, Node, Text } from '../../interfaces'; import fuzzymatch from '../../utils/fuzzymatch'; import list from '../../utils/list'; @@ -401,7 +401,7 @@ function read_attribute(parser: Parser, unique_names: Set) { } if (value[0]) { - if (value.length > 1 || value[0].type === 'Text') { + if ((value as Array).length > 1 || value[0].type === 'Text') { parser.error({ code: `invalid-directive-value`, message: `Directive value must be a JavaScript expression enclosed in curly braces` @@ -409,7 +409,7 @@ function read_attribute(parser: Parser, unique_names: Set) { } } - const directive = { + const directive: Directive = { start, end, type, @@ -445,7 +445,7 @@ function read_attribute(parser: Parser, unique_names: Set) { }; } -function get_directive_type(name) { +function get_directive_type(name: string):DirectiveType { if (name === 'use') return 'Action'; if (name === 'animate') return 'Animation'; if (name === 'bind') return 'Binding'; @@ -471,15 +471,15 @@ function read_attribute_value(parser: Parser) { return value; } -function read_sequence(parser: Parser, done: () => boolean) { - let current_chunk: Node = { +function read_sequence(parser: Parser, done: () => boolean): Node[] { + let current_chunk: Text = { start: parser.index, end: null, type: 'Text', data: '', }; - const chunks = []; + const chunks: Node[] = []; while (parser.index < parser.template.length) { const index = parser.index; From b7ec99e8c7442c5ef85fde2e4e3382e48fd2ecd8 Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Tue, 21 May 2019 20:55:04 +0200 Subject: [PATCH 03/21] fix compile/nodes typings --- src/compile/nodes/Attribute.ts | 9 +++- src/compile/nodes/AwaitBlock.ts | 1 + src/compile/nodes/Binding.ts | 1 + src/compile/nodes/CatchBlock.ts | 1 + src/compile/nodes/DebugTag.ts | 3 +- src/compile/nodes/EachBlock.ts | 17 +++++-- src/compile/nodes/Element.ts | 16 +++--- src/compile/nodes/ElseBlock.ts | 3 +- src/compile/nodes/EventHandler.ts | 3 +- src/compile/nodes/Fragment.ts | 6 ++- src/compile/nodes/Head.ts | 1 - src/compile/nodes/InlineComponent.ts | 3 +- src/compile/nodes/MustacheTag.ts | 4 +- src/compile/nodes/PendingBlock.ts | 2 +- src/compile/nodes/RawMustacheTag.ts | 4 +- src/compile/nodes/Slot.ts | 8 +-- src/compile/nodes/Text.ts | 8 +-- src/compile/nodes/ThenBlock.ts | 1 + src/compile/nodes/Title.ts | 10 ++-- src/compile/nodes/interfaces.ts | 62 +++++++++++++++++++++++ src/compile/nodes/shared/AbstractBlock.ts | 3 +- src/compile/nodes/shared/Expression.ts | 13 +++-- src/compile/nodes/shared/Node.ts | 12 +++-- src/compile/nodes/shared/Tag.ts | 3 +- src/compile/nodes/shared/TemplateScope.ts | 3 +- src/compile/nodes/shared/map_children.ts | 8 +-- src/compile/utils/add_to_set.ts | 5 +- src/compile/utils/scope.ts | 4 +- src/compile/utils/stringify_attribute.ts | 5 +- 29 files changed, 163 insertions(+), 56 deletions(-) create mode 100644 src/compile/nodes/interfaces.ts diff --git a/src/compile/nodes/Attribute.ts b/src/compile/nodes/Attribute.ts index c07960ce47..0b2d3a3700 100644 --- a/src/compile/nodes/Attribute.ts +++ b/src/compile/nodes/Attribute.ts @@ -67,6 +67,7 @@ export default class Attribute extends Node { this.should_cache = this.is_dynamic ? this.chunks.length === 1 + // @ts-ignore todo: probably error ? this.chunks[0].node.type !== 'Identifier' || scope.names.has(this.chunks[0].node.name) : true : false; @@ -91,8 +92,10 @@ export default class Attribute extends Node { if (this.chunks.length === 0) return `""`; if (this.chunks.length === 1) { + return this.chunks[0].type === 'Text' - ? stringify(this.chunks[0].data) + ? stringify((this.chunks[0] as Text).data) + // @ts-ignore todo: probably error : this.chunks[0].render(block); } @@ -102,6 +105,7 @@ export default class Attribute extends Node { if (chunk.type === 'Text') { return stringify(chunk.data); } else { + // @ts-ignore todo: probably error return chunk.get_precedence() <= 13 ? `(${chunk.render()})` : chunk.render(); } }) @@ -114,7 +118,8 @@ export default class Attribute extends Node { return this.is_true ? true : this.chunks[0] - ? this.chunks[0].data + // method should be called only when `is_static = true` + ? (this.chunks[0] as Text).data : ''; } } diff --git a/src/compile/nodes/AwaitBlock.ts b/src/compile/nodes/AwaitBlock.ts index f8e6896b5d..cd57750d29 100644 --- a/src/compile/nodes/AwaitBlock.ts +++ b/src/compile/nodes/AwaitBlock.ts @@ -5,6 +5,7 @@ import CatchBlock from './CatchBlock'; import Expression from './shared/Expression'; export default class AwaitBlock extends Node { + type: 'AwaitBlock'; expression: Expression; value: string; error: string; diff --git a/src/compile/nodes/Binding.ts b/src/compile/nodes/Binding.ts index b03eba0c36..0d666a543f 100644 --- a/src/compile/nodes/Binding.ts +++ b/src/compile/nodes/Binding.ts @@ -5,6 +5,7 @@ import Component from '../Component'; import TemplateScope from './shared/TemplateScope'; export default class Binding extends Node { + type: 'Binding'; name: string; expression: Expression; is_contextual: boolean; diff --git a/src/compile/nodes/CatchBlock.ts b/src/compile/nodes/CatchBlock.ts index 23c08a494c..0edc0f76d8 100644 --- a/src/compile/nodes/CatchBlock.ts +++ b/src/compile/nodes/CatchBlock.ts @@ -3,6 +3,7 @@ import TemplateScope from './shared/TemplateScope'; import AbstractBlock from './shared/AbstractBlock'; export default class CatchBlock extends AbstractBlock { + type: 'CatchBlock'; scope: TemplateScope; constructor(component, parent, scope, info) { diff --git a/src/compile/nodes/DebugTag.ts b/src/compile/nodes/DebugTag.ts index 4d2c3f6ae4..0fbfa592ad 100644 --- a/src/compile/nodes/DebugTag.ts +++ b/src/compile/nodes/DebugTag.ts @@ -2,6 +2,7 @@ import Node from './shared/Node'; import Expression from './shared/Expression'; export default class DebugTag extends Node { + type: 'DebugTag'; expressions: Expression[]; constructor(component, parent, scope, info) { @@ -11,4 +12,4 @@ export default class DebugTag extends Node { return new Expression(component, parent, scope, node); }); } -} \ No newline at end of file +} diff --git a/src/compile/nodes/EachBlock.ts b/src/compile/nodes/EachBlock.ts index b58c023ac9..2f18373137 100644 --- a/src/compile/nodes/EachBlock.ts +++ b/src/compile/nodes/EachBlock.ts @@ -6,8 +6,15 @@ import TemplateScope from './shared/TemplateScope'; import AbstractBlock from './shared/AbstractBlock'; import { Node as INode } from '../../interfaces'; import { new_tail } from '../utils/tail'; +import Element from './Element'; -function unpack_destructuring(contexts: Array<{ name: string, tail: string }>, node: INode, tail: string) { +type Context = { + key: INode, + name?: string, + tail: string +}; + +function unpack_destructuring(contexts: Array, node: INode, tail: string) { if (!node) return; if (node.type === 'Identifier' || node.type === 'RestIdentifier') { @@ -53,7 +60,7 @@ export default class EachBlock extends AbstractBlock { context: string; key: Expression; scope: TemplateScope; - contexts: Array<{ name: string, tail: string }>; + contexts: Array; has_animation: boolean; has_binding = false; @@ -82,7 +89,7 @@ export default class EachBlock extends AbstractBlock { if (this.index) { // index can only change if this is a keyed each block - const dependencies = this.key ? this.expression.dependencies : []; + const dependencies = this.key ? this.expression.dependencies : new Set([]); this.scope.add(this.index, dependencies, this); } @@ -92,8 +99,8 @@ export default class EachBlock extends AbstractBlock { if (this.has_animation) { if (this.children.length !== 1) { - const child = this.children.find(child => !!child.animation); - component.error(child.animation, { + const child = this.children.find(child => !!(child as Element).animation); + component.error((child as Element).animation, { code: `invalid-animation`, message: `An element that use the animate directive must be the sole child of a keyed each block` }); diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index ac2b81b3e7..aa7c14a679 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -15,6 +15,7 @@ import fuzzymatch from '../../utils/fuzzymatch'; import list from '../../utils/list'; import Let from './Let'; import TemplateScope from './shared/TemplateScope'; +import { INode } from './interfaces'; const svg = /^(?:altGlyph|altGlyphDef|altGlyphItem|animate|animateColor|animateMotion|animateTransform|circle|clipPath|color-profile|cursor|defs|desc|discard|ellipse|feBlend|feColorMatrix|feComponentTransfer|feComposite|feConvolveMatrix|feDiffuseLighting|feDisplacementMap|feDistantLight|feDropShadow|feFlood|feFuncA|feFuncB|feFuncG|feFuncR|feGaussianBlur|feImage|feMerge|feMergeNode|feMorphology|feOffset|fePointLight|feSpecularLighting|feSpotLight|feTile|feTurbulence|filter|font|font-face|font-face-format|font-face-name|font-face-src|font-face-uri|foreignObject|g|glyph|glyphRef|hatch|hatchpath|hkern|image|line|linearGradient|marker|mask|mesh|meshgradient|meshpatch|meshrow|metadata|missing-glyph|mpath|path|pattern|polygon|polyline|radialGradient|rect|set|solidcolor|stop|svg|switch|symbol|text|textPath|tref|tspan|unknown|use|view|vkern)$/; @@ -101,7 +102,7 @@ export default class Element extends Node { intro?: Transition = null; outro?: Transition = null; animation?: Animation = null; - children: Node[]; + children: INode[]; namespace: string; constructor(component, parent, scope, info: any) { @@ -136,7 +137,7 @@ export default class Element extends Node { // Special case — treat these the same way: // // - const value_attribute = info.attributes.find((attribute: Node) => attribute.name === 'value'); + const value_attribute = info.attributes.find(attribute => attribute.name === 'value'); if (!value_attribute) { info.attributes.push({ @@ -228,7 +229,7 @@ export default class Element extends Node { let is_figure_parent = false; while (parent) { - if (parent.name === 'figure') { + if ((parent as Element).name === 'figure') { is_figure_parent = true; break; } @@ -249,11 +250,11 @@ export default class Element extends Node { if (this.name === 'figure') { const children = this.children.filter(node => { if (node.type === 'Comment') return false; - if (node.type === 'Text') return /\S/.test(node.data); + if (node.type === 'Text') return /\S/.test((node as Text).data ); return true; }); - const index = children.findIndex(child => child.name === 'figcaption'); + const index = children.findIndex(child => (child as Element).name === 'figcaption'); if (index !== -1 && (index !== 0 && index !== children.length - 1)) { this.component.warn(children[index], { @@ -320,7 +321,9 @@ export default class Element extends Node { } const value = attribute.get_static_value(); + // @ts-ignore if (value && !aria_role_set.has(value)) { + // @ts-ignore const match = fuzzymatch(value, aria_roles); let message = `A11y: Unknown role '${value}'`; if (match) message += ` (did you mean '${match}'?)`; @@ -359,6 +362,7 @@ export default class Element extends Node { // tabindex-no-positive if (name === 'tabindex') { const value = attribute.get_static_value(); + // @ts-ignore todo is tabindex=true correct case? if (!isNaN(value) && +value > 0) { component.warn(attribute, { code: `a11y-positive-tabindex`, @@ -387,7 +391,7 @@ export default class Element extends Node { let ancestor = this.parent; do { if (ancestor.type === 'InlineComponent') break; - if (ancestor.type === 'Element' && /-/.test(ancestor.name)) break; + if (ancestor.type === 'Element' && /-/.test((ancestor as Element).name)) break; if (ancestor.type === 'IfBlock' || ancestor.type === 'EachBlock') { const type = ancestor.type === 'IfBlock' ? 'if' : 'each'; diff --git a/src/compile/nodes/ElseBlock.ts b/src/compile/nodes/ElseBlock.ts index 61c1aa5455..5f3aa29529 100644 --- a/src/compile/nodes/ElseBlock.ts +++ b/src/compile/nodes/ElseBlock.ts @@ -1,10 +1,11 @@ import map_children from './shared/map_children'; import AbstractBlock from './shared/AbstractBlock'; +import Component from '../Component'; export default class ElseBlock extends AbstractBlock { type: 'ElseBlock'; - constructor(component, parent, scope, info) { + constructor(component: Component, parent, scope, info) { super(component, parent, scope, info); this.children = map_children(component, this, scope, info.children); diff --git a/src/compile/nodes/EventHandler.ts b/src/compile/nodes/EventHandler.ts index f5e7e0e898..dab60858d5 100644 --- a/src/compile/nodes/EventHandler.ts +++ b/src/compile/nodes/EventHandler.ts @@ -5,6 +5,7 @@ import deindent from '../utils/deindent'; import Block from '../render-dom/Block'; export default class EventHandler extends Node { + type: 'EventHandler'; name: string; modifiers: Set; expression: Expression; @@ -65,4 +66,4 @@ export default class EventHandler extends Node { // this.component.add_reference(this.handler_name); return `ctx.${this.handler_name}`; } -} \ No newline at end of file +} diff --git a/src/compile/nodes/Fragment.ts b/src/compile/nodes/Fragment.ts index ec25d41a1c..6025b036a6 100644 --- a/src/compile/nodes/Fragment.ts +++ b/src/compile/nodes/Fragment.ts @@ -3,10 +3,12 @@ import Component from '../Component'; import map_children from './shared/map_children'; import Block from '../render-dom/Block'; import TemplateScope from './shared/TemplateScope'; +import { INode } from './interfaces'; export default class Fragment extends Node { + type: 'Fragment'; block: Block; - children: Node[]; + children: INode[]; scope: TemplateScope; constructor(component: Component, info: any) { @@ -16,4 +18,4 @@ export default class Fragment extends Node { this.scope = scope; this.children = map_children(component, this, scope, info.children); } -} \ No newline at end of file +} diff --git a/src/compile/nodes/Head.ts b/src/compile/nodes/Head.ts index bc6e9bde40..2c08dcd595 100644 --- a/src/compile/nodes/Head.ts +++ b/src/compile/nodes/Head.ts @@ -1,5 +1,4 @@ import Node from './shared/Node'; -import Block from '../render-dom/Block'; import map_children from './shared/map_children'; export default class Head extends Node { diff --git a/src/compile/nodes/InlineComponent.ts b/src/compile/nodes/InlineComponent.ts index 3359e981ed..8b6cd77282 100644 --- a/src/compile/nodes/InlineComponent.ts +++ b/src/compile/nodes/InlineComponent.ts @@ -7,6 +7,7 @@ import Expression from './shared/Expression'; import Component from '../Component'; import Let from './Let'; import TemplateScope from './shared/TemplateScope'; +import { INode } from './interfaces'; export default class InlineComponent extends Node { type: 'InlineComponent'; @@ -16,7 +17,7 @@ export default class InlineComponent extends Node { bindings: Binding[] = []; handlers: EventHandler[] = []; lets: Let[] = []; - children: Node[]; + children: INode[]; scope: TemplateScope; constructor(component: Component, parent, scope, info) { diff --git a/src/compile/nodes/MustacheTag.ts b/src/compile/nodes/MustacheTag.ts index e668987a9c..ac6688d503 100644 --- a/src/compile/nodes/MustacheTag.ts +++ b/src/compile/nodes/MustacheTag.ts @@ -1,3 +1,5 @@ import Tag from './shared/Tag'; -export default class MustacheTag extends Tag {} \ No newline at end of file +export default class MustacheTag extends Tag { + type: 'MustacheTag'; +} diff --git a/src/compile/nodes/PendingBlock.ts b/src/compile/nodes/PendingBlock.ts index 0fd71c0221..5ff7352558 100644 --- a/src/compile/nodes/PendingBlock.ts +++ b/src/compile/nodes/PendingBlock.ts @@ -2,7 +2,7 @@ import map_children from './shared/map_children'; import AbstractBlock from './shared/AbstractBlock'; export default class PendingBlock extends AbstractBlock { - + type: 'PendingBlock'; constructor(component, parent, scope, info) { super(component, parent, scope, info); this.children = map_children(component, parent, scope, info.children); diff --git a/src/compile/nodes/RawMustacheTag.ts b/src/compile/nodes/RawMustacheTag.ts index ada3123410..fc63885942 100644 --- a/src/compile/nodes/RawMustacheTag.ts +++ b/src/compile/nodes/RawMustacheTag.ts @@ -1,3 +1,5 @@ import Tag from './shared/Tag'; -export default class RawMustacheTag extends Tag {} \ No newline at end of file +export default class RawMustacheTag extends Tag { + type: 'RawMustacheTag' +} diff --git a/src/compile/nodes/Slot.ts b/src/compile/nodes/Slot.ts index dbb502b41a..a03fe8c026 100644 --- a/src/compile/nodes/Slot.ts +++ b/src/compile/nodes/Slot.ts @@ -1,17 +1,17 @@ -import Node from './shared/Node'; import Element from './Element'; import Attribute from './Attribute'; import Component from '../Component'; import TemplateScope from './shared/TemplateScope'; +import { INode } from './interfaces'; export default class Slot extends Element { type: 'Element'; name: string; - children: Node[]; + children: INode[]; slot_name: string; values: Map = new Map(); - constructor(component: Component, parent: Node, scope: TemplateScope, info: any) { + constructor(component: Component, parent: INode, scope: TemplateScope, info: any) { super(component, parent, scope, info); info.attributes.forEach(attr => { @@ -68,4 +68,4 @@ export default class Slot extends Element { component.slots.set(this.slot_name, this); } -} \ No newline at end of file +} diff --git a/src/compile/nodes/Text.ts b/src/compile/nodes/Text.ts index 1c31c9d83d..a3b9241ce2 100644 --- a/src/compile/nodes/Text.ts +++ b/src/compile/nodes/Text.ts @@ -1,20 +1,22 @@ import Node from './shared/Node'; import Component from '../Component'; import TemplateScope from './shared/TemplateScope'; +import { INode } from './interfaces'; +import Element from './Element'; export default class Text extends Node { type: 'Text'; data: string; use_space = false; - constructor(component: Component, parent: Node, scope: TemplateScope, info: any) { + constructor(component: Component, parent: INode, scope: TemplateScope, info: any) { super(component, parent, scope, info); this.data = info.data; if (!component.component_options.preserveWhitespace && !/\S/.test(info.data)) { let node = parent; while (node) { - if (node.type === 'Element' && node.name === 'pre') { + if (node.type === 'Element' && (node as Element).name === 'pre') { return; } node = node.parent; @@ -23,4 +25,4 @@ export default class Text extends Node { this.use_space = true; } } -} \ No newline at end of file +} diff --git a/src/compile/nodes/ThenBlock.ts b/src/compile/nodes/ThenBlock.ts index 7e4ed0e5da..7f9bbde0f0 100644 --- a/src/compile/nodes/ThenBlock.ts +++ b/src/compile/nodes/ThenBlock.ts @@ -3,6 +3,7 @@ import TemplateScope from './shared/TemplateScope'; import AbstractBlock from './shared/AbstractBlock'; export default class ThenBlock extends AbstractBlock { + type: 'ThenBlock'; scope: TemplateScope; constructor(component, parent, scope, info) { diff --git a/src/compile/nodes/Title.ts b/src/compile/nodes/Title.ts index fd58d3043d..4c459c181f 100644 --- a/src/compile/nodes/Title.ts +++ b/src/compile/nodes/Title.ts @@ -1,12 +1,14 @@ import Node from './shared/Node'; -import map_children from './shared/map_children'; +import map_children, { Children } from './shared/map_children'; +import Component from '../Component'; export default class Title extends Node { type: 'Title'; - children: any[]; // TODO + should_cache: boolean; + children: Children; - constructor(component, parent, scope, info) { + constructor(component: Component, parent, scope, info) { super(component, parent, scope, info); this.children = map_children(component, parent, scope, info.children); @@ -33,4 +35,4 @@ export default class Title extends Node { ) : true; } -} \ No newline at end of file +} diff --git a/src/compile/nodes/interfaces.ts b/src/compile/nodes/interfaces.ts new file mode 100644 index 0000000000..6613d39769 --- /dev/null +++ b/src/compile/nodes/interfaces.ts @@ -0,0 +1,62 @@ +import Tag from './shared/Tag'; + +import Action from './Action'; +import Animation from './Animation'; +import Attribute from './Attribute'; +import AwaitBlock from './AwaitBlock'; +import Binding from './Binding'; +import Body from './Body'; +import CatchBlock from './CatchBlock'; +import Class from './Class'; +import Comment from './Comment'; +import DebugTag from './DebugTag'; +import EachBlock from './EachBlock'; +import Element from './Element'; +import ElseBlock from './ElseBlock'; +import EventHandler from './EventHandler'; +import Fragment from './Fragment'; +import Head from './Head'; +import IfBlock from './IfBlock'; +import InlineComponent from './InlineComponent'; +import Let from './Let'; +import MustacheTag from './MustacheTag'; +import Options from './Options'; +import PendingBlock from './PendingBlock'; +import RawMustacheTag from './RawMustacheTag'; +import Slot from './Slot'; +import Text from './Text'; +import ThenBlock from './ThenBlock'; +import Title from './Title'; +import Transition from './Transition'; +import Window from './Window'; + +export type INode = Action + | Animation + | Attribute + | AwaitBlock + | Binding + | Body + | CatchBlock + | Class + | Comment + | DebugTag + | EachBlock + | Element + | ElseBlock + | EventHandler + | Fragment + | Head + | IfBlock + | InlineComponent + | Let + | MustacheTag + | Options + | PendingBlock + | RawMustacheTag + | Slot + | Tag + | Text + | ThenBlock + | Title + | Transition + | Window; diff --git a/src/compile/nodes/shared/AbstractBlock.ts b/src/compile/nodes/shared/AbstractBlock.ts index 1dfebd51f0..e1104e4928 100644 --- a/src/compile/nodes/shared/AbstractBlock.ts +++ b/src/compile/nodes/shared/AbstractBlock.ts @@ -1,10 +1,11 @@ import Block from '../../render-dom/Block'; import Component from './../../Component'; import Node from './Node'; +import { INode } from '../interfaces'; export default class AbstractBlock extends Node { block: Block; - children: Node[]; + children: INode[]; constructor(component: Component, parent, scope, info: any) { super(component, parent, scope, info); diff --git a/src/compile/nodes/shared/Expression.ts b/src/compile/nodes/shared/Expression.ts index fc188e9673..f7c9582115 100644 --- a/src/compile/nodes/shared/Expression.ts +++ b/src/compile/nodes/shared/Expression.ts @@ -12,6 +12,7 @@ import TemplateScope from './TemplateScope'; import get_object from '../../utils/get_object'; import { nodes_match } from '../../../utils/nodes_match'; import Block from '../../render-dom/Block'; +import { INode } from '../interfaces'; const binary_operators: Record = { '**': 15, @@ -61,10 +62,12 @@ const precedence: Record number> = { SequenceExpression: () => 0 }; +type Owner = Wrapper | INode; + export default class Expression { - type = 'Expression'; + type: 'Expression' = 'Expression'; component: Component; - owner: Wrapper; + owner: Owner; node: any; snippet: string; references: Set; @@ -81,7 +84,8 @@ export default class Expression { rendered: string; - constructor(component: Component, owner: Wrapper, template_scope: TemplateScope, info) { + // todo: owner type + constructor(component: Component, owner: Owner, template_scope: TemplateScope, info) { // TODO revert to direct property access in prod? Object.defineProperties(this, { component: { @@ -92,6 +96,7 @@ 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; @@ -510,4 +515,4 @@ function is_contextual(component: Component, scope: TemplateScope, name: string) // assume contextual return true; -} \ No newline at end of file +} diff --git a/src/compile/nodes/shared/Node.ts b/src/compile/nodes/shared/Node.ts index b6eaf9965d..daba0d62b2 100644 --- a/src/compile/nodes/shared/Node.ts +++ b/src/compile/nodes/shared/Node.ts @@ -1,21 +1,23 @@ import Attribute from './../Attribute'; import Component from './../../Component'; +import { INode } from '../interfaces'; +import Text from '../Text'; export default class Node { readonly start: number; readonly end: number; readonly component: Component; - readonly parent: Node; + readonly parent: INode; readonly type: string; - prev?: Node; - next?: Node; + prev?: INode; + next?: INode; can_use_innerhtml: boolean; var: string; attributes: Attribute[]; - constructor(component: Component, parent, scope, info: any) { + constructor(component: Component, parent: any, scope: any, info: { start: number; end: number; type: string; }) { this.start = info.start; this.end = info.end; this.type = info.type; @@ -55,7 +57,7 @@ export default class Node { if (attribute.chunks.length === 0) return ''; if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') { - return attribute.chunks[0].data; + return (attribute.chunks[0] as Text).data; } return null; diff --git a/src/compile/nodes/shared/Tag.ts b/src/compile/nodes/shared/Tag.ts index 94971bef11..bc826458d9 100644 --- a/src/compile/nodes/shared/Tag.ts +++ b/src/compile/nodes/shared/Tag.ts @@ -2,6 +2,7 @@ import Node from './Node'; import Expression from './Expression'; export default class Tag extends Node { + type: 'MustacheTag' | 'RawMustacheTag'; expression: Expression; should_cache: boolean; @@ -14,4 +15,4 @@ export default class Tag extends Node { (this.expression.dependencies.size && scope.names.has(info.expression.name)) ); } -} \ No newline at end of file +} diff --git a/src/compile/nodes/shared/TemplateScope.ts b/src/compile/nodes/shared/TemplateScope.ts index abd366642e..5f30d0c883 100644 --- a/src/compile/nodes/shared/TemplateScope.ts +++ b/src/compile/nodes/shared/TemplateScope.ts @@ -2,6 +2,7 @@ import EachBlock from '../EachBlock'; import ThenBlock from '../ThenBlock'; import CatchBlock from '../CatchBlock'; import InlineComponent from '../InlineComponent'; +import Element from '../Element'; type NodeWithScope = EachBlock | ThenBlock | CatchBlock | InlineComponent | Element; @@ -41,4 +42,4 @@ export default class TemplateScope { const owner = this.get_owner(name); return owner && (owner.type === 'Element' || owner.type === 'InlineComponent'); } -} \ No newline at end of file +} diff --git a/src/compile/nodes/shared/map_children.ts b/src/compile/nodes/shared/map_children.ts index b903853016..71d764a889 100644 --- a/src/compile/nodes/shared/map_children.ts +++ b/src/compile/nodes/shared/map_children.ts @@ -14,9 +14,11 @@ import Slot from '../Slot'; import Text from '../Text'; import Title from '../Title'; import Window from '../Window'; -import Node from './Node'; +import { Node } from '../../../interfaces'; -function get_constructor(type): typeof Node { +export type Children = ReturnType; + +function get_constructor(type) { switch (type) { case 'AwaitBlock': return AwaitBlock; case 'Body': return Body; @@ -38,7 +40,7 @@ function get_constructor(type): typeof Node { } } -export default function map_children(component, parent, scope, children: any[]) { +export default function map_children(component, parent, scope, children: Node[]) { let last = null; return children.map(child => { const constructor = get_constructor(child.type); diff --git a/src/compile/utils/add_to_set.ts b/src/compile/utils/add_to_set.ts index 262d7d32e7..b37e0db931 100644 --- a/src/compile/utils/add_to_set.ts +++ b/src/compile/utils/add_to_set.ts @@ -1,5 +1,6 @@ -export default function add_to_set(a: Set, b: Set) { +export default function add_to_set(a: Set, b: Set | Array) { + // @ts-ignore b.forEach(item => { a.add(item); }); -} \ No newline at end of file +} diff --git a/src/compile/utils/scope.ts b/src/compile/utils/scope.ts index 6488986d83..a3e341be49 100644 --- a/src/compile/utils/scope.ts +++ b/src/compile/utils/scope.ts @@ -9,7 +9,7 @@ export function create_scopes(expression: Node) { let scope = new Scope(null, false); walk(expression, { - enter(node: Node, parent: Node) { + enter(node, parent) { if (node.type === 'ImportDeclaration') { node.specifiers.forEach(specifier => { scope.declarations.set(specifier.local.name, specifier); @@ -25,7 +25,7 @@ export function create_scopes(expression: Node) { if (node.id) scope.declarations.set(node.id.name, node); } - node.params.forEach((param: Node) => { + node.params.forEach((param) => { extract_names(param).forEach(name => { scope.declarations.set(name, node); }); diff --git a/src/compile/utils/stringify_attribute.ts b/src/compile/utils/stringify_attribute.ts index 9df2d18344..ee3450edbb 100644 --- a/src/compile/utils/stringify_attribute.ts +++ b/src/compile/utils/stringify_attribute.ts @@ -1,11 +1,10 @@ import Attribute from '../nodes/Attribute'; -import Node from '../nodes/shared/Node'; import { escape_template, escape } from './stringify'; import { snip } from './snip'; export function stringify_attribute(attribute: Attribute, is_ssr: boolean) { return attribute.chunks - .map((chunk: Node) => { + .map((chunk) => { if (chunk.type === 'Text') { return escape_template(escape(chunk.data).replace(/"/g, '"')); } @@ -15,4 +14,4 @@ export function stringify_attribute(attribute: Attribute, is_ssr: boolean) { : '${' + snip(chunk) + '}'; }) .join(''); -} \ No newline at end of file +} From 231603df7bbf0ff9bb5ecf573ccabaa9211bfea5 Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Tue, 21 May 2019 20:56:01 +0200 Subject: [PATCH 04/21] fix compile/render-ssr typings --- src/compile/render-ssr/Renderer.ts | 7 ++++++- src/compile/render-ssr/handlers/AwaitBlock.ts | 8 ++++---- src/compile/render-ssr/handlers/Comment.ts | 8 ++++---- src/compile/render-ssr/handlers/DebugTag.ts | 9 +++++---- src/compile/render-ssr/handlers/EachBlock.ts | 6 ++++-- src/compile/render-ssr/handlers/Element.ts | 13 +++++++++---- src/compile/render-ssr/handlers/Head.ts | 7 +++++-- src/compile/render-ssr/handlers/HtmlTag.ts | 6 ++++-- src/compile/render-ssr/handlers/IfBlock.ts | 7 ++++--- src/compile/render-ssr/handlers/InlineComponent.ts | 11 +++++++---- src/compile/render-ssr/handlers/Slot.ts | 6 ++++-- src/compile/render-ssr/handlers/Tag.ts | 6 +++--- src/compile/render-ssr/handlers/Text.ts | 9 ++++++--- src/compile/render-ssr/handlers/Title.ts | 7 +++++-- src/compile/render-ssr/index.ts | 8 +++++--- 15 files changed, 75 insertions(+), 43 deletions(-) diff --git a/src/compile/render-ssr/Renderer.ts b/src/compile/render-ssr/Renderer.ts index c97965de14..ef1d16429e 100644 --- a/src/compile/render-ssr/Renderer.ts +++ b/src/compile/render-ssr/Renderer.ts @@ -12,6 +12,7 @@ import Tag from './handlers/Tag'; import Text from './handlers/Text'; import Title from './handlers/Title'; import { AppendTarget, CompileOptions } from '../../interfaces'; +import { INode } from '../nodes/interfaces'; type Handler = (node: any, renderer: Renderer, options: CompileOptions) => void; @@ -36,6 +37,10 @@ const handlers: Record = { Window: noop }; +export interface RenderOptions extends CompileOptions{ + locate: (c: number) => { line: number; column: number; }; +}; + export default class Renderer { has_bindings = false; code = ''; @@ -51,7 +56,7 @@ export default class Renderer { } } - render(nodes, options) { + render(nodes: INode[], options: RenderOptions) { nodes.forEach(node => { const handler = handlers[node.type]; diff --git a/src/compile/render-ssr/handlers/AwaitBlock.ts b/src/compile/render-ssr/handlers/AwaitBlock.ts index bbc4a15e05..85bf7b3135 100644 --- a/src/compile/render-ssr/handlers/AwaitBlock.ts +++ b/src/compile/render-ssr/handlers/AwaitBlock.ts @@ -1,8 +1,8 @@ -import Renderer from '../Renderer'; -import { CompileOptions } from '../../../interfaces'; +import Renderer, { RenderOptions } from '../Renderer'; import { snip } from '../../utils/snip'; +import AwaitBlock from '../../nodes/AwaitBlock'; -export default function(node, renderer: Renderer, options: CompileOptions) { +export default function(node: AwaitBlock, renderer: Renderer, options: RenderOptions) { renderer.append('${(function(__value) { if(@is_promise(__value)) return `'); renderer.render(node.pending.children, options); @@ -13,4 +13,4 @@ export default function(node, renderer: Renderer, options: CompileOptions) { const snippet = snip(node.expression); renderer.append(`\`;}(__value);}(${snippet})) }`); -} \ No newline at end of file +} diff --git a/src/compile/render-ssr/handlers/Comment.ts b/src/compile/render-ssr/handlers/Comment.ts index 4517faace5..237c260230 100644 --- a/src/compile/render-ssr/handlers/Comment.ts +++ b/src/compile/render-ssr/handlers/Comment.ts @@ -1,8 +1,8 @@ -import Renderer from '../Renderer'; -import { CompileOptions } from '../../../interfaces'; +import Renderer, { RenderOptions } from '../Renderer'; +import Comment from '../../nodes/Comment'; -export default function(node, renderer: Renderer, options: CompileOptions) { +export default function(node: Comment, renderer: Renderer, options: RenderOptions) { if (options.preserveComments) { renderer.append(``); } -} \ No newline at end of file +} diff --git a/src/compile/render-ssr/handlers/DebugTag.ts b/src/compile/render-ssr/handlers/DebugTag.ts index b04d541105..3fd7584d57 100644 --- a/src/compile/render-ssr/handlers/DebugTag.ts +++ b/src/compile/render-ssr/handlers/DebugTag.ts @@ -1,9 +1,10 @@ import { stringify } from '../../utils/stringify'; - -export default function(node, renderer, options) { +import DebugTag from '../../nodes/DebugTag'; +import Renderer, { RenderOptions } from '../Renderer'; +export default function(node: DebugTag, renderer: Renderer, options: RenderOptions) { if (!options.dev) return; - const filename = options.file || null; + const filename = options.filename || null; const { line, column } = options.locate(node.start + 1); const obj = node.expressions.length === 0 @@ -15,4 +16,4 @@ export default function(node, renderer, options) { const str = '${@debug(' + `${filename && stringify(filename)}, ${line}, ${column}, ${obj})}`; renderer.append(str); -} \ No newline at end of file +} diff --git a/src/compile/render-ssr/handlers/EachBlock.ts b/src/compile/render-ssr/handlers/EachBlock.ts index 3731093a9b..5ed27dff15 100644 --- a/src/compile/render-ssr/handlers/EachBlock.ts +++ b/src/compile/render-ssr/handlers/EachBlock.ts @@ -1,6 +1,8 @@ import { snip } from '../../utils/snip'; +import Renderer, { RenderOptions } from '../Renderer'; +import EachBlock from '../../nodes/EachBlock'; -export default function(node, renderer, options) { +export default function(node: EachBlock, renderer: Renderer, options: RenderOptions) { const snippet = snip(node.expression); const { start, end } = node.context_node; @@ -24,4 +26,4 @@ export default function(node, renderer, options) { } renderer.append('}'); -} \ No newline at end of file +} diff --git a/src/compile/render-ssr/handlers/Element.ts b/src/compile/render-ssr/handlers/Element.ts index 7717be48e3..fc6bc5b969 100644 --- a/src/compile/render-ssr/handlers/Element.ts +++ b/src/compile/render-ssr/handlers/Element.ts @@ -5,6 +5,9 @@ import Node from '../../nodes/shared/Node'; import { snip } from '../../utils/snip'; import { stringify_attribute } from '../../utils/stringify_attribute'; import { get_slot_scope } from './shared/get_slot_scope'; +import Renderer, { RenderOptions } from '../Renderer'; +import Element from '../../nodes/Element'; +import Text from '../../nodes/Text'; // source: https://gist.github.com/ArjanSchouten/0b8574a6ad7f5065a5e7 const boolean_attributes = new Set([ @@ -47,15 +50,17 @@ const boolean_attributes = new Set([ 'translate' ]); -export default function(node, renderer, options) { +export default function(node: Element, renderer: Renderer, options: RenderOptions & { + slot_scopes: Map; +}) { let opening_tag = `<${node.name}`; let textarea_contents; // awkward special case const slot = node.get_static_attribute_value('slot'); const component = node.find_nearest(/InlineComponent/); if (slot && component) { - const slot = node.attributes.find((attribute: Node) => attribute.name === 'slot'); - const slot_name = slot.chunks[0].data; + const slot = node.attributes.find((attribute) => attribute.name === 'slot'); + const slot_name = (slot.chunks[0] as Text).data; const target = renderer.targets[renderer.targets.length - 1]; target.slot_stack.push(slot_name); target.slots[slot_name] = ''; @@ -160,4 +165,4 @@ export default function(node, renderer, options) { if (!is_void(node.name)) { renderer.append(``); } -} \ No newline at end of file +} diff --git a/src/compile/render-ssr/handlers/Head.ts b/src/compile/render-ssr/handlers/Head.ts index 656759af3c..ecd32cc0ef 100644 --- a/src/compile/render-ssr/handlers/Head.ts +++ b/src/compile/render-ssr/handlers/Head.ts @@ -1,7 +1,10 @@ -export default function(node, renderer, options) { +import Renderer, { RenderOptions } from '../Renderer'; +import Head from '../../nodes/Head'; + +export default function(node: Head, renderer: Renderer, options: RenderOptions) { renderer.append('${($$result.head += `'); renderer.render(node.children, options); renderer.append('`, "")}'); -} \ No newline at end of file +} diff --git a/src/compile/render-ssr/handlers/HtmlTag.ts b/src/compile/render-ssr/handlers/HtmlTag.ts index 7562186a4b..84e2e1f573 100644 --- a/src/compile/render-ssr/handlers/HtmlTag.ts +++ b/src/compile/render-ssr/handlers/HtmlTag.ts @@ -1,5 +1,7 @@ import { snip } from '../../utils/snip'; +import Renderer, { RenderOptions } from '../Renderer'; +import RawMustacheTag from '../../nodes/RawMustacheTag'; -export default function(node, renderer, options) { +export default function(node: RawMustacheTag, renderer: Renderer, options: RenderOptions) { renderer.append('${' + snip(node.expression) + '}'); -} \ No newline at end of file +} diff --git a/src/compile/render-ssr/handlers/IfBlock.ts b/src/compile/render-ssr/handlers/IfBlock.ts index cbe505fef8..c841f1d593 100644 --- a/src/compile/render-ssr/handlers/IfBlock.ts +++ b/src/compile/render-ssr/handlers/IfBlock.ts @@ -1,6 +1,7 @@ import { snip } from '../../utils/snip'; - -export default function(node, renderer, options) { +import IfBlock from '../../nodes/IfBlock'; +import Renderer, { RenderOptions } from '../Renderer'; +export default function(node: IfBlock, renderer: Renderer, options: RenderOptions) { const snippet = snip(node.expression); renderer.append('${ ' + snippet + ' ? `'); @@ -14,4 +15,4 @@ export default function(node, renderer, options) { } renderer.append('` }'); -} \ No newline at end of file +} diff --git a/src/compile/render-ssr/handlers/InlineComponent.ts b/src/compile/render-ssr/handlers/InlineComponent.ts index bc58be5df9..94fdcfd434 100644 --- a/src/compile/render-ssr/handlers/InlineComponent.ts +++ b/src/compile/render-ssr/handlers/InlineComponent.ts @@ -1,14 +1,17 @@ import { escape, escape_template, stringify } from '../../utils/stringify'; import { quote_name_if_necessary } from '../../../utils/names'; import { snip } from '../../utils/snip'; -import Renderer from '../Renderer'; +import Renderer, { RenderOptions } from '../Renderer'; import { stringify_props } from '../../utils/stringify_props'; import { get_slot_scope } from './shared/get_slot_scope'; import { AppendTarget } from '../../../interfaces'; +import InlineComponent from '../../nodes/InlineComponent'; +import { INode } from '../../nodes/interfaces'; +import Text from '../../nodes/Text'; -function stringify_attribute(chunk: Node) { +function stringify_attribute(chunk: INode) { if (chunk.type === 'Text') { - return escape_template(escape(chunk.data)); + return escape_template(escape((chunk as Text).data)); } return '${@escape(' + snip(chunk) + ')}'; @@ -30,7 +33,7 @@ function get_attribute_value(attribute) { return '`' + attribute.chunks.map(stringify_attribute).join('') + '`'; } -export default function(node, renderer: Renderer, options) { +export default function(node: InlineComponent, renderer: Renderer, options: RenderOptions) { const binding_props = []; const binding_fns = []; diff --git a/src/compile/render-ssr/handlers/Slot.ts b/src/compile/render-ssr/handlers/Slot.ts index b2e67f9e79..087519979b 100644 --- a/src/compile/render-ssr/handlers/Slot.ts +++ b/src/compile/render-ssr/handlers/Slot.ts @@ -1,7 +1,9 @@ import { quote_prop_if_necessary } from '../../../utils/names'; import get_slot_data from '../../utils/get_slot_data'; +import Renderer, { RenderOptions } from '../Renderer'; +import Slot from '../../nodes/Slot'; -export default function(node, renderer, options) { +export default function(node: Slot, renderer: Renderer, options: RenderOptions) { const prop = quote_prop_if_necessary(node.slot_name); const slot_data = get_slot_data(node.values, true); @@ -13,4 +15,4 @@ export default function(node, renderer, options) { renderer.render(node.children, options); renderer.append(`\`}`); -} \ No newline at end of file +} diff --git a/src/compile/render-ssr/handlers/Tag.ts b/src/compile/render-ssr/handlers/Tag.ts index eb887b8688..d03f46fe0a 100644 --- a/src/compile/render-ssr/handlers/Tag.ts +++ b/src/compile/render-ssr/handlers/Tag.ts @@ -1,6 +1,6 @@ import { snip } from '../../utils/snip'; - -export default function(node, renderer, options) { +import Renderer, { RenderOptions } from '../Renderer'; +export default function(node, renderer: Renderer, options: RenderOptions) { const snippet = snip(node.expression); renderer.append( @@ -10,4 +10,4 @@ export default function(node, renderer, options) { ? '${' + snippet + '}' : '${@escape(' + snippet + ')}' ); -} \ No newline at end of file +} diff --git a/src/compile/render-ssr/handlers/Text.ts b/src/compile/render-ssr/handlers/Text.ts index e794025370..1d2906d10a 100644 --- a/src/compile/render-ssr/handlers/Text.ts +++ b/src/compile/render-ssr/handlers/Text.ts @@ -1,14 +1,17 @@ import { escape_html, escape_template, escape } from '../../utils/stringify'; +import Renderer, { RenderOptions } from '../Renderer'; +import Text from '../../nodes/Text'; +import Element from '../../nodes/Element'; -export default function(node, renderer, options) { +export default function(node: Text, renderer: Renderer, options: RenderOptions) { let text = node.data; if ( !node.parent || node.parent.type !== 'Element' || - (node.parent.name !== 'script' && node.parent.name !== 'style') + ((node.parent as Element).name !== 'script' && (node.parent as Element).name !== 'style') ) { // unless this Text node is inside a + +
{foo}
diff --git a/test/runtime/samples/dev-warning-unknown-props/_config.js b/test/runtime/samples/dev-warning-unknown-props/_config.js new file mode 100644 index 0000000000..31b605e214 --- /dev/null +++ b/test/runtime/samples/dev-warning-unknown-props/_config.js @@ -0,0 +1,9 @@ +export default { + compileOptions: { + dev: true + }, + + warnings: [ + ` was created with unknown attribute 'fo'` + ] +}; diff --git a/test/runtime/samples/dev-warning-unknown-props/main.svelte b/test/runtime/samples/dev-warning-unknown-props/main.svelte new file mode 100644 index 0000000000..1566cf3e41 --- /dev/null +++ b/test/runtime/samples/dev-warning-unknown-props/main.svelte @@ -0,0 +1,5 @@ + + + From c29c389a72fe4fe130d58728c1c95e826ac1ba1d Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Wed, 22 May 2019 05:20:43 +0200 Subject: [PATCH 10/21] convert everything to TypeScript --- .gitignore | 10 +-- index.mjs | 10 --- package.json | 2 +- rollup.config.js | 76 ++++++++----------- animate.mjs => src/animate.ts | 6 +- src/compile/index.ts | 2 +- src/compiler.ts | 6 ++ easing.mjs => src/easing.ts | 2 +- src/index.ts | 16 ++-- src/internal/{Component.js => Component.ts} | 35 +++++++-- src/internal/{animations.js => animations.ts} | 8 +- .../{await-block.js => await-block.ts} | 10 +-- src/internal/{dom.js => dom.ts} | 43 ++++++----- src/internal/index.js | 12 --- src/internal/index.ts | 12 +++ src/internal/{keyed-each.js => keyed-each.ts} | 4 +- src/internal/{lifecycle.js => lifecycle.ts} | 0 src/internal/{loop.js => loop.ts} | 10 ++- src/internal/{scheduler.js => scheduler.ts} | 4 +- src/internal/{spread.js => spread.ts} | 0 src/internal/{ssr.js => ssr.ts} | 6 +- .../{style_manager.js => style_manager.ts} | 6 +- .../{transitions.js => transitions.ts} | 13 ++-- src/internal/{utils.js => utils.ts} | 4 +- src/motion/index.js | 2 - src/motion/index.ts | 2 + src/motion/{spring.js => spring.ts} | 42 ++++++---- src/motion/{tweened.js => tweened.ts} | 4 +- src/motion/{utils.js => utils.ts} | 4 +- src/store.ts | 2 +- transition.mjs => src/transition.ts | 6 +- src/utils/indentation.ts | 2 +- tsconfig.json | 7 +- 33 files changed, 204 insertions(+), 164 deletions(-) delete mode 100644 index.mjs rename animate.mjs => src/animate.ts (86%) create mode 100644 src/compiler.ts rename easing.mjs => src/easing.ts (98%) rename src/internal/{Component.js => Component.ts} (89%) rename src/internal/{animations.js => animations.ts} (92%) rename src/internal/{await-block.js => await-block.ts} (89%) rename src/internal/{dom.js => dom.ts} (80%) delete mode 100644 src/internal/index.js create mode 100644 src/internal/index.ts rename src/internal/{keyed-each.js => keyed-each.ts} (98%) rename src/internal/{lifecycle.js => lifecycle.ts} (100%) rename src/internal/{loop.js => loop.ts} (73%) rename src/internal/{scheduler.js => scheduler.ts} (94%) rename src/internal/{spread.js => spread.ts} (100%) rename src/internal/{ssr.js => ssr.ts} (97%) rename src/internal/{style_manager.js => style_manager.ts} (95%) rename src/internal/{transitions.js => transitions.ts} (95%) rename src/internal/{utils.js => utils.ts} (96%) delete mode 100644 src/motion/index.js create mode 100644 src/motion/index.ts rename src/motion/{spring.js => spring.ts} (73%) rename src/motion/{tweened.js => tweened.ts} (98%) rename src/motion/{utils.js => utils.ts} (63%) rename transition.mjs => src/transition.ts (97%) diff --git a/.gitignore b/.gitignore index 3d1322c33e..b50d83fd2e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,14 +4,14 @@ node_modules *.map /src/compile/internal-exports.ts -/compiler.js -/index.js +/compiler.* +/index.* /internal.* /store.* -/easing.js +/easing.* /motion.* -/transition.js -/animate.js +/transition.* +/animate.* /scratch/ /coverage/ /coverage.lcov/ diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ee5b575171..0000000000 --- a/index.mjs +++ /dev/null @@ -1,10 +0,0 @@ -export { - onMount, - onDestroy, - beforeUpdate, - afterUpdate, - setContext, - getContext, - tick, - createEventDispatcher -} from './internal'; diff --git a/package.json b/package.json index b32e19786f..8665648abb 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "prepare": "npm run build && npm run tsd", "dev": "rollup -cw", "pretest": "npm run build", - "posttest": "agadoo src/internal/index.js", + "posttest": "agadoo internal.mjs", "prepublishOnly": "export PUBLISH=true && npm run lint && npm test", "tsd": "tsc -d src/store.ts --outDir .", "typecheck": "tsc --noEmit" diff --git a/rollup.config.js b/rollup.config.js index 0d19e59d4a..9fd49f3e8f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -9,10 +9,19 @@ import pkg from './package.json'; const is_publish = !!process.env.PUBLISH; +const tsPlugin = is_publish + ? typescript({ + include: 'src/**', + typescript: require('typescript') + }) + : sucrase({ + transforms: ['typescript'] + }); + export default [ /* internal.[m]js */ { - input: `src/internal/index.js`, + input: `src/internal/index.ts`, output: [ { file: `internal.mjs`, @@ -26,19 +35,22 @@ export default [ } ], external: id => id.startsWith('svelte/'), - plugins: [{ - generateBundle(options, bundle) { - const mod = bundle['internal.mjs']; - if (mod) { - fs.writeFileSync('src/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`); + + plugins: [ + tsPlugin, + { + generateBundle(options, bundle) { + const mod = bundle['internal.mjs']; + if (mod) { + fs.writeFileSync('src/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`); + } } - } - }] + }] }, /* compiler.js */ { - input: 'src/index.ts', + input: 'src/compiler.ts', plugins: [ replace({ __VERSION__: pkg.version @@ -48,15 +60,7 @@ export default [ include: ['node_modules/**'] }), json(), - is_publish - ? typescript({ - include: 'src/**', - exclude: 'src/internal/**', - typescript: require('typescript') - }) - : sucrase({ - transforms: ['typescript'] - }) + tsPlugin ], output: { file: 'compiler.js', @@ -71,7 +75,7 @@ export default [ /* motion.mjs */ { - input: `src/motion/index.js`, + input: `src/motion/index.ts`, output: [ { file: `motion.mjs`, @@ -84,46 +88,30 @@ export default [ paths: id => id.startsWith('svelte/') && id.replace('svelte', '.') } ], + plugins: [ + tsPlugin + ], external: id => id.startsWith('svelte/') }, - /* store.mjs */ - { - input: `src/store.ts`, + // everything else + ...['index', 'easing', 'transition', 'animate', 'store'].map(name => ({ + input: `src/${name}.ts`, output: [ { - file: `store.mjs`, + file: `${name}.mjs`, format: 'esm', paths: id => id.startsWith('svelte/') && id.replace('svelte', '.') }, { - file: `store.js`, + file: `${name}.js`, format: 'cjs', paths: id => id.startsWith('svelte/') && id.replace('svelte', '.') } ], plugins: [ - is_publish - ? typescript({ - include: 'src/**', - exclude: 'src/internal/**', - typescript: require('typescript') - }) - : sucrase({ - transforms: ['typescript'] - }) + tsPlugin ], external: id => id.startsWith('svelte/') - }, - - // everything else - ...['index', 'easing', 'transition', 'animate'].map(name => ({ - input: `${name}.mjs`, - output: { - file: `${name}.js`, - format: 'cjs', - paths: id => id.startsWith('svelte/') && id.replace('svelte', '.') - }, - external: id => id !== `${name}.mjs` })) ]; diff --git a/animate.mjs b/src/animate.ts similarity index 86% rename from animate.mjs rename to src/animate.ts index f22fabe401..cf64cd060a 100644 --- a/animate.mjs +++ b/src/animate.ts @@ -1,5 +1,5 @@ -import { cubicOut } from './easing'; -import { is_function } from './internal'; +import { cubicOut } from 'svelte/easing'; +import { is_function } from 'svelte/internal'; export function flip(node, animation, params) { const style = getComputedStyle(node); @@ -22,4 +22,4 @@ export function flip(node, animation, params) { easing, css: (t, u) => `transform: ${transform} translate(${u * dx}px, ${u * dy}px);` }; -} \ No newline at end of file +} diff --git a/src/compile/index.ts b/src/compile/index.ts index 526d8abaeb..dac75f23e0 100644 --- a/src/compile/index.ts +++ b/src/compile/index.ts @@ -1,4 +1,4 @@ -import { assign } from '../internal'; +import { assign } from '../internal/index'; import Stats from '../Stats'; import parse from '../parse/index'; import render_dom from './render-dom/index'; diff --git a/src/compiler.ts b/src/compiler.ts new file mode 100644 index 0000000000..4987c18a15 --- /dev/null +++ b/src/compiler.ts @@ -0,0 +1,6 @@ +export { default as compile } from './compile/index'; +export { default as parse } from './parse/index'; +export { default as preprocess } from './preprocess/index'; +export { walk } from 'estree-walker'; + +export const VERSION = '__VERSION__'; \ No newline at end of file diff --git a/easing.mjs b/src/easing.ts similarity index 98% rename from easing.mjs rename to src/easing.ts index 4fc625c24f..7a762394c2 100644 --- a/easing.mjs +++ b/src/easing.ts @@ -3,7 +3,7 @@ Adapted from https://github.com/mattdesl Distributed under MIT License https://github.com/mattdesl/eases/blob/master/LICENSE.md */ -export { identity as linear } from './internal'; +export { identity as linear } from 'svelte/internal'; export function backInOut(t) { const s = 1.70158 * 1.525; diff --git a/src/index.ts b/src/index.ts index 4987c18a15..40928da8a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,10 @@ -export { default as compile } from './compile/index'; -export { default as parse } from './parse/index'; -export { default as preprocess } from './preprocess/index'; -export { walk } from 'estree-walker'; - -export const VERSION = '__VERSION__'; \ No newline at end of file +export { + onMount, + onDestroy, + beforeUpdate, + afterUpdate, + setContext, + getContext, + tick, + createEventDispatcher +} from 'svelte/internal'; diff --git a/src/internal/Component.js b/src/internal/Component.ts similarity index 89% rename from src/internal/Component.js rename to src/internal/Component.ts index 871dbd6054..714d15df34 100644 --- a/src/internal/Component.js +++ b/src/internal/Component.ts @@ -1,7 +1,23 @@ -import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler.js'; -import { current_component, set_current_component } from './lifecycle.js'; -import { blank_object, is_function, run, run_all, noop } from './utils.js'; -import { children } from './dom.js'; +import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler'; +import { current_component, set_current_component } from './lifecycle'; +import { blank_object, is_function, run, run_all, noop } from './utils'; +import { children } from './dom'; + +interface T$$ { + dirty: null; + ctx: null|any; + bound: any; + update: () => void; + callbacks: any; + after_render: any[]; + props: any; + fragment: null|any; + not_equal: any; + before_render: any[]; + context: Map; + on_mount: any[]; + on_destroy: any[] +} export function bind(component, name, callback) { if (component.$$.props.indexOf(name) === -1) return; @@ -59,7 +75,7 @@ export function init(component, options, instance, create_fragment, not_equal, p const props = options.props || {}; - const $$ = component.$$ = { + const $$: T$$ = component.$$ = { fragment: null, ctx: null, @@ -99,9 +115,9 @@ export function init(component, options, instance, create_fragment, not_equal, p if (options.target) { if (options.hydrate) { - $$.fragment.l(children(options.target)); + $$.fragment!.l(children(options.target)); } else { - $$.fragment.c(); + $$.fragment!.c(); } if (options.intro && component.$$.fragment.i) component.$$.fragment.i(); @@ -115,13 +131,16 @@ export function init(component, options, instance, create_fragment, not_equal, p export let SvelteElement; if (typeof HTMLElement !== 'undefined') { SvelteElement = class extends HTMLElement { + $$: T$$; constructor() { super(); this.attachShadow({ mode: 'open' }); } connectedCallback() { + // @ts-ignore todo: improve typings for (const key in this.$$.slotted) { + // @ts-ignore todo: improve typings this.appendChild(this.$$.slotted[key]); } } @@ -153,6 +172,8 @@ if (typeof HTMLElement !== 'undefined') { } export class SvelteComponent { + $$: T$$; + $destroy() { destroy(this, true); this.$destroy = noop; diff --git a/src/internal/animations.js b/src/internal/animations.ts similarity index 92% rename from src/internal/animations.js rename to src/internal/animations.ts index 8d55c196ee..b6c7ae2df2 100644 --- a/src/internal/animations.js +++ b/src/internal/animations.ts @@ -1,6 +1,6 @@ -import { identity as linear, noop, now } from './utils.js'; -import { loop } from './loop.js'; -import { create_rule, delete_rule } from './style_manager.js'; +import { identity as linear, noop, now } from './utils'; +import { loop } from './loop'; +import { create_rule, delete_rule } from './style_manager'; export function create_animation(node, from, fn, params) { if (!from) return noop; @@ -90,4 +90,4 @@ export function fix_position(node) { node.style.transform = `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`; } } -} \ No newline at end of file +} diff --git a/src/internal/await-block.js b/src/internal/await-block.ts similarity index 89% rename from src/internal/await-block.js rename to src/internal/await-block.ts index 9e14c50342..9527b000ca 100644 --- a/src/internal/await-block.js +++ b/src/internal/await-block.ts @@ -1,11 +1,11 @@ -import { assign, is_promise } from './utils.js'; -import { check_outros, group_outros, on_outro } from './transitions.js'; -import { flush } from '../internal/scheduler.js'; +import { assign, is_promise } from './utils'; +import { check_outros, group_outros, on_outro } from './transitions'; +import { flush } from '../internal/scheduler'; export function handle_promise(promise, info) { const token = info.token = {}; - function update(type, index, key, value) { + function update(type, index, key?, value?) { if (info.token !== token) return; info.resolved = key && { [key]: value }; @@ -61,4 +61,4 @@ export function handle_promise(promise, info) { info.resolved = { [info.value]: promise }; } -} \ No newline at end of file +} diff --git a/src/internal/dom.js b/src/internal/dom.ts similarity index 80% rename from src/internal/dom.js rename to src/internal/dom.ts index 46ffaa8472..293040ce20 100644 --- a/src/internal/dom.js +++ b/src/internal/dom.ts @@ -1,28 +1,28 @@ -export function append(target, node) { +export function append(target:Node, node:Node) { target.appendChild(node); } -export function insert(target, node, anchor) { +export function insert(target: Node, node: Node, anchor?:Node) { target.insertBefore(node, anchor || null); } -export function detach(node) { +export function detach(node: Node) { node.parentNode.removeChild(node); } -export function detach_between(before, after) { +export function detach_between(before: Node, after: Node) { while (before.nextSibling && before.nextSibling !== after) { before.parentNode.removeChild(before.nextSibling); } } -export function detach_before(after) { +export function detach_before(after:Node) { while (after.previousSibling) { after.parentNode.removeChild(after.previousSibling); } } -export function detach_after(before) { +export function detach_after(before:Node) { while (before.nextSibling) { before.parentNode.removeChild(before.nextSibling); } @@ -34,25 +34,30 @@ export function destroy_each(iterations, detaching) { } } -export function element(name) { - return document.createElement(name); +export function element(name: K) { + return document.createElement(name); } -export function object_without_properties(obj, exclude) { - const target = {}; +export function object_without_properties(obj:T, exclude: K[]) { + const target = {} as Pick>; for (const k in obj) { - if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) { + if ( + Object.prototype.hasOwnProperty.call(obj, k) + // @ts-ignore + && exclude.indexOf(k) === -1 + ) { + // @ts-ignore target[k] = obj[k]; } } return target; } -export function svg_element(name) { +export function svg_element(name:string):SVGElement { return document.createElementNS('http://www.w3.org/2000/svg', name); } -export function text(data) { +export function text(data:string) { return document.createTextNode(data); } @@ -64,7 +69,7 @@ export function empty() { return text(''); } -export function listen(node, event, handler, options) { +export function listen(node: Node, event: string, handler: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | EventListenerOptions) { node.addEventListener(event, handler, options); return () => node.removeEventListener(event, handler, options); } @@ -72,6 +77,7 @@ export function listen(node, event, handler, options) { export function prevent_default(fn) { return function(event) { event.preventDefault(); + // @ts-ignore return fn.call(this, event); }; } @@ -79,16 +85,17 @@ export function prevent_default(fn) { export function stop_propagation(fn) { return function(event) { event.stopPropagation(); + // @ts-ignore return fn.call(this, event); }; } -export function attr(node, attribute, value) { +export function attr(node: Element, attribute: string, value?: string) { if (value == null) node.removeAttribute(attribute); else node.setAttribute(attribute, value); } -export function set_attributes(node, attributes) { +export function set_attributes(node: HTMLElement, attributes: { [x: string]: string; }) { for (const key in attributes) { if (key === 'style') { node.style.cssText = attributes[key]; @@ -243,8 +250,8 @@ export function toggle_class(element, name, toggle) { element.classList[toggle ? 'add' : 'remove'](name); } -export function custom_event(type, detail) { - const e = document.createEvent('CustomEvent'); +export function custom_event(type: string, detail?: T) { + const e: CustomEvent = document.createEvent('CustomEvent'); e.initCustomEvent(type, false, false, detail); return e; } diff --git a/src/internal/index.js b/src/internal/index.js deleted file mode 100644 index f3654f6b77..0000000000 --- a/src/internal/index.js +++ /dev/null @@ -1,12 +0,0 @@ -export * from './animations.js'; -export * from './await-block.js'; -export * from './dom.js'; -export * from './keyed-each.js'; -export * from './lifecycle.js'; -export * from './loop.js'; -export * from './scheduler.js'; -export * from './spread.js'; -export * from './ssr.js'; -export * from './transitions.js'; -export * from './utils.js'; -export * from './Component.js'; \ No newline at end of file diff --git a/src/internal/index.ts b/src/internal/index.ts new file mode 100644 index 0000000000..6487f04525 --- /dev/null +++ b/src/internal/index.ts @@ -0,0 +1,12 @@ +export * from './animations'; +export * from './await-block'; +export * from './dom'; +export * from './keyed-each'; +export * from './lifecycle'; +export * from './loop'; +export * from './scheduler'; +export * from './spread'; +export * from './ssr'; +export * from './transitions'; +export * from './utils'; +export * from './Component'; diff --git a/src/internal/keyed-each.js b/src/internal/keyed-each.ts similarity index 98% rename from src/internal/keyed-each.js rename to src/internal/keyed-each.ts index c40a1cc00b..0ec8b09400 100644 --- a/src/internal/keyed-each.js +++ b/src/internal/keyed-each.ts @@ -1,4 +1,4 @@ -import { on_outro } from './transitions.js'; +import { on_outro } from './transitions'; export function destroy_block(block, lookup) { block.d(1); @@ -110,4 +110,4 @@ export function measure(blocks) { let i = blocks.length; while (i--) rects[blocks[i].key] = blocks[i].node.getBoundingClientRect(); return rects; -} \ No newline at end of file +} diff --git a/src/internal/lifecycle.js b/src/internal/lifecycle.ts similarity index 100% rename from src/internal/lifecycle.js rename to src/internal/lifecycle.ts diff --git a/src/internal/loop.js b/src/internal/loop.ts similarity index 73% rename from src/internal/loop.js rename to src/internal/loop.ts index 8150727441..b6cd53a189 100644 --- a/src/internal/loop.js +++ b/src/internal/loop.ts @@ -1,4 +1,6 @@ -import { now } from './utils.js'; +import { now } from './utils'; + +export interface Task { abort(): void; promise: Promise } const tasks = new Set(); let running = false; @@ -21,7 +23,7 @@ export function clear_loops() { running = false; } -export function loop(fn) { +export function loop(fn: (number)=>void): Task { let task; if (!running) { @@ -30,11 +32,11 @@ export function loop(fn) { } return { - promise: new Promise(fulfil => { + promise: new Promise(fulfil => { tasks.add(task = [fn, fulfil]); }), abort() { tasks.delete(task); } }; -} \ No newline at end of file +} diff --git a/src/internal/scheduler.js b/src/internal/scheduler.ts similarity index 94% rename from src/internal/scheduler.js rename to src/internal/scheduler.ts index 749c3971dc..a26a4f8c33 100644 --- a/src/internal/scheduler.js +++ b/src/internal/scheduler.ts @@ -1,5 +1,5 @@ -import { run_all } from './utils.js'; -import { set_current_component } from './lifecycle.js'; +import { run_all } from './utils'; +import { set_current_component } from './lifecycle'; export const dirty_components = []; export const intros = { enabled: false }; diff --git a/src/internal/spread.js b/src/internal/spread.ts similarity index 100% rename from src/internal/spread.js rename to src/internal/spread.ts diff --git a/src/internal/ssr.js b/src/internal/ssr.ts similarity index 97% rename from src/internal/ssr.js rename to src/internal/ssr.ts index e8d96c609c..aaa391b4dc 100644 --- a/src/internal/ssr.js +++ b/src/internal/ssr.ts @@ -1,5 +1,5 @@ -import { set_current_component, current_component } from './lifecycle.js'; -import { run_all, blank_object } from './utils.js'; +import { set_current_component, current_component } from './lifecycle'; +import { run_all, blank_object } from './utils'; export const invalid_attribute_name_character = /[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u; // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 @@ -117,4 +117,4 @@ export function get_store_value(store) { let value; store.subscribe(_ => value = _)(); return value; -} \ No newline at end of file +} diff --git a/src/internal/style_manager.js b/src/internal/style_manager.ts similarity index 95% rename from src/internal/style_manager.js rename to src/internal/style_manager.ts index d71e922f01..8e4d35ca38 100644 --- a/src/internal/style_manager.js +++ b/src/internal/style_manager.ts @@ -1,4 +1,4 @@ -import { element } from './dom.js'; +import { element } from './dom'; let stylesheet; let active = 0; @@ -43,7 +43,7 @@ export function create_rule(node, a, b, duration, delay, ease, fn, uid = 0) { return name; } -export function delete_rule(node, name) { +export function delete_rule(node, name?) { node.style.animation = (node.style.animation || '') .split(', ') .filter(name @@ -62,4 +62,4 @@ export function clear_rules() { while (i--) stylesheet.deleteRule(i); current_rules = {}; }); -} \ No newline at end of file +} diff --git a/src/internal/transitions.js b/src/internal/transitions.ts similarity index 95% rename from src/internal/transitions.js rename to src/internal/transitions.ts index af15e8969e..04942e3d16 100644 --- a/src/internal/transitions.js +++ b/src/internal/transitions.ts @@ -1,8 +1,8 @@ -import { identity as linear, noop, now, run_all } from './utils.js'; -import { loop } from './loop.js'; -import { create_rule, delete_rule } from './style_manager.js'; -import { custom_event } from './dom.js'; -import { add_render_callback } from './scheduler.js'; +import { identity as linear, noop, now, run_all } from './utils'; +import { loop } from './loop'; +import { create_rule, delete_rule } from './style_manager'; +import { custom_event } from './dom'; +import { add_render_callback } from './scheduler'; let promise; @@ -229,6 +229,7 @@ export function create_bidirectional_transition(node, fn, params, intro) { }; if (!b) { + // @ts-ignore todo: improve typings program.group = outros; outros.remaining += 1; } @@ -309,4 +310,4 @@ export function create_bidirectional_transition(node, fn, params, intro) { running_program = pending_program = null; } }; -} \ No newline at end of file +} diff --git a/src/internal/utils.js b/src/internal/utils.ts similarity index 96% rename from src/internal/utils.js rename to src/internal/utils.ts index e6d66d8717..8bb40ac071 100644 --- a/src/internal/utils.js +++ b/src/internal/utils.ts @@ -80,11 +80,11 @@ export function exclude_internal_props(props) { return result; } -export let now = typeof window !== 'undefined' +export let now: () => number = typeof window !== 'undefined' ? () => window.performance.now() : () => Date.now(); // used internally for testing export function set_now(fn) { now = fn; -} \ No newline at end of file +} diff --git a/src/motion/index.js b/src/motion/index.js deleted file mode 100644 index e0e9bcf1ae..0000000000 --- a/src/motion/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from './spring.js'; -export * from './tweened.js'; \ No newline at end of file diff --git a/src/motion/index.ts b/src/motion/index.ts new file mode 100644 index 0000000000..ea6c646dd9 --- /dev/null +++ b/src/motion/index.ts @@ -0,0 +1,2 @@ +export * from './spring'; +export * from './tweened'; diff --git a/src/motion/spring.js b/src/motion/spring.ts similarity index 73% rename from src/motion/spring.js rename to src/motion/spring.ts index 8b280366b2..3977c08f79 100644 --- a/src/motion/spring.js +++ b/src/motion/spring.ts @@ -1,6 +1,6 @@ -import { writable } from 'svelte/store'; // eslint-disable-line import/no-unresolved -import { loop, now } from 'svelte/internal'; // eslint-disable-line import/no-unresolved -import { is_date } from './utils.js'; +import { Readable, writable } from 'svelte/store'; +import { loop, now, Task } from 'svelte/internal'; +import { is_date } from './utils'; function tick_spring(ctx, last_value, current_value, target_value) { if (typeof current_value === 'number' || is_date(current_value)) { @@ -27,25 +27,41 @@ function tick_spring(ctx, last_value, current_value, target_value) { next_value[k] = tick_spring(ctx, last_value[k], current_value[k], target_value[k]); return next_value; } else { - throw new Error(`Cannot spring ${typeof value} values`); + throw new Error(`Cannot spring ${typeof current_value} values`); } } -export function spring(value, opts = {}) { +interface SpringOpts { + stiffness?: number, + damping?: number, + precision?: number, +} + +type SpringUpdateOpts = { hard?: any; soft?: string | number | boolean; }; + +interface Spring extends Readable{ + set: (new_value: T, opts?: SpringUpdateOpts) => (Promise | Promise); + precision: number; + update: (fn, opts: SpringUpdateOpts) => Promise; + damping: number; + stiffness: number +} + +export function spring(value: T, opts: SpringOpts = {}) { const store = writable(value); const { stiffness = 0.15, damping = 0.8, precision = 0.01 } = opts; - let last_time; - let task; - let current_token; - let last_value = value; - let target_value = value; + let last_time: number; + let task: Task; + let current_token: object; + let last_value:T = value; + let target_value:T = value; let inv_mass = 1; let inv_mass_recovery_rate = 0; let cancel_task = false; - function set(new_value, opts = {}) { + function set(new_value: any, opts: SpringUpdateOpts={}) { target_value = new_value; const token = current_token = {}; @@ -100,9 +116,9 @@ export function spring(value, opts = {}) { }); } - const spring = { + const spring: Spring = { set, - update: (fn, opts) => set(fn(target_value, value), opts), + update: (fn, opts:SpringUpdateOpts) => set(fn(target_value, value), opts), subscribe: store.subscribe, stiffness, damping, diff --git a/src/motion/tweened.js b/src/motion/tweened.ts similarity index 98% rename from src/motion/tweened.js rename to src/motion/tweened.ts index 45520832b7..3b2d0ef5a2 100644 --- a/src/motion/tweened.js +++ b/src/motion/tweened.ts @@ -1,7 +1,7 @@ import { writable } from 'svelte/store'; // eslint-disable-line import/no-unresolved import { assign, loop, now } from 'svelte/internal'; // eslint-disable-line import/no-unresolved import { linear } from 'svelte/easing'; // eslint-disable-line import/no-unresolved -import { is_date } from './utils.js'; +import { is_date } from './utils'; function get_interpolator(a, b) { if (a === b || a !== a) return () => a; @@ -109,4 +109,4 @@ export function tweened(value, defaults = {}) { update: (fn, opts) => set(fn(target_value, value), opts), subscribe: store.subscribe }; -} \ No newline at end of file +} diff --git a/src/motion/utils.js b/src/motion/utils.ts similarity index 63% rename from src/motion/utils.js rename to src/motion/utils.ts index 97a764bf46..f8bfcce14c 100644 --- a/src/motion/utils.js +++ b/src/motion/utils.ts @@ -1,3 +1,3 @@ -export function is_date(obj) { +export function is_date(obj: any) { return Object.prototype.toString.call(obj) === '[object Date]'; -} \ No newline at end of file +} diff --git a/src/store.ts b/src/store.ts index b0ee41fc8d..361632b61d 100644 --- a/src/store.ts +++ b/src/store.ts @@ -1,4 +1,4 @@ -import { run_all, noop, safe_not_equal, is_function } from './internal/utils'; +import { run_all, noop, safe_not_equal, is_function } from 'svelte/internal'; /** Callback to inform of a value updates. */ type Subscriber = (value: T) => void; diff --git a/transition.mjs b/src/transition.ts similarity index 97% rename from transition.mjs rename to src/transition.ts index 857fd03165..20619ee131 100644 --- a/transition.mjs +++ b/src/transition.ts @@ -1,5 +1,5 @@ -import { cubicOut, cubicInOut } from './easing'; -import { assign, is_function } from './internal'; +import { cubicOut, cubicInOut } from 'svelte/easing'; +import { assign, is_function } from 'svelte/internal'; export function fade(node, { delay = 0, @@ -179,4 +179,4 @@ export function crossfade({ fallback, ...defaults }) { transition(to_send, to_receive, false), transition(to_receive, to_send, true) ]; -} \ No newline at end of file +} diff --git a/src/utils/indentation.ts b/src/utils/indentation.ts index 765a62bfbf..54ededc37d 100644 --- a/src/utils/indentation.ts +++ b/src/utils/indentation.ts @@ -54,4 +54,4 @@ export function add_indentation(code: MagicString, node: Node, levels = 1) { code.appendLeft(index + 1, indent); } -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index fdb7367e05..acbca11ac7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,12 +7,17 @@ "allowJs": true, "lib": ["es5", "es6", "dom"], "importHelpers": true, - "moduleResolution": "node" + "moduleResolution": "node", + "baseUrl": ".", + "paths": { + "svelte/*": ["./src/*"] + } }, "include": [ "src" ], "exclude": [ + "./*.*js", "node_modules" ] } From d5d5caba600b9bbc1b0e0e2000a0a3c34d1ed303 Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Wed, 22 May 2019 07:31:39 +0200 Subject: [PATCH 11/21] type declarations for bundled files --- .gitignore | 17 ++++++++-------- animate.d.ts | 1 + compiler.d.ts | 1 + easing.d.ts | 1 + index.d.ts | 1 + internal.d.ts | 1 + motion.d.ts | 1 + package.json | 4 ++-- store.d.ts | 1 + transition.d.ts | 1 + tsconfig.json | 53 +++++++++++++++++++++++++++++-------------------- 11 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 animate.d.ts create mode 100644 compiler.d.ts create mode 100644 easing.d.ts create mode 100644 index.d.ts create mode 100644 internal.d.ts create mode 100644 motion.d.ts create mode 100644 store.d.ts create mode 100644 transition.d.ts diff --git a/.gitignore b/.gitignore index b50d83fd2e..35888493fa 100644 --- a/.gitignore +++ b/.gitignore @@ -4,14 +4,14 @@ node_modules *.map /src/compile/internal-exports.ts -/compiler.* -/index.* -/internal.* -/store.* -/easing.* -/motion.* -/transition.* -/animate.* +/compiler.*js +/index.*js +/internal.*js +/store.*js +/easing.*js +/motion.*js +/transition.*js +/animate.*js /scratch/ /coverage/ /coverage.lcov/ @@ -21,6 +21,7 @@ node_modules /test/sourcemaps/samples/*/output.css.map /yarn-error.log _actual*.* +/dist /site/cypress/screenshots/ /site/__sapper__/ diff --git a/animate.d.ts b/animate.d.ts new file mode 100644 index 0000000000..3284bfd8c0 --- /dev/null +++ b/animate.d.ts @@ -0,0 +1 @@ +export * from './dist/animate'; diff --git a/compiler.d.ts b/compiler.d.ts new file mode 100644 index 0000000000..977efefb6d --- /dev/null +++ b/compiler.d.ts @@ -0,0 +1 @@ +export * from './dist/compiler'; diff --git a/easing.d.ts b/easing.d.ts new file mode 100644 index 0000000000..c07764f4f0 --- /dev/null +++ b/easing.d.ts @@ -0,0 +1 @@ +export * from './dist/easing'; diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000000..e4ddc9027e --- /dev/null +++ b/index.d.ts @@ -0,0 +1 @@ +export * from './dist/index'; diff --git a/internal.d.ts b/internal.d.ts new file mode 100644 index 0000000000..be034cd88a --- /dev/null +++ b/internal.d.ts @@ -0,0 +1 @@ +export * from './dist/internal'; diff --git a/motion.d.ts b/motion.d.ts new file mode 100644 index 0000000000..2fdaa86c4e --- /dev/null +++ b/motion.d.ts @@ -0,0 +1 @@ +export * from './dist/motion'; diff --git a/package.json b/package.json index 8665648abb..7963e2178d 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,8 @@ "pretest": "npm run build", "posttest": "agadoo internal.mjs", "prepublishOnly": "export PUBLISH=true && npm run lint && npm test", - "tsd": "tsc -d src/store.ts --outDir .", - "typecheck": "tsc --noEmit" + "tsd": "tsc -p . --emitDeclarationOnly", + "typecheck": "tsc -p . --noEmit" }, "repository": { "type": "git", diff --git a/store.d.ts b/store.d.ts new file mode 100644 index 0000000000..2c1307011b --- /dev/null +++ b/store.d.ts @@ -0,0 +1 @@ +export * from './dist/store'; diff --git a/transition.d.ts b/transition.d.ts new file mode 100644 index 0000000000..54d5f036da --- /dev/null +++ b/transition.d.ts @@ -0,0 +1 @@ +export * from './dist/transition'; diff --git a/tsconfig.json b/tsconfig.json index acbca11ac7..ff11591679 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,23 +1,34 @@ { - "compilerOptions": { - "target": "ES6", - "diagnostics": true, - "noImplicitThis": true, - "noEmitOnError": true, - "allowJs": true, - "lib": ["es5", "es6", "dom"], - "importHelpers": true, - "moduleResolution": "node", - "baseUrl": ".", - "paths": { - "svelte/*": ["./src/*"] - } - }, - "include": [ - "src" - ], - "exclude": [ - "./*.*js", - "node_modules" - ] + "compilerOptions": { + "target": "es2015", + "module": "es6", + "declarationDir": "./dist", + "outDir": "./dist", + "declaration": true, + "noImplicitThis": true, + "noEmitOnError": true, + "lib": [ + "es5", + "es6", + "dom", + "es2015" + ], + "importHelpers": true, + "moduleResolution": "node", + "baseUrl": ".", + "paths": { + "svelte/*": [ + "./src/*" + ] + }, + "typeRoots": [ + "node_modules/@types" + ] + }, + "include": [ + "src/**/*" + ], + "exclude": [ + "dist" + ] } From 33f827ca0a6f1a82f9123c0d3e6655482a687ec8 Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Wed, 22 May 2019 08:06:47 +0200 Subject: [PATCH 12/21] fix case sensitive import name, improve tsconfig --- src/compile/render-dom/wrappers/RawMustacheTag.ts | 2 +- tsconfig.json | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compile/render-dom/wrappers/RawMustacheTag.ts b/src/compile/render-dom/wrappers/RawMustacheTag.ts index d8f863c674..326852bb18 100644 --- a/src/compile/render-dom/wrappers/RawMustacheTag.ts +++ b/src/compile/render-dom/wrappers/RawMustacheTag.ts @@ -1,7 +1,7 @@ import Renderer from '../Renderer'; import Block from '../Block'; import Tag from './shared/Tag'; -import Wrapper from './shared/wrapper'; +import Wrapper from './shared/Wrapper'; import deindent from '../../utils/deindent'; import MustacheTag from '../../nodes/MustacheTag'; import RawMustacheTag from '../../nodes/RawMustacheTag'; diff --git a/tsconfig.json b/tsconfig.json index ff11591679..994bc61b85 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,9 +17,10 @@ "moduleResolution": "node", "baseUrl": ".", "paths": { - "svelte/*": [ - "./src/*" - ] + "svelte/internal": ["./src/internal"], + "svelte/easing": ["./src/easing"], + "svelte/motion": ["./src/motion"], + "svelte/store": ["./src/store"] }, "typeRoots": [ "node_modules/@types" From dabc9c3e5310316d82bfd8ef16f13e9a4fed3e66 Mon Sep 17 00:00:00 2001 From: Benjamin Milde Date: Fri, 24 May 2019 17:13:58 +0200 Subject: [PATCH 13/21] Allow binding of
open --- src/compile/nodes/Element.ts | 10 ++- .../render-dom/wrappers/Element/index.ts | 6 ++ test/js/samples/bind-open/expected.js | 69 +++++++++++++++++++ test/js/samples/bind-open/input.svelte | 7 ++ .../samples/binding-details-open/_config.js | 25 +++++++ .../samples/binding-details-open/main.svelte | 9 +++ 6 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 test/js/samples/bind-open/expected.js create mode 100644 test/js/samples/bind-open/input.svelte create mode 100644 test/runtime/samples/binding-details-open/_config.js create mode 100644 test/runtime/samples/binding-details-open/main.svelte diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index ac2b81b3e7..2b76d68e6d 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -544,7 +544,7 @@ export default class Element extends Node { message: `'group' binding can only be used with or ` }); } - } else if (name == 'files') { + } else if (name === 'files') { if (this.name !== 'input') { component.error(binding, { code: `invalid-binding`, @@ -560,6 +560,14 @@ export default class Element extends Node { message: `'files' binding can only be used with ` }); } + + } else if (name === 'open') { + if (this.name !== 'details') { + component.error(binding, { + code: `invalid-binding`, + message: `'${name}' binding can only be used with
` + }); + } } else if ( name === 'currentTime' || name === 'duration' || diff --git a/src/compile/render-dom/wrappers/Element/index.ts b/src/compile/render-dom/wrappers/Element/index.ts index 22ea7a78cd..ad85a46db3 100644 --- a/src/compile/render-dom/wrappers/Element/index.ts +++ b/src/compile/render-dom/wrappers/Element/index.ts @@ -91,6 +91,12 @@ const events = [ name === 'playbackRate' }, + // details event + { + event_names: ['toggle'], + filter: (node: Element, name: string) => + node.name === 'details' + }, ]; export default class ElementWrapper extends Wrapper { diff --git a/test/js/samples/bind-open/expected.js b/test/js/samples/bind-open/expected.js new file mode 100644 index 0000000000..7c73c8ddac --- /dev/null +++ b/test/js/samples/bind-open/expected.js @@ -0,0 +1,69 @@ +/* generated by Svelte vX.Y.Z */ +import { + SvelteComponent, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal +} from "svelte/internal"; + +function create_fragment(ctx) { + var details, dispose; + + return { + c() { + details = element("details"); + details.innerHTML = `summarycontent + `; + dispose = listen(details, "toggle", ctx.details_toggle_handler); + }, + + m(target, anchor) { + insert(target, details, anchor); + + details.open = ctx.open; + }, + + p(changed, ctx) { + if (changed.open) details.open = ctx.open; + }, + + i: noop, + o: noop, + + d(detaching) { + if (detaching) { + detach(details); + } + + dispose(); + } + }; +} + +function instance($$self, $$props, $$invalidate) { + let { open } = $$props; + + function details_toggle_handler() { + open = this.open; + $$invalidate('open', open); + } + + $$self.$set = $$props => { + if ('open' in $$props) $$invalidate('open', open = $$props.open); + }; + + return { open, details_toggle_handler }; +} + +class Component extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance, create_fragment, safe_not_equal, ["open"]); + } +} + +export default Component; diff --git a/test/js/samples/bind-open/input.svelte b/test/js/samples/bind-open/input.svelte new file mode 100644 index 0000000000..3dd2b03a73 --- /dev/null +++ b/test/js/samples/bind-open/input.svelte @@ -0,0 +1,7 @@ + + +
+ summarycontent +
diff --git a/test/runtime/samples/binding-details-open/_config.js b/test/runtime/samples/binding-details-open/_config.js new file mode 100644 index 0000000000..e5e81b2c93 --- /dev/null +++ b/test/runtime/samples/binding-details-open/_config.js @@ -0,0 +1,25 @@ +export default { + html: ` +
toggle
+ `, + + async test({ assert, component, target, window }) { + const details = target.querySelector('details'); + const event = new window.Event('toggle'); + + details.open = true; + await details.dispatchEvent(event); + assert.equal(component.open, true); + assert.htmlEqual(target.innerHTML, ` +
toggle
+

hello!

+ `); + + details.open = false; + await details.dispatchEvent(event); + assert.equal(component.open, false); + assert.htmlEqual(target.innerHTML, ` +
toggle
+ `); + } +}; diff --git a/test/runtime/samples/binding-details-open/main.svelte b/test/runtime/samples/binding-details-open/main.svelte new file mode 100644 index 0000000000..3a7a08e121 --- /dev/null +++ b/test/runtime/samples/binding-details-open/main.svelte @@ -0,0 +1,9 @@ + + +
toggle
+ +{#if visible} +

hello!

+{/if} From a5fe09c48154c9b993dfc5386e8f7c72ce748d09 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 24 May 2019 14:12:41 -0400 Subject: [PATCH 14/21] treat requestAnimationFrame as a noop on the server --- package-lock.json | 2 +- src/compile/render-dom/wrappers/Element/index.ts | 2 +- src/internal/loop.js | 6 +++--- src/internal/style_manager.js | 3 ++- src/internal/utils.js | 8 ++++++-- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index bb2b7d7d7e..28ecb0eedb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.4.0", + "version": "3.4.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/compile/render-dom/wrappers/Element/index.ts b/src/compile/render-dom/wrappers/Element/index.ts index 22ea7a78cd..ad624c8d6c 100644 --- a/src/compile/render-dom/wrappers/Element/index.ts +++ b/src/compile/render-dom/wrappers/Element/index.ts @@ -455,7 +455,7 @@ export default class ElementWrapper extends Wrapper { function ${handler}() { ${animation_frame && deindent` cancelAnimationFrame(${animation_frame}); - if (!${this.var}.paused) ${animation_frame} = requestAnimationFrame(${handler});`} + if (!${this.var}.paused) ${animation_frame} = @raf(${handler});`} ${needs_lock && `${lock} = true;`} ctx.${handler}.call(${this.var}${contextual_dependencies.size > 0 ? ', ctx' : ''}); } diff --git a/src/internal/loop.js b/src/internal/loop.js index 8150727441..60c7df4d70 100644 --- a/src/internal/loop.js +++ b/src/internal/loop.js @@ -1,4 +1,4 @@ -import { now } from './utils.js'; +import { now, raf } from './utils.js'; const tasks = new Set(); let running = false; @@ -12,7 +12,7 @@ function run_tasks() { }); running = tasks.size > 0; - if (running) requestAnimationFrame(run_tasks); + if (running) raf(run_tasks); } export function clear_loops() { @@ -26,7 +26,7 @@ export function loop(fn) { if (!running) { running = true; - requestAnimationFrame(run_tasks); + raf(run_tasks); } return { diff --git a/src/internal/style_manager.js b/src/internal/style_manager.js index d71e922f01..3679470399 100644 --- a/src/internal/style_manager.js +++ b/src/internal/style_manager.js @@ -1,4 +1,5 @@ import { element } from './dom.js'; +import { raf } from './utils.js'; let stylesheet; let active = 0; @@ -56,7 +57,7 @@ export function delete_rule(node, name) { } export function clear_rules() { - requestAnimationFrame(() => { + raf(() => { if (active) return; let i = stylesheet.cssRules.length; while (i--) stylesheet.deleteRule(i); diff --git a/src/internal/utils.js b/src/internal/utils.js index e6d66d8717..c493eacb96 100644 --- a/src/internal/utils.js +++ b/src/internal/utils.js @@ -80,11 +80,15 @@ export function exclude_internal_props(props) { return result; } -export let now = typeof window !== 'undefined' +const is_client = typeof window !== 'undefined'; + +export let now = is_client ? () => window.performance.now() : () => Date.now(); // used internally for testing export function set_now(fn) { now = fn; -} \ No newline at end of file +} + +export const raf = is_client ? requestAnimationFrame : noop; \ No newline at end of file From ef59c32099ef27620be6ad5759e136925db4d819 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Fri, 24 May 2019 16:31:01 -0700 Subject: [PATCH 15/21] Fixes #2714 --- src/parse/state/tag.ts | 9 +++++++-- src/parse/state/text.ts | 9 +++++++-- test/parser/samples/attribute-escaped/output.json | 3 ++- .../samples/convert-entities-in-element/output.json | 3 ++- test/parser/samples/convert-entities/output.json | 3 ++- test/parser/samples/nbsp/output.json | 3 ++- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index 56195549d8..fc5fc3620d 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -490,8 +490,13 @@ function read_sequence(parser: Parser, done: () => boolean) { if (current_chunk.data) chunks.push(current_chunk); chunks.forEach(chunk => { - if (chunk.type === 'Text') - chunk.data = decode_character_references(chunk.data); + if (chunk.type === 'Text') { + let decoded = decode_character_references(chunk.data); + if (chunk.data != decoded) { + chunk.raw = chunk.data; + chunk.data = decoded; + } + } }); return chunks; diff --git a/src/parse/state/text.ts b/src/parse/state/text.ts index f739c8cc9e..503d79aa08 100644 --- a/src/parse/state/text.ts +++ b/src/parse/state/text.ts @@ -14,10 +14,15 @@ export default function text(parser: Parser) { data += parser.template[parser.index++]; } - parser.current().children.push({ + let node = { start, end: parser.index, type: 'Text', data: decode_character_references(data), - }); + }; + + if (node.data != data) + node.raw = data; + + parser.current().children.push(node); } diff --git a/test/parser/samples/attribute-escaped/output.json b/test/parser/samples/attribute-escaped/output.json index 6a4143e674..79b135eb86 100644 --- a/test/parser/samples/attribute-escaped/output.json +++ b/test/parser/samples/attribute-escaped/output.json @@ -20,7 +20,8 @@ "start": 15, "end": 33, "type": "Text", - "data": "\"quoted\"" + "data": "\"quoted\"", + "raw": ""quoted"" } ] } diff --git a/test/parser/samples/convert-entities-in-element/output.json b/test/parser/samples/convert-entities-in-element/output.json index fb0f5b288e..92b5aafb00 100644 --- a/test/parser/samples/convert-entities-in-element/output.json +++ b/test/parser/samples/convert-entities-in-element/output.json @@ -15,7 +15,8 @@ "start": 3, "end": 20, "type": "Text", - "data": "Hello & World" + "data": "Hello & World", + "raw": "Hello & World" } ] } diff --git a/test/parser/samples/convert-entities/output.json b/test/parser/samples/convert-entities/output.json index ca1c1356f8..967895383d 100644 --- a/test/parser/samples/convert-entities/output.json +++ b/test/parser/samples/convert-entities/output.json @@ -8,7 +8,8 @@ "start": 0, "end": 17, "type": "Text", - "data": "Hello & World" + "data": "Hello & World", + "raw": "Hello & World" } ] }, diff --git a/test/parser/samples/nbsp/output.json b/test/parser/samples/nbsp/output.json index 4fa318ce48..c47257c873 100644 --- a/test/parser/samples/nbsp/output.json +++ b/test/parser/samples/nbsp/output.json @@ -15,7 +15,8 @@ "start": 6, "end": 12, "type": "Text", - "data": " " + "data": " ", + "raw": " " } ] } From 4c805018e4d20218e95017ca571fa908f10cdaec Mon Sep 17 00:00:00 2001 From: Elliot Waite <1767836+elliotwaite@users.noreply.github.com> Date: Fri, 24 May 2019 15:55:18 -1000 Subject: [PATCH 16/21] Fix CRUD example to allow changing input values. Currently, the first name and last name inputs fields can't be edited without the changes immediately being overwritten back to the selected person's first name and last name. This change will make it so that the input fields only get overwritten with the selected person's first name and last name when the selected person is changed. --- site/content/examples/19-7guis/05-7guis-crud/App.svelte | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/site/content/examples/19-7guis/05-7guis-crud/App.svelte b/site/content/examples/19-7guis/05-7guis-crud/App.svelte index 1f39fe6642..a0d6ef7f3e 100644 --- a/site/content/examples/19-7guis/05-7guis-crud/App.svelte +++ b/site/content/examples/19-7guis/05-7guis-crud/App.svelte @@ -30,10 +30,7 @@ $: selected = filteredPeople[i]; - $: { - first = selected ? selected.first : ''; - last = selected ? selected.last : ''; - } + $: reset_inputs(selected); function create() { people = people.concat({ first, last }); @@ -53,7 +50,8 @@ } function reset_inputs(person) { - ({ first, last } = person); + first = person ? person.first : ''; + last = person ? person.last : ''; } From 9d53f568fab23b82c8b344c5969c8bfab44de03a Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sat, 25 May 2019 11:25:09 +0100 Subject: [PATCH 17/21] fix tests --- src/internal/utils.js | 6 +++++- test/js/samples/debug-hoisted/expected.js | 2 +- test/js/samples/media-bindings/expected.js | 3 ++- test/runtime/index.js | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/internal/utils.js b/src/internal/utils.js index c493eacb96..7823a5b920 100644 --- a/src/internal/utils.js +++ b/src/internal/utils.js @@ -86,9 +86,13 @@ export let now = is_client ? () => window.performance.now() : () => Date.now(); +export let raf = is_client ? requestAnimationFrame : noop; + // used internally for testing export function set_now(fn) { now = fn; } -export const raf = is_client ? requestAnimationFrame : noop; \ No newline at end of file +export function set_raf(fn) { + raf = fn; +} \ No newline at end of file diff --git a/test/js/samples/debug-hoisted/expected.js b/test/js/samples/debug-hoisted/expected.js index 153f92bad8..51d8bf63a3 100644 --- a/test/js/samples/debug-hoisted/expected.js +++ b/test/js/samples/debug-hoisted/expected.js @@ -53,4 +53,4 @@ class Component extends SvelteComponentDev { } } -export default Component; +export default Component; \ No newline at end of file diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index 8a193f698b..f45f9ce8db 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -8,6 +8,7 @@ import { insert, listen, noop, + raf, run_all, safe_not_equal, time_ranges_to_array @@ -18,7 +19,7 @@ function create_fragment(ctx) { function audio_timeupdate_handler() { cancelAnimationFrame(audio_animationframe); - if (!audio.paused) audio_animationframe = requestAnimationFrame(audio_timeupdate_handler); + if (!audio.paused) audio_animationframe = raf(audio_timeupdate_handler); audio_updating = true; ctx.audio_timeupdate_handler.call(audio); } diff --git a/test/runtime/index.js b/test/runtime/index.js index db02ce13d4..fd5ffdef04 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -3,7 +3,7 @@ import * as path from "path"; import * as fs from "fs"; import { rollup } from 'rollup'; import * as virtual from 'rollup-plugin-virtual'; -import { clear_loops, set_now } from "../../internal.js"; +import { clear_loops, set_now, set_raf } from "../../internal.js"; import { showOutput, @@ -101,7 +101,7 @@ describe("runtime", () => { } }; set_now(() => raf.time); - global.requestAnimationFrame = cb => { + set_raf(cb => { let called = false; raf.callback = () => { if (!called) { @@ -109,7 +109,7 @@ describe("runtime", () => { cb(); } }; - }; + }); try { mod = require(`./samples/${dir}/main.svelte`); From cce9f14e380db04f1365ca97ca0acc4f0ca1f619 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 26 May 2019 13:49:06 +0200 Subject: [PATCH 18/21] fix test --- test/runtime/samples/binding-details-open/_config.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runtime/samples/binding-details-open/_config.js b/test/runtime/samples/binding-details-open/_config.js index e5e81b2c93..cf2459c3f1 100644 --- a/test/runtime/samples/binding-details-open/_config.js +++ b/test/runtime/samples/binding-details-open/_config.js @@ -9,7 +9,7 @@ export default { details.open = true; await details.dispatchEvent(event); - assert.equal(component.open, true); + assert.equal(component.visible, true); assert.htmlEqual(target.innerHTML, `
toggle

hello!

@@ -17,9 +17,9 @@ export default { details.open = false; await details.dispatchEvent(event); - assert.equal(component.open, false); + assert.equal(component.visible, false); assert.htmlEqual(target.innerHTML, ` -
toggle
+
toggle
`); } }; From 089149564799fd4f22799128315bc91208dda84f Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 26 May 2019 14:04:29 +0200 Subject: [PATCH 19/21] code style --- src/compile/render-dom/index.ts | 12 ++++++------ test/js/samples/bind-open/expected.js | 2 +- test/js/samples/debug-empty/expected.js | 6 +++--- test/js/samples/debug-foo-bar-baz-things/expected.js | 6 +++--- test/js/samples/debug-foo/expected.js | 6 +++--- .../dev-warning-missing-data-computed/expected.js | 6 +++--- .../samples/dev-warning-unknown-props/_config.js | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index e7f063d086..1432813e9d 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -394,12 +394,12 @@ export default function dom( return $name; }); - let unknownPropsCheck; + let unknown_props_check; if (component.compile_options.dev && writable_props.length) { - unknownPropsCheck = deindent` - const writableProps = [${writable_props.map(prop => `'${prop.export_name}'`).join(', ')}]; + unknown_props_check = deindent` + const writable_props = [${writable_props.map(prop => `'${prop.export_name}'`).join(', ')}]; Object.keys($$props).forEach(key => { - if (!writableProps.includes(key)) console.warn(\`<${component.tag}> was created with unknown attribute '\${key}'\`); + if (!writable_props.includes(key)) console.warn(\`<${component.tag}> was created with unknown prop '\${key}'\`); }); `; } @@ -413,8 +413,8 @@ export default function dom( ${resubscribable_reactive_store_unsubscribers} ${component.javascript} - - ${unknownPropsCheck} + + ${unknown_props_check} ${component.slots.size && `let { $$slots = {}, $$scope } = $$props;`} diff --git a/test/js/samples/bind-open/expected.js b/test/js/samples/bind-open/expected.js index 7c73c8ddac..7f739aec8b 100644 --- a/test/js/samples/bind-open/expected.js +++ b/test/js/samples/bind-open/expected.js @@ -66,4 +66,4 @@ class Component extends SvelteComponent { } } -export default Component; +export default Component; \ No newline at end of file diff --git a/test/js/samples/debug-empty/expected.js b/test/js/samples/debug-empty/expected.js index 9b6ef447b4..c82cbeddd3 100644 --- a/test/js/samples/debug-empty/expected.js +++ b/test/js/samples/debug-empty/expected.js @@ -65,9 +65,9 @@ function create_fragment(ctx) { function instance($$self, $$props, $$invalidate) { let { name } = $$props; - const writableProps = ['name']; + const writable_props = ['name']; Object.keys($$props).forEach(key => { - if (!writableProps.includes(key)) console.warn(` was created with unknown attribute '${key}'`); + if (!writable_props.includes(key)) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => { @@ -98,4 +98,4 @@ class Component extends SvelteComponentDev { } } -export default Component; +export default Component; \ No newline at end of file diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js index 006b25aba5..3e1571b890 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected.js @@ -151,9 +151,9 @@ function create_fragment(ctx) { function instance($$self, $$props, $$invalidate) { let { things, foo, bar, baz } = $$props; - const writableProps = ['things', 'foo', 'bar', 'baz']; + const writable_props = ['things', 'foo', 'bar', 'baz']; Object.keys($$props).forEach(key => { - if (!writableProps.includes(key)) console.warn(` was created with unknown attribute '${key}'`); + if (!writable_props.includes(key)) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => { @@ -220,4 +220,4 @@ class Component extends SvelteComponentDev { } } -export default Component; +export default Component; \ No newline at end of file diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index 7bc58434a8..1af0fcaebe 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -151,9 +151,9 @@ function create_fragment(ctx) { function instance($$self, $$props, $$invalidate) { let { things, foo } = $$props; - const writableProps = ['things', 'foo']; + const writable_props = ['things', 'foo']; Object.keys($$props).forEach(key => { - if (!writableProps.includes(key)) console.warn(` was created with unknown attribute '${key}'`); + if (!writable_props.includes(key)) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => { @@ -196,4 +196,4 @@ class Component extends SvelteComponentDev { } } -export default Component; +export default Component; \ No newline at end of file diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index e181486512..0c193934c0 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -65,9 +65,9 @@ function instance($$self, $$props, $$invalidate) { let bar; - const writableProps = ['foo']; + const writable_props = ['foo']; Object.keys($$props).forEach(key => { - if (!writableProps.includes(key)) console.warn(` was created with unknown attribute '${key}'`); + if (!writable_props.includes(key)) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => { @@ -102,4 +102,4 @@ class Component extends SvelteComponentDev { } } -export default Component; +export default Component; \ No newline at end of file diff --git a/test/runtime/samples/dev-warning-unknown-props/_config.js b/test/runtime/samples/dev-warning-unknown-props/_config.js index 31b605e214..9bff4a2a74 100644 --- a/test/runtime/samples/dev-warning-unknown-props/_config.js +++ b/test/runtime/samples/dev-warning-unknown-props/_config.js @@ -4,6 +4,6 @@ export default { }, warnings: [ - ` was created with unknown attribute 'fo'` + ` was created with unknown prop 'fo'` ] }; From 0d7f6fb795fc461aced9c3470932d715caf395f5 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 26 May 2019 14:29:30 +0200 Subject: [PATCH 20/21] flesh out in/out transition tutorial chapter (#2792) --- .../content/tutorial/10-transitions/03-in-and-out/text.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/site/content/tutorial/10-transitions/03-in-and-out/text.md b/site/content/tutorial/10-transitions/03-in-and-out/text.md index 21cb221342..1f1ac2c80b 100644 --- a/site/content/tutorial/10-transitions/03-in-and-out/text.md +++ b/site/content/tutorial/10-transitions/03-in-and-out/text.md @@ -2,7 +2,13 @@ title: In and out --- -Instead of the `transition` directive, an element can have an `in` or an `out` directive, or both together: +Instead of the `transition` directive, an element can have an `in` or an `out` directive, or both together. Import `fade` alongside `fly`... + +```js +import { fade, fly } from 'svelte/transition'; +``` + +...then replace the `transition` directive with separate `in` and `out` directives: ```html

From b7f9c9c95444fb15d20eaa170253f1c3982c1148 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 26 May 2019 14:48:10 +0200 Subject: [PATCH 21/21] always add raw property to text nodes --- src/parse/state/tag.ts | 36 ++++++++----------- src/parse/state/text.ts | 4 +-- .../samples/action-with-call/output.json | 5 +-- .../action-with-identifier/output.json | 5 +-- .../samples/action-with-literal/output.json | 5 +-- test/parser/samples/action/output.json | 5 +-- test/parser/samples/animation/output.json | 6 ++-- .../attribute-containing-solidus/output.json | 7 ++-- .../attribute-dynamic-boolean/output.json | 5 +-- .../attribute-dynamic-reserved/output.json | 5 +-- .../samples/attribute-dynamic/output.json | 9 +++-- .../samples/attribute-escaped/output.json | 9 ++--- .../samples/attribute-multiple/output.json | 7 ++-- .../samples/attribute-shorthand/output.json | 5 +-- .../attribute-static-boolean/output.json | 5 +-- .../samples/attribute-static/output.json | 6 ++-- .../samples/attribute-unquoted/output.json | 6 ++-- .../samples/await-then-catch/output.json | 28 +++++++++------ .../samples/binding-shorthand/output.json | 1 + test/parser/samples/binding/output.json | 1 + test/parser/samples/comment/output.json | 5 +-- .../samples/component-dynamic/output.json | 5 +-- .../convert-entities-in-element/output.json | 9 ++--- .../samples/convert-entities/output.json | 9 ++--- test/parser/samples/css/output.json | 6 ++-- .../parser/samples/dynamic-import/output.json | 5 ++- .../each-block-destructured/output.json | 8 ++--- .../samples/each-block-else/output.json | 6 ++-- .../samples/each-block-indexed/output.json | 6 ++-- .../samples/each-block-keyed/output.json | 5 +-- test/parser/samples/each-block/output.json | 5 +-- .../samples/element-with-mustache/output.json | 7 ++-- .../samples/element-with-text/output.json | 6 ++-- test/parser/samples/elements/output.json | 5 +-- test/parser/samples/event-handler/output.json | 10 +++--- test/parser/samples/if-block-else/output.json | 7 ++-- .../samples/if-block-elseif/output.json | 2 ++ test/parser/samples/if-block/output.json | 6 ++-- .../samples/implicitly-closed-li/output.json | 9 ++--- test/parser/samples/nbsp/output.json | 9 ++--- test/parser/samples/raw-mustaches/output.json | 8 ++--- test/parser/samples/refs/output.json | 1 + .../samples/script-comment-only/output.json | 1 + .../output.json | 3 ++ .../script-comment-trailing/output.json | 3 ++ test/parser/samples/script/output.json | 3 ++ .../samples/self-closing-element/output.json | 5 +-- .../parser/samples/self-reference/output.json | 5 +-- .../space-between-mustaches/output.json | 9 ++--- test/parser/samples/spread/output.json | 5 +-- .../samples/textarea-children/output.json | 9 +++-- .../transition-intro-no-params/output.json | 6 ++-- .../samples/transition-intro/output.json | 6 ++-- .../samples/unusual-identifier/output.json | 5 +-- .../whitespace-leading-trailing/output.json | 7 ++-- .../samples/whitespace-normal/output.json | 8 ++--- test/parser/samples/yield/output.json | 5 +-- 57 files changed, 150 insertions(+), 229 deletions(-) diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index d6e9706714..108cfce3e1 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -476,35 +476,28 @@ function read_sequence(parser: Parser, done: () => boolean): Node[] { start: parser.index, end: null, type: 'Text', - data: '', + raw: '', + data: null }; + function flush() { + if (current_chunk.raw) { + current_chunk.data = decode_character_references(current_chunk.raw); + current_chunk.end = parser.index; + chunks.push(current_chunk); + } + } + const chunks: Node[] = []; while (parser.index < parser.template.length) { const index = parser.index; if (done()) { - current_chunk.end = parser.index; - - if (current_chunk.data) chunks.push(current_chunk); - - chunks.forEach(chunk => { - if (chunk.type === 'Text') { - let decoded = decode_character_references(chunk.data); - if (chunk.data != decoded) { - chunk.raw = chunk.data; - chunk.data = decoded; - } - } - }); - + flush(); return chunks; } else if (parser.eat('{')) { - if (current_chunk.data) { - current_chunk.end = index; - chunks.push(current_chunk); - } + flush(); parser.allow_whitespace(); const expression = read_expression(parser); @@ -522,10 +515,11 @@ function read_sequence(parser: Parser, done: () => boolean): Node[] { start: parser.index, end: null, type: 'Text', - data: '', + raw: '', + data: null }; } else { - current_chunk.data += parser.template[parser.index++]; + current_chunk.raw += parser.template[parser.index++]; } } diff --git a/src/parse/state/text.ts b/src/parse/state/text.ts index 503d79aa08..1d9099055e 100644 --- a/src/parse/state/text.ts +++ b/src/parse/state/text.ts @@ -18,11 +18,9 @@ export default function text(parser: Parser) { start, end: parser.index, type: 'Text', + raw: data, data: decode_character_references(data), }; - if (node.data != data) - node.raw = data; - parser.current().children.push(node); } diff --git a/test/parser/samples/action-with-call/output.json b/test/parser/samples/action-with-call/output.json index d6aaa72892..e910f0b49f 100644 --- a/test/parser/samples/action-with-call/output.json +++ b/test/parser/samples/action-with-call/output.json @@ -41,8 +41,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/action-with-identifier/output.json b/test/parser/samples/action-with-identifier/output.json index d58b9097b7..435aee4444 100644 --- a/test/parser/samples/action-with-identifier/output.json +++ b/test/parser/samples/action-with-identifier/output.json @@ -27,8 +27,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/action-with-literal/output.json b/test/parser/samples/action-with-literal/output.json index 4a6f596d10..01a6b67549 100644 --- a/test/parser/samples/action-with-literal/output.json +++ b/test/parser/samples/action-with-literal/output.json @@ -28,8 +28,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/action/output.json b/test/parser/samples/action/output.json index 2f553b5efa..9828e200dd 100644 --- a/test/parser/samples/action/output.json +++ b/test/parser/samples/action/output.json @@ -22,8 +22,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/animation/output.json b/test/parser/samples/animation/output.json index 8332b3ad04..f4d183eb5c 100644 --- a/test/parser/samples/animation/output.json +++ b/test/parser/samples/animation/output.json @@ -35,6 +35,7 @@ "start": 51, "end": 56, "type": "Text", + "raw": "flips", "data": "flips" } ] @@ -54,8 +55,5 @@ } } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/attribute-containing-solidus/output.json b/test/parser/samples/attribute-containing-solidus/output.json index 95372bd77d..f1158b4f50 100644 --- a/test/parser/samples/attribute-containing-solidus/output.json +++ b/test/parser/samples/attribute-containing-solidus/output.json @@ -20,6 +20,7 @@ "start": 8, "end": 30, "type": "Text", + "raw": "https://www.google.com", "data": "https://www.google.com" } ] @@ -30,13 +31,11 @@ "start": 31, "end": 37, "type": "Text", + "raw": "Google", "data": "Google" } ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-boolean/output.json b/test/parser/samples/attribute-dynamic-boolean/output.json index 81a19f49b9..478144152a 100644 --- a/test/parser/samples/attribute-dynamic-boolean/output.json +++ b/test/parser/samples/attribute-dynamic-boolean/output.json @@ -33,8 +33,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-reserved/output.json b/test/parser/samples/attribute-dynamic-reserved/output.json index 3a830d448f..22be3c9087 100644 --- a/test/parser/samples/attribute-dynamic-reserved/output.json +++ b/test/parser/samples/attribute-dynamic-reserved/output.json @@ -33,8 +33,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic/output.json b/test/parser/samples/attribute-dynamic/output.json index 50d8ec60a5..a48f376876 100644 --- a/test/parser/samples/attribute-dynamic/output.json +++ b/test/parser/samples/attribute-dynamic/output.json @@ -18,8 +18,9 @@ "value": [ { "start": 12, - "end": 19, + "end": 20, "type": "Text", + "raw": "color: ", "data": "color: " }, { @@ -37,6 +38,7 @@ "start": 26, "end": 27, "type": "Text", + "raw": ";", "data": ";" } ] @@ -57,8 +59,5 @@ ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/attribute-escaped/output.json b/test/parser/samples/attribute-escaped/output.json index 79b135eb86..e60a8c2531 100644 --- a/test/parser/samples/attribute-escaped/output.json +++ b/test/parser/samples/attribute-escaped/output.json @@ -20,8 +20,8 @@ "start": 15, "end": 33, "type": "Text", - "data": "\"quoted\"", - "raw": ""quoted"" + "raw": ""quoted"", + "data": "\"quoted\"" } ] } @@ -29,8 +29,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/attribute-multiple/output.json b/test/parser/samples/attribute-multiple/output.json index 668409c0ef..c4be13e6ee 100644 --- a/test/parser/samples/attribute-multiple/output.json +++ b/test/parser/samples/attribute-multiple/output.json @@ -20,6 +20,7 @@ "start": 9, "end": 10, "type": "Text", + "raw": "x", "data": "x" } ] @@ -34,6 +35,7 @@ "start": 19, "end": 20, "type": "Text", + "raw": "y", "data": "y" } ] @@ -42,8 +44,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/attribute-shorthand/output.json b/test/parser/samples/attribute-shorthand/output.json index 08ddf5eda9..f23e62b04e 100644 --- a/test/parser/samples/attribute-shorthand/output.json +++ b/test/parser/samples/attribute-shorthand/output.json @@ -33,8 +33,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/attribute-static-boolean/output.json b/test/parser/samples/attribute-static-boolean/output.json index f63b5734e0..7d635004c1 100644 --- a/test/parser/samples/attribute-static-boolean/output.json +++ b/test/parser/samples/attribute-static-boolean/output.json @@ -21,8 +21,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/attribute-static/output.json b/test/parser/samples/attribute-static/output.json index 3185e48736..37b41d9a89 100644 --- a/test/parser/samples/attribute-static/output.json +++ b/test/parser/samples/attribute-static/output.json @@ -20,6 +20,7 @@ "start": 12, "end": 15, "type": "Text", + "raw": "foo", "data": "foo" } ] @@ -28,8 +29,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/attribute-unquoted/output.json b/test/parser/samples/attribute-unquoted/output.json index c7556f2eba..11fa397819 100644 --- a/test/parser/samples/attribute-unquoted/output.json +++ b/test/parser/samples/attribute-unquoted/output.json @@ -20,6 +20,7 @@ "start": 11, "end": 14, "type": "Text", + "raw": "foo", "data": "foo" } ] @@ -28,8 +29,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/await-then-catch/output.json b/test/parser/samples/await-then-catch/output.json index f62ad16574..ac598a403a 100644 --- a/test/parser/samples/await-then-catch/output.json +++ b/test/parser/samples/await-then-catch/output.json @@ -19,13 +19,13 @@ "pending": { "start": 19, "end": 39, - "skip": false, "type": "PendingBlock", "children": [ { "start": 19, "end": 21, "type": "Text", + "raw": "\n\t", "data": "\n\t" }, { @@ -39,6 +39,7 @@ "start": 24, "end": 34, "type": "Text", + "raw": "loading...", "data": "loading..." } ] @@ -47,20 +48,22 @@ "start": 38, "end": 39, "type": "Text", + "raw": "\n", "data": "\n" } - ] + ], + "skip": false }, "then": { "start": 39, "end": 88, - "skip": false, "type": "ThenBlock", "children": [ { "start": 55, "end": 57, "type": "Text", + "raw": "\n\t", "data": "\n\t" }, { @@ -74,6 +77,7 @@ "start": 60, "end": 73, "type": "Text", + "raw": "the value is ", "data": "the value is " }, { @@ -93,20 +97,22 @@ "start": 87, "end": 88, "type": "Text", + "raw": "\n", "data": "\n" } - ] + ], + "skip": false }, "catch": { "start": 88, "end": 140, - "skip": false, "type": "CatchBlock", "children": [ { "start": 105, "end": 107, "type": "Text", + "raw": "\n\t", "data": "\n\t" }, { @@ -120,6 +126,7 @@ "start": 110, "end": 117, "type": "Text", + "raw": "oh no! ", "data": "oh no! " }, { @@ -151,14 +158,13 @@ "start": 139, "end": 140, "type": "Text", + "raw": "\n", "data": "\n" } - ] + ], + "skip": false } } ] - }, - "css": null, - "instance": null, - "module": null -} + } +} \ No newline at end of file diff --git a/test/parser/samples/binding-shorthand/output.json b/test/parser/samples/binding-shorthand/output.json index 8f92101042..7fe7acb5b3 100644 --- a/test/parser/samples/binding-shorthand/output.json +++ b/test/parser/samples/binding-shorthand/output.json @@ -8,6 +8,7 @@ "start": 28, "end": 30, "type": "Text", + "raw": "\n\n", "data": "\n\n" }, { diff --git a/test/parser/samples/binding/output.json b/test/parser/samples/binding/output.json index d084050617..72ad60202c 100644 --- a/test/parser/samples/binding/output.json +++ b/test/parser/samples/binding/output.json @@ -8,6 +8,7 @@ "start": 29, "end": 31, "type": "Text", + "raw": "\n\n", "data": "\n\n" }, { diff --git a/test/parser/samples/comment/output.json b/test/parser/samples/comment/output.json index 89295c188a..2a57c4fa5d 100644 --- a/test/parser/samples/comment/output.json +++ b/test/parser/samples/comment/output.json @@ -11,8 +11,5 @@ "data": " a comment " } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/component-dynamic/output.json b/test/parser/samples/component-dynamic/output.json index c2e4e3ee79..77837d1ca9 100644 --- a/test/parser/samples/component-dynamic/output.json +++ b/test/parser/samples/component-dynamic/output.json @@ -36,8 +36,5 @@ } } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/convert-entities-in-element/output.json b/test/parser/samples/convert-entities-in-element/output.json index 92b5aafb00..c830c276de 100644 --- a/test/parser/samples/convert-entities-in-element/output.json +++ b/test/parser/samples/convert-entities-in-element/output.json @@ -15,14 +15,11 @@ "start": 3, "end": 20, "type": "Text", - "data": "Hello & World", - "raw": "Hello & World" + "raw": "Hello & World", + "data": "Hello & World" } ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/convert-entities/output.json b/test/parser/samples/convert-entities/output.json index 967895383d..f4cc1a6662 100644 --- a/test/parser/samples/convert-entities/output.json +++ b/test/parser/samples/convert-entities/output.json @@ -8,12 +8,9 @@ "start": 0, "end": 17, "type": "Text", - "data": "Hello & World", - "raw": "Hello & World" + "raw": "Hello & World", + "data": "Hello & World" } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/css/output.json b/test/parser/samples/css/output.json index 3127e01c71..12d74ae7f8 100644 --- a/test/parser/samples/css/output.json +++ b/test/parser/samples/css/output.json @@ -15,6 +15,7 @@ "start": 5, "end": 8, "type": "Text", + "raw": "foo", "data": "foo" } ] @@ -23,6 +24,7 @@ "start": 14, "end": 16, "type": "Text", + "raw": "\n\n", "data": "\n\n" } ] @@ -90,7 +92,5 @@ "end": 48, "styles": "\n\tdiv {\n\t\tcolor: red;\n\t}\n" } - }, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/dynamic-import/output.json b/test/parser/samples/dynamic-import/output.json index c0d4a45e0d..fa1acf7d9b 100644 --- a/test/parser/samples/dynamic-import/output.json +++ b/test/parser/samples/dynamic-import/output.json @@ -5,7 +5,6 @@ "type": "Fragment", "children": [] }, - "css": null, "instance": { "start": 0, "end": 146, @@ -66,8 +65,8 @@ "start": 54, "end": 134, "id": null, - "generator": false, "expression": false, + "generator": false, "async": false, "params": [], "body": { @@ -120,8 +119,8 @@ "start": 88, "end": 129, "id": null, - "generator": false, "expression": false, + "generator": false, "async": false, "params": [ { diff --git a/test/parser/samples/each-block-destructured/output.json b/test/parser/samples/each-block-destructured/output.json index 0c4b1a5c54..6368b445d6 100644 --- a/test/parser/samples/each-block-destructured/output.json +++ b/test/parser/samples/each-block-destructured/output.json @@ -37,6 +37,7 @@ "start": 50, "end": 52, "type": "Text", + "raw": ": ", "data": ": " }, { @@ -80,8 +81,5 @@ } } ] - }, - "css": null, - "instance": null, - "module": null -} + } +} \ No newline at end of file diff --git a/test/parser/samples/each-block-else/output.json b/test/parser/samples/each-block-else/output.json index aefc8c2f39..1e8ac455e6 100644 --- a/test/parser/samples/each-block-else/output.json +++ b/test/parser/samples/each-block-else/output.json @@ -58,6 +58,7 @@ "start": 55, "end": 65, "type": "Text", + "raw": "no animals", "data": "no animals" } ] @@ -66,8 +67,5 @@ } } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/each-block-indexed/output.json b/test/parser/samples/each-block-indexed/output.json index 7518652468..77417ba67a 100644 --- a/test/parser/samples/each-block-indexed/output.json +++ b/test/parser/samples/each-block-indexed/output.json @@ -37,6 +37,7 @@ "start": 36, "end": 38, "type": "Text", + "raw": ": ", "data": ": " }, { @@ -62,8 +63,5 @@ "index": "i" } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/each-block-keyed/output.json b/test/parser/samples/each-block-keyed/output.json index fe893bcdb9..11cdd45ff1 100644 --- a/test/parser/samples/each-block-keyed/output.json +++ b/test/parser/samples/each-block-keyed/output.json @@ -62,8 +62,5 @@ } } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/each-block/output.json b/test/parser/samples/each-block/output.json index c16a71ad5d..6a60823952 100644 --- a/test/parser/samples/each-block/output.json +++ b/test/parser/samples/each-block/output.json @@ -44,8 +44,5 @@ } } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/element-with-mustache/output.json b/test/parser/samples/element-with-mustache/output.json index c8a386d681..f7c2e9936b 100644 --- a/test/parser/samples/element-with-mustache/output.json +++ b/test/parser/samples/element-with-mustache/output.json @@ -15,6 +15,7 @@ "start": 4, "end": 10, "type": "Text", + "raw": "hello ", "data": "hello " }, { @@ -32,13 +33,11 @@ "start": 16, "end": 17, "type": "Text", + "raw": "!", "data": "!" } ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/element-with-text/output.json b/test/parser/samples/element-with-text/output.json index 70f6163c93..b0e0f5c6cc 100644 --- a/test/parser/samples/element-with-text/output.json +++ b/test/parser/samples/element-with-text/output.json @@ -15,13 +15,11 @@ "start": 6, "end": 10, "type": "Text", + "raw": "test", "data": "test" } ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/elements/output.json b/test/parser/samples/elements/output.json index d216f7f5d8..75548c20f0 100644 --- a/test/parser/samples/elements/output.json +++ b/test/parser/samples/elements/output.json @@ -21,8 +21,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/event-handler/output.json b/test/parser/samples/event-handler/output.json index b1fe89fc2a..f792ffadcc 100644 --- a/test/parser/samples/event-handler/output.json +++ b/test/parser/samples/event-handler/output.json @@ -21,8 +21,8 @@ "start": 19, "end": 43, "id": null, - "generator": false, "expression": true, + "generator": false, "async": false, "params": [], "body": { @@ -58,6 +58,7 @@ "start": 46, "end": 52, "type": "Text", + "raw": "toggle", "data": "toggle" } ] @@ -66,6 +67,7 @@ "start": 61, "end": 63, "type": "Text", + "raw": "\n\n", "data": "\n\n" }, { @@ -90,6 +92,7 @@ "start": 81, "end": 87, "type": "Text", + "raw": "hello!", "data": "hello!" } ] @@ -97,8 +100,5 @@ ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/if-block-else/output.json b/test/parser/samples/if-block-else/output.json index dedf2797c4..8b22cfa26b 100644 --- a/test/parser/samples/if-block-else/output.json +++ b/test/parser/samples/if-block-else/output.json @@ -26,6 +26,7 @@ "start": 14, "end": 17, "type": "Text", + "raw": "foo", "data": "foo" } ] @@ -47,6 +48,7 @@ "start": 34, "end": 41, "type": "Text", + "raw": "not foo", "data": "not foo" } ] @@ -55,8 +57,5 @@ } } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/if-block-elseif/output.json b/test/parser/samples/if-block-elseif/output.json index 188b57aaad..54fb53dacb 100644 --- a/test/parser/samples/if-block-elseif/output.json +++ b/test/parser/samples/if-block-elseif/output.json @@ -39,6 +39,7 @@ "start": 17, "end": 37, "type": "Text", + "raw": "x is greater than 10", "data": "x is greater than 10" } ] @@ -85,6 +86,7 @@ "start": 63, "end": 79, "type": "Text", + "raw": "x is less than 5", "data": "x is less than 5" } ] diff --git a/test/parser/samples/if-block/output.json b/test/parser/samples/if-block/output.json index d560824766..1714bb7141 100644 --- a/test/parser/samples/if-block/output.json +++ b/test/parser/samples/if-block/output.json @@ -19,13 +19,11 @@ "start": 9, "end": 12, "type": "Text", + "raw": "bar", "data": "bar" } ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/implicitly-closed-li/output.json b/test/parser/samples/implicitly-closed-li/output.json index caf69d7109..f46a2b1a26 100644 --- a/test/parser/samples/implicitly-closed-li/output.json +++ b/test/parser/samples/implicitly-closed-li/output.json @@ -15,6 +15,7 @@ "start": 4, "end": 6, "type": "Text", + "raw": "\n\t", "data": "\n\t" }, { @@ -28,6 +29,7 @@ "start": 10, "end": 13, "type": "Text", + "raw": "a\n\t", "data": "a\n\t" } ] @@ -43,6 +45,7 @@ "start": 17, "end": 20, "type": "Text", + "raw": "b\n\t", "data": "b\n\t" } ] @@ -58,6 +61,7 @@ "start": 24, "end": 26, "type": "Text", + "raw": "c\n", "data": "c\n" } ] @@ -65,8 +69,5 @@ ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/nbsp/output.json b/test/parser/samples/nbsp/output.json index c47257c873..044de64cba 100644 --- a/test/parser/samples/nbsp/output.json +++ b/test/parser/samples/nbsp/output.json @@ -15,14 +15,11 @@ "start": 6, "end": 12, "type": "Text", - "data": " ", - "raw": " " + "raw": " ", + "data": " " } ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/raw-mustaches/output.json b/test/parser/samples/raw-mustaches/output.json index 1d92b21c85..1b3d9b7a9c 100644 --- a/test/parser/samples/raw-mustaches/output.json +++ b/test/parser/samples/raw-mustaches/output.json @@ -15,6 +15,7 @@ "start": 3, "end": 4, "type": "Text", + "raw": " ", "data": " " }, { @@ -32,6 +33,7 @@ "start": 16, "end": 17, "type": "Text", + "raw": " ", "data": " " }, { @@ -49,13 +51,11 @@ "start": 29, "end": 30, "type": "Text", + "raw": " ", "data": " " } ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/refs/output.json b/test/parser/samples/refs/output.json index d15753b0a2..e09383f9b6 100644 --- a/test/parser/samples/refs/output.json +++ b/test/parser/samples/refs/output.json @@ -8,6 +8,7 @@ "start": 28, "end": 30, "type": "Text", + "raw": "\n\n", "data": "\n\n" }, { diff --git a/test/parser/samples/script-comment-only/output.json b/test/parser/samples/script-comment-only/output.json index 95ca769b20..ba28434318 100644 --- a/test/parser/samples/script-comment-only/output.json +++ b/test/parser/samples/script-comment-only/output.json @@ -8,6 +8,7 @@ "start": 43, "end": 45, "type": "Text", + "raw": "\n\n", "data": "\n\n" }, { diff --git a/test/parser/samples/script-comment-trailing-multiline/output.json b/test/parser/samples/script-comment-trailing-multiline/output.json index d4a45911a1..7d01599efa 100644 --- a/test/parser/samples/script-comment-trailing-multiline/output.json +++ b/test/parser/samples/script-comment-trailing-multiline/output.json @@ -8,6 +8,7 @@ "start": 77, "end": 79, "type": "Text", + "raw": "\n\n", "data": "\n\n" }, { @@ -21,6 +22,7 @@ "start": 83, "end": 89, "type": "Text", + "raw": "Hello ", "data": "Hello " }, { @@ -38,6 +40,7 @@ "start": 95, "end": 96, "type": "Text", + "raw": "!", "data": "!" } ] diff --git a/test/parser/samples/script-comment-trailing/output.json b/test/parser/samples/script-comment-trailing/output.json index 92d431b558..bc8f3e4e67 100644 --- a/test/parser/samples/script-comment-trailing/output.json +++ b/test/parser/samples/script-comment-trailing/output.json @@ -8,6 +8,7 @@ "start": 66, "end": 68, "type": "Text", + "raw": "\n\n", "data": "\n\n" }, { @@ -21,6 +22,7 @@ "start": 72, "end": 78, "type": "Text", + "raw": "Hello ", "data": "Hello " }, { @@ -38,6 +40,7 @@ "start": 84, "end": 85, "type": "Text", + "raw": "!", "data": "!" } ] diff --git a/test/parser/samples/script/output.json b/test/parser/samples/script/output.json index 95966f5dc6..75aa0a7d2c 100644 --- a/test/parser/samples/script/output.json +++ b/test/parser/samples/script/output.json @@ -8,6 +8,7 @@ "start": 39, "end": 41, "type": "Text", + "raw": "\n\n", "data": "\n\n" }, { @@ -21,6 +22,7 @@ "start": 45, "end": 51, "type": "Text", + "raw": "Hello ", "data": "Hello " }, { @@ -38,6 +40,7 @@ "start": 57, "end": 58, "type": "Text", + "raw": "!", "data": "!" } ] diff --git a/test/parser/samples/self-closing-element/output.json b/test/parser/samples/self-closing-element/output.json index 47eea2f333..63ff17a466 100644 --- a/test/parser/samples/self-closing-element/output.json +++ b/test/parser/samples/self-closing-element/output.json @@ -13,8 +13,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/self-reference/output.json b/test/parser/samples/self-reference/output.json index de5112a087..92dfdfe4d0 100644 --- a/test/parser/samples/self-reference/output.json +++ b/test/parser/samples/self-reference/output.json @@ -72,8 +72,5 @@ ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/space-between-mustaches/output.json b/test/parser/samples/space-between-mustaches/output.json index c89409daeb..9a367bd2c1 100644 --- a/test/parser/samples/space-between-mustaches/output.json +++ b/test/parser/samples/space-between-mustaches/output.json @@ -15,6 +15,7 @@ "start": 3, "end": 4, "type": "Text", + "raw": " ", "data": " " }, { @@ -32,6 +33,7 @@ "start": 7, "end": 8, "type": "Text", + "raw": " ", "data": " " }, { @@ -49,6 +51,7 @@ "start": 11, "end": 14, "type": "Text", + "raw": " : ", "data": " : " }, { @@ -66,13 +69,11 @@ "start": 17, "end": 20, "type": "Text", + "raw": " : ", "data": " : " } ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/spread/output.json b/test/parser/samples/spread/output.json index 3986da3578..73a0dc9777 100644 --- a/test/parser/samples/spread/output.json +++ b/test/parser/samples/spread/output.json @@ -25,8 +25,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/textarea-children/output.json b/test/parser/samples/textarea-children/output.json index 3b403458fc..90f31f3caf 100644 --- a/test/parser/samples/textarea-children/output.json +++ b/test/parser/samples/textarea-children/output.json @@ -16,8 +16,9 @@ "value": [ { "start": 10, - "end": 40, + "end": 41, "type": "Text", + "raw": "\n\t

not actually an element. ", "data": "\n\t

not actually an element. " }, { @@ -35,6 +36,7 @@ "start": 45, "end": 50, "type": "Text", + "raw": "

\n", "data": "

\n" } ] @@ -43,8 +45,5 @@ "children": [] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/transition-intro-no-params/output.json b/test/parser/samples/transition-intro-no-params/output.json index edb15457e6..91b50f3ec8 100644 --- a/test/parser/samples/transition-intro-no-params/output.json +++ b/test/parser/samples/transition-intro-no-params/output.json @@ -26,13 +26,11 @@ "start": 13, "end": 21, "type": "Text", + "raw": "fades in", "data": "fades in" } ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/transition-intro/output.json b/test/parser/samples/transition-intro/output.json index 5583dd89bc..418bb97e16 100644 --- a/test/parser/samples/transition-intro/output.json +++ b/test/parser/samples/transition-intro/output.json @@ -54,13 +54,11 @@ "start": 31, "end": 39, "type": "Text", + "raw": "fades in", "data": "fades in" } ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/unusual-identifier/output.json b/test/parser/samples/unusual-identifier/output.json index c0d4ecc3ff..e4a2a18619 100644 --- a/test/parser/samples/unusual-identifier/output.json +++ b/test/parser/samples/unusual-identifier/output.json @@ -44,8 +44,5 @@ } } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/whitespace-leading-trailing/output.json b/test/parser/samples/whitespace-leading-trailing/output.json index f164af01ba..e4f387856e 100644 --- a/test/parser/samples/whitespace-leading-trailing/output.json +++ b/test/parser/samples/whitespace-leading-trailing/output.json @@ -8,6 +8,7 @@ "start": 0, "end": 6, "type": "Text", + "raw": "\n\n\t\t\t\t", "data": "\n\n\t\t\t\t" }, { @@ -21,13 +22,11 @@ "start": 9, "end": 32, "type": "Text", + "raw": "just chillin' over here", "data": "just chillin' over here" } ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/whitespace-normal/output.json b/test/parser/samples/whitespace-normal/output.json index e4ce956331..acbae7ae17 100644 --- a/test/parser/samples/whitespace-normal/output.json +++ b/test/parser/samples/whitespace-normal/output.json @@ -15,6 +15,7 @@ "start": 4, "end": 10, "type": "Text", + "raw": "Hello ", "data": "Hello " }, { @@ -39,6 +40,7 @@ "start": 24, "end": 26, "type": "Text", + "raw": "! ", "data": "! " } ] @@ -54,6 +56,7 @@ "start": 41, "end": 53, "type": "Text", + "raw": "How are you?", "data": "How are you?" } ] @@ -61,8 +64,5 @@ ] } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/parser/samples/yield/output.json b/test/parser/samples/yield/output.json index 16ea79d8e8..b2e4b9430f 100644 --- a/test/parser/samples/yield/output.json +++ b/test/parser/samples/yield/output.json @@ -16,8 +16,5 @@ } } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file