diff --git a/site/src/components/Repl/Output/ReplProxy.js b/site/src/components/Repl/Output/ReplProxy.js index 7ae56e35b7..5988c20f19 100644 --- a/site/src/components/Repl/Output/ReplProxy.js +++ b/site/src/components/Repl/Output/ReplProxy.js @@ -15,7 +15,7 @@ export default class ReplProxy { } iframeCommand(command, args) { - return new Promise( (resolve, reject) => { + return new Promise((resolve, reject) => { this.cmdId += 1; this.pendingCmds.set(this.cmdId, { resolve, reject }); @@ -23,7 +23,7 @@ export default class ReplProxy { action: command, cmdId: this.cmdId, args - }, '*') + }, '*'); }); } diff --git a/src/Stats.ts b/src/Stats.ts index 87c6c2173a..c54f1e8ea9 100644 --- a/src/Stats.ts +++ b/src/Stats.ts @@ -12,27 +12,27 @@ type Timing = { children: Timing[]; } -function collapseTimings(timings) { +function collapse_timings(timings) { const result = {}; timings.forEach(timing => { result[timing.label] = Object.assign({ total: timing.end - timing.start - }, timing.children && collapseTimings(timing.children)); + }, timing.children && collapse_timings(timing.children)); }); return result; } export default class Stats { - startTime: number; - currentTiming: Timing; - currentChildren: Timing[]; + start_time: number; + current_timing: Timing; + current_children: Timing[]; timings: Timing[]; stack: Timing[]; constructor() { - this.startTime = now(); + this.start_time = now(); this.stack = []; - this.currentChildren = this.timings = []; + this.current_children = this.timings = []; } start(label) { @@ -43,28 +43,28 @@ export default class Stats { children: [] }; - this.currentChildren.push(timing); + this.current_children.push(timing); this.stack.push(timing); - this.currentTiming = timing; - this.currentChildren = timing.children; + this.current_timing = timing; + this.current_children = timing.children; } stop(label) { - if (label !== this.currentTiming.label) { - throw new Error(`Mismatched timing labels (expected ${this.currentTiming.label}, got ${label})`); + if (label !== this.current_timing.label) { + throw new Error(`Mismatched timing labels (expected ${this.current_timing.label}, got ${label})`); } - this.currentTiming.end = now(); + this.current_timing.end = now(); this.stack.pop(); - this.currentTiming = this.stack[this.stack.length - 1]; - this.currentChildren = this.currentTiming ? this.currentTiming.children : this.timings; + this.current_timing = this.stack[this.stack.length - 1]; + this.current_children = this.current_timing ? this.current_timing.children : this.timings; } render() { const timings = Object.assign({ - total: now() - this.startTime - }, collapseTimings(this.timings)); + total: now() - this.start_time + }, collapse_timings(this.timings)); return { timings diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 27380a04df..f7c1c7dc5d 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -2,25 +2,23 @@ import MagicString, { Bundle } from 'magic-string'; import { walk, childKeys } from 'estree-walker'; import { getLocator } from 'locate-character'; import Stats from '../Stats'; -import reservedNames from '../utils/reservedNames'; -import { namespaces, validNamespaces } from '../utils/namespaces'; -import { removeNode } from '../utils/removeNode'; -import wrapModule from './wrapModule'; -import { createScopes, extractNames, Scope } from '../utils/annotateWithScopes'; +import { globals, reserved } from '../utils/names'; +import { namespaces, valid_namespaces } from '../utils/namespaces'; +import create_module from './create_module'; +import { create_scopes, extract_names, Scope } from './utils/scope'; import Stylesheet from './css/Stylesheet'; import { test } from '../config'; import Fragment from './nodes/Fragment'; import internal_exports from './internal-exports'; import { Node, Ast, CompileOptions, Var, Warning } from '../interfaces'; import error from '../utils/error'; -import getCodeFrame from '../utils/getCodeFrame'; -import flattenReference from '../utils/flattenReference'; -import isReference from 'is-reference'; +import get_code_frame from '../utils/get_code_frame'; +import flatten_reference from './utils/flatten_reference'; +import is_reference from 'is-reference'; import TemplateScope from './nodes/shared/TemplateScope'; import fuzzymatch from '../utils/fuzzymatch'; import { remove_indentation, add_indentation } from '../utils/indentation'; -import getObject from '../utils/getObject'; -import globalWhitelist from '../utils/globalWhitelist'; +import get_object from './utils/get_object'; type ComponentOptions = { namespace?: string; @@ -36,6 +34,34 @@ childKeys.EachBlock = childKeys.IfBlock = ['children', 'else']; childKeys.Attribute = ['value']; childKeys.ExportNamedDeclaration = ['declaration', 'specifiers']; +function remove_node(code: MagicString, start: number, end: number, body: Node, node: Node) { + const i = body.indexOf(node); + if (i === -1) throw new Error('node not in list'); + + let a; + let b; + + if (body.length === 1) { + // remove everything, leave {} + a = start; + b = end; + } else if (i === 0) { + // remove everything before second node, including comments + a = start; + while (/\s/.test(code.original[a])) a += 1; + + b = body[i].end; + while (/[\s,]/.test(code.original[b])) b += 1; + } else { + // remove the end of the previous node to the end of this one + a = body[i - 1].end; + b = node.end; + } + + code.remove(a, b); + return; +} + export default class Component { stats: Stats; warnings: Warning[]; @@ -44,13 +70,13 @@ export default class Component { source: string; code: MagicString; name: string; - compileOptions: CompileOptions; + compile_options: CompileOptions; fragment: Fragment; module_scope: Scope; instance_scope: Scope; instance_scope_map: WeakMap; - componentOptions: ComponentOptions; + component_options: ComponentOptions; namespace: string; tag: string; accessors: boolean; @@ -72,7 +98,7 @@ export default class Component { injected_reactive_declaration_vars: Set = new Set(); helpers: Set = new Set(); - indirectDependencies: Map> = new Map(); + indirect_dependencies: Map> = new Map(); file: string; locate: (c: number) => { line: number, column: number }; @@ -86,13 +112,14 @@ export default class Component { stylesheet: Stylesheet; aliases: Map = new Map(); - usedNames: Set = new Set(); + used_names: Set = new Set(); + globally_used_names: Set = new Set(); constructor( ast: Ast, source: string, name: string, - compileOptions: CompileOptions, + compile_options: CompileOptions, stats: Stats, warnings: Warning[] ) { @@ -102,24 +129,24 @@ export default class Component { this.warnings = warnings; this.ast = ast; this.source = source; - this.compileOptions = compileOptions; + this.compile_options = compile_options; - this.file = compileOptions.filename && ( - typeof process !== 'undefined' ? compileOptions.filename.replace(process.cwd(), '').replace(/^[\/\\]/, '') : compileOptions.filename + this.file = compile_options.filename && ( + typeof process !== 'undefined' ? compile_options.filename.replace(process.cwd(), '').replace(/^[\/\\]/, '') : compile_options.filename ); this.locate = getLocator(this.source); this.code = new MagicString(source); // styles - this.stylesheet = new Stylesheet(source, ast, compileOptions.filename, compileOptions.dev); + this.stylesheet = new Stylesheet(source, ast, compile_options.filename, compile_options.dev); this.stylesheet.validate(this); - this.componentOptions = process_component_options(this, this.ast.html.children); - this.namespace = namespaces[this.componentOptions.namespace] || this.componentOptions.namespace; + this.component_options = process_component_options(this, this.ast.html.children); + this.namespace = namespaces[this.component_options.namespace] || this.component_options.namespace; - if (compileOptions.customElement) { - this.tag = this.componentOptions.tag || compileOptions.tag; + if (compile_options.customElement) { + this.tag = this.component_options.tag || compile_options.tag; if (!this.tag) { throw new Error(`Cannot compile to a custom element without specifying a tag name via options.tag or `); } @@ -131,13 +158,13 @@ export default class Component { this.walk_instance_js_pre_template(); this.fragment = new Fragment(this, ast.html); - this.name = this.getUniqueName(name); + this.name = this.get_unique_name(name); this.walk_instance_js_post_template(); - if (!compileOptions.customElement) this.stylesheet.reify(); + if (!compile_options.customElement) this.stylesheet.reify(); - this.stylesheet.warnOnUnusedSelectors(this); + this.stylesheet.warn_on_unused_selectors(this); } add_var(variable: Var) { @@ -171,11 +198,11 @@ export default class Component { const variable = this.var_lookup.get(subscribable_name); if (variable) variable.subscribable = true; } else { - this.usedNames.add(name); + this.used_names.add(name); } } - addSourcemapLocations(node: Node) { + add_sourcemap_locations(node: Node) { walk(node, { enter: (node: Node) => { this.code.addSourcemapLocation(node.start); @@ -186,7 +213,7 @@ export default class Component { alias(name: string) { if (!this.aliases.has(name)) { - this.aliases.set(name, this.getUniqueName(name)); + this.aliases.set(name, this.get_unique_name(name)); } return this.aliases.get(name); @@ -202,17 +229,17 @@ export default class Component { let css = null; if (result) { - const { compileOptions, name } = this; - const { format = 'esm' } = compileOptions; + const { compile_options, name } = this; + const { format = 'esm' } = compile_options; const banner = `/* ${this.file ? `${this.file} ` : ``}generated by Svelte v${"__VERSION__"} */`; result = result .replace(/__svelte:self__/g, this.name) - .replace(compileOptions.generate === 'ssr' ? /(@+|#+)(\w*(?:-\w*)?)/g : /(@+)(\w*(?:-\w*)?)/g, (match: string, sigil: string, name: string) => { + .replace(compile_options.generate === 'ssr' ? /(@+|#+)(\w*(?:-\w*)?)/g : /(@+)(\w*(?:-\w*)?)/g, (match: string, sigil: string, name: string) => { if (sigil === '@') { if (internal_exports.has(name)) { - if (compileOptions.dev && internal_exports.has(`${name}Dev`)) name = `${name}Dev`; + if (compile_options.dev && internal_exports.has(`${name}Dev`)) name = `${name}Dev`; this.helpers.add(name); } @@ -222,21 +249,20 @@ export default class Component { return sigil.slice(1) + name; }); - const importedHelpers = Array.from(this.helpers) + const imported_helpers = Array.from(this.helpers) .sort() .map(name => { const alias = this.alias(name); return { name, alias }; }); - const module = wrapModule( + const module = create_module( result, format, name, - compileOptions, banner, - compileOptions.sveltePath, - importedHelpers, + compile_options.sveltePath, + imported_helpers, this.imports, this.vars.filter(variable => variable.module && variable.export_name).map(variable => ({ name: variable.name, @@ -246,17 +272,17 @@ export default class Component { ); const parts = module.split('✂]'); - const finalChunk = parts.pop(); + const final_chunk = parts.pop(); const compiled = new Bundle({ separator: '' }); - function addString(str: string) { + function add_string(str: string) { compiled.addSource({ content: new MagicString(str), }); } - const { filename } = compileOptions; + const { filename } = compile_options; // special case — the source file doesn't actually get used anywhere. we need // to add an empty file to populate map.sources and map.sourcesContent @@ -271,7 +297,7 @@ export default class Component { parts.forEach((str: string) => { const chunk = str.replace(pattern, ''); - if (chunk) addString(chunk); + if (chunk) add_string(chunk); const match = pattern.exec(str); @@ -283,17 +309,17 @@ export default class Component { }); }); - addString(finalChunk); + add_string(final_chunk); - css = compileOptions.customElement ? + css = compile_options.customElement ? { code: null, map: null } : - this.stylesheet.render(compileOptions.cssOutputFilename, true); + this.stylesheet.render(compile_options.cssOutputFilename, true); js = { code: compiled.toString(), map: compiled.generateMap({ includeContent: true, - file: compileOptions.outputFilename, + file: compile_options.outputFilename, }) }; } @@ -317,28 +343,30 @@ export default class Component { }; } - getUniqueName(name: string) { + get_unique_name(name: string) { if (test) name = `${name}$`; let alias = name; for ( let i = 1; - reservedNames.has(alias) || + reserved.has(alias) || this.var_lookup.has(alias) || - this.usedNames.has(alias); + this.used_names.has(alias) || + this.globally_used_names.has(alias); alias = `${name}_${i++}` ); - this.usedNames.add(alias); + this.used_names.add(alias); return alias; } - getUniqueNameMaker() { - const localUsedNames = new Set(); + get_unique_name_maker() { + const local_used_names = new Set(); function add(name: string) { - localUsedNames.add(name); + local_used_names.add(name); } - reservedNames.forEach(add); + reserved.forEach(add); + internal_exports.forEach(add); this.var_lookup.forEach((value, key) => add(key)); return (name: string) => { @@ -346,11 +374,12 @@ export default class Component { let alias = name; for ( let i = 1; - this.usedNames.has(alias) || - localUsedNames.has(alias); + this.used_names.has(alias) || + local_used_names.has(alias); alias = `${name}_${i++}` ); - localUsedNames.add(alias); + local_used_names.add(alias); + this.globally_used_names.add(alias); return alias; }; } @@ -371,7 +400,7 @@ export default class Component { source: this.source, start: pos.start, end: pos.end, - filename: this.compileOptions.filename + filename: this.compile_options.filename }); } @@ -392,7 +421,7 @@ export default class Component { const start = this.locator(pos.start); const end = this.locator(pos.end); - const frame = getCodeFrame(this.source, start.line - 1, start.column); + const frame = get_code_frame(this.source, start.line - 1, start.column); this.warnings.push({ code: warning.code, @@ -401,7 +430,7 @@ export default class Component { start, end, pos: pos.start, - filename: this.compileOptions.filename, + filename: this.compile_options.filename, toString: () => `${warning.message} (${start.line + 1}:${start.column})\n${frame}`, }); } @@ -412,7 +441,7 @@ export default class Component { content.body.forEach(node => { if (node.type === 'ImportDeclaration') { // imports need to be hoisted out of the IIFE - removeNode(code, content.start, content.end, content.body, node); + remove_node(code, content.start, content.end, content.body, node); this.imports.push(node); } }); @@ -439,7 +468,7 @@ export default class Component { if (node.declaration) { if (node.declaration.type === 'VariableDeclaration') { node.declaration.declarations.forEach(declarator => { - extractNames(declarator.id).forEach(name => { + extract_names(declarator.id).forEach(name => { const variable = this.var_lookup.get(name); variable.export_name = name; }); @@ -453,7 +482,7 @@ export default class Component { code.remove(node.start, node.declaration.start); } else { - removeNode(code, content.start, content.end, content.body, node); + remove_node(code, content.start, content.end, content.body, node); node.specifiers.forEach(specifier => { const variable = this.var_lookup.get(specifier.local.name); @@ -509,9 +538,9 @@ export default class Component { const script = this.ast.module; if (!script) return; - this.addSourcemapLocations(script.content); + this.add_sourcemap_locations(script.content); - let { scope, globals } = createScopes(script.content); + let { scope, globals } = create_scopes(script.content); this.module_scope = scope; scope.declarations.forEach((node, name) => { @@ -554,7 +583,7 @@ export default class Component { const script = this.ast.instance; if (!script) return; - this.addSourcemapLocations(script.content); + this.add_sourcemap_locations(script.content); // inject vars for reactive declarations script.content.body.forEach(node => { @@ -569,7 +598,7 @@ export default class Component { } }); - let { scope: instance_scope, map, globals } = createScopes(script.content); + let { scope: instance_scope, map, globals } = create_scopes(script.content); this.instance_scope = instance_scope; this.instance_scope_map = map; @@ -662,15 +691,15 @@ export default class Component { deep = node.left.type === 'MemberExpression'; names = deep - ? [getObject(node.left).name] - : extractNames(node.left); + ? [get_object(node.left).name] + : extract_names(node.left); } else if (node.type === 'UpdateExpression') { - names = [getObject(node.argument).name]; + names = [get_object(node.argument).name]; } if (names) { names.forEach(name => { - if (scope.findOwner(name) === instance_scope) { + if (scope.find_owner(name) === instance_scope) { const variable = component.var_lookup.get(name); variable[deep ? 'mutated' : 'reassigned'] = true; } @@ -698,8 +727,8 @@ export default class Component { scope = map.get(node); } - if (isReference(node, parent)) { - const object = getObject(node); + if (is_reference(node, parent)) { + const object = get_object(node); const { name } = object; if (name[0] === '$' && !scope.has(name)) { @@ -732,7 +761,7 @@ export default class Component { rewrite_props(get_insert: (variable: Var) => string) { const component = this; - const { code, instance_scope, instance_scope_map: map, componentOptions } = this; + const { code, instance_scope, instance_scope_map: map, component_options } = this; let scope = instance_scope; const coalesced_declarations = []; @@ -757,7 +786,7 @@ export default class Component { if (declarator.id.type !== 'Identifier') { const inserts = []; - extractNames(declarator.id).forEach(name => { + extract_names(declarator.id).forEach(name => { const variable = component.var_lookup.get(name); if (variable.export_name) { @@ -946,9 +975,9 @@ export default class Component { scope = map.get(node); } - if (isReference(node, parent)) { - const { name } = flattenReference(node); - const owner = scope.findOwner(name); + if (is_reference(node, parent)) { + const { name } = flatten_reference(node); + const owner = scope.find_owner(name); if (name[0] === '$' && !owner) { hoistable = false; @@ -1028,17 +1057,17 @@ export default class Component { } if (node.type === 'AssignmentExpression') { - const identifier = getObject(node.left) + const identifier = get_object(node.left) assignee_nodes.add(identifier); assignees.add(identifier.name); } else if (node.type === 'UpdateExpression') { - const identifier = getObject(node.argument); + const identifier = get_object(node.argument); assignees.add(identifier.name); - } else if (isReference(node, parent)) { - const identifier = getObject(node); + } else if (is_reference(node, parent)) { + const identifier = get_object(node); if (!assignee_nodes.has(identifier)) { const { name } = identifier; - const owner = scope.findOwner(name); + const owner = scope.find_owner(name); if ( (!owner || owner === component.instance_scope) && (name[0] === '$' || component.var_lookup.has(name) && component.var_lookup.get(name).writable) @@ -1149,7 +1178,7 @@ export default class Component { if (this.var_lookup.has(name)) return; if (template_scope && template_scope.names.has(name)) return; - if (globalWhitelist.has(name)) return; + if (globals.has(name)) return; let message = `'${name}' is not defined`; if (!this.ast.instance) message += `. Consider adding a '; +const script_closing_tag = ''; function get_context(parser: Parser, attributes: Node[], start: number) { const context = attributes.find(attribute => attribute.name === 'context'); @@ -28,28 +28,28 @@ function get_context(parser: Parser, attributes: Node[], start: number) { return value; } -export default function readScript(parser: Parser, start: number, attributes: Node[]) { - const scriptStart = parser.index; - const scriptEnd = parser.template.indexOf(scriptClosingTag, scriptStart); +export default function read_script(parser: Parser, start: number, attributes: Node[]) { + const script_start = parser.index; + const script_end = parser.template.indexOf(script_closing_tag, script_start); - if (scriptEnd === -1) parser.error({ + if (script_end === -1) parser.error({ code: `unclosed-script`, message: `', true); @@ -271,7 +250,7 @@ export default function tag(parser: Parser) { } else if (name === 'style') { // special case const start = parser.index; - const data = parser.readUntil(/<\/style>/); + const data = parser.read_until(/<\/style>/); const end = parser.index; element.children.push({ start, end, type: 'Text', data }); parser.eat('', true); @@ -280,7 +259,7 @@ export default function tag(parser: Parser) { } } -function readTagName(parser: Parser) { +function read_tag_name(parser: Parser) { const start = parser.index; if (parser.read(SELF)) { @@ -309,9 +288,9 @@ function readTagName(parser: Parser) { if (parser.read(COMPONENT)) return 'svelte:component'; - const name = parser.readUntil(/(\s|\/|>)/); + const name = parser.read_until(/(\s|\/|>)/); - if (metaTags.has(name)) return name; + if (meta_tags.has(name)) return name; if (name.startsWith('svelte:')) { const match = fuzzymatch(name.slice(7), valid_meta_tags); @@ -325,7 +304,7 @@ function readTagName(parser: Parser) { }, start); } - if (!validTagName.test(name)) { + if (!valid_tag_name.test(name)) { parser.error({ code: `invalid-tag-name`, message: `Expected valid tag name` @@ -335,16 +314,16 @@ function readTagName(parser: Parser) { return name; } -function readAttribute(parser: Parser, uniqueNames: Set) { +function read_attribute(parser: Parser, unique_names: Set) { const start = parser.index; if (parser.eat('{')) { - parser.allowWhitespace(); + parser.allow_whitespace(); if (parser.eat('...')) { - const expression = readExpression(parser); + const expression = read_expression(parser); - parser.allowWhitespace(); + parser.allow_whitespace(); parser.eat('}', true); return { @@ -354,10 +333,10 @@ function readAttribute(parser: Parser, uniqueNames: Set) { expression }; } else { - const valueStart = parser.index; + const value_start = parser.index; - const name = parser.readIdentifier(); - parser.allowWhitespace(); + const name = parser.read_identifier(); + parser.allow_whitespace(); parser.eat('}', true); return { @@ -366,12 +345,12 @@ function readAttribute(parser: Parser, uniqueNames: Set) { type: 'Attribute', name, value: [{ - start: valueStart, - end: valueStart + name.length, + start: value_start, + end: value_start + name.length, type: 'AttributeShorthand', expression: { - start: valueStart, - end: valueStart + name.length, + start: value_start, + end: value_start + name.length, type: 'Identifier', name } @@ -380,27 +359,27 @@ function readAttribute(parser: Parser, uniqueNames: Set) { } } - let name = parser.readUntil(/(\s|=|\/|>)/); + let name = parser.read_until(/(\s|=|\/|>)/); if (!name) return null; - if (uniqueNames.has(name)) { + if (unique_names.has(name)) { parser.error({ code: `duplicate-attribute`, message: 'Attributes need to be unique' }, start); } - uniqueNames.add(name); + unique_names.add(name); let end = parser.index; - parser.allowWhitespace(); + parser.allow_whitespace(); const colon_index = name.indexOf(':'); const type = colon_index !== -1 && get_directive_type(name.slice(0, colon_index)); let value: any[] | true = true; if (parser.eat('=')) { - value = readAttributeValue(parser); + value = read_attribute_value(parser); end = parser.index; } @@ -470,23 +449,23 @@ function get_directive_type(name) { if (name === 'in' || name === 'out' || name === 'transition') return 'Transition'; } -function readAttributeValue(parser: Parser) { - const quoteMark = parser.eat(`'`) ? `'` : parser.eat(`"`) ? `"` : null; +function read_attribute_value(parser: Parser) { + const quote_mark = parser.eat(`'`) ? `'` : parser.eat(`"`) ? `"` : null; const regex = ( - quoteMark === `'` ? /'/ : - quoteMark === `"` ? /"/ : + quote_mark === `'` ? /'/ : + quote_mark === `"` ? /"/ : /(\/>|[\s"'=<>`])/ ); - const value = readSequence(parser, () => !!parser.matchRegex(regex)); + const value = read_sequence(parser, () => !!parser.match_regex(regex)); - if (quoteMark) parser.index += 1; + if (quote_mark) parser.index += 1; return value; } -function readSequence(parser: Parser, done: () => boolean) { - let currentChunk: Node = { +function read_sequence(parser: Parser, done: () => boolean) { + let current_chunk: Node = { start: parser.index, end: null, type: 'Text', @@ -499,25 +478,25 @@ function readSequence(parser: Parser, done: () => boolean) { const index = parser.index; if (done()) { - currentChunk.end = parser.index; + current_chunk.end = parser.index; - if (currentChunk.data) chunks.push(currentChunk); + if (current_chunk.data) chunks.push(current_chunk); chunks.forEach(chunk => { if (chunk.type === 'Text') - chunk.data = decodeCharacterReferences(chunk.data); + chunk.data = decode_character_references(chunk.data); }); return chunks; } else if (parser.eat('{')) { - if (currentChunk.data) { - currentChunk.end = index; - chunks.push(currentChunk); + if (current_chunk.data) { + current_chunk.end = index; + chunks.push(current_chunk); } - parser.allowWhitespace(); - const expression = readExpression(parser); - parser.allowWhitespace(); + parser.allow_whitespace(); + const expression = read_expression(parser); + parser.allow_whitespace(); parser.eat('}', true); chunks.push({ @@ -527,14 +506,14 @@ function readSequence(parser: Parser, done: () => boolean) { expression, }); - currentChunk = { + current_chunk = { start: parser.index, end: null, type: 'Text', data: '', }; } else { - currentChunk.data += parser.template[parser.index++]; + current_chunk.data += parser.template[parser.index++]; } } diff --git a/src/parse/state/text.ts b/src/parse/state/text.ts index 72fea496ce..f739c8cc9e 100644 --- a/src/parse/state/text.ts +++ b/src/parse/state/text.ts @@ -1,4 +1,4 @@ -import { decodeCharacterReferences } from '../utils/html'; +import { decode_character_references } from '../utils/html'; import { Parser } from '../index'; export default function text(parser: Parser) { @@ -18,6 +18,6 @@ export default function text(parser: Parser) { start, end: parser.index, type: 'Text', - data: decodeCharacterReferences(data), + data: decode_character_references(data), }); } diff --git a/src/parse/utils/html.ts b/src/parse/utils/html.ts index dd4296a8d0..b49989eacd 100644 --- a/src/parse/utils/html.ts +++ b/src/parse/utils/html.ts @@ -1,6 +1,6 @@ -import htmlEntities from './entities'; +import entities from './entities'; -const windows1252 = [ +const windows_1252 = [ 8364, 129, 8218, @@ -34,18 +34,19 @@ const windows1252 = [ 382, 376, ]; -const entityPattern = new RegExp( - `&(#?(?:x[\\w\\d]+|\\d+|${Object.keys(htmlEntities).join('|')}));?`, + +const entity_pattern = new RegExp( + `&(#?(?:x[\\w\\d]+|\\d+|${Object.keys(entities).join('|')}));?`, 'g' ); -export function decodeCharacterReferences(html: string) { - return html.replace(entityPattern, (match, entity) => { +export function decode_character_references(html: string) { + return html.replace(entity_pattern, (match, entity) => { let code; // Handle named entities if (entity[0] !== '#') { - code = htmlEntities[entity]; + code = entities[entity]; } else if (entity[1] === 'x') { code = parseInt(entity.substring(2), 16); } else { @@ -56,7 +57,7 @@ export function decodeCharacterReferences(html: string) { return match; } - return String.fromCodePoint(validateCode(code)); + return String.fromCodePoint(validate_code(code)); }); } @@ -67,7 +68,7 @@ const NUL = 0; // to replace them ourselves // // Source: http://en.wikipedia.org/wiki/Character_encodings_in_HTML#Illegal_characters -function validateCode(code: number) { +function validate_code(code: number) { // line feed becomes generic whitespace if (code === 10) { return 32; @@ -81,7 +82,7 @@ function validateCode(code: number) { // code points 128-159 are dealt with leniently by browsers, but they're incorrect. We need // to correct the mistake or we'll end up with missing € signs and so on if (code <= 159) { - return windows1252[code - 128]; + return windows_1252[code - 128]; } // basic multilingual plane diff --git a/src/preprocess/index.ts b/src/preprocess/index.ts index 4aaa033270..8538a65acc 100644 --- a/src/preprocess/index.ts +++ b/src/preprocess/index.ts @@ -1,5 +1,4 @@ import { SourceMap } from 'magic-string'; -import replaceAsync from '../utils/replaceAsync'; export interface PreprocessorGroup { markup?: (options: { @@ -22,21 +21,54 @@ interface Processed { dependencies?: string[]; } -function parseAttributeValue(value: string) { +function parse_attribute_value(value: string) { return /^['"]/.test(value) ? value.slice(1, -1) : value; } -function parseAttributes(str: string) { +function parse_attributes(str: string) { const attrs = {}; str.split(/\s+/).filter(Boolean).forEach(attr => { const [name, value] = attr.split('='); - attrs[name] = value ? parseAttributeValue(value) : true; + attrs[name] = value ? parse_attribute_value(value) : true; }); return attrs; } +interface Replacement { + offset: number; + length: number; + replacement: string; +} + +async function replace_async(str: string, re: RegExp, func: (...any) => Promise) { + const replacements: Promise[] = []; + str.replace(re, (...args) => { + replacements.push( + func(...args).then( + res => + ({ + offset: args[args.length - 2], + length: args[0].length, + replacement: res, + }) + ) + ); + return ''; + }); + let out = ''; + let last_end = 0; + for (const { offset, length, replacement } of await Promise.all( + replacements + )) { + out += str.slice(last_end, offset) + replacement; + last_end = offset + length; + } + out += str.slice(last_end); + return out; +} + export default async function preprocess( source: string, preprocessor: PreprocessorGroup | PreprocessorGroup[], @@ -61,13 +93,13 @@ export default async function preprocess( } for (const fn of script) { - source = await replaceAsync( + source = await replace_async( source, /([^]*?)<\/script>/gi, async (match, attributes, content) => { const processed: Processed = await fn({ content, - attributes: parseAttributes(attributes), + attributes: parse_attributes(attributes), filename }); if (processed && processed.dependencies) dependencies.push(...processed.dependencies); @@ -77,13 +109,13 @@ export default async function preprocess( } for (const fn of style) { - source = await replaceAsync( + source = await replace_async( source, /([^]*?)<\/style>/gi, async (match, attributes, content) => { const processed: Processed = await fn({ content, - attributes: parseAttributes(attributes), + attributes: parse_attributes(attributes), filename }); if (processed && processed.dependencies) dependencies.push(...processed.dependencies); diff --git a/src/utils/addToSet.ts b/src/utils/addToSet.ts deleted file mode 100644 index 5197e96972..0000000000 --- a/src/utils/addToSet.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default function addToSet(a: Set, b: Set) { - b.forEach(item => { - a.add(item); - }); -} \ No newline at end of file diff --git a/src/utils/error.ts b/src/utils/error.ts index acaab37117..f89cc3d721 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -1,5 +1,5 @@ import { locate } from 'locate-character'; -import getCodeFrame from '../utils/getCodeFrame'; +import get_code_frame from '../utils/get_code_frame'; class CompileError extends Error { code: string; @@ -34,7 +34,7 @@ export default function error(message: string, props: { error.pos = props.start; error.filename = props.filename; - error.frame = getCodeFrame(props.source, start.line - 1, start.column); + error.frame = get_code_frame(props.source, start.line - 1, start.column); throw error; } \ No newline at end of file diff --git a/src/utils/fixAttributeCasing.ts b/src/utils/fixAttributeCasing.ts deleted file mode 100644 index bcd7f50edd..0000000000 --- a/src/utils/fixAttributeCasing.ts +++ /dev/null @@ -1,12 +0,0 @@ -const svgAttributes = 'accent-height accumulate additive alignment-baseline allowReorder alphabetic amplitude arabic-form ascent attributeName attributeType autoReverse azimuth baseFrequency baseline-shift baseProfile bbox begin bias by calcMode cap-height class clip clipPathUnits clip-path clip-rule color color-interpolation color-interpolation-filters color-profile color-rendering contentScriptType contentStyleType cursor cx cy d decelerate descent diffuseConstant direction display divisor dominant-baseline dur dx dy edgeMode elevation enable-background end exponent externalResourcesRequired fill fill-opacity fill-rule filter filterRes filterUnits flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight format from fr fx fy g1 g2 glyph-name glyph-orientation-horizontal glyph-orientation-vertical glyphRef gradientTransform gradientUnits hanging height href horiz-adv-x horiz-origin-x id ideographic image-rendering in in2 intercept k k1 k2 k3 k4 kernelMatrix kernelUnitLength kerning keyPoints keySplines keyTimes lang lengthAdjust letter-spacing lighting-color limitingConeAngle local marker-end marker-mid marker-start markerHeight markerUnits markerWidth mask maskContentUnits maskUnits mathematical max media method min mode name numOctaves offset onabort onactivate onbegin onclick onend onerror onfocusin onfocusout onload onmousedown onmousemove onmouseout onmouseover onmouseup onrepeat onresize onscroll onunload opacity operator order orient orientation origin overflow overline-position overline-thickness panose-1 paint-order pathLength patternContentUnits patternTransform patternUnits pointer-events points pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits r radius refX refY rendering-intent repeatCount repeatDur requiredExtensions requiredFeatures restart result rotate rx ry scale seed shape-rendering slope spacing specularConstant specularExponent speed spreadMethod startOffset stdDeviation stemh stemv stitchTiles stop-color stop-opacity strikethrough-position strikethrough-thickness string stroke stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width style surfaceScale systemLanguage tabindex tableValues target targetX targetY text-anchor text-decoration text-rendering textLength to transform type u1 u2 underline-position underline-thickness unicode unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical values version vert-adv-y vert-origin-x vert-origin-y viewBox viewTarget visibility width widths word-spacing writing-mode x x-height x1 x2 xChannelSelector xlink:actuate xlink:arcrole xlink:href xlink:role xlink:show xlink:title xlink:type xml:base xml:lang xml:space y y1 y2 yChannelSelector z zoomAndPan'.split(' '); - -const svgAttributeLookup = new Map(); - -svgAttributes.forEach(name => { - svgAttributeLookup.set(name.toLowerCase(), name); -}); - -export default function fixAttributeCasing(name) { - name = name.toLowerCase(); - return svgAttributeLookup.get(name) || name; -} diff --git a/src/utils/fullCharCodeAt.ts b/src/utils/full_char_code_at.ts similarity index 82% rename from src/utils/fullCharCodeAt.ts rename to src/utils/full_char_code_at.ts index 034da9258b..e0c15588c7 100644 --- a/src/utils/fullCharCodeAt.ts +++ b/src/utils/full_char_code_at.ts @@ -1,7 +1,7 @@ // Adapted from https://github.com/acornjs/acorn/blob/6584815dca7440e00de841d1dad152302fdd7ca5/src/tokenize.js // Reproduced under MIT License https://github.com/acornjs/acorn/blob/master/LICENSE -export default function fullCharCodeAt(str: string, i: number): number { +export default function full_char_code_at(str: string, i: number): number { let code = str.charCodeAt(i) if (code <= 0xd7ff || code >= 0xe000) return code; diff --git a/src/utils/fuzzymatch.ts b/src/utils/fuzzymatch.ts index ff528a79c1..89d98fe1c1 100644 --- a/src/utils/fuzzymatch.ts +++ b/src/utils/fuzzymatch.ts @@ -53,30 +53,28 @@ function levenshtein(str1: string, str2: string) { return current.pop(); } -const _nonWordRe = /[^\w, ]+/; +const non_word_regex = /[^\w, ]+/; -function _iterateGrams(value: string, gramSize: number) { - gramSize = gramSize || 2; - const simplified = '-' + value.toLowerCase().replace(_nonWordRe, '') + '-'; - const lenDiff = gramSize - simplified.length; +function iterate_grams(value: string, gram_size = 2) { + const simplified = '-' + value.toLowerCase().replace(non_word_regex, '') + '-'; + const len_diff = gram_size - simplified.length; const results = []; - if (lenDiff > 0) { - for (let i = 0; i < lenDiff; ++i) { + if (len_diff > 0) { + for (let i = 0; i < len_diff; ++i) { value += '-'; } } - for (let i = 0; i < simplified.length - gramSize + 1; ++i) { - results.push(simplified.slice(i, i + gramSize)); + for (let i = 0; i < simplified.length - gram_size + 1; ++i) { + results.push(simplified.slice(i, i + gram_size)); } return results; } -function _gramCounter(value: string, gramSize: number) { +function gram_counter(value: string, gram_size = 2) { // return an object where key=gram, value=number of occurrences - gramSize = gramSize || 2; const result = {}; - const grams = _iterateGrams(value, gramSize); + const grams = iterate_grams(value, gram_size); let i = 0; for (i; i < grams.length; ++i) { @@ -89,25 +87,21 @@ function _gramCounter(value: string, gramSize: number) { return result; } -function sortDescending(a, b) { +function sort_descending(a, b) { return b[0] - a[0]; } class FuzzySet { - exactSet: object; - matchDict: object; - items: object; + exact_set = {}; + match_dict = {}; + items = {}; constructor(arr: string[]) { - // define all the object functions and attributes - this.exactSet = {}; - this.matchDict = {}; - this.items = {}; - // initialization for (let i = GRAM_SIZE_LOWER; i < GRAM_SIZE_UPPER + 1; ++i) { this.items[i] = []; } + // add all the items to the set for (let i = 0; i < arr.length; ++i) { this.add(arr[i]); @@ -115,8 +109,8 @@ class FuzzySet { } add(value: string) { - const normalizedValue = value.toLowerCase(); - if (normalizedValue in this.exactSet) { + const normalized_value = value.toLowerCase(); + if (normalized_value in this.exact_set) { return false; } @@ -126,35 +120,35 @@ class FuzzySet { } } - _add(value: string, gramSize: number) { - const normalizedValue = value.toLowerCase(); - const items = this.items[gramSize] || []; + _add(value: string, gram_size: number) { + const normalized_value = value.toLowerCase(); + const items = this.items[gram_size] || []; const index = items.length; items.push(0); - const gramCounts = _gramCounter(normalizedValue, gramSize); - let sumOfSquareGramCounts = 0; + const gram_counts = gram_counter(normalized_value, gram_size); + let sum_of_square_gram_counts = 0; let gram; - let gramCount; + let gram_count; - for (gram in gramCounts) { - gramCount = gramCounts[gram]; - sumOfSquareGramCounts += Math.pow(gramCount, 2); - if (gram in this.matchDict) { - this.matchDict[gram].push([index, gramCount]); + for (gram in gram_counts) { + gram_count = gram_counts[gram]; + sum_of_square_gram_counts += Math.pow(gram_count, 2); + if (gram in this.match_dict) { + this.match_dict[gram].push([index, gram_count]); } else { - this.matchDict[gram] = [[index, gramCount]]; + this.match_dict[gram] = [[index, gram_count]]; } } - const vectorNormal = Math.sqrt(sumOfSquareGramCounts); - items[index] = [vectorNormal, normalizedValue]; - this.items[gramSize] = items; - this.exactSet[normalizedValue] = value; + const vector_normal = Math.sqrt(sum_of_square_gram_counts); + items[index] = [vector_normal, normalized_value]; + this.items[gram_size] = items; + this.exact_set[normalized_value] = value; }; get(value: string) { - const normalizedValue = value.toLowerCase(); - const result = this.exactSet[normalizedValue]; + const normalized_value = value.toLowerCase(); + const result = this.exact_set[normalized_value]; if (result) { return [[1, result]]; @@ -163,11 +157,11 @@ class FuzzySet { let results = []; // start with high gram size and if there are no results, go to lower gram sizes for ( - let gramSize = GRAM_SIZE_UPPER; - gramSize >= GRAM_SIZE_LOWER; - --gramSize + let gram_size = GRAM_SIZE_UPPER; + gram_size >= GRAM_SIZE_LOWER; + --gram_size ) { - results = this.__get(value, gramSize); + results = this.__get(value, gram_size); if (results) { return results; } @@ -175,68 +169,68 @@ class FuzzySet { return null; } - __get(value: string, gramSize: number) { - const normalizedValue = value.toLowerCase(); + __get(value: string, gram_size: number) { + const normalized_value = value.toLowerCase(); const matches = {}; - const gramCounts = _gramCounter(normalizedValue, gramSize); - const items = this.items[gramSize]; - let sumOfSquareGramCounts = 0; + const gram_counts = gram_counter(normalized_value, gram_size); + const items = this.items[gram_size]; + let sum_of_square_gram_counts = 0; let gram; - let gramCount; + let gram_count; let i; let index; - let otherGramCount; - - for (gram in gramCounts) { - gramCount = gramCounts[gram]; - sumOfSquareGramCounts += Math.pow(gramCount, 2); - if (gram in this.matchDict) { - for (i = 0; i < this.matchDict[gram].length; ++i) { - index = this.matchDict[gram][i][0]; - otherGramCount = this.matchDict[gram][i][1]; + let other_gram_count; + + for (gram in gram_counts) { + gram_count = gram_counts[gram]; + sum_of_square_gram_counts += Math.pow(gram_count, 2); + if (gram in this.match_dict) { + for (i = 0; i < this.match_dict[gram].length; ++i) { + index = this.match_dict[gram][i][0]; + other_gram_count = this.match_dict[gram][i][1]; if (index in matches) { - matches[index] += gramCount * otherGramCount; + matches[index] += gram_count * other_gram_count; } else { - matches[index] = gramCount * otherGramCount; + matches[index] = gram_count * other_gram_count; } } } } - const vectorNormal = Math.sqrt(sumOfSquareGramCounts); + const vector_normal = Math.sqrt(sum_of_square_gram_counts); let results = []; - let matchScore; + let match_score; // build a results list of [score, str] - for (const matchIndex in matches) { - matchScore = matches[matchIndex]; + for (const match_index in matches) { + match_score = matches[match_index]; results.push([ - matchScore / (vectorNormal * items[matchIndex][0]), - items[matchIndex][1], + match_score / (vector_normal * items[match_index][0]), + items[match_index][1], ]); } - results.sort(sortDescending); + results.sort(sort_descending); - let newResults = []; - const endIndex = Math.min(50, results.length); + let new_results = []; + const end_index = Math.min(50, results.length); // truncate somewhat arbitrarily to 50 - for (let i = 0; i < endIndex; ++i) { - newResults.push([ - _distance(results[i][1], normalizedValue), + for (let i = 0; i < end_index; ++i) { + new_results.push([ + _distance(results[i][1], normalized_value), results[i][1], ]); } - results = newResults; - results.sort(sortDescending); + results = new_results; + results.sort(sort_descending); - newResults = []; + new_results = []; for (let i = 0; i < results.length; ++i) { if (results[i][0] == results[0][0]) { - newResults.push([results[i][0], this.exactSet[results[i][1]]]); + new_results.push([results[i][0], this.exact_set[results[i][1]]]); } } - return newResults; + return new_results; }; } \ No newline at end of file diff --git a/src/utils/getCodeFrame.ts b/src/utils/getCodeFrame.ts deleted file mode 100644 index c14089ee4a..0000000000 --- a/src/utils/getCodeFrame.ts +++ /dev/null @@ -1,36 +0,0 @@ -import repeat from './repeat'; - -function tabsToSpaces(str: string) { - return str.replace(/^\t+/, match => match.split('\t').join(' ')); -} - -export default function getCodeFrame( - source: string, - line: number, - column: number -) { - const lines = source.split('\n'); - - const frameStart = Math.max(0, line - 2); - const frameEnd = Math.min(line + 3, lines.length); - - const digits = String(frameEnd + 1).length; - - return lines - .slice(frameStart, frameEnd) - .map((str, i) => { - const isErrorLine = frameStart + i === line; - - let lineNum = String(i + frameStart + 1); - while (lineNum.length < digits) lineNum = ` ${lineNum}`; - - if (isErrorLine) { - const indicator = - repeat(' ', digits + 2 + tabsToSpaces(str.slice(0, column)).length) + '^'; - return `${lineNum}: ${tabsToSpaces(str)}\n${indicator}`; - } - - return `${lineNum}: ${tabsToSpaces(str)}`; - }) - .join('\n'); -} diff --git a/src/utils/get_code_frame.ts b/src/utils/get_code_frame.ts new file mode 100644 index 0000000000..b15378be2c --- /dev/null +++ b/src/utils/get_code_frame.ts @@ -0,0 +1,36 @@ +import repeat from './repeat'; + +function tabs_to_spaces(str: string) { + return str.replace(/^\t+/, match => match.split('\t').join(' ')); +} + +export default function get_code_frame( + source: string, + line: number, + column: number +) { + const lines = source.split('\n'); + + const frame_start = Math.max(0, line - 2); + const frame_end = Math.min(line + 3, lines.length); + + const digits = String(frame_end + 1).length; + + return lines + .slice(frame_start, frame_end) + .map((str, i) => { + const isErrorLine = frame_start + i === line; + + let line_num = String(i + frame_start + 1); + while (line_num.length < digits) line_num = ` ${line_num}`; + + if (isErrorLine) { + const indicator = + repeat(' ', digits + 2 + tabs_to_spaces(str.slice(0, column)).length) + '^'; + return `${line_num}: ${tabs_to_spaces(str)}\n${indicator}`; + } + + return `${line_num}: ${tabs_to_spaces(str)}`; + }) + .join('\n'); +} diff --git a/src/utils/get_tail_snippet.ts b/src/utils/get_tail_snippet.ts deleted file mode 100644 index 8fc38c5be1..0000000000 --- a/src/utils/get_tail_snippet.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Node } from '../interfaces'; - -export function get_tail_snippet(node: Node) { - const { start, end } = get_tail(node); - return `[✂${start}-${end}✂]`; -} - -export function get_tail(node: Node) { - const end = node.end; - while (node.type === 'MemberExpression') node = node.object; - return { start: node.end, end }; -} \ No newline at end of file diff --git a/src/utils/globalWhitelist.ts b/src/utils/globalWhitelist.ts deleted file mode 100644 index 1c115c372b..0000000000 --- a/src/utils/globalWhitelist.ts +++ /dev/null @@ -1,28 +0,0 @@ -export default new Set([ - 'Array', - 'Boolean', - 'console', - 'Date', - 'decodeURI', - 'decodeURIComponent', - 'encodeURI', - 'encodeURIComponent', - 'Infinity', - 'Intl', - 'isFinite', - 'isNaN', - 'JSON', - 'Map', - 'Math', - 'NaN', - 'Number', - 'Object', - 'parseFloat', - 'parseInt', - 'process', - 'Promise', - 'RegExp', - 'Set', - 'String', - 'undefined', -]); diff --git a/src/utils/hash.ts b/src/utils/hash.ts deleted file mode 100644 index c68476a5bb..0000000000 --- a/src/utils/hash.ts +++ /dev/null @@ -1,8 +0,0 @@ -// https://github.com/darkskyapp/string-hash/blob/master/index.js -export default function hash(str: string): string { - let hash = 5381; - let i = str.length; - - while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i); - return (hash >>> 0).toString(36); -} diff --git a/src/utils/isValidIdentifier.ts b/src/utils/isValidIdentifier.ts deleted file mode 100644 index 20ceeb4bbf..0000000000 --- a/src/utils/isValidIdentifier.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { isIdentifierStart, isIdentifierChar } from 'acorn'; -import fullCharCodeAt from './fullCharCodeAt'; - -export default function isValidIdentifier(str: string): boolean { - let i = 0; - - while (i < str.length) { - const code = fullCharCodeAt(str, i); - if (!(i === 0 ? isIdentifierStart : isIdentifierChar)(code, true)) return false; - - i += code <= 0xffff ? 1 : 2; - } - - return true; -} \ No newline at end of file diff --git a/src/utils/isVoidElementName.ts b/src/utils/isVoidElementName.ts deleted file mode 100644 index 2396a0cde2..0000000000 --- a/src/utils/isVoidElementName.ts +++ /dev/null @@ -1,5 +0,0 @@ -const voidElementNames = /^(?:area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/; - -export default function isVoidElementName(name: string) { - return voidElementNames.test(name) || name.toLowerCase() === '!doctype'; -} diff --git a/src/utils/names.ts b/src/utils/names.ts new file mode 100644 index 0000000000..5047fe850c --- /dev/null +++ b/src/utils/names.ts @@ -0,0 +1,115 @@ +import { isIdentifierStart, isIdentifierChar } from 'acorn'; +import full_char_code_at from './full_char_code_at'; + +export const globals = new Set([ + 'Array', + 'Boolean', + 'console', + 'Date', + 'decodeURI', + 'decodeURIComponent', + 'encodeURI', + 'encodeURIComponent', + 'Infinity', + 'Intl', + 'isFinite', + 'isNaN', + 'JSON', + 'Map', + 'Math', + 'NaN', + 'Number', + 'Object', + 'parseFloat', + 'parseInt', + 'process', + 'Promise', + 'RegExp', + 'Set', + 'String', + 'undefined', +]); + +export const reserved = new Set([ + 'arguments', + 'await', + 'break', + 'case', + 'catch', + 'class', + 'const', + 'continue', + 'debugger', + 'default', + 'delete', + 'do', + 'else', + 'enum', + 'eval', + 'export', + 'extends', + 'false', + 'finally', + 'for', + 'function', + 'if', + 'implements', + 'import', + 'in', + 'instanceof', + 'interface', + 'let', + 'new', + 'null', + 'package', + 'private', + 'protected', + 'public', + 'return', + 'static', + 'super', + 'switch', + 'this', + 'throw', + 'true', + 'try', + 'typeof', + 'var', + 'void', + 'while', + 'with', + 'yield', +]); + +const void_element_names = /^(?:area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/; + +export function is_void(name: string) { + return void_element_names.test(name) || name.toLowerCase() === '!doctype'; +} + +function is_valid(str: string): boolean { + let i = 0; + + while (i < str.length) { + const code = full_char_code_at(str, i); + if (!(i === 0 ? isIdentifierStart : isIdentifierChar)(code, true)) return false; + + i += code <= 0xffff ? 1 : 2; + } + + return true; +} + +export function quote_name_if_necessary(name: string) { + if (!is_valid(name)) return `"${name}"`; + return name; +} + +export function quote_prop_if_necessary(name: string) { + if (!is_valid(name)) return `["${name}"]`; + return `.${name}`; +} + +export function sanitize(name: string) { + return name.replace(/[^a-zA-Z]+/g, '_').replace(/^_/, '').replace(/_$/, ''); +} \ No newline at end of file diff --git a/src/utils/namespaces.ts b/src/utils/namespaces.ts index bac1797b49..3bde3ee308 100644 --- a/src/utils/namespaces.ts +++ b/src/utils/namespaces.ts @@ -5,7 +5,7 @@ export const xlink = 'http://www.w3.org/1999/xlink'; export const xml = 'http://www.w3.org/XML/1998/namespace'; export const xmlns = 'http://www.w3.org/2000/xmlns'; -export const validNamespaces = [ +export const valid_namespaces = [ 'html', 'mathml', 'svg', diff --git a/src/utils/quoteIfNecessary.ts b/src/utils/quoteIfNecessary.ts deleted file mode 100644 index 6a6f829e98..0000000000 --- a/src/utils/quoteIfNecessary.ts +++ /dev/null @@ -1,12 +0,0 @@ -import isValidIdentifier from './isValidIdentifier'; -import reservedNames from './reservedNames'; - -export function quoteNameIfNecessary(name) { - if (!isValidIdentifier(name)) return `"${name}"`; - return name; -} - -export function quotePropIfNecessary(name) { - if (!isValidIdentifier(name)) return `["${name}"]`; - return `.${name}`; -} \ No newline at end of file diff --git a/src/utils/removeCSSPrefix.ts b/src/utils/removeCSSPrefix.ts deleted file mode 100644 index df1849f119..0000000000 --- a/src/utils/removeCSSPrefix.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default function(name: string): string { - return name.replace(/^-((webkit)|(moz)|(o)|(ms))-/, ''); -} diff --git a/src/utils/removeNode.ts b/src/utils/removeNode.ts deleted file mode 100644 index 4405803dcf..0000000000 --- a/src/utils/removeNode.ts +++ /dev/null @@ -1,36 +0,0 @@ -import MagicString from 'magic-string'; -import { Node } from '../interfaces'; - -export function removeNode( - code: MagicString, - start: number, - end: number, - body: Node, - node: Node -) { - const i = body.indexOf(node); - if (i === -1) throw new Error('node not in list'); - - let a; - let b; - - if (body.length === 1) { - // remove everything, leave {} - a = start; - b = end; - } else if (i === 0) { - // remove everything before second node, including comments - a = start; - while (/\s/.test(code.original[a])) a += 1; - - b = body[i].end; - while (/[\s,]/.test(code.original[b])) b += 1; - } else { - // remove the end of the previous node to the end of this one - a = body[i - 1].end; - b = node.end; - } - - code.remove(a, b); - return; -} \ No newline at end of file diff --git a/src/utils/replaceAsync.ts b/src/utils/replaceAsync.ts deleted file mode 100644 index fe76cf2e6d..0000000000 --- a/src/utils/replaceAsync.ts +++ /dev/null @@ -1,38 +0,0 @@ -// asynchronous String#replace - -export default async function replaceAsync( - str: string, - re: RegExp, - func: (...any) => Promise -) { - const replacements: Promise[] = []; - str.replace(re, (...args) => { - replacements.push( - func(...args).then( - res => - ({ - offset: args[args.length - 2], - length: args[0].length, - replacement: res, - }) - ) - ); - return ''; - }); - let out = ''; - let lastEnd = 0; - for (const { offset, length, replacement } of await Promise.all( - replacements - )) { - out += str.slice(lastEnd, offset) + replacement; - lastEnd = offset + length; - } - out += str.slice(lastEnd); - return out; -} - -interface Replacement { - offset: number; - length: number; - replacement: string; -} diff --git a/src/utils/reservedNames.ts b/src/utils/reservedNames.ts deleted file mode 100644 index e0d1e860e3..0000000000 --- a/src/utils/reservedNames.ts +++ /dev/null @@ -1,52 +0,0 @@ -const reservedNames = new Set([ - 'arguments', - 'await', - 'break', - 'case', - 'catch', - 'class', - 'const', - 'continue', - 'debugger', - 'default', - 'delete', - 'do', - 'else', - 'enum', - 'eval', - 'export', - 'extends', - 'false', - 'finally', - 'for', - 'function', - 'if', - 'implements', - 'import', - 'in', - 'instanceof', - 'interface', - 'let', - 'new', - 'null', - 'package', - 'private', - 'protected', - 'public', - 'return', - 'static', - 'super', - 'switch', - 'this', - 'throw', - 'true', - 'try', - 'typeof', - 'var', - 'void', - 'while', - 'with', - 'yield', -]); - -export default reservedNames; diff --git a/src/utils/sanitize.ts b/src/utils/sanitize.ts deleted file mode 100644 index 04cd9732b4..0000000000 --- a/src/utils/sanitize.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default function sanitize(name) { - return name.replace(/[^a-zA-Z]+/g, '_').replace(/^_/, '').replace(/_$/, ''); -} \ No newline at end of file diff --git a/src/utils/trim.ts b/src/utils/trim.ts index 387b368826..43f413bb1d 100644 --- a/src/utils/trim.ts +++ b/src/utils/trim.ts @@ -1,13 +1,13 @@ import { whitespace } from './patterns'; -export function trimStart(str: string) { +export function trim_start(str: string) { let i = 0; while (whitespace.test(str[i])) i += 1; return str.slice(i); } -export function trimEnd(str: string) { +export function trim_end(str: string) { let i = str.length; while (whitespace.test(str[i - 1])) i -= 1; diff --git a/src/utils/unpackDestructuring.ts b/src/utils/unpackDestructuring.ts deleted file mode 100644 index 749d26b34b..0000000000 --- a/src/utils/unpackDestructuring.ts +++ /dev/null @@ -1,22 +0,0 @@ -export default function unpackDestructuring( - contexts: Array<{ name: string, tail: string }>, - node: Node, - tail: string -) { - if (!node) return; - - if (node.type === 'Identifier') { - contexts.push({ - key: node, - tail - }); - } else if (node.type === 'ArrayPattern') { - node.elements.forEach((element, i) => { - unpackDestructuring(contexts, element, `${tail}[${i}]`); - }); - } else if (node.type === 'ObjectPattern') { - node.properties.forEach((property) => { - unpackDestructuring(contexts, property.value, `${tail}.${property.key.name}`); - }); - } -} \ No newline at end of file diff --git a/test/js/samples/action-custom-event-handler/expected.js b/test/js/samples/action-custom-event-handler/expected.js index f5b3a87c84..8ecabf94be 100644 --- a/test/js/samples/action-custom-event-handler/expected.js +++ b/test/js/samples/action-custom-event-handler/expected.js @@ -1,12 +1,20 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createElement, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var button, foo_action; return { c() { - button = createElement("button"); + button = element("button"); button.textContent = "foo"; }, @@ -19,9 +27,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(button); + d(detaching) { + if (detaching) { + detach(button); } if (foo_action && typeof foo_action.destroy === 'function') foo_action.destroy(); diff --git a/test/js/samples/action/expected.js b/test/js/samples/action/expected.js index 2284061a1b..edc82cc67e 100644 --- a/test/js/samples/action/expected.js +++ b/test/js/samples/action/expected.js @@ -1,12 +1,20 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createElement, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var a, link_action; return { c() { - a = createElement("a"); + a = element("a"); a.textContent = "Test"; a.href = "#"; }, @@ -20,9 +28,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(a); + d(detaching) { + if (detaching) { + detach(a); } if (link_action && typeof link_action.destroy === 'function') link_action.destroy(); diff --git a/test/js/samples/bind-width-height/expected.js b/test/js/samples/bind-width-height/expected.js index f8b17f3de7..45c9e6a835 100644 --- a/test/js/samples/bind-width-height/expected.js +++ b/test/js/samples/bind-width-height/expected.js @@ -1,28 +1,38 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addResizeListener, add_render_callback, createElement, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + add_render_callback, + add_resize_listener, + detach, + element, + init, + insert, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var div, div_resize_listener; return { c() { - div = createElement("div"); + div = element("div"); div.textContent = "some content"; add_render_callback(() => ctx.div_resize_handler.call(div)); }, m(target, anchor) { insert(target, div, anchor); - div_resize_listener = addResizeListener(div, ctx.div_resize_handler.bind(div)); + div_resize_listener = add_resize_listener(div, ctx.div_resize_handler.bind(div)); }, p: noop, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } div_resize_listener.cancel(); diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 5a8971391c..e40997203b 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,40 +1,51 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; function add_css() { - var style = createElement("style"); + var style = element("style"); style.id = 'svelte-1a7i8ec-style'; style.textContent = "p.svelte-1a7i8ec{color:red}"; append(document.head, style); } function create_fragment(ctx) { - var p, text; + var p, t; return { c() { - p = createElement("p"); - text = createText(ctx.foo); + p = element("p"); + t = text(ctx.foo); p.className = "svelte-1a7i8ec"; }, m(target, anchor) { insert(target, p, anchor); - append(p, text); + append(p, t); }, p(changed, ctx) { if (changed.foo) { - setData(text, ctx.foo); + set_data(t, ctx.foo); } }, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(p); + d(detaching) { + if (detaching) { + detach(p); } } }; diff --git a/test/js/samples/component-static-array/expected.js b/test/js/samples/component-static-array/expected.js index 8967fdfa63..5cb7afde75 100644 --- a/test/js/samples/component-static-array/expected.js +++ b/test/js/samples/component-static-array/expected.js @@ -1,5 +1,11 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, init, mount_component, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + init, + mount_component, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var current; @@ -30,8 +36,8 @@ function create_fragment(ctx) { current = false; }, - d(detach) { - nested.$destroy(detach); + d(detaching) { + nested.$destroy(detaching); } }; } diff --git a/test/js/samples/component-static-immutable/expected.js b/test/js/samples/component-static-immutable/expected.js index 2f3bd46416..d0335b6ba0 100644 --- a/test/js/samples/component-static-immutable/expected.js +++ b/test/js/samples/component-static-immutable/expected.js @@ -1,5 +1,11 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, init, mount_component, noop, not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + init, + mount_component, + noop, + not_equal +} from "svelte/internal"; function create_fragment(ctx) { var current; @@ -30,8 +36,8 @@ function create_fragment(ctx) { current = false; }, - d(detach) { - nested.$destroy(detach); + d(detaching) { + nested.$destroy(detaching); } }; } diff --git a/test/js/samples/component-static-immutable2/expected.js b/test/js/samples/component-static-immutable2/expected.js index 2f3bd46416..d0335b6ba0 100644 --- a/test/js/samples/component-static-immutable2/expected.js +++ b/test/js/samples/component-static-immutable2/expected.js @@ -1,5 +1,11 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, init, mount_component, noop, not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + init, + mount_component, + noop, + not_equal +} from "svelte/internal"; function create_fragment(ctx) { var current; @@ -30,8 +36,8 @@ function create_fragment(ctx) { current = false; }, - d(detach) { - nested.$destroy(detach); + d(detaching) { + nested.$destroy(detaching); } }; } diff --git a/test/js/samples/component-static/expected.js b/test/js/samples/component-static/expected.js index 0fe7feb2ca..faad84b26c 100644 --- a/test/js/samples/component-static/expected.js +++ b/test/js/samples/component-static/expected.js @@ -1,5 +1,11 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, init, mount_component, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + init, + mount_component, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var current; @@ -30,8 +36,8 @@ function create_fragment(ctx) { current = false; }, - d(detach) { - nested.$destroy(detach); + d(detaching) { + nested.$destroy(detaching); } }; } diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 855a70e7ae..754d202429 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,5 +1,10 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, init, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + init, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { return { diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index c44218d0fb..25ee94e03f 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,8 +1,17 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createElement, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + insert, + noop, + safe_not_equal +} from "svelte/internal"; function add_css() { - var style = createElement("style"); + var style = element("style"); style.id = 'svelte-1slhpfn-style'; style.textContent = "@media(min-width: 1px){div.svelte-1slhpfn{color:red}}"; append(document.head, style); @@ -13,7 +22,7 @@ function create_fragment(ctx) { return { c() { - div = createElement("div"); + div = element("div"); div.className = "svelte-1slhpfn"; }, @@ -25,9 +34,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } } }; diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 0fbe7a0cd3..2e410e11dd 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,12 +1,20 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteElement, createElement, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteElement, + detach, + element, + init, + insert, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var div; return { c() { - div = createElement("div"); + div = element("div"); div.textContent = "fades in"; this.c = noop; }, @@ -19,9 +27,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } } }; diff --git a/test/js/samples/debug-empty/expected.js b/test/js/samples/debug-empty/expected.js index 9fd782a3c4..f122a7b979 100644 --- a/test/js/samples/debug-empty/expected.js +++ b/test/js/samples/debug-empty/expected.js @@ -1,20 +1,32 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponentDev, addLoc, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponentDev, + add_location, + append, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; const file = undefined; function create_fragment(ctx) { - var h1, text0, text1, text2, text3; + var h1, t0, t1, t2, t3; return { c: function create() { - h1 = createElement("h1"); - text0 = createText("Hello "); - text1 = createText(ctx.name); - text2 = createText("!"); - text3 = createText("\n"); + h1 = element("h1"); + t0 = text("Hello "); + t1 = text(ctx.name); + t2 = text("!"); + t3 = text("\n"); debugger; - addLoc(h1, file, 4, 0, 38); + add_location(h1, file, 4, 0, 38); }, l: function claim(nodes) { @@ -23,15 +35,15 @@ function create_fragment(ctx) { m: function mount(target, anchor) { insert(target, h1, anchor); - append(h1, text0); - append(h1, text1); - append(h1, text2); - insert(target, text3, anchor); + append(h1, t0); + append(h1, t1); + append(h1, t2); + insert(target, t3, anchor); }, p: function update(changed, ctx) { if (changed.name) { - setData(text1, ctx.name); + set_data(t1, ctx.name); } debugger; @@ -40,10 +52,10 @@ function create_fragment(ctx) { i: noop, o: noop, - d: function destroy(detach) { - if (detach) { - detachNode(h1); - detachNode(text3); + d: function destroy(detaching) { + if (detaching) { + detach(h1); + detach(t3); } } }; 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 ad8e0b24ab..b8b134606c 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected.js @@ -1,5 +1,18 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponentDev, addLoc, append, createElement, createText, destroyEach, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponentDev, + add_location, + append, + destroy_each, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; const file = undefined; @@ -11,31 +24,31 @@ function get_each_context(ctx, list, i) { // (8:0) {#each things as thing} function create_each_block(ctx) { - var span, text0_value = ctx.thing.name, text0, text1; + var span, t0_value = ctx.thing.name, t0, t1; return { c: function create() { - span = createElement("span"); - text0 = createText(text0_value); - text1 = createText("\n\t"); + span = element("span"); + t0 = text(t0_value); + t1 = text("\n\t"); { const { foo, bar, baz, thing } = ctx; console.log({ foo, bar, baz, thing }); debugger; } - addLoc(span, file, 8, 1, 116); + add_location(span, file, 8, 1, 116); }, m: function mount(target, anchor) { insert(target, span, anchor); - append(span, text0); - insert(target, text1, anchor); + append(span, t0); + insert(target, t1, anchor); }, p: function update(changed, ctx) { - if ((changed.things) && text0_value !== (text0_value = ctx.thing.name)) { - setData(text0, text0_value); + if ((changed.things) && t0_value !== (t0_value = ctx.thing.name)) { + set_data(t0, t0_value); } if (changed.foo || changed.bar || changed.baz || changed.things) { @@ -45,17 +58,17 @@ function create_each_block(ctx) { } }, - d: function destroy(detach) { - if (detach) { - detachNode(span); - detachNode(text1); + d: function destroy(detaching) { + if (detaching) { + detach(span); + detach(t1); } } }; } function create_fragment(ctx) { - var text0, p, text1, text2; + var t0, p, t1, t2; var each_value = ctx.things; @@ -71,11 +84,11 @@ function create_fragment(ctx) { each_blocks[i].c(); } - text0 = createText("\n\n"); - p = createElement("p"); - text1 = createText("foo: "); - text2 = createText(ctx.foo); - addLoc(p, file, 12, 0, 182); + t0 = text("\n\n"); + p = element("p"); + t1 = text("foo: "); + t2 = text(ctx.foo); + add_location(p, file, 12, 0, 182); }, l: function claim(nodes) { @@ -87,10 +100,10 @@ function create_fragment(ctx) { each_blocks[i].m(target, anchor); } - insert(target, text0, anchor); + insert(target, t0, anchor); insert(target, p, anchor); - append(p, text1); - append(p, text2); + append(p, t1); + append(p, t2); }, p: function update(changed, ctx) { @@ -105,7 +118,7 @@ function create_fragment(ctx) { } else { each_blocks[i] = create_each_block(child_ctx); each_blocks[i].c(); - each_blocks[i].m(text0.parentNode, text0); + each_blocks[i].m(t0.parentNode, t0); } } @@ -116,19 +129,19 @@ function create_fragment(ctx) { } if (changed.foo) { - setData(text2, ctx.foo); + set_data(t2, ctx.foo); } }, i: noop, o: noop, - d: function destroy(detach) { - destroyEach(each_blocks, detach); + d: function destroy(detaching) { + destroy_each(each_blocks, detaching); - if (detach) { - detachNode(text0); - detachNode(p); + if (detaching) { + detach(t0); + detach(p); } } }; diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index a9af1676e2..94f580ed9d 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -1,5 +1,18 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponentDev, addLoc, append, createElement, createText, destroyEach, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponentDev, + add_location, + append, + destroy_each, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; const file = undefined; @@ -11,31 +24,31 @@ function get_each_context(ctx, list, i) { // (6:0) {#each things as thing} function create_each_block(ctx) { - var span, text0_value = ctx.thing.name, text0, text1; + var span, t0_value = ctx.thing.name, t0, t1; return { c: function create() { - span = createElement("span"); - text0 = createText(text0_value); - text1 = createText("\n\t"); + span = element("span"); + t0 = text(t0_value); + t1 = text("\n\t"); { const { foo } = ctx; console.log({ foo }); debugger; } - addLoc(span, file, 6, 1, 82); + add_location(span, file, 6, 1, 82); }, m: function mount(target, anchor) { insert(target, span, anchor); - append(span, text0); - insert(target, text1, anchor); + append(span, t0); + insert(target, t1, anchor); }, p: function update(changed, ctx) { - if ((changed.things) && text0_value !== (text0_value = ctx.thing.name)) { - setData(text0, text0_value); + if ((changed.things) && t0_value !== (t0_value = ctx.thing.name)) { + set_data(t0, t0_value); } if (changed.foo) { @@ -45,17 +58,17 @@ function create_each_block(ctx) { } }, - d: function destroy(detach) { - if (detach) { - detachNode(span); - detachNode(text1); + d: function destroy(detaching) { + if (detaching) { + detach(span); + detach(t1); } } }; } function create_fragment(ctx) { - var text0, p, text1, text2; + var t0, p, t1, t2; var each_value = ctx.things; @@ -71,11 +84,11 @@ function create_fragment(ctx) { each_blocks[i].c(); } - text0 = createText("\n\n"); - p = createElement("p"); - text1 = createText("foo: "); - text2 = createText(ctx.foo); - addLoc(p, file, 10, 0, 131); + t0 = text("\n\n"); + p = element("p"); + t1 = text("foo: "); + t2 = text(ctx.foo); + add_location(p, file, 10, 0, 131); }, l: function claim(nodes) { @@ -87,10 +100,10 @@ function create_fragment(ctx) { each_blocks[i].m(target, anchor); } - insert(target, text0, anchor); + insert(target, t0, anchor); insert(target, p, anchor); - append(p, text1); - append(p, text2); + append(p, t1); + append(p, t2); }, p: function update(changed, ctx) { @@ -105,7 +118,7 @@ function create_fragment(ctx) { } else { each_blocks[i] = create_each_block(child_ctx); each_blocks[i].c(); - each_blocks[i].m(text0.parentNode, text0); + each_blocks[i].m(t0.parentNode, t0); } } @@ -116,19 +129,19 @@ function create_fragment(ctx) { } if (changed.foo) { - setData(text2, ctx.foo); + set_data(t2, ctx.foo); } }, i: noop, o: noop, - d: function destroy(detach) { - destroyEach(each_blocks, detach); + d: function destroy(detaching) { + destroy_each(each_blocks, detaching); - if (detach) { - detachNode(text0); - detachNode(p); + if (detaching) { + detach(t0); + detach(p); } } }; diff --git a/test/js/samples/debug-ssr-foo/expected.js b/test/js/samples/debug-ssr-foo/expected.js index c7edd8bf0a..02bbec5fba 100644 --- a/test/js/samples/debug-ssr-foo/expected.js +++ b/test/js/samples/debug-ssr-foo/expected.js @@ -1,5 +1,10 @@ /* generated by Svelte vX.Y.Z */ -import { create_ssr_component, debug, each, escape } from "svelte/internal"; +import { + create_ssr_component, + debug, + each, + escape +} from "svelte/internal"; const SvelteComponent = create_ssr_component(($$result, $$props, $$bindings, $$slots) => { let { things, foo } = $$props; diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js index 8161f7c661..32bbdb4394 100644 --- a/test/js/samples/deconflict-builtins/expected.js +++ b/test/js/samples/deconflict-builtins/expected.js @@ -1,5 +1,18 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createComment, createElement as createElement_1, createText, destroyEach, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + comment, + destroy_each, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; function get_each_context(ctx, list, i) { const child_ctx = Object.create(ctx); @@ -9,35 +22,35 @@ function get_each_context(ctx, list, i) { // (5:0) {#each createElement as node} function create_each_block(ctx) { - var span, text_value = ctx.node, text; + var span, t_value = ctx.node, t; return { c() { - span = createElement_1("span"); - text = createText(text_value); + span = element("span"); + t = text(t_value); }, m(target, anchor) { insert(target, span, anchor); - append(span, text); + append(span, t); }, p(changed, ctx) { - if ((changed.createElement) && text_value !== (text_value = ctx.node)) { - setData(text, text_value); + if ((changed.createElement) && t_value !== (t_value = ctx.node)) { + set_data(t, t_value); } }, - d(detach) { - if (detach) { - detachNode(span); + d(detaching) { + if (detaching) { + detach(span); } } }; } function create_fragment(ctx) { - var each_anchor; + var each_1_anchor; var each_value = ctx.createElement; @@ -53,7 +66,7 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_anchor = createComment(); + each_1_anchor = comment(); }, m(target, anchor) { @@ -61,7 +74,7 @@ function create_fragment(ctx) { each_blocks[i].m(target, anchor); } - insert(target, each_anchor, anchor); + insert(target, each_1_anchor, anchor); }, p(changed, ctx) { @@ -76,7 +89,7 @@ function create_fragment(ctx) { } else { each_blocks[i] = create_each_block(child_ctx); each_blocks[i].c(); - each_blocks[i].m(each_anchor.parentNode, each_anchor); + each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor); } } @@ -90,11 +103,11 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - destroyEach(each_blocks, detach); + d(detaching) { + destroy_each(each_blocks, detaching); - if (detach) { - detachNode(each_anchor); + if (detaching) { + detach(each_1_anchor); } } }; diff --git a/test/js/samples/deconflict-globals/expected.js b/test/js/samples/deconflict-globals/expected.js index c9754108af..fe941d2b24 100644 --- a/test/js/samples/deconflict-globals/expected.js +++ b/test/js/samples/deconflict-globals/expected.js @@ -1,5 +1,10 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, init, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + init, + noop, + safe_not_equal +} from "svelte/internal"; import { onMount } from "svelte"; function create_fragment(ctx) { 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 b8976fd405..447477bea5 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -1,18 +1,30 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponentDev, addLoc, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponentDev, + add_location, + append, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; const file = undefined; function create_fragment(ctx) { - var p, text0_value = Math.max(0, ctx.foo), text0, text1, text2; + var p, t0_value = Math.max(0, ctx.foo), t0, t1, t2; return { c: function create() { - p = createElement("p"); - text0 = createText(text0_value); - text1 = createText("\n\t"); - text2 = createText(ctx.bar); - addLoc(p, file, 7, 0, 67); + p = element("p"); + t0 = text(t0_value); + t1 = text("\n\t"); + t2 = text(ctx.bar); + add_location(p, file, 7, 0, 67); }, l: function claim(nodes) { @@ -21,27 +33,27 @@ function create_fragment(ctx) { m: function mount(target, anchor) { insert(target, p, anchor); - append(p, text0); - append(p, text1); - append(p, text2); + append(p, t0); + append(p, t1); + append(p, t2); }, p: function update(changed, ctx) { - if ((changed.foo) && text0_value !== (text0_value = Math.max(0, ctx.foo))) { - setData(text0, text0_value); + if ((changed.foo) && t0_value !== (t0_value = Math.max(0, ctx.foo))) { + set_data(t0, t0_value); } if (changed.bar) { - setData(text2, ctx.bar); + set_data(t2, ctx.bar); } }, i: noop, o: noop, - d: function destroy(detach) { - if (detach) { - detachNode(p); + d: function destroy(detaching) { + if (detaching) { + detach(p); } } }; diff --git a/test/js/samples/do-use-dataset/expected.js b/test/js/samples/do-use-dataset/expected.js index fd8aeab7b2..51c5a83f9d 100644 --- a/test/js/samples/do-use-dataset/expected.js +++ b/test/js/samples/do-use-dataset/expected.js @@ -1,21 +1,30 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createElement, createText, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + noop, + safe_not_equal, + text +} from "svelte/internal"; function create_fragment(ctx) { - var div0, text, div1; + var div0, t, div1; return { c() { - div0 = createElement("div"); - text = createText("\n"); - div1 = createElement("div"); + div0 = element("div"); + t = text("\n"); + div1 = element("div"); div0.dataset.foo = "bar"; div1.dataset.foo = ctx.bar; }, m(target, anchor) { insert(target, div0, anchor); - insert(target, text, anchor); + insert(target, t, anchor); insert(target, div1, anchor); }, @@ -28,11 +37,11 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(div0); - detachNode(text); - detachNode(div1); + d(detaching) { + if (detaching) { + detach(div0); + detach(t); + detach(div1); } } }; diff --git a/test/js/samples/dont-invalidate-this/expected.js b/test/js/samples/dont-invalidate-this/expected.js index 573bafd826..2b3cd63514 100644 --- a/test/js/samples/dont-invalidate-this/expected.js +++ b/test/js/samples/dont-invalidate-this/expected.js @@ -1,13 +1,22 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, createElement, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var input, dispose; return { c() { - input = createElement("input"); - dispose = addListener(input, "input", make_uppercase); + input = element("input"); + dispose = listen(input, "input", make_uppercase); }, m(target, anchor) { @@ -18,9 +27,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(input); + d(detaching) { + if (detaching) { + detach(input); } dispose(); diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected.js b/test/js/samples/dont-use-dataset-in-legacy/expected.js index ab0db608ee..700280901f 100644 --- a/test/js/samples/dont-use-dataset-in-legacy/expected.js +++ b/test/js/samples/dont-use-dataset-in-legacy/expected.js @@ -1,38 +1,48 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createElement, createText, detachNode, init, insert, noop, safe_not_equal, setAttribute } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + attr, + detach, + element, + init, + insert, + noop, + safe_not_equal, + text +} from "svelte/internal"; function create_fragment(ctx) { - var div0, text, div1; + var div0, t, div1; return { c() { - div0 = createElement("div"); - text = createText("\n"); - div1 = createElement("div"); - setAttribute(div0, "data-foo", "bar"); - setAttribute(div1, "data-foo", ctx.bar); + div0 = element("div"); + t = text("\n"); + div1 = element("div"); + attr(div0, "data-foo", "bar"); + attr(div1, "data-foo", ctx.bar); }, m(target, anchor) { insert(target, div0, anchor); - insert(target, text, anchor); + insert(target, t, anchor); insert(target, div1, anchor); }, p(changed, ctx) { if (changed.bar) { - setAttribute(div1, "data-foo", ctx.bar); + attr(div1, "data-foo", ctx.bar); } }, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(div0); - detachNode(text); - detachNode(div1); + d(detaching) { + if (detaching) { + detach(div0); + detach(t); + detach(div1); } } }; diff --git a/test/js/samples/dont-use-dataset-in-svg/expected.js b/test/js/samples/dont-use-dataset-in-svg/expected.js index 7648e60313..3f58d7f155 100644 --- a/test/js/samples/dont-use-dataset-in-svg/expected.js +++ b/test/js/samples/dont-use-dataset-in-svg/expected.js @@ -1,16 +1,26 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createSvgElement, detachNode, init, insert, noop, safe_not_equal, setAttribute } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + attr, + detach, + init, + insert, + noop, + safe_not_equal, + svg_element +} from "svelte/internal"; function create_fragment(ctx) { var svg, g0, g1; return { c() { - svg = createSvgElement("svg"); - g0 = createSvgElement("g"); - g1 = createSvgElement("g"); - setAttribute(g0, "data-foo", "bar"); - setAttribute(g1, "data-foo", ctx.bar); + svg = svg_element("svg"); + g0 = svg_element("g"); + g1 = svg_element("g"); + attr(g0, "data-foo", "bar"); + attr(g1, "data-foo", ctx.bar); }, m(target, anchor) { @@ -21,16 +31,16 @@ function create_fragment(ctx) { p(changed, ctx) { if (changed.bar) { - setAttribute(g1, "data-foo", ctx.bar); + attr(g1, "data-foo", ctx.bar); } }, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(svg); + d(detaching) { + if (detaching) { + detach(svg); } } }; diff --git a/test/js/samples/dynamic-import/expected.js b/test/js/samples/dynamic-import/expected.js index 6647619329..85d5ed0cbe 100644 --- a/test/js/samples/dynamic-import/expected.js +++ b/test/js/samples/dynamic-import/expected.js @@ -1,5 +1,11 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, init, mount_component, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + init, + mount_component, + noop, + safe_not_equal +} from "svelte/internal"; import LazyLoad from "./LazyLoad.svelte"; function create_fragment(ctx) { @@ -31,8 +37,8 @@ function create_fragment(ctx) { current = false; }, - d(detach) { - lazyload.$destroy(detach); + d(detaching) { + lazyload.$destroy(detaching); } }; } diff --git a/test/js/samples/each-block-array-literal/expected.js b/test/js/samples/each-block-array-literal/expected.js index 8cc11dff47..be3b4a3b45 100644 --- a/test/js/samples/each-block-array-literal/expected.js +++ b/test/js/samples/each-block-array-literal/expected.js @@ -1,5 +1,18 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createComment, createElement, createText, destroyEach, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + comment, + destroy_each, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; function get_each_context(ctx, list, i) { const child_ctx = Object.create(ctx); @@ -9,35 +22,35 @@ function get_each_context(ctx, list, i) { // (9:0) {#each [a, b, c, d, e] as num} function create_each_block(ctx) { - var span, text_value = ctx.num, text; + var span, t_value = ctx.num, t; return { c() { - span = createElement("span"); - text = createText(text_value); + span = element("span"); + t = text(t_value); }, m(target, anchor) { insert(target, span, anchor); - append(span, text); + append(span, t); }, p(changed, ctx) { - if ((changed.a || changed.b || changed.c || changed.d || changed.e) && text_value !== (text_value = ctx.num)) { - setData(text, text_value); + if ((changed.a || changed.b || changed.c || changed.d || changed.e) && t_value !== (t_value = ctx.num)) { + set_data(t, t_value); } }, - d(detach) { - if (detach) { - detachNode(span); + d(detaching) { + if (detaching) { + detach(span); } } }; } function create_fragment(ctx) { - var each_anchor; + var each_1_anchor; var each_value = [ctx.a, ctx.b, ctx.c, ctx.d, ctx.e]; @@ -53,7 +66,7 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_anchor = createComment(); + each_1_anchor = comment(); }, m(target, anchor) { @@ -61,7 +74,7 @@ function create_fragment(ctx) { each_blocks[i].m(target, anchor); } - insert(target, each_anchor, anchor); + insert(target, each_1_anchor, anchor); }, p(changed, ctx) { @@ -76,7 +89,7 @@ function create_fragment(ctx) { } else { each_blocks[i] = create_each_block(child_ctx); each_blocks[i].c(); - each_blocks[i].m(each_anchor.parentNode, each_anchor); + each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor); } } @@ -89,11 +102,11 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - destroyEach(each_blocks, detach); + d(detaching) { + destroy_each(each_blocks, detaching); - if (detach) { - detachNode(each_anchor); + if (detaching) { + detach(each_1_anchor); } } }; diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index d43771b9a2..89906806bc 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,5 +1,18 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createElement, createText, destroyEach, detachAfter, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + destroy_each, + detach, + detach_after, + element, + init, + insert, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; function get_each_context(ctx, list, i) { const child_ctx = Object.create(ctx); @@ -10,21 +23,21 @@ function get_each_context(ctx, list, i) { // (8:0) {#each comments as comment, i} function create_each_block(ctx) { - var div, strong, text0, text1, span, text2_value = ctx.comment.author, text2, text3, text4_value = ctx.elapsed(ctx.comment.time, ctx.time), text4, text5, text6, raw_value = ctx.comment.html, raw_before; + var div, strong, t0, t1, span, t2_value = ctx.comment.author, t2, t3, t4_value = ctx.elapsed(ctx.comment.time, ctx.time), t4, t5, t6, raw_value = ctx.comment.html, raw_before; return { c() { - div = createElement("div"); - strong = createElement("strong"); - text0 = createText(ctx.i); - text1 = createText("\n\n\t\t"); - span = createElement("span"); - text2 = createText(text2_value); - text3 = createText(" wrote "); - text4 = createText(text4_value); - text5 = createText(" ago:"); - text6 = createText("\n\n\t\t"); - raw_before = createElement('noscript'); + div = element("div"); + strong = element("strong"); + t0 = text(ctx.i); + t1 = text("\n\n\t\t"); + span = element("span"); + t2 = text(t2_value); + t3 = text(" wrote "); + t4 = text(t4_value); + t5 = text(" ago:"); + t6 = text("\n\n\t\t"); + raw_before = element('noscript'); span.className = "meta"; div.className = "comment"; }, @@ -32,43 +45,43 @@ function create_each_block(ctx) { m(target, anchor) { insert(target, div, anchor); append(div, strong); - append(strong, text0); - append(div, text1); + append(strong, t0); + append(div, t1); append(div, span); - append(span, text2); - append(span, text3); - append(span, text4); - append(span, text5); - append(div, text6); + append(span, t2); + append(span, t3); + append(span, t4); + append(span, t5); + append(div, t6); append(div, raw_before); raw_before.insertAdjacentHTML("afterend", raw_value); }, p(changed, ctx) { - if ((changed.comments) && text2_value !== (text2_value = ctx.comment.author)) { - setData(text2, text2_value); + if ((changed.comments) && t2_value !== (t2_value = ctx.comment.author)) { + set_data(t2, t2_value); } - if ((changed.elapsed || changed.comments || changed.time) && text4_value !== (text4_value = ctx.elapsed(ctx.comment.time, ctx.time))) { - setData(text4, text4_value); + if ((changed.elapsed || changed.comments || changed.time) && t4_value !== (t4_value = ctx.elapsed(ctx.comment.time, ctx.time))) { + set_data(t4, t4_value); } if ((changed.comments) && raw_value !== (raw_value = ctx.comment.html)) { - detachAfter(raw_before); + detach_after(raw_before); raw_before.insertAdjacentHTML("afterend", raw_value); } }, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } } }; } function create_fragment(ctx) { - var text0, p, text1; + var t0, p, t1; var each_value = ctx.comments; @@ -84,9 +97,9 @@ function create_fragment(ctx) { each_blocks[i].c(); } - text0 = createText("\n\n"); - p = createElement("p"); - text1 = createText(ctx.foo); + t0 = text("\n\n"); + p = element("p"); + t1 = text(ctx.foo); }, m(target, anchor) { @@ -94,9 +107,9 @@ function create_fragment(ctx) { each_blocks[i].m(target, anchor); } - insert(target, text0, anchor); + insert(target, t0, anchor); insert(target, p, anchor); - append(p, text1); + append(p, t1); }, p(changed, ctx) { @@ -111,7 +124,7 @@ function create_fragment(ctx) { } else { each_blocks[i] = create_each_block(child_ctx); each_blocks[i].c(); - each_blocks[i].m(text0.parentNode, text0); + each_blocks[i].m(t0.parentNode, t0); } } @@ -122,19 +135,19 @@ function create_fragment(ctx) { } if (changed.foo) { - setData(text1, ctx.foo); + set_data(t1, ctx.foo); } }, i: noop, o: noop, - d(detach) { - destroyEach(each_blocks, detach); + d(detaching) { + destroy_each(each_blocks, detaching); - if (detach) { - detachNode(text0); - detachNode(p); + if (detaching) { + detach(t0); + detach(p); } } }; diff --git a/test/js/samples/each-block-keyed-animated/expected.js b/test/js/samples/each-block-keyed-animated/expected.js index cd37a916f6..fd879530ea 100644 --- a/test/js/samples/each-block-keyed-animated/expected.js +++ b/test/js/samples/each-block-keyed-animated/expected.js @@ -1,5 +1,22 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, blankObject, createComment, createElement, createText, create_animation, detachNode, fixAndOutroAndDestroyBlock, fix_position, init, insert, noop, safe_not_equal, setData, updateKeyedEach } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + blank_object, + comment, + create_animation, + detach, + element, + fix_and_outro_and_destroy_block, + fix_position, + init, + insert, + noop, + safe_not_equal, + set_data, + text, + update_keyed_each +} from "svelte/internal"; function get_each_context(ctx, list, i) { const child_ctx = Object.create(ctx); @@ -9,7 +26,7 @@ function get_each_context(ctx, list, i) { // (19:0) {#each things as thing (thing.id)} function create_each_block(key_1, ctx) { - var div, text_value = ctx.thing.name, text, rect, stop_animation = noop; + var div, t_value = ctx.thing.name, t, rect, stop_animation = noop; return { key: key_1, @@ -17,19 +34,19 @@ function create_each_block(key_1, ctx) { first: null, c() { - div = createElement("div"); - text = createText(text_value); + div = element("div"); + t = text(t_value); this.first = div; }, m(target, anchor) { insert(target, div, anchor); - append(div, text); + append(div, t); }, p(changed, ctx) { - if ((changed.things) && text_value !== (text_value = ctx.thing.name)) { - setData(text, text_value); + if ((changed.things) && t_value !== (t_value = ctx.thing.name)) { + set_data(t, t_value); } }, @@ -47,16 +64,16 @@ function create_each_block(key_1, ctx) { stop_animation = create_animation(div, rect, foo, {}); }, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } } }; } function create_fragment(ctx) { - var each_blocks = [], each_lookup = blankObject(), each_anchor; + var each_blocks = [], each_1_lookup = blank_object(), each_1_anchor; var each_value = ctx.things; @@ -65,37 +82,37 @@ function create_fragment(ctx) { for (var i = 0; i < each_value.length; i += 1) { let child_ctx = get_each_context(ctx, each_value, i); let key = get_key(child_ctx); - each_blocks[i] = each_lookup[key] = create_each_block(key, child_ctx); + each_blocks[i] = each_1_lookup[key] = create_each_block(key, child_ctx); } return { c() { for (i = 0; i < each_blocks.length; i += 1) each_blocks[i].c(); - each_anchor = createComment(); + each_1_anchor = comment(); }, m(target, anchor) { for (i = 0; i < each_blocks.length; i += 1) each_blocks[i].m(target, anchor); - insert(target, each_anchor, anchor); + insert(target, each_1_anchor, anchor); }, p(changed, ctx) { const each_value = ctx.things; for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].r(); - each_blocks = updateKeyedEach(each_blocks, changed, get_key, 1, ctx, each_value, each_lookup, each_anchor.parentNode, fixAndOutroAndDestroyBlock, create_each_block, each_anchor, get_each_context); + each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_1_lookup, each_1_anchor.parentNode, fix_and_outro_and_destroy_block, create_each_block, each_1_anchor, get_each_context); for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].a(); }, i: noop, o: noop, - d(detach) { - for (i = 0; i < each_blocks.length; i += 1) each_blocks[i].d(detach); + d(detaching) { + for (i = 0; i < each_blocks.length; i += 1) each_blocks[i].d(detaching); - if (detach) { - detachNode(each_anchor); + if (detaching) { + detach(each_1_anchor); } } }; diff --git a/test/js/samples/each-block-keyed/expected.js b/test/js/samples/each-block-keyed/expected.js index 081391780f..c20a43d4d4 100644 --- a/test/js/samples/each-block-keyed/expected.js +++ b/test/js/samples/each-block-keyed/expected.js @@ -1,5 +1,20 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, blankObject, createComment, createElement, createText, destroyBlock, detachNode, init, insert, noop, safe_not_equal, setData, updateKeyedEach } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + blank_object, + comment, + destroy_block, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_data, + text, + update_keyed_each +} from "svelte/internal"; function get_each_context(ctx, list, i) { const child_ctx = Object.create(ctx); @@ -9,7 +24,7 @@ function get_each_context(ctx, list, i) { // (5:0) {#each things as thing (thing.id)} function create_each_block(key_1, ctx) { - var div, text_value = ctx.thing.name, text; + var div, t_value = ctx.thing.name, t; return { key: key_1, @@ -17,32 +32,32 @@ function create_each_block(key_1, ctx) { first: null, c() { - div = createElement("div"); - text = createText(text_value); + div = element("div"); + t = text(t_value); this.first = div; }, m(target, anchor) { insert(target, div, anchor); - append(div, text); + append(div, t); }, p(changed, ctx) { - if ((changed.things) && text_value !== (text_value = ctx.thing.name)) { - setData(text, text_value); + if ((changed.things) && t_value !== (t_value = ctx.thing.name)) { + set_data(t, t_value); } }, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } } }; } function create_fragment(ctx) { - var each_blocks = [], each_lookup = blankObject(), each_anchor; + var each_blocks = [], each_1_lookup = blank_object(), each_1_anchor; var each_value = ctx.things; @@ -51,35 +66,35 @@ function create_fragment(ctx) { for (var i = 0; i < each_value.length; i += 1) { let child_ctx = get_each_context(ctx, each_value, i); let key = get_key(child_ctx); - each_blocks[i] = each_lookup[key] = create_each_block(key, child_ctx); + each_blocks[i] = each_1_lookup[key] = create_each_block(key, child_ctx); } return { c() { for (i = 0; i < each_blocks.length; i += 1) each_blocks[i].c(); - each_anchor = createComment(); + each_1_anchor = comment(); }, m(target, anchor) { for (i = 0; i < each_blocks.length; i += 1) each_blocks[i].m(target, anchor); - insert(target, each_anchor, anchor); + insert(target, each_1_anchor, anchor); }, p(changed, ctx) { const each_value = ctx.things; - each_blocks = updateKeyedEach(each_blocks, changed, get_key, 1, ctx, each_value, each_lookup, each_anchor.parentNode, destroyBlock, create_each_block, each_anchor, get_each_context); + each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_1_lookup, each_1_anchor.parentNode, destroy_block, create_each_block, each_1_anchor, get_each_context); }, i: noop, o: noop, - d(detach) { - for (i = 0; i < each_blocks.length; i += 1) each_blocks[i].d(detach); + d(detaching) { + for (i = 0; i < each_blocks.length; i += 1) each_blocks[i].d(detaching); - if (detach) { - detachNode(each_anchor); + if (detaching) { + detach(each_1_anchor); } } }; diff --git a/test/js/samples/event-handler-no-passive/expected.js b/test/js/samples/event-handler-no-passive/expected.js index da7882fdff..55e22666c1 100644 --- a/test/js/samples/event-handler-no-passive/expected.js +++ b/test/js/samples/event-handler-no-passive/expected.js @@ -1,15 +1,24 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, createElement, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var a, dispose; return { c() { - a = createElement("a"); + a = element("a"); a.textContent = "this should not navigate to example.com"; a.href = "https://example.com"; - dispose = addListener(a, "touchstart", touchstart_handler); + dispose = listen(a, "touchstart", touchstart_handler); }, m(target, anchor) { @@ -20,9 +29,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(a); + d(detaching) { + if (detaching) { + detach(a); } dispose(); diff --git a/test/js/samples/event-modifiers/expected.js b/test/js/samples/event-modifiers/expected.js index f31ad09238..9d83341f1b 100644 --- a/test/js/samples/event-modifiers/expected.js +++ b/test/js/samples/event-modifiers/expected.js @@ -1,34 +1,48 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, append, createElement, createText, detachNode, init, insert, noop, preventDefault, run_all, safe_not_equal, stopPropagation } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + insert, + listen, + noop, + prevent_default, + run_all, + safe_not_equal, + stop_propagation, + text +} from "svelte/internal"; function create_fragment(ctx) { - var div, button0, text1, button1, text3, button2, dispose; + var div, button0, t1, button1, t3, button2, dispose; return { c() { - div = createElement("div"); - button0 = createElement("button"); + div = element("div"); + button0 = element("button"); button0.textContent = "click me"; - text1 = createText("\n\t"); - button1 = createElement("button"); + t1 = text("\n\t"); + button1 = element("button"); button1.textContent = "or me"; - text3 = createText("\n\t"); - button2 = createElement("button"); + t3 = text("\n\t"); + button2 = element("button"); button2.textContent = "or me!"; dispose = [ - addListener(button0, "click", stopPropagation(preventDefault(handleClick))), - addListener(button1, "click", handleClick, { once: true, capture: true }), - addListener(button2, "click", handleClick, true), - addListener(div, "touchstart", handleTouchstart, { passive: true }) + listen(button0, "click", stop_propagation(prevent_default(handleClick))), + listen(button1, "click", handleClick, { once: true, capture: true }), + listen(button2, "click", handleClick, true), + listen(div, "touchstart", handleTouchstart, { passive: true }) ]; }, m(target, anchor) { insert(target, div, anchor); append(div, button0); - append(div, text1); + append(div, t1); append(div, button1); - append(div, text3); + append(div, t3); append(div, button2); }, @@ -36,9 +50,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } run_all(dispose); diff --git a/test/js/samples/head-no-whitespace/expected.js b/test/js/samples/head-no-whitespace/expected.js index 136be77b59..552281ba66 100644 --- a/test/js/samples/head-no-whitespace/expected.js +++ b/test/js/samples/head-no-whitespace/expected.js @@ -1,13 +1,21 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createElement, detachNode, init, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var meta0, meta1; return { c() { - meta0 = createElement("meta"); - meta1 = createElement("meta"); + meta0 = element("meta"); + meta1 = element("meta"); meta0.name = "twitter:creator"; meta0.content = "@sveltejs"; meta1.name = "twitter:title"; @@ -23,9 +31,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - detachNode(meta0); - detachNode(meta1); + d(detaching) { + detach(meta0); + detach(meta1); } }; } diff --git a/test/js/samples/hoisted-const/expected.js b/test/js/samples/hoisted-const/expected.js index 26169b25fe..8f061bf80b 100644 --- a/test/js/samples/hoisted-const/expected.js +++ b/test/js/samples/hoisted-const/expected.js @@ -1,27 +1,37 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + insert, + noop, + safe_not_equal, + text +} from "svelte/internal"; function create_fragment(ctx) { - var b, text_value = get_answer(), text; + var b, t_value = get_answer(), t; return { c() { - b = createElement("b"); - text = createText(text_value); + b = element("b"); + t = text(t_value); }, m(target, anchor) { insert(target, b, anchor); - append(b, text); + append(b, t); }, p: noop, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(b); + d(detaching) { + if (detaching) { + detach(b); } } }; diff --git a/test/js/samples/hoisted-let/expected.js b/test/js/samples/hoisted-let/expected.js index 409e5b1b45..52390c1e26 100644 --- a/test/js/samples/hoisted-let/expected.js +++ b/test/js/samples/hoisted-let/expected.js @@ -1,27 +1,37 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + insert, + noop, + safe_not_equal, + text +} from "svelte/internal"; function create_fragment(ctx) { - var b, text_value = get_answer(), text; + var b, t_value = get_answer(), t; return { c() { - b = createElement("b"); - text = createText(text_value); + b = element("b"); + t = text(t_value); }, m(target, anchor) { insert(target, b, anchor); - append(b, text); + append(b, t); }, p: noop, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(b); + d(detaching) { + if (detaching) { + detach(b); } } }; diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index b161285ffb..11fbf604b1 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,5 +1,14 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createComment, createElement, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + comment, + detach, + element, + init, + insert, + noop, + safe_not_equal +} from "svelte/internal"; // (7:0) {:else} function create_else_block(ctx) { @@ -7,7 +16,7 @@ function create_else_block(ctx) { return { c() { - p = createElement("p"); + p = element("p"); p.textContent = "not foo!"; }, @@ -15,9 +24,9 @@ function create_else_block(ctx) { insert(target, p, anchor); }, - d(detach) { - if (detach) { - detachNode(p); + d(detaching) { + if (detaching) { + detach(p); } } }; @@ -29,7 +38,7 @@ function create_if_block(ctx) { return { c() { - p = createElement("p"); + p = element("p"); p.textContent = "foo!"; }, @@ -37,9 +46,9 @@ function create_if_block(ctx) { insert(target, p, anchor); }, - d(detach) { - if (detach) { - detachNode(p); + d(detaching) { + if (detaching) { + detach(p); } } }; @@ -59,7 +68,7 @@ function create_fragment(ctx) { return { c() { if_block.c(); - if_block_anchor = createComment(); + if_block_anchor = comment(); }, m(target, anchor) { @@ -81,11 +90,11 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if_block.d(detach); + d(detaching) { + if_block.d(detaching); - if (detach) { - detachNode(if_block_anchor); + if (detaching) { + detach(if_block_anchor); } } }; diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index db5fe0c42c..af8d45974f 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,5 +1,14 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createComment, createElement, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + comment, + detach, + element, + init, + insert, + noop, + safe_not_equal +} from "svelte/internal"; // (5:0) {#if foo} function create_if_block(ctx) { @@ -7,7 +16,7 @@ function create_if_block(ctx) { return { c() { - p = createElement("p"); + p = element("p"); p.textContent = "foo!"; }, @@ -15,9 +24,9 @@ function create_if_block(ctx) { insert(target, p, anchor); }, - d(detach) { - if (detach) { - detachNode(p); + d(detaching) { + if (detaching) { + detach(p); } } }; @@ -31,7 +40,7 @@ function create_fragment(ctx) { return { c() { if (if_block) if_block.c(); - if_block_anchor = createComment(); + if_block_anchor = comment(); }, m(target, anchor) { @@ -55,11 +64,11 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (if_block) if_block.d(detach); + d(detaching) { + if (if_block) if_block.d(detaching); - if (detach) { - detachNode(if_block_anchor); + if (detaching) { + detach(if_block_anchor); } } }; diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index 4b2c59672a..9766ca3738 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,14 +1,23 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createElement, detachNode, init, insert, noop, safe_not_equal, setStyle } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_style +} from "svelte/internal"; function create_fragment(ctx) { var div; return { c() { - div = createElement("div"); - setStyle(div, "color", ctx.color); - setStyle(div, "transform", "translate(" + ctx.x + "px," + ctx.y + "px)"); + div = element("div"); + set_style(div, "color", ctx.color); + set_style(div, "transform", "translate(" + ctx.x + "px," + ctx.y + "px)"); }, m(target, anchor) { @@ -17,20 +26,20 @@ function create_fragment(ctx) { p(changed, ctx) { if (changed.color) { - setStyle(div, "color", ctx.color); + set_style(div, "color", ctx.color); } if (changed.x || changed.y) { - setStyle(div, "transform", "translate(" + ctx.x + "px," + ctx.y + "px)"); + set_style(div, "transform", "translate(" + ctx.x + "px," + ctx.y + "px)"); } }, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } } }; diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index dd64e40950..ffa679c429 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,13 +1,22 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createElement, detachNode, init, insert, noop, safe_not_equal, setStyle } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_style +} from "svelte/internal"; function create_fragment(ctx) { var div; return { c() { - div = createElement("div"); - setStyle(div, "background", "url(data:image/png;base64," + ctx.data + ")"); + div = element("div"); + set_style(div, "background", "url(data:image/png;base64," + ctx.data + ")"); }, m(target, anchor) { @@ -16,16 +25,16 @@ function create_fragment(ctx) { p(changed, ctx) { if (changed.data) { - setStyle(div, "background", "url(data:image/png;base64," + ctx.data + ")"); + set_style(div, "background", "url(data:image/png;base64," + ctx.data + ")"); } }, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } } }; diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index 3948bc5fb0..0b97d34d56 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,13 +1,22 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createElement, detachNode, init, insert, noop, safe_not_equal, setStyle } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_style +} from "svelte/internal"; function create_fragment(ctx) { var div; return { c() { - div = createElement("div"); - setStyle(div, "color", ctx.color); + div = element("div"); + set_style(div, "color", ctx.color); }, m(target, anchor) { @@ -16,16 +25,16 @@ function create_fragment(ctx) { p(changed, ctx) { if (changed.color) { - setStyle(div, "color", ctx.color); + set_style(div, "color", ctx.color); } }, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } } }; diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index b9379a6838..0516cc3ef1 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -1,21 +1,30 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createElement, createText, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + noop, + safe_not_equal, + text +} from "svelte/internal"; function create_fragment(ctx) { - var div0, text, div1, div1_style_value; + var div0, t, div1, div1_style_value; return { c() { - div0 = createElement("div"); - text = createText("\n"); - div1 = createElement("div"); + div0 = element("div"); + t = text("\n"); + div1 = element("div"); div0.style.cssText = ctx.style; div1.style.cssText = div1_style_value = "" + ctx.key + ": " + ctx.value; }, m(target, anchor) { insert(target, div0, anchor); - insert(target, text, anchor); + insert(target, t, anchor); insert(target, div1, anchor); }, @@ -32,11 +41,11 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(div0); - detachNode(text); - detachNode(div1); + d(detaching) { + if (detaching) { + detach(div0); + detach(t); + detach(div1); } } }; diff --git a/test/js/samples/input-files/expected.js b/test/js/samples/input-files/expected.js index 697364106b..dad2af168c 100644 --- a/test/js/samples/input-files/expected.js +++ b/test/js/samples/input-files/expected.js @@ -1,15 +1,25 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, createElement, detachNode, init, insert, noop, safe_not_equal, setAttribute } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + attr, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var input, dispose; return { c() { - input = createElement("input"); - setAttribute(input, "type", "file"); + input = element("input"); + attr(input, "type", "file"); input.multiple = true; - dispose = addListener(input, "input", ctx.input_input_handler); + dispose = listen(input, "input", ctx.input_input_handler); }, m(target, anchor) { @@ -20,9 +30,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(input); + d(detaching) { + if (detaching) { + detach(input); } dispose(); diff --git a/test/js/samples/input-range/expected.js b/test/js/samples/input-range/expected.js index fff193f8e5..c57ef4f73b 100644 --- a/test/js/samples/input-range/expected.js +++ b/test/js/samples/input-range/expected.js @@ -1,17 +1,29 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, createElement, detachNode, init, insert, noop, run_all, safe_not_equal, setAttribute, toNumber } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + attr, + detach, + element, + init, + insert, + listen, + noop, + run_all, + safe_not_equal, + to_number +} from "svelte/internal"; function create_fragment(ctx) { var input, dispose; return { c() { - input = createElement("input"); - setAttribute(input, "type", "range"); + input = element("input"); + attr(input, "type", "range"); dispose = [ - addListener(input, "change", ctx.input_change_input_handler), - addListener(input, "input", ctx.input_change_input_handler) + listen(input, "change", ctx.input_change_input_handler), + listen(input, "input", ctx.input_change_input_handler) ]; }, @@ -28,9 +40,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(input); + d(detaching) { + if (detaching) { + detach(input); } run_all(dispose); @@ -42,7 +54,7 @@ function instance($$self, $$props, $$invalidate) { let { value } = $$props; function input_change_input_handler() { - value = toNumber(this.value); + value = to_number(this.value); $$invalidate('value', value); } diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index e97e4d1b0d..d47753396f 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -1,14 +1,24 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, createElement, detachNode, init, insert, noop, safe_not_equal, setAttribute } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + attr, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var input, dispose; return { c() { - input = createElement("input"); - setAttribute(input, "type", "checkbox"); - dispose = addListener(input, "change", ctx.input_change_handler); + input = element("input"); + attr(input, "type", "checkbox"); + dispose = listen(input, "change", ctx.input_change_handler); }, m(target, anchor) { @@ -24,9 +34,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(input); + d(detaching) { + if (detaching) { + detach(input); } dispose(); diff --git a/test/js/samples/instrumentation-script-if-no-block/expected.js b/test/js/samples/instrumentation-script-if-no-block/expected.js index 4f7153e19e..bb6e3f8ef5 100644 --- a/test/js/samples/instrumentation-script-if-no-block/expected.js +++ b/test/js/samples/instrumentation-script-if-no-block/expected.js @@ -1,42 +1,54 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; function create_fragment(ctx) { - var button, text1, p, text2, text3, dispose; + var button, t1, p, t2, t3, dispose; return { c() { - button = createElement("button"); + button = element("button"); button.textContent = "foo"; - text1 = createText("\n\n"); - p = createElement("p"); - text2 = createText("x: "); - text3 = createText(ctx.x); - dispose = addListener(button, "click", ctx.foo); + t1 = text("\n\n"); + p = element("p"); + t2 = text("x: "); + t3 = text(ctx.x); + dispose = listen(button, "click", ctx.foo); }, m(target, anchor) { insert(target, button, anchor); - insert(target, text1, anchor); + insert(target, t1, anchor); insert(target, p, anchor); - append(p, text2); - append(p, text3); + append(p, t2); + append(p, t3); }, p(changed, ctx) { if (changed.x) { - setData(text3, ctx.x); + set_data(t3, ctx.x); } }, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(button); - detachNode(text1); - detachNode(p); + d(detaching) { + if (detaching) { + detach(button); + detach(t1); + detach(p); } dispose(); diff --git a/test/js/samples/instrumentation-script-x-equals-x/expected.js b/test/js/samples/instrumentation-script-x-equals-x/expected.js index 408e11279f..015dd39415 100644 --- a/test/js/samples/instrumentation-script-x-equals-x/expected.js +++ b/test/js/samples/instrumentation-script-x-equals-x/expected.js @@ -1,42 +1,54 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; function create_fragment(ctx) { - var button, text1, p, text2, text3_value = ctx.things.length, text3, dispose; + var button, t1, p, t2, t3_value = ctx.things.length, t3, dispose; return { c() { - button = createElement("button"); + button = element("button"); button.textContent = "foo"; - text1 = createText("\n\n"); - p = createElement("p"); - text2 = createText("number of things: "); - text3 = createText(text3_value); - dispose = addListener(button, "click", ctx.foo); + t1 = text("\n\n"); + p = element("p"); + t2 = text("number of things: "); + t3 = text(t3_value); + dispose = listen(button, "click", ctx.foo); }, m(target, anchor) { insert(target, button, anchor); - insert(target, text1, anchor); + insert(target, t1, anchor); insert(target, p, anchor); - append(p, text2); - append(p, text3); + append(p, t2); + append(p, t3); }, p(changed, ctx) { - if ((changed.things) && text3_value !== (text3_value = ctx.things.length)) { - setData(text3, text3_value); + if ((changed.things) && t3_value !== (t3_value = ctx.things.length)) { + set_data(t3, t3_value); } }, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(button); - detachNode(text1); - detachNode(p); + d(detaching) { + if (detaching) { + detach(button); + detach(t1); + detach(p); } dispose(); diff --git a/test/js/samples/instrumentation-template-if-no-block/expected.js b/test/js/samples/instrumentation-template-if-no-block/expected.js index 29a764a8d5..fc50a8b850 100644 --- a/test/js/samples/instrumentation-template-if-no-block/expected.js +++ b/test/js/samples/instrumentation-template-if-no-block/expected.js @@ -1,42 +1,54 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; function create_fragment(ctx) { - var button, text1, p, text2, text3, dispose; + var button, t1, p, t2, t3, dispose; return { c() { - button = createElement("button"); + button = element("button"); button.textContent = "foo"; - text1 = createText("\n\n"); - p = createElement("p"); - text2 = createText("x: "); - text3 = createText(ctx.x); - dispose = addListener(button, "click", ctx.click_handler); + t1 = text("\n\n"); + p = element("p"); + t2 = text("x: "); + t3 = text(ctx.x); + dispose = listen(button, "click", ctx.click_handler); }, m(target, anchor) { insert(target, button, anchor); - insert(target, text1, anchor); + insert(target, t1, anchor); insert(target, p, anchor); - append(p, text2); - append(p, text3); + append(p, t2); + append(p, t3); }, p(changed, ctx) { if (changed.x) { - setData(text3, ctx.x); + set_data(t3, ctx.x); } }, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(button); - detachNode(text1); - detachNode(p); + d(detaching) { + if (detaching) { + detach(button); + detach(t1); + detach(p); } dispose(); diff --git a/test/js/samples/instrumentation-template-x-equals-x/expected.js b/test/js/samples/instrumentation-template-x-equals-x/expected.js index 909c4bfef6..14a7e61274 100644 --- a/test/js/samples/instrumentation-template-x-equals-x/expected.js +++ b/test/js/samples/instrumentation-template-x-equals-x/expected.js @@ -1,42 +1,54 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; function create_fragment(ctx) { - var button, text1, p, text2, text3_value = ctx.things.length, text3, dispose; + var button, t1, p, t2, t3_value = ctx.things.length, t3, dispose; return { c() { - button = createElement("button"); + button = element("button"); button.textContent = "foo"; - text1 = createText("\n\n"); - p = createElement("p"); - text2 = createText("number of things: "); - text3 = createText(text3_value); - dispose = addListener(button, "click", ctx.click_handler); + t1 = text("\n\n"); + p = element("p"); + t2 = text("number of things: "); + t3 = text(t3_value); + dispose = listen(button, "click", ctx.click_handler); }, m(target, anchor) { insert(target, button, anchor); - insert(target, text1, anchor); + insert(target, t1, anchor); insert(target, p, anchor); - append(p, text2); - append(p, text3); + append(p, t2); + append(p, t3); }, p(changed, ctx) { - if ((changed.things) && text3_value !== (text3_value = ctx.things.length)) { - setData(text3, text3_value); + if ((changed.things) && t3_value !== (t3_value = ctx.things.length)) { + set_data(t3, t3_value); } }, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(button); - detachNode(text1); - detachNode(p); + d(detaching) { + if (detaching) { + detach(button); + detach(t1); + detach(p); } dispose(); diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index bc1d1f0155..1b3b32f6ce 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -1,13 +1,22 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createElement, detachNode, init, insert, noop, safe_not_equal, setInputType } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_input_type +} from "svelte/internal"; function create_fragment(ctx) { var input; return { c() { - input = createElement("input"); - setInputType(input, "search"); + input = element("input"); + set_input_type(input, "search"); }, m(target, anchor) { @@ -18,9 +27,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(input); + d(detaching) { + if (detaching) { + detach(input); } } }; diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index 97b6dbc82c..a2b64d7a49 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -1,5 +1,17 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, add_render_callback, createElement, detachNode, init, insert, noop, run_all, safe_not_equal, timeRangesToArray } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + add_render_callback, + detach, + element, + init, + insert, + listen, + noop, + run_all, + safe_not_equal, + time_ranges_to_array +} from "svelte/internal"; function create_fragment(ctx) { var audio, audio_updating = false, audio_animationframe, audio_is_paused = true, dispose; @@ -13,20 +25,20 @@ function create_fragment(ctx) { return { c() { - audio = createElement("audio"); + audio = element("audio"); if (ctx.played === void 0 || ctx.currentTime === void 0) add_render_callback(audio_timeupdate_handler); if (ctx.duration === void 0) add_render_callback(() => ctx.audio_durationchange_handler.call(audio)); if (ctx.buffered === void 0) add_render_callback(() => ctx.audio_progress_handler.call(audio)); if (ctx.buffered === void 0 || ctx.seekable === void 0) add_render_callback(() => ctx.audio_loadedmetadata_handler.call(audio)); dispose = [ - addListener(audio, "timeupdate", audio_timeupdate_handler), - addListener(audio, "durationchange", ctx.audio_durationchange_handler), - addListener(audio, "play", ctx.audio_play_pause_handler), - addListener(audio, "pause", ctx.audio_play_pause_handler), - addListener(audio, "progress", ctx.audio_progress_handler), - addListener(audio, "loadedmetadata", ctx.audio_loadedmetadata_handler), - addListener(audio, "volumechange", ctx.audio_volumechange_handler) + listen(audio, "timeupdate", audio_timeupdate_handler), + listen(audio, "durationchange", ctx.audio_durationchange_handler), + listen(audio, "play", ctx.audio_play_pause_handler), + listen(audio, "pause", ctx.audio_play_pause_handler), + listen(audio, "progress", ctx.audio_progress_handler), + listen(audio, "loadedmetadata", ctx.audio_loadedmetadata_handler), + listen(audio, "volumechange", ctx.audio_volumechange_handler) ]; }, @@ -46,9 +58,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(audio); + d(detaching) { + if (detaching) { + detach(audio); } run_all(dispose); @@ -60,7 +72,7 @@ function instance($$self, $$props, $$invalidate) { let { buffered, seekable, played, currentTime, duration, paused, volume } = $$props; function audio_timeupdate_handler() { - played = timeRangesToArray(this.played); + played = time_ranges_to_array(this.played); currentTime = this.currentTime; $$invalidate('played', played); $$invalidate('currentTime', currentTime); @@ -77,13 +89,13 @@ function instance($$self, $$props, $$invalidate) { } function audio_progress_handler() { - buffered = timeRangesToArray(this.buffered); + buffered = time_ranges_to_array(this.buffered); $$invalidate('buffered', buffered); } function audio_loadedmetadata_handler() { - buffered = timeRangesToArray(this.buffered); - seekable = timeRangesToArray(this.seekable); + buffered = time_ranges_to_array(this.buffered); + seekable = time_ranges_to_array(this.seekable); $$invalidate('buffered', buffered); $$invalidate('seekable', seekable); } diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index 6dcc5e6777..ccde3230d3 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -1,9 +1,18 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createText, detachNode, init, insert, mount_component, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + init, + insert, + mount_component, + noop, + safe_not_equal, + text +} from "svelte/internal"; import Imported from "Imported.svelte"; function create_fragment(ctx) { - var text, current; + var t, current; var imported = new Imported({}); @@ -12,13 +21,13 @@ function create_fragment(ctx) { return { c() { imported.$$.fragment.c(); - text = createText("\n"); + t = text("\n"); nonimported.$$.fragment.c(); }, m(target, anchor) { mount_component(imported, target, anchor); - insert(target, text, anchor); + insert(target, t, anchor); mount_component(nonimported, target, anchor); current = true; }, @@ -40,14 +49,14 @@ function create_fragment(ctx) { current = false; }, - d(detach) { - imported.$destroy(detach); + d(detaching) { + imported.$destroy(detaching); - if (detach) { - detachNode(text); + if (detaching) { + detach(t); } - nonimported.$destroy(detach); + nonimported.$destroy(detaching); } }; } diff --git a/test/js/samples/non-mutable-reference/expected.js b/test/js/samples/non-mutable-reference/expected.js index 7d28dfab80..1bad71a937 100644 --- a/test/js/samples/non-mutable-reference/expected.js +++ b/test/js/samples/non-mutable-reference/expected.js @@ -1,31 +1,41 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + insert, + noop, + safe_not_equal, + text +} from "svelte/internal"; function create_fragment(ctx) { - var h1, text0, text1, text2; + var h1, t0, t1, t2; return { c() { - h1 = createElement("h1"); - text0 = createText("Hello "); - text1 = createText(name); - text2 = createText("!"); + h1 = element("h1"); + t0 = text("Hello "); + t1 = text(name); + t2 = text("!"); }, m(target, anchor) { insert(target, h1, anchor); - append(h1, text0); - append(h1, text1); - append(h1, text2); + append(h1, t0); + append(h1, t1); + append(h1, t2); }, p: noop, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(h1); + d(detaching) { + if (detaching) { + detach(h1); } } }; diff --git a/test/js/samples/reactive-values-non-topologically-ordered/expected.js b/test/js/samples/reactive-values-non-topologically-ordered/expected.js index 1145cf9b7e..bac07ebc7c 100644 --- a/test/js/samples/reactive-values-non-topologically-ordered/expected.js +++ b/test/js/samples/reactive-values-non-topologically-ordered/expected.js @@ -1,5 +1,10 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, init, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + init, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { return { diff --git a/test/js/samples/reactive-values-non-writable-dependencies/expected.js b/test/js/samples/reactive-values-non-writable-dependencies/expected.js index 76af68e6a8..b9aabdf76e 100644 --- a/test/js/samples/reactive-values-non-writable-dependencies/expected.js +++ b/test/js/samples/reactive-values-non-writable-dependencies/expected.js @@ -1,5 +1,10 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, init, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + init, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { return { diff --git a/test/js/samples/select-dynamic-value/expected.js b/test/js/samples/select-dynamic-value/expected.js index 8e875e3dd0..82698aafdc 100644 --- a/test/js/samples/select-dynamic-value/expected.js +++ b/test/js/samples/select-dynamic-value/expected.js @@ -1,15 +1,24 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createElement, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + element, + init, + insert, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var select, option0, option1, select_value_value; return { c() { - select = createElement("select"); - option0 = createElement("option"); + select = element("select"); + option0 = element("option"); option0.textContent = "1"; - option1 = createElement("option"); + option1 = element("option"); option1.textContent = "2"; option0.__value = "1"; option0.value = option0.__value; @@ -49,9 +58,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(select); + d(detaching) { + if (detaching) { + detach(select); } } }; diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 3cb71af431..dbde1c9039 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,5 +1,10 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, init, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + init, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { return { diff --git a/test/js/samples/svg-title/expected.js b/test/js/samples/svg-title/expected.js index 5d4bc61ee8..49bd406987 100644 --- a/test/js/samples/svg-title/expected.js +++ b/test/js/samples/svg-title/expected.js @@ -1,29 +1,39 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createSvgElement, createText, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + detach, + init, + insert, + noop, + safe_not_equal, + svg_element, + text +} from "svelte/internal"; function create_fragment(ctx) { - var svg, title, text; + var svg, title, t; return { c() { - svg = createSvgElement("svg"); - title = createSvgElement("title"); - text = createText("a title"); + svg = svg_element("svg"); + title = svg_element("title"); + t = text("a title"); }, m(target, anchor) { insert(target, svg, anchor); append(svg, title); - append(title, text); + append(title, t); }, p: noop, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(svg); + d(detaching) { + if (detaching) { + detach(svg); } } }; diff --git a/test/js/samples/title/expected.js b/test/js/samples/title/expected.js index c9be2e6039..076582ac6f 100644 --- a/test/js/samples/title/expected.js +++ b/test/js/samples/title/expected.js @@ -1,5 +1,10 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, init, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + init, + noop, + safe_not_equal +} from "svelte/internal"; function create_fragment(ctx) { var title_value; diff --git a/test/js/samples/transition-local/expected.js b/test/js/samples/transition-local/expected.js index c24e680820..b98d2a4520 100644 --- a/test/js/samples/transition-local/expected.js +++ b/test/js/samples/transition-local/expected.js @@ -1,5 +1,16 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, add_render_callback, createComment, createElement, create_in_transition, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + add_render_callback, + comment, + create_in_transition, + detach, + element, + init, + insert, + noop, + safe_not_equal +} from "svelte/internal"; // (8:0) {#if x} function create_if_block(ctx) { @@ -10,7 +21,7 @@ function create_if_block(ctx) { return { c() { if (if_block) if_block.c(); - if_block_anchor = createComment(); + if_block_anchor = comment(); }, m(target, anchor) { @@ -34,11 +45,11 @@ function create_if_block(ctx) { } }, - d(detach) { - if (if_block) if_block.d(detach); + d(detaching) { + if (if_block) if_block.d(detaching); - if (detach) { - detachNode(if_block_anchor); + if (detaching) { + detach(if_block_anchor); } } }; @@ -50,7 +61,7 @@ function create_if_block_1(ctx) { return { c() { - div = createElement("div"); + div = element("div"); div.textContent = "..."; }, @@ -71,9 +82,9 @@ function create_if_block_1(ctx) { o: noop, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } } }; @@ -87,7 +98,7 @@ function create_fragment(ctx) { return { c() { if (if_block) if_block.c(); - if_block_anchor = createComment(); + if_block_anchor = comment(); }, m(target, anchor) { @@ -113,11 +124,11 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (if_block) if_block.d(detach); + d(detaching) { + if (if_block) if_block.d(detaching); - if (detach) { - detachNode(if_block_anchor); + if (detaching) { + detach(if_block_anchor); } } }; diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 2c46938496..4a7d84bf01 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,5 +1,16 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createComment, createElement, createText, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + append, + comment, + detach, + element, + init, + insert, + noop, + safe_not_equal, + text +} from "svelte/internal"; // (10:1) {#if a} function create_if_block_4(ctx) { @@ -7,7 +18,7 @@ function create_if_block_4(ctx) { return { c() { - p = createElement("p"); + p = element("p"); p.textContent = "a"; }, @@ -15,9 +26,9 @@ function create_if_block_4(ctx) { insert(target, p, anchor); }, - d(detach) { - if (detach) { - detachNode(p); + d(detaching) { + if (detaching) { + detach(p); } } }; @@ -29,7 +40,7 @@ function create_if_block_3(ctx) { return { c() { - p = createElement("p"); + p = element("p"); p.textContent = "b"; }, @@ -37,9 +48,9 @@ function create_if_block_3(ctx) { insert(target, p, anchor); }, - d(detach) { - if (detach) { - detachNode(p); + d(detaching) { + if (detaching) { + detach(p); } } }; @@ -51,7 +62,7 @@ function create_if_block_2(ctx) { return { c() { - p = createElement("p"); + p = element("p"); p.textContent = "c"; }, @@ -59,9 +70,9 @@ function create_if_block_2(ctx) { insert(target, p, anchor); }, - d(detach) { - if (detach) { - detachNode(p); + d(detaching) { + if (detaching) { + detach(p); } } }; @@ -73,7 +84,7 @@ function create_if_block_1(ctx) { return { c() { - p = createElement("p"); + p = element("p"); p.textContent = "d"; }, @@ -81,9 +92,9 @@ function create_if_block_1(ctx) { insert(target, p, anchor); }, - d(detach) { - if (detach) { - detachNode(p); + d(detaching) { + if (detaching) { + detach(p); } } }; @@ -95,7 +106,7 @@ function create_if_block(ctx) { return { c() { - p = createElement("p"); + p = element("p"); p.textContent = "e"; }, @@ -103,16 +114,16 @@ function create_if_block(ctx) { insert(target, p, anchor); }, - d(detach) { - if (detach) { - detachNode(p); + d(detaching) { + if (detaching) { + detach(p); } } }; } function create_fragment(ctx) { - var div, text0, p0, text2, text3, text4, p1, text6, text7, if_block4_anchor; + var div, t0, p0, t2, t3, t4, p1, t6, t7, if_block4_anchor; var if_block0 = (ctx.a) && create_if_block_4(ctx); @@ -126,39 +137,39 @@ function create_fragment(ctx) { return { c() { - div = createElement("div"); + div = element("div"); if (if_block0) if_block0.c(); - text0 = createText("\n\n\t"); - p0 = createElement("p"); + t0 = text("\n\n\t"); + p0 = element("p"); p0.textContent = "this can be used as an anchor"; - text2 = createText("\n\n\t"); + t2 = text("\n\n\t"); if (if_block1) if_block1.c(); - text3 = createText("\n\n\t"); + t3 = text("\n\n\t"); if (if_block2) if_block2.c(); - text4 = createText("\n\n\t"); - p1 = createElement("p"); + t4 = text("\n\n\t"); + p1 = element("p"); p1.textContent = "so can this"; - text6 = createText("\n\n\t"); + t6 = text("\n\n\t"); if (if_block3) if_block3.c(); - text7 = createText("\n\n"); + t7 = text("\n\n"); if (if_block4) if_block4.c(); - if_block4_anchor = createComment(); + if_block4_anchor = comment(); }, m(target, anchor) { insert(target, div, anchor); if (if_block0) if_block0.m(div, null); - append(div, text0); + append(div, t0); append(div, p0); - append(div, text2); + append(div, t2); if (if_block1) if_block1.m(div, null); - append(div, text3); + append(div, t3); if (if_block2) if_block2.m(div, null); - append(div, text4); + append(div, t4); append(div, p1); - append(div, text6); + append(div, t6); if (if_block3) if_block3.m(div, null); - insert(target, text7, anchor); + insert(target, t7, anchor); if (if_block4) if_block4.m(target, anchor); insert(target, if_block4_anchor, anchor); }, @@ -168,7 +179,7 @@ function create_fragment(ctx) { if (!if_block0) { if_block0 = create_if_block_4(ctx); if_block0.c(); - if_block0.m(div, text0); + if_block0.m(div, t0); } } else if (if_block0) { if_block0.d(1); @@ -179,7 +190,7 @@ function create_fragment(ctx) { if (!if_block1) { if_block1 = create_if_block_3(ctx); if_block1.c(); - if_block1.m(div, text3); + if_block1.m(div, t3); } } else if (if_block1) { if_block1.d(1); @@ -190,7 +201,7 @@ function create_fragment(ctx) { if (!if_block2) { if_block2 = create_if_block_2(ctx); if_block2.c(); - if_block2.m(div, text4); + if_block2.m(div, t4); } } else if (if_block2) { if_block2.d(1); @@ -223,9 +234,9 @@ function create_fragment(ctx) { i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(div); + d(detaching) { + if (detaching) { + detach(div); } if (if_block0) if_block0.d(); @@ -233,14 +244,14 @@ function create_fragment(ctx) { if (if_block2) if_block2.d(); if (if_block3) if_block3.d(); - if (detach) { - detachNode(text7); + if (detaching) { + detach(t7); } - if (if_block4) if_block4.d(detach); + if (if_block4) if_block4.d(detaching); - if (detach) { - detachNode(if_block4_anchor); + if (detaching) { + detach(if_block4_anchor); } } }; diff --git a/test/js/samples/window-binding-scroll/expected.js b/test/js/samples/window-binding-scroll/expected.js index e1e03bf66d..5a6601b851 100644 --- a/test/js/samples/window-binding-scroll/expected.js +++ b/test/js/samples/window-binding-scroll/expected.js @@ -1,17 +1,30 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, addListener, add_render_callback, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal, setData } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + add_render_callback, + append, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; function create_fragment(ctx) { - var scrolling = false, clear_scrolling = () => { scrolling = false }, scrolling_timeout, p, text0, text1, dispose; + var scrolling = false, clear_scrolling = () => { scrolling = false }, scrolling_timeout, p, t0, t1, dispose; add_render_callback(ctx.onwindowscroll); return { c() { - p = createElement("p"); - text0 = createText("scrolled to "); - text1 = createText(ctx.y); - dispose = addListener(window, "scroll", () => { + p = element("p"); + t0 = text("scrolled to "); + t1 = text(ctx.y); + dispose = listen(window, "scroll", () => { scrolling = true; clearTimeout(scrolling_timeout); scrolling_timeout = setTimeout(clear_scrolling, 100); @@ -21,8 +34,8 @@ function create_fragment(ctx) { m(target, anchor) { insert(target, p, anchor); - append(p, text0); - append(p, text1); + append(p, t0); + append(p, t1); }, p(changed, ctx) { @@ -34,16 +47,16 @@ function create_fragment(ctx) { } if (changed.y) { - setData(text1, ctx.y); + set_data(t1, ctx.y); } }, i: noop, o: noop, - d(detach) { - if (detach) { - detachNode(p); + d(detaching) { + if (detaching) { + detach(p); } dispose(); diff --git a/test/runtime/index.js b/test/runtime/index.js index 5f5d6eb573..579dc665c6 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -115,7 +115,7 @@ describe("runtime", () => { mod = require(`./samples/${dir}/main.svelte`); SvelteComponent = mod.default; } catch (err) { - showOutput(cwd, compileOptions, svelte.compile); // eslint-disable-line no-console + showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console throw err; } @@ -186,13 +186,13 @@ describe("runtime", () => { } } else { failed.add(dir); - showOutput(cwd, compileOptions, svelte.compile); // eslint-disable-line no-console + showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console throw err; } }) .then(() => { if (config.show) { - showOutput(cwd, compileOptions, svelte.compile); + showOutput(cwd, compileOptions, compile); } flush(); diff --git a/test/runtime/samples/attribute-casing/_config.js b/test/runtime/samples/attribute-casing/_config.js index 27d496da9d..f706c769b9 100644 --- a/test/runtime/samples/attribute-casing/_config.js +++ b/test/runtime/samples/attribute-casing/_config.js @@ -11,7 +11,7 @@ export default { `, - test({ assert, component, target }) { + test({ assert, target }) { const attr = sel => target.querySelector(sel).attributes[0].name; assert.equal(attr('div'), 'class');