diff --git a/package-lock.json b/package-lock.json index 51ee2c94a1..059554afd8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.0.0-beta.16", + "version": "3.0.0-beta.20", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -139,7 +139,7 @@ }, "ansi-escapes": { "version": "3.1.0", - "resolved": "http://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz", "integrity": "sha512-UgAb8H9D41AQnu/PbWlCofQVcnV4Gs2bBJi9eZPxfU/hgglFh3SMDMENRIqdr7H6XFnXdoknctFByVsCOotTVw==", "dev": true }, @@ -199,7 +199,7 @@ }, "array-equal": { "version": "1.0.0", - "resolved": "http://registry.npmjs.org/array-equal/-/array-equal-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/array-equal/-/array-equal-1.0.0.tgz", "integrity": "sha1-jCpe8kcv2ep0KwTHenUJO6J1fJM=", "dev": true }, @@ -627,7 +627,7 @@ }, "commander": { "version": "2.15.1", - "resolved": "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", "dev": true }, @@ -878,7 +878,7 @@ "dependencies": { "domelementtype": { "version": "1.1.3", - "resolved": "http://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz", "integrity": "sha1-vSh3PiZCiBrsUVRJJCmcXNgiGFs=", "dev": true } @@ -1131,7 +1131,7 @@ }, "doctrine": { "version": "1.5.0", - "resolved": "http://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", "dev": true, "requires": { @@ -1826,7 +1826,7 @@ }, "is-builtin-module": { "version": "1.0.0", - "resolved": "http://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz", "integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=", "dev": true, "requires": { @@ -2112,7 +2112,7 @@ }, "load-json-file": { "version": "2.0.0", - "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=", "dev": true, "requires": { @@ -2271,7 +2271,7 @@ }, "minimist": { "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true }, @@ -2298,7 +2298,7 @@ }, "mkdirp": { "version": "0.5.1", - "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, "requires": { @@ -2608,7 +2608,7 @@ }, "os-tmpdir": { "version": "1.0.2", - "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "dev": true }, @@ -2692,7 +2692,7 @@ }, "path-is-absolute": { "version": "1.0.1", - "resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, @@ -2737,7 +2737,7 @@ }, "pify": { "version": "2.3.0", - "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "dev": true }, @@ -3440,7 +3440,7 @@ }, "safe-regex": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=", "dev": true, "requires": { @@ -4024,7 +4024,7 @@ }, "through": { "version": "2.3.8", - "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, diff --git a/package.json b/package.json index 2f272a882d..72e3785315 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.0.0-beta.16", + "version": "3.0.0-beta.20", "description": "The magical disappearing UI framework", "module": "index.mjs", "main": "index", diff --git a/site/content/examples/00-introduction/00-hello-world/meta.json b/site/content/examples/00-introduction/00-hello-world/meta.json index 2f47184710..6cf02c2ed1 100644 --- a/site/content/examples/00-introduction/00-hello-world/meta.json +++ b/site/content/examples/00-introduction/00-hello-world/meta.json @@ -1,3 +1,3 @@ { - "title": "Adding data" + "title": "Hello world" } \ No newline at end of file diff --git a/site/content/examples/08-motion/01-spring/App.svelte b/site/content/examples/08-motion/01-spring/App.svelte index 2cb0fd1eb7..9918cf40e8 100644 --- a/site/content/examples/08-motion/01-spring/App.svelte +++ b/site/content/examples/08-motion/01-spring/App.svelte @@ -10,7 +10,7 @@ diff --git a/site/content/examples/11-svg/05-svg-transitions/App.svelte b/site/content/examples/11-svg/05-svg-transitions/App.svelte index 485bbf2558..6059b3645f 100644 --- a/site/content/examples/11-svg/05-svg-transitions/App.svelte +++ b/site/content/examples/11-svg/05-svg-transitions/App.svelte @@ -1,7 +1,7 @@ + + + +
+ +
\ No newline at end of file diff --git a/site/src/components/Lazy.svelte b/site/src/components/Lazy.svelte new file mode 100644 index 0000000000..ef81d68f00 --- /dev/null +++ b/site/src/components/Lazy.svelte @@ -0,0 +1,11 @@ + + + \ No newline at end of file diff --git a/site/src/components/Repl/Bundler.js b/site/src/components/Repl/Bundler.js new file mode 100644 index 0000000000..ddde546e7f --- /dev/null +++ b/site/src/components/Repl/Bundler.js @@ -0,0 +1,44 @@ +const workers = new Map(); + +let uid = 1; + +export default class Bundler { + constructor(version) { + if (!workers.has(version)) { + const worker = new Worker('/workers/bundler.js'); + worker.postMessage({ type: 'init', version }); + workers.set(version, worker); + } + + this.worker = workers.get(version); + + this.handlers = new Map(); + + this.worker.addEventListener('message', event => { + const handler = this.handlers.get(event.data.id); + + if (handler) { // if no handler, was meant for a different REPL + handler(event.data); + this.handlers.delete(event.data.id); + } + }); + } + + bundle(components) { + return new Promise(fulfil => { + const id = uid++; + + this.handlers.set(id, fulfil); + + this.worker.postMessage({ + id, + type: 'bundle', + components + }); + }); + } + + destroy() { + this.worker.terminate(); + } +} \ No newline at end of file diff --git a/site/src/components/Repl/CodeMirror.svelte b/site/src/components/Repl/CodeMirror.svelte index e9519e516e..a1a92fe344 100644 --- a/site/src/components/Repl/CodeMirror.svelte +++ b/site/src/components/Repl/CodeMirror.svelte @@ -33,9 +33,9 @@ // than making this state-driven through props, // because it's difficult to update an editor // without resetting scroll otherwise - export function set(new_code, new_mode) { + export async function set(new_code, new_mode) { if (new_mode !== mode) { - createEditor(mode = new_mode); + await createEditor(mode = new_mode); } code = new_code; @@ -121,12 +121,13 @@ onMount(() => { if (_CodeMirror) { CodeMirror = _CodeMirror; - createEditor(mode || 'svelte'); - editor.setValue(code || ''); + createEditor(mode || 'svelte').then(() => { + editor.setValue(code || ''); + }); } else { - codemirror_promise.then(mod => { + codemirror_promise.then(async mod => { CodeMirror = mod.default; - createEditor(mode || 'svelte'); + await createEditor(mode || 'svelte'); editor.setValue(code || ''); }); } @@ -137,12 +138,10 @@ } }); - function createEditor(mode) { + async function createEditor(mode) { if (destroyed || !CodeMirror) return; - if (editor) { - editor.toTextArea(); - } + if (editor) editor.toTextArea(); const opts = { lineNumbers, @@ -162,6 +161,12 @@ 'Shift-Tab': tab }; + // Creating a text editor is a lot of work, so we yield + // the main thread for a moment. This helps reduce jank + await sleep(50); + + if (destroyed) return; + editor = CodeMirror.fromTextArea(refs.editor, opts); editor.on('change', instance => { @@ -171,8 +176,13 @@ } }); + await sleep(50); editor.refresh(); } + + function sleep(ms) { + return new Promise(fulfil => setTimeout(fulfil, ms)); + }
- - - -
-
-

CSS is component-scoped by default — no more style collisions or specificity wars. Or you can use your favourite CSS-in-JS library.

-
- - -
- -
-
-

Trigger efficient, granular updates by assigning to local variables. The compiler does the rest.

-
- - -
- -
-
-

Build beautiful UIs with a powerful, performant transition engine built right into the framework.

-
- - -
+
+
+
+

Svelte components are written in HTML files. Just add data.

+
+ +
+ + {#if intersecting} + + + {/if} + +
+
+ +
+
+

CSS is component-scoped by default — no more style collisions or specificity wars. Or you can use your favourite CSS-in-JS library.

+
+ +
+ + {#if intersecting} + + + {/if} + +
+
+ +
+
+

Trigger efficient, granular updates by assigning to local variables. The compiler does the rest.

+
+ +
+ + {#if intersecting} + + + {/if} + +
+
+ +
+
+

Build beautiful UIs with a powerful, performant transition engine built right into the framework.

+
+ +
+ + {#if intersecting} + + + {/if} + +
+
+

Who's using Svelte?

diff --git a/site/src/routes/repl/index.svelte b/site/src/routes/repl/index.svelte index 8671717f5d..655b8144a8 100644 --- a/site/src/routes/repl/index.svelte +++ b/site/src/routes/repl/index.svelte @@ -11,7 +11,7 @@ '; +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/css/samples/nested/input.svelte b/test/css/samples/nested/input.svelte index 525860acbe..2f97681c74 100644 --- a/test/css/samples/nested/input.svelte +++ b/test/css/samples/nested/input.svelte @@ -1,3 +1,7 @@ + + text diff --git a/test/css/samples/omit-scoping-attribute-attribute-selector-equals-dynamic/input.svelte b/test/css/samples/omit-scoping-attribute-attribute-selector-equals-dynamic/input.svelte index dda0d98c7c..e66777cd08 100644 --- a/test/css/samples/omit-scoping-attribute-attribute-selector-equals-dynamic/input.svelte +++ b/test/css/samples/omit-scoping-attribute-attribute-selector-equals-dynamic/input.svelte @@ -1,3 +1,7 @@ + +

this is styled

this is unstyled

diff --git a/test/css/samples/spread/input.svelte b/test/css/samples/spread/input.svelte index ab5f2e937e..aa43e4ae11 100644 --- a/test/css/samples/spread/input.svelte +++ b/test/css/samples/spread/input.svelte @@ -1,3 +1,7 @@ + +
Big red Comic Sans
diff --git a/test/css/samples/unused-selector-ternary/_config.js b/test/css/samples/unused-selector-ternary/_config.js index 68254477d9..4ff2713108 100644 --- a/test/css/samples/unused-selector-ternary/_config.js +++ b/test/css/samples/unused-selector-ternary/_config.js @@ -8,22 +8,22 @@ export default { code: `css-unused-selector`, message: "Unused CSS selector", start: { - line: 12, + line: 16, column: 1, - character: 123 + character: 163 }, end: { - line: 12, + line: 16, column: 13, - character: 135 + character: 175 }, - pos: 123, + pos: 163, frame: ` - 10: } - 11: - 12: .maybeactive { + 14: } + 15: + 16: .maybeactive { ^ - 13: color: green; - 14: }` + 17: color: green; + 18: }` }] }; \ No newline at end of file diff --git a/test/css/samples/unused-selector-ternary/input.svelte b/test/css/samples/unused-selector-ternary/input.svelte index 728dfa766a..f72592834f 100644 --- a/test/css/samples/unused-selector-ternary/input.svelte +++ b/test/css/samples/unused-selector-ternary/input.svelte @@ -1,3 +1,7 @@ + +
`; - init(this, { target: this.shadowRoot }, null, create_fragment, safe_not_equal); + init(this, { target: this.shadowRoot }, null, create_fragment, safe_not_equal, []); if (options) { if (options.target) { diff --git a/test/js/samples/debug-empty/expected.js b/test/js/samples/debug-empty/expected.js index 4a6393388c..efe966c552 100644 --- a/test/js/samples/debug-empty/expected.js +++ b/test/js/samples/debug-empty/expected.js @@ -1,20 +1,33 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponentDev, addLoc, append, createElement, createText, detachNode, flush, 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, + space, + 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 = space(); debugger; - addLoc(h1, file, 0, 0, 0); + add_location(h1, file, 4, 0, 38); }, l: function claim(nodes) { @@ -23,15 +36,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 +53,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); } } }; @@ -62,7 +75,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponentDev { constructor(options) { super(options); - init(this, options, instance, create_fragment, safe_not_equal); + init(this, options, instance, create_fragment, safe_not_equal, ["name"]); const { ctx } = this.$$; const props = options.props || {}; @@ -72,12 +85,11 @@ class SvelteComponent extends SvelteComponentDev { } get name() { - return this.$$.ctx.name; + throw new Error(": Props cannot be read directly from the component instance unless compiling with 'accessors: true' or ''"); } - set name(name) { - this.$set({ name }); - flush(); + set name(value) { + throw new Error(": Props cannot be set directly on the component instance unless compiling with 'accessors: true' or ''"); } } diff --git a/test/js/samples/debug-empty/input.svelte b/test/js/samples/debug-empty/input.svelte index 11da4f6d15..24f03b00c1 100644 --- a/test/js/samples/debug-empty/input.svelte +++ b/test/js/samples/debug-empty/input.svelte @@ -1,2 +1,6 @@ + +

Hello {name}!

{@debug} \ No newline at end of file diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js index b56d333238..0220664d12 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,19 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponentDev, addLoc, append, createElement, createText, destroyEach, detachNode, flush, 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, + space, + text +} from "svelte/internal"; const file = undefined; @@ -9,33 +23,33 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (1:0) {#each things as thing} +// (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 = space(); { const { foo, bar, baz, thing } = ctx; console.log({ foo, bar, baz, thing }); debugger; } - addLoc(span, file, 1, 1, 25); + 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 +59,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 +85,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, 5, 0, 91); + t0 = space(); + p = element("p"); + t1 = text("foo: "); + t2 = text(ctx.foo); + add_location(p, file, 12, 0, 182); }, l: function claim(nodes) { @@ -87,10 +101,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 +119,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 +130,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); } } }; @@ -150,7 +164,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponentDev { constructor(options) { super(options); - init(this, options, instance, create_fragment, safe_not_equal); + init(this, options, instance, create_fragment, safe_not_equal, ["things", "foo", "bar", "baz"]); const { ctx } = this.$$; const props = options.props || {}; @@ -169,39 +183,35 @@ class SvelteComponent extends SvelteComponentDev { } get things() { - return this.$$.ctx.things; + throw new Error(": Props cannot be read directly from the component instance unless compiling with 'accessors: true' or ''"); } - set things(things) { - this.$set({ things }); - flush(); + set things(value) { + throw new Error(": Props cannot be set directly on the component instance unless compiling with 'accessors: true' or ''"); } get foo() { - return this.$$.ctx.foo; + throw new Error(": Props cannot be read directly from the component instance unless compiling with 'accessors: true' or ''"); } - set foo(foo) { - this.$set({ foo }); - flush(); + set foo(value) { + throw new Error(": Props cannot be set directly on the component instance unless compiling with 'accessors: true' or ''"); } get bar() { - return this.$$.ctx.bar; + throw new Error(": Props cannot be read directly from the component instance unless compiling with 'accessors: true' or ''"); } - set bar(bar) { - this.$set({ bar }); - flush(); + set bar(value) { + throw new Error(": Props cannot be set directly on the component instance unless compiling with 'accessors: true' or ''"); } get baz() { - return this.$$.ctx.baz; + throw new Error(": Props cannot be read directly from the component instance unless compiling with 'accessors: true' or ''"); } - set baz(baz) { - this.$set({ baz }); - flush(); + set baz(value) { + throw new Error(": Props cannot be set directly on the component instance unless compiling with 'accessors: true' or ''"); } } diff --git a/test/js/samples/debug-foo-bar-baz-things/input.svelte b/test/js/samples/debug-foo-bar-baz-things/input.svelte index 6fa8611415..df6095c52d 100644 --- a/test/js/samples/debug-foo-bar-baz-things/input.svelte +++ b/test/js/samples/debug-foo-bar-baz-things/input.svelte @@ -1,3 +1,10 @@ + + {#each things as thing} {thing.name} {@debug foo, bar, baz, thing} diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index 35d0a1f18f..ccd5f14ec4 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -1,5 +1,19 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponentDev, addLoc, append, createElement, createText, destroyEach, detachNode, flush, 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, + space, + text +} from "svelte/internal"; const file = undefined; @@ -9,33 +23,33 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (1:0) {#each things as thing} +// (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 = space(); { const { foo } = ctx; console.log({ foo }); debugger; } - addLoc(span, file, 1, 1, 25); + 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 +59,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 +85,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, 5, 0, 74); + t0 = space(); + p = element("p"); + t1 = text("foo: "); + t2 = text(ctx.foo); + add_location(p, file, 10, 0, 131); }, l: function claim(nodes) { @@ -87,10 +101,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 +119,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 +130,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); } } }; @@ -148,7 +162,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponentDev { constructor(options) { super(options); - init(this, options, instance, create_fragment, safe_not_equal); + init(this, options, instance, create_fragment, safe_not_equal, ["things", "foo"]); const { ctx } = this.$$; const props = options.props || {}; @@ -161,21 +175,19 @@ class SvelteComponent extends SvelteComponentDev { } get things() { - return this.$$.ctx.things; + throw new Error(": Props cannot be read directly from the component instance unless compiling with 'accessors: true' or ''"); } - set things(things) { - this.$set({ things }); - flush(); + set things(value) { + throw new Error(": Props cannot be set directly on the component instance unless compiling with 'accessors: true' or ''"); } get foo() { - return this.$$.ctx.foo; + throw new Error(": Props cannot be read directly from the component instance unless compiling with 'accessors: true' or ''"); } - set foo(foo) { - this.$set({ foo }); - flush(); + set foo(value) { + throw new Error(": Props cannot be set directly on the component instance unless compiling with 'accessors: true' or ''"); } } diff --git a/test/js/samples/debug-foo/input.svelte b/test/js/samples/debug-foo/input.svelte index 6e926a4015..553f080d94 100644 --- a/test/js/samples/debug-foo/input.svelte +++ b/test/js/samples/debug-foo/input.svelte @@ -1,3 +1,8 @@ + + {#each things as thing} {thing.name} {@debug foo} diff --git a/test/js/samples/debug-ssr-foo/expected.js b/test/js/samples/debug-ssr-foo/expected.js index afad023a3f..02bbec5fba 100644 --- a/test/js/samples/debug-ssr-foo/expected.js +++ b/test/js/samples/debug-ssr-foo/expected.js @@ -1,11 +1,19 @@ /* 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; + if ($$props.things === void 0 && $$bindings.things && things !== void 0) $$bindings.things(things); + if ($$props.foo === void 0 && $$bindings.foo && foo !== void 0) $$bindings.foo(foo); + return `${each(things, (thing) => `${escape(thing.name)} - ${debug(null, 2, 2, { foo })}`)} + ${debug(null, 7, 2, { foo })}`)}

foo: ${escape(foo)}

`; }); diff --git a/test/js/samples/debug-ssr-foo/input.svelte b/test/js/samples/debug-ssr-foo/input.svelte index 6e926a4015..553f080d94 100644 --- a/test/js/samples/debug-ssr-foo/input.svelte +++ b/test/js/samples/debug-ssr-foo/input.svelte @@ -1,3 +1,8 @@ + + {#each things as thing} {thing.name} {@debug foo} diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js index 7ad954e330..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, flush, 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); @@ -7,37 +20,37 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (1:0) {#each createElement as node} +// (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); } } }; @@ -113,16 +126,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get createElement() { - return this.$$.ctx.createElement; - } - - set createElement(createElement) { - this.$set({ createElement }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["createElement"]); } } diff --git a/test/js/samples/deconflict-builtins/input.svelte b/test/js/samples/deconflict-builtins/input.svelte index 48a413b323..01052de947 100644 --- a/test/js/samples/deconflict-builtins/input.svelte +++ b/test/js/samples/deconflict-builtins/input.svelte @@ -1,3 +1,7 @@ + + {#each createElement as node} {node} {/each} \ No newline at end of file diff --git a/test/js/samples/deconflict-globals/expected.js b/test/js/samples/deconflict-globals/expected.js index f3e8c93ebe..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, flush, 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) { @@ -30,16 +35,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get foo() { - return this.$$.ctx.foo; - } - - set foo(foo) { - this.$set({ foo }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["foo"]); } } 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 dcd1078a6d..3840e9544d 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,31 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponentDev, addLoc, append, createElement, createText, detachNode, flush, 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, + space, + 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 = space(); + t2 = text(ctx.bar); + add_location(p, file, 7, 0, 67); }, l: function claim(nodes) { @@ -21,27 +34,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); } } }; @@ -68,7 +81,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponentDev { constructor(options) { super(options); - init(this, options, instance, create_fragment, safe_not_equal); + init(this, options, instance, create_fragment, safe_not_equal, ["foo"]); const { ctx } = this.$$; const props = options.props || {}; @@ -78,12 +91,11 @@ class SvelteComponent extends SvelteComponentDev { } get foo() { - return this.$$.ctx.foo; + throw new Error(": Props cannot be read directly from the component instance unless compiling with 'accessors: true' or ''"); } - set foo(foo) { - this.$set({ foo }); - flush(); + set foo(value) { + throw new Error(": Props cannot be set directly on the component instance unless compiling with 'accessors: true' or ''"); } } diff --git a/test/js/samples/do-use-dataset/expected.js b/test/js/samples/do-use-dataset/expected.js index f340f71b01..60a8c54869 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, flush, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + noop, + safe_not_equal, + space +} 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 = space(); + 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); } } }; @@ -51,16 +60,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get bar() { - return this.$$.ctx.bar; - } - - set bar(bar) { - this.$set({ bar }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["bar"]); } } diff --git a/test/js/samples/do-use-dataset/input.svelte b/test/js/samples/do-use-dataset/input.svelte index ffd72ac6ee..e340b2610f 100644 --- a/test/js/samples/do-use-dataset/input.svelte +++ b/test/js/samples/do-use-dataset/input.svelte @@ -1,2 +1,6 @@ + +
\ No newline at end of file diff --git a/test/js/samples/dont-invalidate-this/expected.js b/test/js/samples/dont-invalidate-this/expected.js index db21ccdd64..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(); @@ -35,8 +44,8 @@ function make_uppercase() { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, null, create_fragment, safe_not_equal); + init(this, options, null, create_fragment, safe_not_equal, []); } } -export default SvelteComponent; +export default SvelteComponent; \ No newline at end of file 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 974ed23b28..4d63cb8c73 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, flush, init, insert, noop, safe_not_equal, setAttribute } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + attr, + detach, + element, + init, + insert, + noop, + safe_not_equal, + space +} 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 = space(); + 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); } } }; @@ -51,16 +61,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get bar() { - return this.$$.ctx.bar; - } - - set bar(bar) { - this.$set({ bar }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["bar"]); } } diff --git a/test/js/samples/dont-use-dataset-in-legacy/input.svelte b/test/js/samples/dont-use-dataset-in-legacy/input.svelte index ffd72ac6ee..e340b2610f 100644 --- a/test/js/samples/dont-use-dataset-in-legacy/input.svelte +++ b/test/js/samples/dont-use-dataset-in-legacy/input.svelte @@ -1,2 +1,6 @@ + +
\ No newline at end of file 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 cc29258326..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, flush, 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); } } }; @@ -49,16 +59,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get bar() { - return this.$$.ctx.bar; - } - - set bar(bar) { - this.$set({ bar }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["bar"]); } } diff --git a/test/js/samples/dont-use-dataset-in-svg/input.svelte b/test/js/samples/dont-use-dataset-in-svg/input.svelte index fe6c4eba9b..969377de33 100644 --- a/test/js/samples/dont-use-dataset-in-svg/input.svelte +++ b/test/js/samples/dont-use-dataset-in-svg/input.svelte @@ -1,3 +1,7 @@ + + diff --git a/test/js/samples/dynamic-import/expected.js b/test/js/samples/dynamic-import/expected.js index c7a82698c2..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); } }; } @@ -44,7 +50,7 @@ function func() { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, null, create_fragment, safe_not_equal); + init(this, options, null, create_fragment, safe_not_equal, []); } } diff --git a/test/js/samples/each-block-array-literal/expected.js b/test/js/samples/each-block-array-literal/expected.js index b5499707c3..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, flush, 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); @@ -7,37 +20,37 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (1:0) {#each [a, b, c, d, e] as num} +// (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); } } }; @@ -116,52 +129,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get a() { - return this.$$.ctx.a; - } - - set a(a) { - this.$set({ a }); - flush(); - } - - get b() { - return this.$$.ctx.b; - } - - set b(b) { - this.$set({ b }); - flush(); - } - - get c() { - return this.$$.ctx.c; - } - - set c(c) { - this.$set({ c }); - flush(); - } - - get d() { - return this.$$.ctx.d; - } - - set d(d) { - this.$set({ d }); - flush(); - } - - get e() { - return this.$$.ctx.e; - } - - set e(e) { - this.$set({ e }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["a", "b", "c", "d", "e"]); } } diff --git a/test/js/samples/each-block-array-literal/input.svelte b/test/js/samples/each-block-array-literal/input.svelte index aba508f711..cf25c139e0 100644 --- a/test/js/samples/each-block-array-literal/input.svelte +++ b/test/js/samples/each-block-array-literal/input.svelte @@ -1,3 +1,11 @@ + + {#each [a, b, c, d, e] as num} {num} {/each} \ No newline at end of file diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 0032b1c720..c65cd3479a 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,5 +1,19 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createElement, createText, destroyEach, detachAfter, detachNode, flush, 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, + space, + text +} from "svelte/internal"; function get_each_context(ctx, list, i) { const child_ctx = Object.create(ctx); @@ -8,23 +22,23 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (1:0) {#each comments as comment, 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 = space(); + span = element("span"); + t2 = text(t2_value); + t3 = text(" wrote "); + t4 = text(t4_value); + t5 = text(" ago:"); + t6 = space(); + raw_before = element('noscript'); span.className = "meta"; div.className = "comment"; }, @@ -32,43 +46,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 +98,9 @@ function create_fragment(ctx) { each_blocks[i].c(); } - text0 = createText("\n\n"); - p = createElement("p"); - text1 = createText(ctx.foo); + t0 = space(); + p = element("p"); + t1 = text(ctx.foo); }, m(target, anchor) { @@ -94,9 +108,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 +125,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 +136,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); } } }; @@ -156,43 +170,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get comments() { - return this.$$.ctx.comments; - } - - set comments(comments) { - this.$set({ comments }); - flush(); - } - - get elapsed() { - return this.$$.ctx.elapsed; - } - - set elapsed(elapsed) { - this.$set({ elapsed }); - flush(); - } - - get time() { - return this.$$.ctx.time; - } - - set time(time) { - this.$set({ time }); - flush(); - } - - get foo() { - return this.$$.ctx.foo; - } - - set foo(foo) { - this.$set({ foo }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["comments", "elapsed", "time", "foo"]); } } diff --git a/test/js/samples/each-block-changed-check/input.svelte b/test/js/samples/each-block-changed-check/input.svelte index b5b5703857..999b346975 100644 --- a/test/js/samples/each-block-changed-check/input.svelte +++ b/test/js/samples/each-block-changed-check/input.svelte @@ -1,3 +1,10 @@ + + {#each comments as comment, i}
{i} diff --git a/test/js/samples/each-block-keyed-animated/expected.js b/test/js/samples/each-block-keyed-animated/expected.js index e7e10208e4..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, animate, append, blankObject, createComment, createElement, createText, detachNode, fixAndOutroAndDestroyBlock, fix_position, flush, 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); } }, @@ -44,19 +61,19 @@ function create_each_block(key_1, ctx) { a() { stop_animation(); - stop_animation = animate(div, rect, foo, {}); + 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); } } }; @@ -128,16 +145,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get things() { - return this.$$.ctx.things; - } - - set things(things) { - this.$set({ things }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["things"]); } } diff --git a/test/js/samples/each-block-keyed/expected.js b/test/js/samples/each-block-keyed/expected.js index c2dd23fb96..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, flush, 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); @@ -7,9 +22,9 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (1:0) {#each things as thing (thing.id)} +// (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); } } }; @@ -98,16 +113,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get things() { - return this.$$.ctx.things; - } - - set things(things) { - this.$set({ things }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["things"]); } } diff --git a/test/js/samples/each-block-keyed/input.svelte b/test/js/samples/each-block-keyed/input.svelte index 909af032e9..e6493dcd58 100644 --- a/test/js/samples/each-block-keyed/input.svelte +++ b/test/js/samples/each-block-keyed/input.svelte @@ -1,3 +1,7 @@ + + {#each things as thing (thing.id)}
{thing.name}
{/each} \ No newline at end of file diff --git a/test/js/samples/event-handler-no-passive/expected.js b/test/js/samples/event-handler-no-passive/expected.js index 19cfed3124..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(); @@ -37,7 +46,7 @@ function touchstart_handler(e) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, null, create_fragment, safe_not_equal); + init(this, options, null, create_fragment, safe_not_equal, []); } } diff --git a/test/js/samples/event-modifiers/expected.js b/test/js/samples/event-modifiers/expected.js index b6c554a8b6..617ccff197 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, + space, + stop_propagation +} 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 = space(); + button1 = element("button"); button1.textContent = "or me"; - text3 = createText("\n\t"); - button2 = createElement("button"); + t3 = space(); + 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); @@ -57,7 +71,7 @@ function handleClick() { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, null, create_fragment, safe_not_equal); + init(this, options, null, create_fragment, safe_not_equal, []); } } diff --git a/test/js/samples/head-no-whitespace/expected.js b/test/js/samples/head-no-whitespace/expected.js index 9e38fe41d3..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); } }; } @@ -33,7 +41,7 @@ function create_fragment(ctx) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, null, create_fragment, safe_not_equal); + init(this, options, null, create_fragment, safe_not_equal, []); } } diff --git a/test/js/samples/hoisted-const/expected.js b/test/js/samples/hoisted-const/expected.js index 884f765ba7..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); } } }; @@ -34,7 +44,7 @@ function get_answer() { return ANSWER; } class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, null, create_fragment, safe_not_equal); + init(this, options, null, create_fragment, safe_not_equal, []); } } diff --git a/test/js/samples/hoisted-let/expected.js b/test/js/samples/hoisted-let/expected.js index d94eb2a7b7..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); } } }; @@ -34,7 +44,7 @@ function get_answer() { return ANSWER; } class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, null, create_fragment, safe_not_equal); + init(this, options, null, create_fragment, safe_not_equal, []); } } diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index a4c9fbc163..11fbf604b1 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,13 +1,22 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createComment, createElement, detachNode, flush, init, insert, noop, safe_not_equal } from "svelte/internal"; - -// (3:0) {:else} +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) { var p; return { c() { - p = createElement("p"); + p = element("p"); p.textContent = "not foo!"; }, @@ -15,21 +24,21 @@ function create_else_block(ctx) { insert(target, p, anchor); }, - d(detach) { - if (detach) { - detachNode(p); + d(detaching) { + if (detaching) { + detach(p); } } }; } -// (1:0) {#if foo} +// (5:0) {#if foo} function create_if_block(ctx) { var p; 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); } } }; @@ -104,16 +113,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get foo() { - return this.$$.ctx.foo; - } - - set foo(foo) { - this.$set({ foo }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["foo"]); } } diff --git a/test/js/samples/if-block-no-update/input.svelte b/test/js/samples/if-block-no-update/input.svelte index 57de219159..c7a0f6a98c 100644 --- a/test/js/samples/if-block-no-update/input.svelte +++ b/test/js/samples/if-block-no-update/input.svelte @@ -1,3 +1,7 @@ + + {#if foo}

foo!

{:else} diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index 76c69b000f..af8d45974f 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,13 +1,22 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, createComment, createElement, detachNode, flush, init, insert, noop, safe_not_equal } from "svelte/internal"; - -// (1:0) {#if foo} +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) { var p; 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); } } }; @@ -78,16 +87,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get foo() { - return this.$$.ctx.foo; - } - - set foo(foo) { - this.$set({ foo }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["foo"]); } } diff --git a/test/js/samples/if-block-simple/input.svelte b/test/js/samples/if-block-simple/input.svelte index e36517e10c..545d81d44a 100644 --- a/test/js/samples/if-block-simple/input.svelte +++ b/test/js/samples/if-block-simple/input.svelte @@ -1,3 +1,7 @@ + + {#if foo}

foo!

{/if} \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index 5988850ede..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, flush, 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); } } }; @@ -51,34 +60,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get color() { - return this.$$.ctx.color; - } - - set color(color) { - this.$set({ color }); - flush(); - } - - get x() { - return this.$$.ctx.x; - } - - set x(x) { - this.$set({ x }); - flush(); - } - - get y() { - return this.$$.ctx.y; - } - - set y(y) { - this.$set({ y }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["color", "x", "y"]); } } diff --git a/test/js/samples/inline-style-optimized-multiple/input.svelte b/test/js/samples/inline-style-optimized-multiple/input.svelte index d9448e0ab0..d5e2beb609 100644 --- a/test/js/samples/inline-style-optimized-multiple/input.svelte +++ b/test/js/samples/inline-style-optimized-multiple/input.svelte @@ -1 +1,7 @@ + +
\ No newline at end of file diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index c1ed003c83..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, flush, 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); } } }; @@ -44,16 +53,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get data() { - return this.$$.ctx.data; - } - - set data(data) { - this.$set({ data }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["data"]); } } diff --git a/test/js/samples/inline-style-optimized-url/input.svelte b/test/js/samples/inline-style-optimized-url/input.svelte index 677da52c30..2e660fe02d 100644 --- a/test/js/samples/inline-style-optimized-url/input.svelte +++ b/test/js/samples/inline-style-optimized-url/input.svelte @@ -1 +1,5 @@ + +
\ No newline at end of file diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index 9d88cb7d35..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, flush, 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); } } }; @@ -44,16 +53,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get color() { - return this.$$.ctx.color; - } - - set color(color) { - this.$set({ color }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["color"]); } } diff --git a/test/js/samples/inline-style-optimized/input.svelte b/test/js/samples/inline-style-optimized/input.svelte index 004fd595c9..b47ca48093 100644 --- a/test/js/samples/inline-style-optimized/input.svelte +++ b/test/js/samples/inline-style-optimized/input.svelte @@ -1 +1,5 @@ + +
\ No newline at end of file diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index 31bda3a217..f2e52ebb48 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, flush, init, insert, noop, safe_not_equal } from "svelte/internal"; +import { + SvelteComponent as SvelteComponent_1, + detach, + element, + init, + insert, + noop, + safe_not_equal, + space +} 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 = space(); + 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); } } }; @@ -57,34 +66,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get style() { - return this.$$.ctx.style; - } - - set style(style) { - this.$set({ style }); - flush(); - } - - get key() { - return this.$$.ctx.key; - } - - set key(key) { - this.$set({ key }); - flush(); - } - - get value() { - return this.$$.ctx.value; - } - - set value(value) { - this.$set({ value }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["style", "key", "value"]); } } diff --git a/test/js/samples/inline-style-unoptimized/input.svelte b/test/js/samples/inline-style-unoptimized/input.svelte index eac76d5b6e..3893fa3f89 100644 --- a/test/js/samples/inline-style-unoptimized/input.svelte +++ b/test/js/samples/inline-style-unoptimized/input.svelte @@ -1,2 +1,8 @@ -
-
\ No newline at end of file + + +
+
\ No newline at end of file diff --git a/test/js/samples/input-files/expected.js b/test/js/samples/input-files/expected.js index 80a00a9701..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, flush, 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(); @@ -48,16 +58,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get files() { - return this.$$.ctx.files; - } - - set files(files) { - this.$set({ files }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["files"]); } } diff --git a/test/js/samples/input-files/input.svelte b/test/js/samples/input-files/input.svelte index 7c078b4885..f7d4159e37 100644 --- a/test/js/samples/input-files/input.svelte +++ b/test/js/samples/input-files/input.svelte @@ -1 +1,5 @@ + + \ No newline at end of file diff --git a/test/js/samples/input-range/expected.js b/test/js/samples/input-range/expected.js index 7a4cf6079a..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, flush, 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); } @@ -56,16 +68,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get value() { - return this.$$.ctx.value; - } - - set value(value) { - this.$set({ value }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["value"]); } } diff --git a/test/js/samples/input-range/input.svelte b/test/js/samples/input-range/input.svelte index e080b9a81b..2fa0517f47 100644 --- a/test/js/samples/input-range/input.svelte +++ b/test/js/samples/input-range/input.svelte @@ -1 +1,5 @@ + + \ No newline at end of file diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index 18c1535138..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, flush, 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(); @@ -52,16 +62,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get foo() { - return this.$$.ctx.foo; - } - - set foo(foo) { - this.$set({ foo }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["foo"]); } } diff --git a/test/js/samples/input-without-blowback-guard/input.svelte b/test/js/samples/input-without-blowback-guard/input.svelte index 991c5e33ab..9c5bfa35dc 100644 --- a/test/js/samples/input-without-blowback-guard/input.svelte +++ b/test/js/samples/input-without-blowback-guard/input.svelte @@ -1 +1,5 @@ + + \ No newline at end of file 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 f5100961fc..4788fc2e09 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,55 @@ /* 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, + space, + 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 = space(); + 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(); @@ -57,7 +70,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); + init(this, options, instance, create_fragment, safe_not_equal, []); } } 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 45a968f94f..165c4e27b0 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,55 @@ /* 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, + space, + 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 = space(); + 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(); @@ -58,7 +71,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); + init(this, options, instance, create_fragment, safe_not_equal, []); } } 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 e5248cf5dc..38f7f7fcd0 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,55 @@ /* 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, + space, + 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 = space(); + 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(); @@ -57,7 +70,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); + init(this, options, instance, create_fragment, safe_not_equal, []); } } 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 9f7ff64725..4adc229ff7 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,55 @@ /* 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, + space, + 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 = space(); + 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(); @@ -55,7 +68,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); + init(this, options, instance, create_fragment, safe_not_equal, []); } } diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index f9e0807314..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); } } }; @@ -29,7 +38,7 @@ function create_fragment(ctx) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, null, create_fragment, safe_not_equal); + init(this, options, null, create_fragment, safe_not_equal, []); } } diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index 8163a8a947..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, flush, 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); } @@ -123,70 +135,7 @@ function instance($$self, $$props, $$invalidate) { class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal); - } - - get buffered() { - return this.$$.ctx.buffered; - } - - set buffered(buffered) { - this.$set({ buffered }); - flush(); - } - - get seekable() { - return this.$$.ctx.seekable; - } - - set seekable(seekable) { - this.$set({ seekable }); - flush(); - } - - get played() { - return this.$$.ctx.played; - } - - set played(played) { - this.$set({ played }); - flush(); - } - - get currentTime() { - return this.$$.ctx.currentTime; - } - - set currentTime(currentTime) { - this.$set({ currentTime }); - flush(); - } - - get duration() { - return this.$$.ctx.duration; - } - - set duration(duration) { - this.$set({ duration }); - flush(); - } - - get paused() { - return this.$$.ctx.paused; - } - - set paused(paused) { - this.$set({ paused }); - flush(); - } - - get volume() { - return this.$$.ctx.volume; - } - - set volume(volume) { - this.$set({ volume }); - flush(); + init(this, options, instance, create_fragment, safe_not_equal, ["buffered", "seekable", "played", "currentTime", "duration", "paused", "volume"]); } } diff --git a/test/js/samples/media-bindings/input.svelte b/test/js/samples/media-bindings/input.svelte index 3f7a0b66d1..169d5c9341 100644 --- a/test/js/samples/media-bindings/input.svelte +++ b/test/js/samples/media-bindings/input.svelte @@ -1 +1,11 @@ + +