Eslint autofix errors

pull/3404/head
Alexandr Orel 6 years ago
parent 0aee6f470d
commit de7d1a889e

@ -163,7 +163,7 @@ export default class Component {
const svelteOptions = ast.html.children.find(child => child.name === 'svelte:options') || { start: 0, end: 0 }; const svelteOptions = ast.html.children.find(child => child.name === 'svelte:options') || { start: 0, end: 0 };
this.warn(svelteOptions, { this.warn(svelteOptions, {
code: 'custom-element-no-tag', code: 'custom-element-no-tag',
message: `No custom element 'tag' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag="my-thing"/>. To hide this warning, use <svelte:options tag={null}/>` message: 'No custom element \'tag\' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag="my-thing"/>. To hide this warning, use <svelte:options tag={null}/>'
}); });
} }
this.tag = this.component_options.tag || compile_options.tag; this.tag = this.component_options.tag || compile_options.tag;
@ -256,7 +256,7 @@ export default class Component {
const { compile_options, name } = this; const { compile_options, name } = this;
const { format = 'esm' } = compile_options; const { format = 'esm' } = compile_options;
const banner = `/* ${this.file ? `${this.file} ` : ``}generated by Svelte v${"__VERSION__"} */`; const banner = `/* ${this.file ? `${this.file} ` : ''}generated by Svelte v${'__VERSION__'} */`;
result = result result = result
.replace(/__svelte:self__/g, this.name) .replace(/__svelte:self__/g, this.name)
@ -488,16 +488,16 @@ export default class Component {
content.body.forEach(node => { content.body.forEach(node => {
if (node.type === 'ExportDefaultDeclaration') { if (node.type === 'ExportDefaultDeclaration') {
this.error(node, { this.error(node, {
code: `default-export`, code: 'default-export',
message: `A component cannot have a default export` message: 'A component cannot have a default export'
}); });
} }
if (node.type === 'ExportNamedDeclaration') { if (node.type === 'ExportNamedDeclaration') {
if (node.source) { if (node.source) {
this.error(node, { this.error(node, {
code: `not-implemented`, code: 'not-implemented',
message: `A component currently cannot have an export ... from` message: 'A component currently cannot have an export ... from'
}); });
} }
if (node.declaration) { if (node.declaration) {
@ -594,7 +594,7 @@ export default class Component {
if (name[0] === '$') { if (name[0] === '$') {
this.error(node, { this.error(node, {
code: 'illegal-declaration', code: 'illegal-declaration',
message: `The $ prefix is reserved, and cannot be used for variable and import names` message: 'The $ prefix is reserved, and cannot be used for variable and import names'
}); });
} }
@ -610,7 +610,7 @@ export default class Component {
if (name[0] === '$') { if (name[0] === '$') {
this.error(node, { this.error(node, {
code: 'illegal-subscription', code: 'illegal-subscription',
message: `Cannot reference store value inside <script context="module">` message: 'Cannot reference store value inside <script context="module">'
}); });
} else { } else {
this.add_var({ this.add_var({
@ -655,7 +655,7 @@ export default class Component {
if (name[0] === '$') { if (name[0] === '$') {
this.error(node, { this.error(node, {
code: 'illegal-declaration', code: 'illegal-declaration',
message: `The $ prefix is reserved, and cannot be used for variable and import names` message: 'The $ prefix is reserved, and cannot be used for variable and import names'
}); });
} }
@ -875,7 +875,7 @@ export default class Component {
if (variable.export_name) { if (variable.export_name) {
component.error(declarator, { component.error(declarator, {
code: 'destructured-prop', code: 'destructured-prop',
message: `Cannot declare props in destructured declaration` message: 'Cannot declare props in destructured declaration'
}); });
} }
@ -983,7 +983,7 @@ export default class Component {
? `; ${group.insert}` ? `; ${group.insert}`
: ''; : '';
const suffix = `${writable ? ` } = $$props` : ``}${insert}` + (code.original[c] === ';' ? `` : `;`); const suffix = `${writable ? ' } = $$props' : ''}${insert}` + (code.original[c] === ';' ? '' : ';');
code.appendLeft(c, suffix); code.appendLeft(c, suffix);
} }
}); });
@ -1234,7 +1234,7 @@ export default class Component {
} }
qualify(name) { qualify(name) {
if (name === `$$props`) return `ctx.$$props`; if (name === '$$props') return 'ctx.$$props';
const variable = this.var_lookup.get(name); const variable = this.var_lookup.get(name);
@ -1326,15 +1326,15 @@ function process_component_options(component: Component, nodes) {
switch (name) { switch (name) {
case 'tag': { case 'tag': {
const code = 'invalid-tag-attribute'; const code = 'invalid-tag-attribute';
const message = `'tag' must be a string literal`; const message = '\'tag\' must be a string literal';
const tag = get_value(attribute, code, message); const tag = get_value(attribute, code, message);
if (typeof tag !== 'string' && tag !== null) component.error(attribute, { code, message }); if (typeof tag !== 'string' && tag !== null) component.error(attribute, { code, message });
if (tag && !/^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/.test(tag)) { if (tag && !/^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/.test(tag)) {
component.error(attribute, { component.error(attribute, {
code: `invalid-tag-property`, code: 'invalid-tag-property',
message: `tag name must be two or more words joined by the '-' character` message: 'tag name must be two or more words joined by the \'-\' character'
}); });
} }
@ -1344,7 +1344,7 @@ function process_component_options(component: Component, nodes) {
case 'namespace': { case 'namespace': {
const code = 'invalid-namespace-attribute'; const code = 'invalid-namespace-attribute';
const message = `The 'namespace' attribute must be a string literal representing a valid namespace`; const message = 'The \'namespace\' attribute must be a string literal representing a valid namespace';
const ns = get_value(attribute, code, message); const ns = get_value(attribute, code, message);
if (typeof ns !== 'string') component.error(attribute, { code, message }); if (typeof ns !== 'string') component.error(attribute, { code, message });
@ -1353,12 +1353,12 @@ function process_component_options(component: Component, nodes) {
const match = fuzzymatch(ns, valid_namespaces); const match = fuzzymatch(ns, valid_namespaces);
if (match) { if (match) {
component.error(attribute, { component.error(attribute, {
code: `invalid-namespace-property`, code: 'invalid-namespace-property',
message: `Invalid namespace '${ns}' (did you mean '${match}'?)` message: `Invalid namespace '${ns}' (did you mean '${match}'?)`
}); });
} else { } else {
component.error(attribute, { component.error(attribute, {
code: `invalid-namespace-property`, code: 'invalid-namespace-property',
message: `Invalid namespace '${ns}'` message: `Invalid namespace '${ns}'`
}); });
} }
@ -1384,16 +1384,16 @@ function process_component_options(component: Component, nodes) {
default: default:
component.error(attribute, { component.error(attribute, {
code: `invalid-options-attribute`, code: 'invalid-options-attribute',
message: `<svelte:options> unknown attribute` message: '<svelte:options> unknown attribute'
}); });
} }
} }
else { else {
component.error(attribute, { component.error(attribute, {
code: `invalid-options-attribute`, code: 'invalid-options-attribute',
message: `<svelte:options> can only have static 'tag', 'namespace', 'accessors', 'immutable' and 'preserveWhitespace' attributes` message: '<svelte:options> can only have static \'tag\', \'namespace\', \'accessors\', \'immutable\' and \'preserveWhitespace\' attributes'
}); });
} }
}); });

@ -97,8 +97,8 @@ export default class Selector {
const selector = block.selectors[i]; const selector = block.selectors[i];
if (selector.type === 'PseudoClassSelector' && selector.name === 'global') { if (selector.type === 'PseudoClassSelector' && selector.name === 'global') {
component.error(selector, { component.error(selector, {
code: `css-invalid-global`, code: 'css-invalid-global',
message: `:global(...) must be the first element in a compound selector` message: ':global(...) must be the first element in a compound selector'
}); });
} }
} }
@ -118,8 +118,8 @@ export default class Selector {
for (let i = start; i < end; i += 1) { for (let i = start; i < end; i += 1) {
if (this.blocks[i].global) { if (this.blocks[i].global) {
component.error(this.blocks[i].selectors[0], { component.error(this.blocks[i].selectors[0], {
code: `css-invalid-global`, code: 'css-invalid-global',
message: `:global(...) can be at the start or end of a selector sequence, but not in the middle` message: ':global(...) can be at the start or end of a selector sequence, but not in the middle'
}); });
} }
} }

@ -400,8 +400,8 @@ export default class Stylesheet {
this.children.forEach(child => { this.children.forEach(child => {
child.warn_on_unused_selector((selector: Selector) => { child.warn_on_unused_selector((selector: Selector) => {
component.warn(selector.node, { component.warn(selector.node, {
code: `css-unused-selector`, code: 'css-unused-selector',
message: `Unused CSS selector` message: 'Unused CSS selector'
}); });
}); });
}); });

@ -46,9 +46,9 @@ function validate_options(options: CompileOptions, warnings: Warning[]) {
} }
if (name && /^[a-z]/.test(name)) { if (name && /^[a-z]/.test(name)) {
const message = `options.name should be capitalised`; const message = 'options.name should be capitalised';
warnings.push({ warnings.push({
code: `options-lowercase-name`, code: 'options-lowercase-name',
message, message,
filename, filename,
toString: () => message, toString: () => message,

@ -17,8 +17,8 @@ export default class Animation extends Node {
if (parent.animation) { if (parent.animation) {
component.error(this, { component.error(this, {
code: `duplicate-animation`, code: 'duplicate-animation',
message: `An element can only have one 'animate' directive` message: 'An element can only have one \'animate\' directive'
}); });
} }
@ -26,8 +26,8 @@ export default class Animation extends Node {
if (!block || block.type !== 'EachBlock' || !block.key) { if (!block || block.type !== 'EachBlock' || !block.key) {
// TODO can we relax the 'immediate child' rule? // TODO can we relax the 'immediate child' rule?
component.error(this, { component.error(this, {
code: `invalid-animation`, code: 'invalid-animation',
message: `An element that use the animate directive must be the immediate child of a keyed each block` message: 'An element that use the animate directive must be the immediate child of a keyed each block'
}); });
} }

@ -89,7 +89,7 @@ export default class Attribute extends Node {
get_value(block) { get_value(block) {
if (this.is_true) return true; if (this.is_true) return true;
if (this.chunks.length === 0) return `""`; if (this.chunks.length === 0) return '""';
if (this.chunks.length === 1) { if (this.chunks.length === 1) {
@ -99,7 +99,7 @@ export default class Attribute extends Node {
: this.chunks[0].render(block); : this.chunks[0].render(block);
} }
return (this.chunks[0].type === 'Text' ? '' : `"" + `) + return (this.chunks[0].type === 'Text' ? '' : '"" + ') +
this.chunks this.chunks
.map(chunk => { .map(chunk => {
if (chunk.type === 'Text') { if (chunk.type === 'Text') {

@ -3,7 +3,7 @@ import get_object from '../utils/get_object';
import Expression from './shared/Expression'; import Expression from './shared/Expression';
import Component from '../Component'; import Component from '../Component';
import TemplateScope from './shared/TemplateScope'; import TemplateScope from './shared/TemplateScope';
import {dimensions} from "../../utils/patterns"; import {dimensions} from '../../utils/patterns';
// TODO this should live in a specific binding // TODO this should live in a specific binding
const read_only_media_attributes = new Set([ const read_only_media_attributes = new Set([

@ -101,8 +101,8 @@ export default class EachBlock extends AbstractBlock {
if (this.children.length !== 1) { if (this.children.length !== 1) {
const child = this.children.find(child => !!(child as Element).animation); const child = this.children.find(child => !!(child as Element).animation);
component.error((child as Element).animation, { component.error((child as Element).animation, {
code: `invalid-animation`, code: 'invalid-animation',
message: `An element that use the animate directive must be the sole child of a keyed each block` message: 'An element that use the animate directive must be the sole child of a keyed each block'
}); });
} }
} }

@ -117,8 +117,8 @@ export default class Element extends Node {
const value_attribute = info.attributes.find(node => node.name === 'value'); const value_attribute = info.attributes.find(node => node.name === 'value');
if (value_attribute) { if (value_attribute) {
component.error(value_attribute, { component.error(value_attribute, {
code: `textarea-duplicate-value`, code: 'textarea-duplicate-value',
message: `A <textarea> can have either a value attribute or (equivalently) child content, but not both` message: 'A <textarea> can have either a value attribute or (equivalently) child content, but not both'
}); });
} }
@ -222,7 +222,7 @@ export default class Element extends Node {
if (a11y_distracting_elements.has(this.name)) { if (a11y_distracting_elements.has(this.name)) {
// no-distracting-elements // no-distracting-elements
this.component.warn(this, { this.component.warn(this, {
code: `a11y-distracting-elements`, code: 'a11y-distracting-elements',
message: `A11y: Avoid <${this.name}> elements` message: `A11y: Avoid <${this.name}> elements`
}); });
} }
@ -244,8 +244,8 @@ export default class Element extends Node {
if (!is_figure_parent) { if (!is_figure_parent) {
this.component.warn(this, { this.component.warn(this, {
code: `a11y-structure`, code: 'a11y-structure',
message: `A11y: <figcaption> must be an immediate child of <figure>` message: 'A11y: <figcaption> must be an immediate child of <figure>'
}); });
} }
} }
@ -261,8 +261,8 @@ export default class Element extends Node {
if (index !== -1 && (index !== 0 && index !== children.length - 1)) { if (index !== -1 && (index !== 0 && index !== children.length - 1)) {
this.component.warn(children[index], { this.component.warn(children[index], {
code: `a11y-structure`, code: 'a11y-structure',
message: `A11y: <figcaption> must be first or last child of <figure>` message: 'A11y: <figcaption> must be first or last child of <figure>'
}); });
} }
} }
@ -288,7 +288,7 @@ export default class Element extends Node {
if (invisible_elements.has(this.name)) { if (invisible_elements.has(this.name)) {
// aria-unsupported-elements // aria-unsupported-elements
component.warn(attribute, { component.warn(attribute, {
code: `a11y-aria-attributes`, code: 'a11y-aria-attributes',
message: `A11y: <${this.name}> should not have aria-* attributes` message: `A11y: <${this.name}> should not have aria-* attributes`
}); });
} }
@ -300,14 +300,14 @@ export default class Element extends Node {
if (match) message += ` (did you mean '${match}'?)`; if (match) message += ` (did you mean '${match}'?)`;
component.warn(attribute, { component.warn(attribute, {
code: `a11y-unknown-aria-attribute`, code: 'a11y-unknown-aria-attribute',
message message
}); });
} }
if (name === 'aria-hidden' && /^h[1-6]$/.test(this.name)) { if (name === 'aria-hidden' && /^h[1-6]$/.test(this.name)) {
component.warn(attribute, { component.warn(attribute, {
code: `a11y-hidden`, code: 'a11y-hidden',
message: `A11y: <${this.name}> element should not be hidden` message: `A11y: <${this.name}> element should not be hidden`
}); });
} }
@ -318,7 +318,7 @@ export default class Element extends Node {
if (invisible_elements.has(this.name)) { if (invisible_elements.has(this.name)) {
// aria-unsupported-elements // aria-unsupported-elements
component.warn(attribute, { component.warn(attribute, {
code: `a11y-misplaced-role`, code: 'a11y-misplaced-role',
message: `A11y: <${this.name}> should not have role attribute` message: `A11y: <${this.name}> should not have role attribute`
}); });
} }
@ -332,7 +332,7 @@ export default class Element extends Node {
if (match) message += ` (did you mean '${match}'?)`; if (match) message += ` (did you mean '${match}'?)`;
component.warn(attribute, { component.warn(attribute, {
code: `a11y-unknown-role`, code: 'a11y-unknown-role',
message message
}); });
} }
@ -341,24 +341,24 @@ export default class Element extends Node {
// no-access-key // no-access-key
if (name === 'accesskey') { if (name === 'accesskey') {
component.warn(attribute, { component.warn(attribute, {
code: `a11y-accesskey`, code: 'a11y-accesskey',
message: `A11y: Avoid using accesskey` message: 'A11y: Avoid using accesskey'
}); });
} }
// no-autofocus // no-autofocus
if (name === 'autofocus') { if (name === 'autofocus') {
component.warn(attribute, { component.warn(attribute, {
code: `a11y-autofocus`, code: 'a11y-autofocus',
message: `A11y: Avoid using autofocus` message: 'A11y: Avoid using autofocus'
}); });
} }
// scope // scope
if (name === 'scope' && this.name !== 'th') { if (name === 'scope' && this.name !== 'th') {
component.warn(attribute, { component.warn(attribute, {
code: `a11y-misplaced-scope`, code: 'a11y-misplaced-scope',
message: `A11y: The scope attribute should only be used with <th> elements` message: 'A11y: The scope attribute should only be used with <th> elements'
}); });
} }
@ -368,8 +368,8 @@ export default class Element extends Node {
// @ts-ignore todo is tabindex=true correct case? // @ts-ignore todo is tabindex=true correct case?
if (!isNaN(value) && +value > 0) { if (!isNaN(value) && +value > 0) {
component.warn(attribute, { component.warn(attribute, {
code: `a11y-positive-tabindex`, code: 'a11y-positive-tabindex',
message: `A11y: avoid tabindex values above zero` message: 'A11y: avoid tabindex values above zero'
}); });
} }
} }
@ -377,14 +377,14 @@ export default class Element extends Node {
if (name === 'slot') { if (name === 'slot') {
if (!attribute.is_static) { if (!attribute.is_static) {
component.error(attribute, { component.error(attribute, {
code: `invalid-slot-attribute`, code: 'invalid-slot-attribute',
message: `slot attribute cannot have a dynamic value` message: 'slot attribute cannot have a dynamic value'
}); });
} }
if (component.slot_outlets.has(name)) { if (component.slot_outlets.has(name)) {
component.error(attribute, { component.error(attribute, {
code: `duplicate-slot-attribute`, code: 'duplicate-slot-attribute',
message: `Duplicate '${name}' slot` message: `Duplicate '${name}' slot`
}); });
@ -401,7 +401,7 @@ export default class Element extends Node {
const message = `Cannot place slotted elements inside an ${type}-block`; const message = `Cannot place slotted elements inside an ${type}-block`;
component.error(attribute, { component.error(attribute, {
code: `invalid-slotted-content`, code: 'invalid-slotted-content',
message message
}); });
} }
@ -409,8 +409,8 @@ export default class Element extends Node {
if (!ancestor) { if (!ancestor) {
component.error(attribute, { component.error(attribute, {
code: `invalid-slotted-content`, code: 'invalid-slotted-content',
message: `Element with a slot='...' attribute must be a descendant of a component or custom element` message: 'Element with a slot=\'...\' attribute must be a descendant of a component or custom element'
}); });
} }
} }
@ -427,14 +427,14 @@ export default class Element extends Node {
if (value === '' || value === '#') { if (value === '' || value === '#') {
component.warn(attribute, { component.warn(attribute, {
code: `a11y-invalid-attribute`, code: 'a11y-invalid-attribute',
message: `A11y: '${value}' is not a valid ${attribute.name} attribute` message: `A11y: '${value}' is not a valid ${attribute.name} attribute`
}); });
} }
} else { } else {
component.warn(this, { component.warn(this, {
code: `a11y-missing-attribute`, code: 'a11y-missing-attribute',
message: `A11y: <a> element should have an href attribute` message: 'A11y: <a> element should have an href attribute'
}); });
} }
} }
@ -475,8 +475,8 @@ export default class Element extends Node {
if (!attribute.is_static) { if (!attribute.is_static) {
component.error(attribute, { component.error(attribute, {
code: `invalid-type`, code: 'invalid-type',
message: `'type' attribute cannot be dynamic if input uses two-way binding` message: '\'type\' attribute cannot be dynamic if input uses two-way binding'
}); });
} }
@ -484,8 +484,8 @@ export default class Element extends Node {
if (value === true) { if (value === true) {
component.error(attribute, { component.error(attribute, {
code: `missing-type`, code: 'missing-type',
message: `'type' attribute must be specified` message: '\'type\' attribute must be specified'
}); });
} }
@ -502,7 +502,7 @@ export default class Element extends Node {
this.name !== 'select' this.name !== 'select'
) { ) {
component.error(binding, { component.error(binding, {
code: `invalid-binding`, code: 'invalid-binding',
message: `'value' is not a valid binding on <${this.name}> elements` message: `'value' is not a valid binding on <${this.name}> elements`
}); });
} }
@ -514,8 +514,8 @@ export default class Element extends Node {
if (attribute && !attribute.is_static) { if (attribute && !attribute.is_static) {
component.error(attribute, { component.error(attribute, {
code: `dynamic-multiple-attribute`, code: 'dynamic-multiple-attribute',
message: `'multiple' attribute cannot be dynamic if select uses two-way binding` message: '\'multiple\' attribute cannot be dynamic if select uses two-way binding'
}); });
} }
} else { } else {
@ -524,7 +524,7 @@ export default class Element extends Node {
} else if (name === 'checked' || name === 'indeterminate') { } else if (name === 'checked' || name === 'indeterminate') {
if (this.name !== 'input') { if (this.name !== 'input') {
component.error(binding, { component.error(binding, {
code: `invalid-binding`, code: 'invalid-binding',
message: `'${name}' is not a valid binding on <${this.name}> elements` message: `'${name}' is not a valid binding on <${this.name}> elements`
}); });
} }
@ -533,13 +533,13 @@ export default class Element extends Node {
if (type !== 'checkbox') { if (type !== 'checkbox') {
let message = `'${name}' binding can only be used with <input type="checkbox">`; let message = `'${name}' binding can only be used with <input type="checkbox">`;
if (type === 'radio') message += ` — for <input type="radio">, use 'group' binding`; if (type === 'radio') message += ' — for <input type="radio">, use \'group\' binding';
component.error(binding, { code: `invalid-binding`, message }); component.error(binding, { code: 'invalid-binding', message });
} }
} else if (name === 'group') { } else if (name === 'group') {
if (this.name !== 'input') { if (this.name !== 'input') {
component.error(binding, { component.error(binding, {
code: `invalid-binding`, code: 'invalid-binding',
message: `'group' is not a valid binding on <${this.name}> elements` message: `'group' is not a valid binding on <${this.name}> elements`
}); });
} }
@ -548,14 +548,14 @@ export default class Element extends Node {
if (type !== 'checkbox' && type !== 'radio') { if (type !== 'checkbox' && type !== 'radio') {
component.error(binding, { component.error(binding, {
code: `invalid-binding`, code: 'invalid-binding',
message: `'group' binding can only be used with <input type="checkbox"> or <input type="radio">` message: '\'group\' binding can only be used with <input type="checkbox"> or <input type="radio">'
}); });
} }
} else if (name === 'files') { } else if (name === 'files') {
if (this.name !== 'input') { if (this.name !== 'input') {
component.error(binding, { component.error(binding, {
code: `invalid-binding`, code: 'invalid-binding',
message: `'files' is not a valid binding on <${this.name}> elements` message: `'files' is not a valid binding on <${this.name}> elements`
}); });
} }
@ -564,15 +564,15 @@ export default class Element extends Node {
if (type !== 'file') { if (type !== 'file') {
component.error(binding, { component.error(binding, {
code: `invalid-binding`, code: 'invalid-binding',
message: `'files' binding can only be used with <input type="file">` message: '\'files\' binding can only be used with <input type="file">'
}); });
} }
} else if (name === 'open') { } else if (name === 'open') {
if (this.name !== 'details') { if (this.name !== 'details') {
component.error(binding, { component.error(binding, {
code: `invalid-binding`, code: 'invalid-binding',
message: `'${name}' binding can only be used with <details>` message: `'${name}' binding can only be used with <details>`
}); });
} }
@ -588,7 +588,7 @@ export default class Element extends Node {
) { ) {
if (this.name !== 'audio' && this.name !== 'video') { if (this.name !== 'audio' && this.name !== 'video') {
component.error(binding, { component.error(binding, {
code: `invalid-binding`, code: 'invalid-binding',
message: `'${name}' binding can only be used with <audio> or <video>` message: `'${name}' binding can only be used with <audio> or <video>`
}); });
} }
@ -619,18 +619,18 @@ export default class Element extends Node {
if (!contenteditable) { if (!contenteditable) {
component.error(binding, { component.error(binding, {
code: `missing-contenteditable-attribute`, code: 'missing-contenteditable-attribute',
message: `'contenteditable' attribute is required for textContent and innerHTML two-way bindings` message: '\'contenteditable\' attribute is required for textContent and innerHTML two-way bindings'
}); });
} else if (contenteditable && !contenteditable.is_static) { } else if (contenteditable && !contenteditable.is_static) {
component.error(contenteditable, { component.error(contenteditable, {
code: `dynamic-contenteditable-attribute`, code: 'dynamic-contenteditable-attribute',
message: `'contenteditable' attribute cannot be dynamic if element uses two-way binding` message: '\'contenteditable\' attribute cannot be dynamic if element uses two-way binding'
}); });
} }
} else if (name !== 'this') { } else if (name !== 'this') {
component.error(binding, { component.error(binding, {
code: `invalid-binding`, code: 'invalid-binding',
message: `'${binding.name}' is not a valid binding` message: `'${binding.name}' is not a valid binding`
}); });
} }
@ -642,7 +642,7 @@ export default class Element extends Node {
if (this.children.length === 0) { if (this.children.length === 0) {
this.component.warn(this, { this.component.warn(this, {
code: `a11y-missing-content`, code: 'a11y-missing-content',
message: `A11y: <${this.name}> element should have child content` message: `A11y: <${this.name}> element should have child content`
}); });
} }
@ -655,7 +655,7 @@ export default class Element extends Node {
if (handler.modifiers.has('passive') && handler.modifiers.has('preventDefault')) { if (handler.modifiers.has('passive') && handler.modifiers.has('preventDefault')) {
component.error(handler, { component.error(handler, {
code: 'invalid-event-modifier', code: 'invalid-event-modifier',
message: `The 'passive' and 'preventDefault' modifiers cannot be used together` message: 'The \'passive\' and \'preventDefault\' modifiers cannot be used together'
}); });
} }
@ -672,13 +672,13 @@ export default class Element extends Node {
if (handler.can_make_passive) { if (handler.can_make_passive) {
component.warn(handler, { component.warn(handler, {
code: 'redundant-event-modifier', code: 'redundant-event-modifier',
message: `Touch event handlers that don't use the 'event' object are passive by default` message: 'Touch event handlers that don\'t use the \'event\' object are passive by default'
}); });
} }
} else { } else {
component.warn(handler, { component.warn(handler, {
code: 'redundant-event-modifier', code: 'redundant-event-modifier',
message: `The passive modifier only works with wheel and touch events` message: 'The passive modifier only works with wheel and touch events'
}); });
} }
} }
@ -744,7 +744,7 @@ function should_have_attribute(
attributes[0]; attributes[0];
node.component.warn(node, { node.component.warn(node, {
code: `a11y-missing-attribute`, code: 'a11y-missing-attribute',
message: `A11y: <${name}> element should have ${article} ${sequence} attribute` message: `A11y: <${name}> element should have ${article} ${sequence} attribute`
}); });
} }

@ -10,8 +10,8 @@ export default class Head extends Node {
if (info.attributes.length) { if (info.attributes.length) {
component.error(info.attributes[0], { component.error(info.attributes[0], {
code: `invalid-attribute`, code: 'invalid-attribute',
message: `<svelte:head> should not have any attributes or directives` message: '<svelte:head> should not have any attributes or directives'
}); });
} }

@ -40,15 +40,15 @@ export default class InlineComponent extends Node {
switch (node.type) { switch (node.type) {
case 'Action': case 'Action':
component.error(node, { component.error(node, {
code: `invalid-action`, code: 'invalid-action',
message: `Actions can only be applied to DOM elements, not components` message: 'Actions can only be applied to DOM elements, not components'
}); });
case 'Attribute': case 'Attribute':
if (node.name === 'slot') { if (node.name === 'slot') {
component.error(node, { component.error(node, {
code: `invalid-prop`, code: 'invalid-prop',
message: `'slot' is reserved for future use in named slots` message: '\'slot\' is reserved for future use in named slots'
}); });
} }
// fallthrough // fallthrough
@ -62,8 +62,8 @@ export default class InlineComponent extends Node {
case 'Class': case 'Class':
component.error(node, { component.error(node, {
code: `invalid-class`, code: 'invalid-class',
message: `Classes can only be applied to DOM elements, not components` message: 'Classes can only be applied to DOM elements, not components'
}); });
case 'EventHandler': case 'EventHandler':
@ -76,8 +76,8 @@ export default class InlineComponent extends Node {
case 'Transition': case 'Transition':
component.error(node, { component.error(node, {
code: `invalid-transition`, code: 'invalid-transition',
message: `Transitions can only be applied to DOM elements, not components` message: 'Transitions can only be applied to DOM elements, not components'
}); });
default: default:
@ -105,7 +105,7 @@ export default class InlineComponent extends Node {
if (modifier !== 'once') { if (modifier !== 'once') {
component.error(handler, { component.error(handler, {
code: 'invalid-event-modifier', code: 'invalid-event-modifier',
message: `Event modifiers other than 'once' can only be used on DOM elements` message: 'Event modifiers other than \'once\' can only be used on DOM elements'
}); });
} }
}); });

@ -22,7 +22,7 @@ export default class Let extends Node {
if (!applicable.has(node.type)) { if (!applicable.has(node.type)) {
component.error(node, { component.error(node, {
code: 'invalid-let', code: 'invalid-let',
message: `let directive value must be an identifier or an object/array pattern` message: 'let directive value must be an identifier or an object/array pattern'
}); });
} }

@ -17,24 +17,24 @@ export default class Slot extends Element {
info.attributes.forEach(attr => { info.attributes.forEach(attr => {
if (attr.type !== 'Attribute') { if (attr.type !== 'Attribute') {
component.error(attr, { component.error(attr, {
code: `invalid-slot-directive`, code: 'invalid-slot-directive',
message: `<slot> cannot have directives` message: '<slot> cannot have directives'
}); });
} }
if (attr.name === 'name') { if (attr.name === 'name') {
if (attr.value.length !== 1 || attr.value[0].type !== 'Text') { if (attr.value.length !== 1 || attr.value[0].type !== 'Text') {
component.error(attr, { component.error(attr, {
code: `dynamic-slot-name`, code: 'dynamic-slot-name',
message: `<slot> name cannot be dynamic` message: '<slot> name cannot be dynamic'
}); });
} }
this.slot_name = attr.value[0].data; this.slot_name = attr.value[0].data;
if (this.slot_name === 'default') { if (this.slot_name === 'default') {
component.error(attr, { component.error(attr, {
code: `invalid-slot-name`, code: 'invalid-slot-name',
message: `default is a reserved word — it cannot be used as a slot name` message: 'default is a reserved word — it cannot be used as a slot name'
}); });
} }
} }

@ -13,8 +13,8 @@ export default class Title extends Node {
if (info.attributes.length > 0) { if (info.attributes.length > 0) {
component.error(info.attributes[0], { component.error(info.attributes[0], {
code: `illegal-attribute`, code: 'illegal-attribute',
message: `<title> cannot have attributes` message: '<title> cannot have attributes'
}); });
} }
@ -22,7 +22,7 @@ export default class Title extends Node {
if (child.type !== 'Text' && child.type !== 'MustacheTag') { if (child.type !== 'Text' && child.type !== 'MustacheTag') {
component.error(child, { component.error(child, {
code: 'illegal-structure', code: 'illegal-structure',
message: `<title> can only contain text and {tags}` message: '<title> can only contain text and {tags}'
}); });
} }
}); });

@ -28,7 +28,7 @@ export default class Transition extends Node {
: `An element cannot have both ${describe(parent_transition)} directive and ${describe(this)} directive`; : `An element cannot have both ${describe(parent_transition)} directive and ${describe(this)} directive`;
component.error(info, { component.error(info, {
code: `duplicate-transition`, code: 'duplicate-transition',
message message
}); });
} }
@ -41,6 +41,6 @@ export default class Transition extends Node {
function describe(transition: Transition) { function describe(transition: Transition) {
return transition.directive === 'transition' return transition.directive === 'transition'
? `a 'transition'` ? 'a \'transition\''
: `an '${transition.directive}'`; : `an '${transition.directive}'`;
} }

@ -36,7 +36,7 @@ export default class Window extends Node {
// TODO is this constraint necessary? // TODO is this constraint necessary?
component.error(node.expression, { component.error(node.expression, {
code: `invalid-binding`, code: 'invalid-binding',
message: `Bindings on <svelte:window> must be to top-level properties, e.g. '${parts[parts.length - 1]}' rather than '${parts.join('.')}'` message: `Bindings on <svelte:window> must be to top-level properties, e.g. '${parts[parts.length - 1]}' rather than '${parts.join('.')}'`
}); });
} }
@ -52,12 +52,12 @@ export default class Window extends Node {
if (match) { if (match) {
component.error(node, { component.error(node, {
code: `invalid-binding`, code: 'invalid-binding',
message: `${message} (did you mean '${match}'?)` message: `${message} (did you mean '${match}'?)`
}); });
} else { } else {
component.error(node, { component.error(node, {
code: `invalid-binding`, code: 'invalid-binding',
message: `${message} — valid bindings are ${list(valid_bindings)}` message: `${message} — valid bindings are ${list(valid_bindings)}`
}); });
} }

@ -132,8 +132,8 @@ export default class Expression {
if (name[0] === '$' && template_scope.names.has(name.slice(1))) { if (name[0] === '$' && template_scope.names.has(name.slice(1))) {
component.error(node, { component.error(node, {
code: `contextual-store`, code: 'contextual-store',
message: `Stores must be declared at the top level of the component (this may change in a future version of Svelte)` message: 'Stores must be declared at the top level of the component (this may change in a future version of Svelte)'
}); });
} }
@ -309,7 +309,7 @@ export default class Expression {
if (pending_assignments.size > 0) { if (pending_assignments.size > 0) {
if (node.type !== 'ArrowFunctionExpression') { if (node.type !== 'ArrowFunctionExpression') {
// this should never happen! // this should never happen!
throw new Error(`Well that's odd`); throw new Error('Well that\'s odd');
} }
// TOOD optimisation — if this is an event handler, // TOOD optimisation — if this is an event handler,
@ -463,7 +463,7 @@ export default class Expression {
if (/^(Break|Continue|Return)Statement/.test(node.type)) { if (/^(Break|Continue|Return)Statement/.test(node.type)) {
if (node.argument) { if (node.argument) {
code.overwrite(node.start, node.argument.start, `var $$result = `); code.overwrite(node.start, node.argument.start, 'var $$result = ');
code.appendLeft(node.end, `${insert}; return $$result`); code.appendLeft(node.end, `${insert}; return $$result`);
} else { } else {
code.prependRight(node.start, `${insert}; `); code.prependRight(node.start, `${insert}; `);

@ -220,12 +220,12 @@ export default class Block {
this.add_variable('#current'); this.add_variable('#current');
if (!this.builders.intro.is_empty()) { if (!this.builders.intro.is_empty()) {
this.builders.intro.add_line(`#current = true;`); this.builders.intro.add_line('#current = true;');
this.builders.mount.add_line(`#current = true;`); this.builders.mount.add_line('#current = true;');
} }
if (!this.builders.outro.is_empty()) { if (!this.builders.outro.is_empty()) {
this.builders.outro.add_line(`#current = false;`); this.builders.outro.add_line('#current = false;');
} }
} }
@ -244,16 +244,16 @@ export default class Block {
} }
if (this.first) { if (this.first) {
properties.add_block(`first: null,`); properties.add_block('first: null,');
this.builders.hydrate.add_line(`this.first = ${this.first};`); this.builders.hydrate.add_line(`this.first = ${this.first};`);
} }
if (this.builders.create.is_empty() && this.builders.hydrate.is_empty()) { if (this.builders.create.is_empty() && this.builders.hydrate.is_empty()) {
properties.add_line(`c: @noop,`); properties.add_line('c: @noop,');
} else { } else {
const hydrate = !this.builders.hydrate.is_empty() && ( const hydrate = !this.builders.hydrate.is_empty() && (
this.renderer.options.hydratable this.renderer.options.hydratable
? `this.h()` ? 'this.h()'
: this.builders.hydrate : this.builders.hydrate
); );
@ -267,12 +267,12 @@ export default class Block {
if (this.renderer.options.hydratable || !this.builders.claim.is_empty()) { if (this.renderer.options.hydratable || !this.builders.claim.is_empty()) {
if (this.builders.claim.is_empty() && this.builders.hydrate.is_empty()) { if (this.builders.claim.is_empty() && this.builders.hydrate.is_empty()) {
properties.add_line(`l: @noop,`); properties.add_line('l: @noop,');
} else { } else {
properties.add_block(deindent` properties.add_block(deindent`
${method_name('l', 'claim')}(nodes) { ${method_name('l', 'claim')}(nodes) {
${this.builders.claim} ${this.builders.claim}
${this.renderer.options.hydratable && !this.builders.hydrate.is_empty() && `this.h();`} ${this.renderer.options.hydratable && !this.builders.hydrate.is_empty() && 'this.h();'}
}, },
`); `);
} }
@ -287,7 +287,7 @@ export default class Block {
} }
if (this.builders.mount.is_empty()) { if (this.builders.mount.is_empty()) {
properties.add_line(`m: @noop,`); properties.add_line('m: @noop,');
} else { } else {
properties.add_block(deindent` properties.add_block(deindent`
${method_name('m', 'mount')}(#target, anchor) { ${method_name('m', 'mount')}(#target, anchor) {
@ -298,11 +298,11 @@ export default class Block {
if (this.has_update_method || this.maintain_context) { if (this.has_update_method || this.maintain_context) {
if (this.builders.update.is_empty() && !this.maintain_context) { if (this.builders.update.is_empty() && !this.maintain_context) {
properties.add_line(`p: @noop,`); properties.add_line('p: @noop,');
} else { } else {
properties.add_block(deindent` properties.add_block(deindent`
${method_name('p', 'update')}(changed, ${this.maintain_context ? 'new_ctx' : 'ctx'}) { ${method_name('p', 'update')}(changed, ${this.maintain_context ? 'new_ctx' : 'ctx'}) {
${this.maintain_context && `ctx = new_ctx;`} ${this.maintain_context && 'ctx = new_ctx;'}
${this.builders.update} ${this.builders.update}
}, },
`); `);
@ -327,18 +327,18 @@ export default class Block {
if (this.has_intro_method || this.has_outro_method) { if (this.has_intro_method || this.has_outro_method) {
if (this.builders.intro.is_empty()) { if (this.builders.intro.is_empty()) {
properties.add_line(`i: @noop,`); properties.add_line('i: @noop,');
} else { } else {
properties.add_block(deindent` properties.add_block(deindent`
${method_name('i', 'intro')}(#local) { ${method_name('i', 'intro')}(#local) {
${this.has_outros && `if (#current) return;`} ${this.has_outros && 'if (#current) return;'}
${this.builders.intro} ${this.builders.intro}
}, },
`); `);
} }
if (this.builders.outro.is_empty()) { if (this.builders.outro.is_empty()) {
properties.add_line(`o: @noop,`); properties.add_line('o: @noop,');
} else { } else {
properties.add_block(deindent` properties.add_block(deindent`
${method_name('o', 'outro')}(#local) { ${method_name('o', 'outro')}(#local) {
@ -349,7 +349,7 @@ export default class Block {
} }
if (this.builders.destroy.is_empty()) { if (this.builders.destroy.is_empty()) {
properties.add_line(`d: @noop`); properties.add_line('d: @noop');
} else { } else {
properties.add_block(deindent` properties.add_block(deindent`
${method_name('d', 'destroy')}(detaching) { ${method_name('d', 'destroy')}(detaching) {

@ -23,7 +23,7 @@ export default function dom(
block.has_outro_method = true; block.has_outro_method = true;
// prevent fragment being created twice (#1063) // prevent fragment being created twice (#1063)
if (options.customElement) block.builders.create.add_line(`this.c = @noop;`); if (options.customElement) block.builders.create.add_line('this.c = @noop;');
const builder = new CodeBuilder(); const builder = new CodeBuilder();
@ -72,7 +72,7 @@ export default function dom(
); );
const uses_props = component.var_lookup.has('$$props'); const uses_props = component.var_lookup.has('$$props');
const $$props = uses_props ? `$$new_props` : `$$props`; const $$props = uses_props ? '$$new_props' : '$$props';
const props = component.vars.filter(variable => !variable.module && variable.export_name); const props = component.vars.filter(variable => !variable.module && variable.export_name);
const writable_props = props.filter(variable => variable.writable); const writable_props = props.filter(variable => variable.writable);
@ -80,7 +80,7 @@ export default function dom(
const set = (uses_props || writable_props.length > 0 || component.slots.size > 0) const set = (uses_props || writable_props.length > 0 || component.slots.size > 0)
? deindent` ? deindent`
${$$props} => { ${$$props} => {
${uses_props && component.invalidate('$$props', `$$props = @assign(@assign({}, $$props), $$new_props)`)} ${uses_props && component.invalidate('$$props', '$$props = @assign(@assign({}, $$props), $$new_props)')}
${writable_props.map(prop => ${writable_props.map(prop =>
`if ('${prop.export_name}' in ${$$props}) ${component.invalidate(prop.name, `${prop.name} = ${$$props}.${prop.export_name}`)};` `if ('${prop.export_name}' in ${$$props}) ${component.invalidate(prop.name, `${prop.name} = ${$$props}.${prop.export_name}`)};`
)} )}
@ -93,7 +93,7 @@ export default function dom(
const body = []; const body = [];
const not_equal = component.component_options.immutable ? `@not_equal` : `@safe_not_equal`; const not_equal = component.component_options.immutable ? '@not_equal' : '@safe_not_equal';
let dev_props_check; let dev_props_check;
props.forEach(x => { props.forEach(x => {
@ -144,7 +144,7 @@ export default function dom(
if (expected.length) { if (expected.length) {
dev_props_check = deindent` dev_props_check = deindent`
const { ctx } = this.$$; const { ctx } = this.$$;
const props = ${options.customElement ? `this.attributes` : `options.props || {}`}; const props = ${options.customElement ? 'this.attributes' : 'options.props || {}'};
${expected.map(prop => deindent` ${expected.map(prop => deindent`
if (ctx.${prop.name} === undefined && !('${prop.export_name}' in props)) { if (ctx.${prop.name} === undefined && !('${prop.export_name}' in props)) {
@_console.warn("<${component.tag}> was created without expected prop '${prop.export_name}'"); @_console.warn("<${component.tag}> was created without expected prop '${prop.export_name}'");
@ -209,7 +209,7 @@ export default function dom(
if (single && !(variable.subscribable && variable.reassigned)) { if (single && !(variable.subscribable && variable.reassigned)) {
if (variable.referenced || variable.is_reactive_dependency || variable.export_name) { if (variable.referenced || variable.is_reactive_dependency || variable.export_name) {
code.prependRight(node.start, `$$invalidate('${name}', `); code.prependRight(node.start, `$$invalidate('${name}', `);
code.appendLeft(node.end, `)`); code.appendLeft(node.end, ')');
} }
} else { } else {
pending_assignments.add(name); pending_assignments.add(name);
@ -225,7 +225,7 @@ export default function dom(
const insert = Array.from(pending_assignments).map(name => component.invalidate(name)).join('; '); const insert = Array.from(pending_assignments).map(name => component.invalidate(name)).join('; ');
pending_assignments = new Set(); pending_assignments = new Set();
code.prependRight(node.body.start, `{ const $$result = `); code.prependRight(node.body.start, '{ const $$result = ');
code.appendLeft(node.body.end, `; ${insert}; return $$result; }`); code.appendLeft(node.body.end, `; ${insert}; return $$result; }`);
pending_assignments = new Set(); pending_assignments = new Set();
@ -236,7 +236,7 @@ export default function dom(
if (/^(Break|Continue|Return)Statement/.test(node.type)) { if (/^(Break|Continue|Return)Statement/.test(node.type)) {
if (node.argument) { if (node.argument) {
code.overwrite(node.start, node.argument.start, `var $$result = `); code.overwrite(node.start, node.argument.start, 'var $$result = ');
code.appendLeft(node.argument.end, `; ${insert}; return $$result`); code.appendLeft(node.argument.end, `; ${insert}; return $$result`);
} else { } else {
code.prependRight(node.start, `${insert}; `); code.prependRight(node.start, `${insert}; `);
@ -255,7 +255,7 @@ export default function dom(
}); });
if (pending_assignments.size > 0) { if (pending_assignments.size > 0) {
throw new Error(`TODO this should not happen!`); throw new Error('TODO this should not happen!');
} }
component.rewrite_props(({ name, reassigned }) => { component.rewrite_props(({ name, reassigned }) => {
@ -315,7 +315,7 @@ export default function dom(
} }
if (renderer.binding_groups.length > 0) { if (renderer.binding_groups.length > 0) {
filtered_declarations.push(`$$binding_groups`); filtered_declarations.push('$$binding_groups');
} }
const has_definition = ( const has_definition = (
@ -418,9 +418,9 @@ export default function dom(
${unknown_props_check} ${unknown_props_check}
${component.slots.size && `let { $$slots = {}, $$scope } = $$props;`} ${component.slots.size && 'let { $$slots = {}, $$scope } = $$props;'}
${renderer.binding_groups.length > 0 && `const $$binding_groups = [${renderer.binding_groups.map(_ => `[]`).join(', ')}];`} ${renderer.binding_groups.length > 0 && `const $$binding_groups = [${renderer.binding_groups.map(_ => '[]').join(', ')}];`}
${component.partly_hoisted.length > 0 && component.partly_hoisted.join('\n\n')} ${component.partly_hoisted.length > 0 && component.partly_hoisted.join('\n\n')}
@ -488,7 +488,7 @@ export default function dom(
builder.add_block(deindent` builder.add_block(deindent`
class ${name} extends @${superclass} { class ${name} extends @${superclass} {
constructor(options) { constructor(options) {
super(${options.dev && `options`}); super(${options.dev && 'options'});
${should_add_css && `if (!@_document.getElementById("${component.stylesheet.id}-style")) ${add_css}();`} ${should_add_css && `if (!@_document.getElementById("${component.stylesheet.id}-style")) ${add_css}();`}
@init(this, options, ${definition}, create_fragment, ${not_equal}, ${prop_names}); @init(this, options, ${definition}, create_fragment, ${not_equal}, ${prop_names});

@ -127,8 +127,8 @@ export default class AwaitBlockWrapper extends Wrapper {
const snippet = this.node.expression.render(block); const snippet = this.node.expression.render(block);
const info = block.get_unique_name(`info`); const info = block.get_unique_name('info');
const promise = block.get_unique_name(`promise`); const promise = block.get_unique_name('promise');
block.add_variable(promise); block.add_variable(promise);
@ -143,7 +143,7 @@ export default class AwaitBlockWrapper extends Wrapper {
this.catch.block.name && `catch: ${this.catch.block.name}`, this.catch.block.name && `catch: ${this.catch.block.name}`,
this.then.block.name && `value: '${this.node.value}'`, this.then.block.name && `value: '${this.node.value}'`,
this.catch.block.name && `error: '${this.node.error}'`, this.catch.block.name && `error: '${this.node.error}'`,
this.pending.block.has_outro_method && `blocks: [,,,]` this.pending.block.has_outro_method && 'blocks: [,,,]'
].filter(Boolean); ].filter(Boolean);
block.builders.init.add_block(deindent` block.builders.init.add_block(deindent`

@ -28,7 +28,7 @@ export class ElseBlockWrapper extends Wrapper {
this.block = block.child({ this.block = block.child({
comment: create_debugging_comment(node, this.renderer.component), comment: create_debugging_comment(node, this.renderer.component),
name: this.renderer.component.get_unique_name(`create_else_block`) name: this.renderer.component.get_unique_name('create_else_block')
}); });
this.fragment = new FragmentWrapper( this.fragment = new FragmentWrapper(
@ -221,8 +221,8 @@ export default class EachBlockWrapper extends Wrapper {
if (needs_anchor) { if (needs_anchor) {
block.add_element( block.add_element(
update_anchor_node, update_anchor_node,
`@empty()`, '@empty()',
parent_nodes && `@empty()`, parent_nodes && '@empty()',
parent_node parent_node
); );
} }
@ -316,7 +316,7 @@ export default class EachBlockWrapper extends Wrapper {
const lookup = block.get_unique_name(`${this.var}_lookup`); const lookup = block.get_unique_name(`${this.var}_lookup`);
block.add_variable(iterations, '[]'); block.add_variable(iterations, '[]');
block.add_variable(lookup, `new @_Map()`); block.add_variable(lookup, 'new @_Map()');
if (this.fragment.nodes[0].is_dom_node()) { if (this.fragment.nodes[0].is_dom_node()) {
this.block.first = this.fragment.nodes[0].var; this.block.first = this.fragment.nodes[0].var;
@ -324,8 +324,8 @@ export default class EachBlockWrapper extends Wrapper {
this.block.first = this.block.get_unique_name('first'); this.block.first = this.block.get_unique_name('first');
this.block.add_element( this.block.add_element(
this.block.first, this.block.first,
`@empty()`, '@empty()',
parent_nodes && `@empty()`, parent_nodes && '@empty()',
null null
); );
} }
@ -360,20 +360,20 @@ export default class EachBlockWrapper extends Wrapper {
const destroy = this.node.has_animation const destroy = this.node.has_animation
? (this.block.has_outros ? (this.block.has_outros
? `@fix_and_outro_and_destroy_block` ? '@fix_and_outro_and_destroy_block'
: `@fix_and_destroy_block`) : '@fix_and_destroy_block')
: this.block.has_outros : this.block.has_outros
? `@outro_and_destroy_block` ? '@outro_and_destroy_block'
: `@destroy_block`; : '@destroy_block';
block.builders.update.add_block(deindent` block.builders.update.add_block(deindent`
const ${this.vars.each_block_value} = ${snippet}; const ${this.vars.each_block_value} = ${snippet};
${this.block.has_outros && `@group_outros();`} ${this.block.has_outros && '@group_outros();'}
${this.node.has_animation && `for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].r();`} ${this.node.has_animation && `for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].r();`}
${iterations} = @update_keyed_each(${iterations}, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.vars.each_block_value}, ${lookup}, ${update_mount_node}, ${destroy}, ${create_each_block}, ${update_anchor_node}, ${this.vars.get_each_context}); ${iterations} = @update_keyed_each(${iterations}, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.vars.each_block_value}, ${lookup}, ${update_mount_node}, ${destroy}, ${create_each_block}, ${update_anchor_node}, ${this.vars.get_each_context});
${this.node.has_animation && `for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].a();`} ${this.node.has_animation && `for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].a();`}
${this.block.has_outros && `@check_outros();`} ${this.block.has_outros && '@check_outros();'}
`); `);
if (this.block.has_outros) { if (this.block.has_outros) {
@ -485,7 +485,7 @@ export default class EachBlockWrapper extends Wrapper {
} }
`; `;
const start = this.block.has_update_method ? '0' : `#old_length`; const start = this.block.has_update_method ? '0' : '#old_length';
let remove_old_blocks; let remove_old_blocks;
@ -504,7 +504,7 @@ export default class EachBlockWrapper extends Wrapper {
`; `;
} else { } else {
remove_old_blocks = deindent` remove_old_blocks = deindent`
for (${this.block.has_update_method ? `` : `#i = ${this.vars.each_block_value}.${length}`}; #i < ${this.block.has_update_method ? view_length : '#old_length'}; #i += 1) { for (${this.block.has_update_method ? '' : `#i = ${this.vars.each_block_value}.${length}`}; #i < ${this.block.has_update_method ? view_length : '#old_length'}; #i += 1) {
${iterations}[#i].d(1); ${iterations}[#i].d(1);
} }
${!fixed_length && `${view_length} = ${this.vars.each_block_value}.${length};`} ${!fixed_length && `${view_length} = ${this.vars.each_block_value}.${length};`}

@ -80,7 +80,7 @@ export default class AttributeWrapper {
value = (this.node.chunks[0] as Expression).render(block); value = (this.node.chunks[0] as Expression).render(block);
} else { } else {
// '{foo} {bar}' — treat as string concatenation // '{foo} {bar}' — treat as string concatenation
const prefix = this.node.chunks[0].type === 'Text' ? '' : `"" + `; const prefix = this.node.chunks[0].type === 'Text' ? '' : '"" + ';
const text = this.node.name === 'class' const text = this.node.name === 'class'
? this.get_class_name_text() ? this.get_class_name_text()
@ -151,7 +151,7 @@ export default class AttributeWrapper {
const dependencies = this.node.get_dependencies(); const dependencies = this.node.get_dependencies();
if (dependencies.length > 0 || is_select_value_attribute) { if (dependencies.length > 0 || is_select_value_attribute) {
const changed_check = ( const changed_check = (
(block.has_outros ? `!#current || ` : '') + (block.has_outros ? '!#current || ' : '') +
dependencies.map(dependency => `changed.${dependency}`).join(' || ') dependencies.map(dependency => `changed.${dependency}`).join(' || ')
); );
@ -222,7 +222,7 @@ export default class AttributeWrapper {
if (this.node.is_true) return ''; if (this.node.is_true) return '';
const value = this.node.chunks; const value = this.node.chunks;
if (value.length === 0) return `=""`; if (value.length === 0) return '=""';
return `="${value.map(chunk => { return `="${value.map(chunk => {
return chunk.type === 'Text' return chunk.type === 'Text'

@ -109,7 +109,7 @@ export default class BindingWrapper {
if (parent.node.name === 'input') { if (parent.node.name === 'input') {
const type = parent.node.get_static_attribute_value('type'); const type = parent.node.get_static_attribute_value('type');
if (type === null || type === "" || type === "text" || type === "email" || type === "password") { if (type === null || type === '' || type === 'text' || type === 'email' || type === 'password') {
update_conditions.push(`(${parent.var}.${this.node.name} !== ${this.snippet})`); update_conditions.push(`(${parent.var}.${this.node.name} !== ${this.snippet})`);
} }
} }
@ -294,14 +294,14 @@ function get_value_from_dom(
const { name } = binding.node; const { name } = binding.node;
if (name === 'this') { if (name === 'this') {
return `$$node`; return '$$node';
} }
// <select bind:value='selected> // <select bind:value='selected>
if (node.name === 'select') { if (node.name === 'select') {
return node.get_static_attribute_value('multiple') === true ? return node.get_static_attribute_value('multiple') === true ?
`@select_multiple_value(this)` : '@select_multiple_value(this)' :
`@select_value(this)`; '@select_value(this)';
} }
const type = node.get_static_attribute_value('type'); const type = node.get_static_attribute_value('type');
@ -313,7 +313,7 @@ function get_value_from_dom(
return `@get_binding_group_value($$binding_groups[${binding_group}])`; return `@get_binding_group_value($$binding_groups[${binding_group}])`;
} }
return `this.__value`; return 'this.__value';
} }
// <input type='range|number' bind:value> // <input type='range|number' bind:value>

@ -27,7 +27,7 @@ export default class StyleAttributeWrapper extends AttributeWrapper {
const prop_dependencies = new Set(); const prop_dependencies = new Set();
value = value =
((prop.value.length === 1 || prop.value[0].type === 'Text') ? '' : `"" + `) + ((prop.value.length === 1 || prop.value[0].type === 'Text') ? '' : '"" + ') +
prop.value prop.value
.map((chunk) => { .map((chunk) => {
if (chunk.type === 'Text') { if (chunk.type === 'Text') {
@ -45,7 +45,7 @@ export default class StyleAttributeWrapper extends AttributeWrapper {
if (prop_dependencies.size) { if (prop_dependencies.size) {
const dependencies = Array.from(prop_dependencies); const dependencies = Array.from(prop_dependencies);
const condition = ( const condition = (
(block.has_outros ? `!#current || ` : '') + (block.has_outros ? '!#current || ' : '') +
dependencies.map(dependency => `changed.${dependency}`).join(' || ') dependencies.map(dependency => `changed.${dependency}`).join(' || ')
); );

@ -398,7 +398,7 @@ export default class ElementWrapper extends Wrapper {
return `@claim_element(${nodes}, "${name}", ${attributes return `@claim_element(${nodes}, "${name}", ${attributes
? `{ ${attributes} }` ? `{ ${attributes} }`
: `{}`}, ${this.node.namespace === namespaces.svg ? true : false})`; : '{}'}, ${this.node.namespace === namespaces.svg ? true : false})`;
} }
add_bindings(block: Block) { add_bindings(block: Block) {
@ -479,7 +479,7 @@ export default class ElementWrapper extends Wrapper {
} }
this.renderer.component.partly_hoisted.push(deindent` this.renderer.component.partly_hoisted.push(deindent`
function ${handler}(${contextual_dependencies.size > 0 ? `{ ${Array.from(contextual_dependencies).join(', ')} }` : ``}) { function ${handler}(${contextual_dependencies.size > 0 ? `{ ${Array.from(contextual_dependencies).join(', ')} }` : ''}) {
${group.bindings.map(b => b.handler.mutation)} ${group.bindings.map(b => b.handler.mutation)}
${Array.from(dependencies).filter(dep => dep[0] !== '$').map(dep => `${this.renderer.component.invalidate(dep)};`)} ${Array.from(dependencies).filter(dep => dep[0] !== '$').map(dep => `${this.renderer.component.invalidate(dep)};`)}
} }

@ -70,7 +70,7 @@ export default class FragmentWrapper {
const child = nodes[i]; const child = nodes[i];
if (!child.type) { if (!child.type) {
throw new Error(`missing type`); throw new Error('missing type');
} }
if (!(child.type in wrappers)) { if (!(child.type in wrappers)) {

@ -37,7 +37,7 @@ class IfBlockBranch extends Wrapper {
this.block = block.child({ this.block = block.child({
comment: create_debugging_comment(node, parent.renderer.component), comment: create_debugging_comment(node, parent.renderer.component),
name: parent.renderer.component.get_unique_name( name: parent.renderer.component.get_unique_name(
(node as IfBlock).expression ? `create_if_block` : `create_else_block` (node as IfBlock).expression ? 'create_if_block' : 'create_else_block'
) )
}); });
@ -187,8 +187,8 @@ export default class IfBlockWrapper extends Wrapper {
if (needs_anchor) { if (needs_anchor) {
block.add_element( block.add_element(
anchor, anchor,
`@empty()`, '@empty()',
parent_nodes && `@empty()`, parent_nodes && '@empty()',
parent_node parent_node
); );
} }
@ -206,8 +206,8 @@ export default class IfBlockWrapper extends Wrapper {
{ name, anchor, has_else, if_name, has_transitions }, { name, anchor, has_else, if_name, has_transitions },
detaching detaching
) { ) {
const select_block_type = this.renderer.component.get_unique_name(`select_block_type`); const select_block_type = this.renderer.component.get_unique_name('select_block_type');
const current_block_type = block.get_unique_name(`current_block_type`); const current_block_type = block.get_unique_name('current_block_type');
const current_block_type_and = has_else ? '' : `${current_block_type} && `; const current_block_type_and = has_else ? '' : `${current_block_type} && `;
/* eslint-disable @typescript-eslint/indent,indent */ /* eslint-disable @typescript-eslint/indent,indent */
@ -272,11 +272,11 @@ export default class IfBlockWrapper extends Wrapper {
{ name, anchor, has_else, has_transitions }, { name, anchor, has_else, has_transitions },
detaching detaching
) { ) {
const select_block_type = this.renderer.component.get_unique_name(`select_block_type`); const select_block_type = this.renderer.component.get_unique_name('select_block_type');
const current_block_type_index = block.get_unique_name(`current_block_type_index`); const current_block_type_index = block.get_unique_name('current_block_type_index');
const previous_block_index = block.get_unique_name(`previous_block_index`); const previous_block_index = block.get_unique_name('previous_block_index');
const if_block_creators = block.get_unique_name(`if_block_creators`); const if_block_creators = block.get_unique_name('if_block_creators');
const if_blocks = block.get_unique_name(`if_blocks`); const if_blocks = block.get_unique_name('if_blocks');
const if_current_block_type_index = has_else const if_current_block_type_index = has_else
? '' ? ''
@ -297,7 +297,7 @@ export default class IfBlockWrapper extends Wrapper {
${this.branches ${this.branches
.map(({ condition }, i) => `${condition ? `if (${condition}) ` : ''}return ${i};`) .map(({ condition }, i) => `${condition ? `if (${condition}) ` : ''}return ${i};`)
.join('\n')} .join('\n')}
${!has_else && `return -1;`} ${!has_else && 'return -1;'}
} }
`); `);
/* eslint-enable @typescript-eslint/indent,indent */ /* eslint-enable @typescript-eslint/indent,indent */

@ -70,7 +70,7 @@ export default class InlineComponentWrapper extends Wrapper {
if (this.node.children.length) { if (this.node.children.length) {
const default_slot = block.child({ const default_slot = block.child({
comment: create_debugging_comment(node, renderer.component), comment: create_debugging_comment(node, renderer.component),
name: renderer.component.get_unique_name(`create_default_slot`) name: renderer.component.get_unique_name('create_default_slot')
}); });
this.renderer.blocks.push(default_slot); this.renderer.blocks.push(default_slot);
@ -122,7 +122,7 @@ export default class InlineComponentWrapper extends Wrapper {
const slot_props = Array.from(this.slots).map(([name, slot]) => `${quote_name_if_necessary(name)}: [${slot.block.name}${slot.fn ? `, ${slot.fn}` : ''}]`); const slot_props = Array.from(this.slots).map(([name, slot]) => `${quote_name_if_necessary(name)}: [${slot.block.name}${slot.fn ? `, ${slot.fn}` : ''}]`);
const initial_props = slot_props.length > 0 const initial_props = slot_props.length > 0
? [`$$slots: ${stringify_props(slot_props)}`, `$$scope: { ctx }`] ? [`$$slots: ${stringify_props(slot_props)}`, '$$scope: { ctx }']
: []; : [];
const attribute_object = uses_spread const attribute_object = uses_spread
@ -153,7 +153,7 @@ export default class InlineComponentWrapper extends Wrapper {
// will complain that options.target is missing. This would // will complain that options.target is missing. This would
// work better if components had separate public and private // work better if components had separate public and private
// APIs // APIs
component_opts.push(`$$inline: true`); component_opts.push('$$inline: true');
} }
const fragment_dependencies = new Set(this.fragment ? ['$$scope'] : []); const fragment_dependencies = new Set(this.fragment ? ['$$scope'] : []);

@ -144,7 +144,7 @@ export default class SlotWrapper extends Wrapper {
); );
const mount_leadin = block.builders.mount.toString() !== mount_before const mount_leadin = block.builders.mount.toString() !== mount_before
? `else` ? 'else'
: `if (${slot})`; : `if (${slot})`;
block.builders.mount.add_block(deindent` block.builders.mount.add_block(deindent`

@ -69,7 +69,7 @@ export default class TextWrapper extends Wrapper {
block.add_element( block.add_element(
this.var, this.var,
this.use_space() ? `@space()` : `@text(${stringify(this.data)})`, this.use_space() ? '@space()' : `@text(${stringify(this.data)})`,
parent_nodes && `@claim_text(${parent_nodes}, ${stringify(this.data)})`, parent_nodes && `@claim_text(${parent_nodes}, ${stringify(this.data)})`,
parent_node parent_node
); );

@ -39,7 +39,7 @@ export default class TitleWrapper extends Wrapper {
} else { } else {
// '{foo} {bar}' — treat as string concatenation // '{foo} {bar}' — treat as string concatenation
value = value =
(this.node.children[0].type === 'Text' ? '' : `"" + `) + (this.node.children[0].type === 'Text' ? '' : '"" + ') +
this.node.children this.node.children
.map((chunk) => { .map((chunk) => {
if (chunk.type === 'Text') { if (chunk.type === 'Text') {
@ -60,7 +60,7 @@ export default class TitleWrapper extends Wrapper {
} }
const last = this.node.should_cache && block.get_unique_name( const last = this.node.should_cache && block.get_unique_name(
`title_value` 'title_value'
); );
if (this.node.should_cache) block.add_variable(last); if (this.node.should_cache) block.add_variable(last);
@ -75,7 +75,7 @@ export default class TitleWrapper extends Wrapper {
if (all_dependencies.size) { if (all_dependencies.size) {
const dependencies = Array.from(all_dependencies); const dependencies = Array.from(all_dependencies);
const changed_check = ( const changed_check = (
(block.has_outros ? `!#current || ` : '') + (block.has_outros ? '!#current || ' : '') +
dependencies.map(dependency => `changed.${dependency}`).join(' || ') dependencies.map(dependency => `changed.${dependency}`).join(' || ')
); );

@ -68,9 +68,9 @@ export default class WindowWrapper extends Wrapper {
}); });
}); });
const scrolling = block.get_unique_name(`scrolling`); const scrolling = block.get_unique_name('scrolling');
const clear_scrolling = block.get_unique_name(`clear_scrolling`); const clear_scrolling = block.get_unique_name('clear_scrolling');
const scrolling_timeout = block.get_unique_name(`scrolling_timeout`); const scrolling_timeout = block.get_unique_name('scrolling_timeout');
Object.keys(events).forEach(event => { Object.keys(events).forEach(event => {
const handler_name = block.get_unique_name(`onwindow${event}`); const handler_name = block.get_unique_name(`onwindow${event}`);
@ -148,9 +148,9 @@ export default class WindowWrapper extends Wrapper {
${scrolling} = true; ${scrolling} = true;
@_clearTimeout(${scrolling_timeout}); @_clearTimeout(${scrolling_timeout});
@_scrollTo(${ @_scrollTo(${
bindings.scrollX ? `ctx.${bindings.scrollX}` : `@_window.pageXOffset` bindings.scrollX ? `ctx.${bindings.scrollX}` : '@_window.pageXOffset'
}, ${ }, ${
bindings.scrollY ? `ctx.${bindings.scrollY}` : `@_window.pageYOffset` bindings.scrollY ? `ctx.${bindings.scrollY}` : '@_window.pageYOffset'
}); });
${scrolling_timeout} = @_setTimeout(${clear_scrolling}, 100); ${scrolling_timeout} = @_setTimeout(${clear_scrolling}, 100);
} }
@ -159,7 +159,7 @@ export default class WindowWrapper extends Wrapper {
// another special case. (I'm starting to think these are all special cases.) // another special case. (I'm starting to think these are all special cases.)
if (bindings.online) { if (bindings.online) {
const handler_name = block.get_unique_name(`onlinestatuschanged`); const handler_name = block.get_unique_name('onlinestatuschanged');
const name = bindings.online; const name = bindings.online;
component.add_var({ component.add_var({

@ -28,7 +28,7 @@ export default class Tag extends Wrapper {
if (dependencies.length > 0) { if (dependencies.length > 0) {
const changed_check = ( const changed_check = (
(block.has_outros ? `!#current || ` : '') + (block.has_outros ? '!#current || ' : '') +
dependencies.map((dependency: string) => `changed.${dependency}`).join(' || ') dependencies.map((dependency: string) => `changed.${dependency}`).join(' || ')
); );

@ -53,8 +53,8 @@ export default class Wrapper {
if (needs_anchor) { if (needs_anchor) {
block.add_element( block.add_element(
anchor, anchor,
`@empty()`, '@empty()',
parent_nodes && `@empty()`, parent_nodes && '@empty()',
parent_node parent_node
); );
} }

@ -8,7 +8,7 @@ export default function(node: DebugTag, renderer: Renderer, options: RenderOptio
const { line, column } = options.locate(node.start + 1); const { line, column } = options.locate(node.start + 1);
const obj = node.expressions.length === 0 const obj = node.expressions.length === 0
? `{}` ? '{}'
: `{ ${node.expressions : `{ ${node.expressions
.map(e => e.node.name) .map(e => e.node.name)
.join(', ')} }`; .join(', ')} }`;

@ -16,13 +16,13 @@ export default function(node: EachBlock, renderer: Renderer, options: RenderOpti
renderer.render(node.children, options); renderer.render(node.children, options);
const close = `\`)`; const close = '`)';
renderer.append(close); renderer.append(close);
if (node.else) { if (node.else) {
renderer.append(` : \``); renderer.append(' : `');
renderer.render(node.else.children, options); renderer.render(node.else.children, options);
renderer.append(`\``); renderer.append('`');
} }
renderer.append('}'); renderer.append('}');

@ -118,7 +118,7 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
} }
}); });
opening_tag += "${@spread([" + args.join(', ') + "])}"; opening_tag += '${@spread([' + args.join(', ') + '])}';
} else { } else {
node.attributes.forEach((attribute: Attribute) => { node.attributes.forEach((attribute: Attribute) => {
if (attribute.type !== 'Attribute') return; if (attribute.type !== 'Attribute') return;

@ -18,8 +18,8 @@ function stringify_attribute(chunk: INode) {
} }
function get_attribute_value(attribute) { function get_attribute_value(attribute) {
if (attribute.is_true) return `true`; if (attribute.is_true) return 'true';
if (attribute.chunks.length === 0) return `''`; if (attribute.chunks.length === 0) return '\'\'';
if (attribute.chunks.length === 1) { if (attribute.chunks.length === 1) {
const chunk = attribute.chunks[0]; const chunk = attribute.chunks[0];

@ -14,5 +14,5 @@ export default function(node: Slot, renderer: Renderer, options: RenderOptions)
renderer.render(node.children, options); renderer.render(node.children, options);
renderer.append(`\`}`); renderer.append('`}');
} }

@ -2,9 +2,9 @@ import Renderer, { RenderOptions } from '../Renderer';
import Title from '../../nodes/Title'; import Title from '../../nodes/Title';
export default function(node: Title, renderer: Renderer, options: RenderOptions) { export default function(node: Title, renderer: Renderer, options: RenderOptions) {
renderer.append(`<title>`); renderer.append('<title>');
renderer.render(node.children, options); renderer.render(node.children, options);
renderer.append(`</title>`); renderer.append('</title>');
} }

@ -132,14 +132,14 @@ export default function ssr(
.join(', ')};`, .join(', ')};`,
component.javascript, component.javascript,
parent_bindings.join('\n'), parent_bindings.join('\n'),
css.code && `$$result.css.add(#css);`, css.code && '$$result.css.add(#css);',
main main
].filter(Boolean); ].filter(Boolean);
return (deindent` return (deindent`
${css.code && deindent` ${css.code && deindent`
const #css = { const #css = {
code: ${css.code ? stringify(css.code) : `''`}, code: ${css.code ? stringify(css.code) : '\'\''},
map: ${css.map ? stringify(css.map.toString()) : 'null'} map: ${css.map ? stringify(css.map.toString()) : 'null'}
};`} };`}

@ -58,7 +58,7 @@ export default class CodeBuilder {
} }
pop_condition() { pop_condition() {
if (!this.current.parent) throw new Error(`Popping a condition that maybe wasn't pushed.`); if (!this.current.parent) throw new Error('Popping a condition that maybe wasn\'t pushed.');
this.current = this.current.parent; this.current = this.current.parent;
} }

@ -9,7 +9,7 @@ describe('deindent', () => {
deindent me please deindent me please
`; `;
assert.equal(deindented, `deindent me please`); assert.equal(deindented, 'deindent me please');
}); });
it('deindents a multiline string', () => { it('deindents a multiline string', () => {
@ -18,7 +18,7 @@ describe('deindent', () => {
and me as well and me as well
`; `;
assert.equal(deindented, `deindent me please\nand me as well`); assert.equal(deindented, 'deindent me please\nand me as well');
}); });
it('preserves indentation of inserted values', () => { it('preserves indentation of inserted values', () => {
@ -33,7 +33,7 @@ describe('deindent', () => {
after after
`; `;
assert.equal(deindented, `before\n\tline one\n\tline two\nafter`); assert.equal(deindented, 'before\n\tline one\n\tline two\nafter');
}); });
it('removes newlines before an empty expression', () => { it('removes newlines before an empty expression', () => {
@ -44,7 +44,7 @@ describe('deindent', () => {
${null} ${null}
}`; }`;
assert.equal(deindented, `{\n\tsome text\n}`); assert.equal(deindented, '{\n\tsome text\n}');
}); });
it('removes newlines after an empty expression', () => { it('removes newlines after an empty expression', () => {
@ -55,7 +55,7 @@ describe('deindent', () => {
some text some text
}`; }`;
assert.equal(deindented, `{\n\tsome text\n}`); assert.equal(deindented, '{\n\tsome text\n}');
}); });
it('removes newlines around empty expressions', () => { it('removes newlines around empty expressions', () => {
@ -72,7 +72,7 @@ describe('deindent', () => {
${null} ${null}
}`; }`;
assert.equal(deindented, `{\n\tsome text\n\n\tsome text\n}`); assert.equal(deindented, '{\n\tsome text\n\n\tsome text\n}');
}); });
}); });

@ -12,7 +12,7 @@ export default function get_name_from_filename(filename: string) {
} }
const base = parts.pop() const base = parts.pop()
.replace(/\.[^.]+$/, "") .replace(/\.[^.]+$/, '')
.replace(/[^a-zA-Z_$0-9]+/g, '_') .replace(/[^a-zA-Z_$0-9]+/g, '_')
.replace(/^_/, '') .replace(/^_/, '')
.replace(/_$/, '') .replace(/_$/, '')

@ -59,7 +59,7 @@ export class Parser {
if (state !== fragment) { if (state !== fragment) {
this.error({ this.error({
code: `unexpected-eof`, code: 'unexpected-eof',
message: 'Unexpected end of input' message: 'Unexpected end of input'
}); });
} }
@ -84,7 +84,7 @@ export class Parser {
acorn_error(err: any) { acorn_error(err: any) {
this.error({ this.error({
code: `parse-error`, code: 'parse-error',
message: err.message.replace(/ \(\d+:\d+\)$/, '') message: err.message.replace(/ \(\d+:\d+\)$/, '')
}, err.pos); }, err.pos);
} }
@ -162,7 +162,7 @@ export class Parser {
if (reserved.has(identifier)) { if (reserved.has(identifier)) {
this.error({ this.error({
code: `unexpected-reserved-word`, code: 'unexpected-reserved-word',
message: `'${identifier}' is a reserved word in JavaScript and cannot be used here` message: `'${identifier}' is a reserved word in JavaScript and cannot be used here`
}, start); }, start);
} }
@ -173,7 +173,7 @@ export class Parser {
read_until(pattern: RegExp) { read_until(pattern: RegExp) {
if (this.index >= this.template.length) if (this.index >= this.template.length)
this.error({ this.error({
code: `unexpected-eof`, code: 'unexpected-eof',
message: 'Unexpected end of input' message: 'Unexpected end of input'
}); });
@ -192,8 +192,8 @@ export class Parser {
require_whitespace() { require_whitespace() {
if (!whitespace.test(this.template[this.index])) { if (!whitespace.test(this.template[this.index])) {
this.error({ this.error({
code: `missing-whitespace`, code: 'missing-whitespace',
message: `Expected whitespace` message: 'Expected whitespace'
}); });
} }
@ -221,15 +221,15 @@ export default function parse(
if (instance_scripts.length > 1) { if (instance_scripts.length > 1) {
parser.error({ parser.error({
code: `invalid-script`, code: 'invalid-script',
message: `A component can only have one instance-level <script> element` message: 'A component can only have one instance-level <script> element'
}, instance_scripts[1].start); }, instance_scripts[1].start);
} }
if (module_scripts.length > 1) { if (module_scripts.length > 1) {
parser.error({ parser.error({
code: `invalid-script`, code: 'invalid-script',
message: `A component can only have one <script context="module"> element` message: 'A component can only have one <script context="module"> element'
}, module_scripts[1].start); }, module_scripts[1].start);
} }

@ -108,8 +108,8 @@ export default function read_context(parser: Parser) {
if (parser.eat(',')) { if (parser.eat(',')) {
parser.error({ parser.error({
code: `comma-after-rest`, code: 'comma-after-rest',
message: `Comma is not permitted after the rest element` message: 'Comma is not permitted after the rest element'
}, parser.index - 1); }, parser.index - 1);
} }

@ -12,7 +12,7 @@ function get_context(parser: Parser, attributes: Node[], start: number) {
if (context.value.length !== 1 || context.value[0].type !== 'Text') { if (context.value.length !== 1 || context.value[0].type !== 'Text') {
parser.error({ parser.error({
code: 'invalid-script', code: 'invalid-script',
message: `context attribute must be static` message: 'context attribute must be static'
}, start); }, start);
} }
@ -20,8 +20,8 @@ function get_context(parser: Parser, attributes: Node[], start: number) {
if (value !== 'module') { if (value !== 'module') {
parser.error({ parser.error({
code: `invalid-script`, code: 'invalid-script',
message: `If the context attribute is supplied, its value must be "module"` message: 'If the context attribute is supplied, its value must be "module"'
}, context.start); }, context.start);
} }
@ -33,8 +33,8 @@ export default function read_script(parser: Parser, start: number, attributes: N
const script_end = parser.template.indexOf(script_closing_tag, script_start); const script_end = parser.template.indexOf(script_closing_tag, script_start);
if (script_end === -1) parser.error({ if (script_end === -1) parser.error({
code: `unclosed-script`, code: 'unclosed-script',
message: `<script> must have a closing tag` message: '<script> must have a closing tag'
}); });
const source = const source =

@ -18,7 +18,7 @@ export default function read_style(parser: Parser, start: number, attributes: No
} catch (err) { } catch (err) {
if (err.name === 'CssSyntaxError') { if (err.name === 'CssSyntaxError') {
parser.error({ parser.error({
code: `css-syntax-error`, code: 'css-syntax-error',
message: err.message message: err.message
}, err.offset); }, err.offset);
} else { } else {
@ -39,7 +39,7 @@ export default function read_style(parser: Parser, start: number, attributes: No
if (is_ref_selector(a, b)) { if (is_ref_selector(a, b)) {
parser.error({ parser.error({
code: `invalid-ref-selector`, code: 'invalid-ref-selector',
message: 'ref selectors are no longer supported' message: 'ref selectors are no longer supported'
}, a.loc.start.offset); }, a.loc.start.offset);
} }

@ -57,8 +57,8 @@ export default function mustache(parser: Parser) {
expected = 'await'; expected = 'await';
} else { } else {
parser.error({ parser.error({
code: `unexpected-block-close`, code: 'unexpected-block-close',
message: `Unexpected block closing tag` message: 'Unexpected block closing tag'
}); });
} }
@ -90,7 +90,7 @@ export default function mustache(parser: Parser) {
if (parser.eat('if')) { if (parser.eat('if')) {
parser.error({ parser.error({
code: 'invalid-elseif', code: 'invalid-elseif',
message: `'elseif' should be 'else if'` message: '\'elseif\' should be \'else if\''
}); });
} }
@ -101,7 +101,7 @@ export default function mustache(parser: Parser) {
const block = parser.current(); const block = parser.current();
if (block.type !== 'IfBlock') if (block.type !== 'IfBlock')
parser.error({ parser.error({
code: `invalid-elseif-placement`, code: 'invalid-elseif-placement',
message: 'Cannot have an {:else if ...} block outside an {#if ...} block' message: 'Cannot have an {:else if ...} block outside an {#if ...} block'
}); });
@ -136,7 +136,7 @@ export default function mustache(parser: Parser) {
const block = parser.current(); const block = parser.current();
if (block.type !== 'IfBlock' && block.type !== 'EachBlock') { if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
parser.error({ parser.error({
code: `invalid-else-placement`, code: 'invalid-else-placement',
message: 'Cannot have an {:else} block outside an {#if ...} or {#each ...} block' message: 'Cannot have an {:else} block outside an {#if ...} or {#each ...} block'
}); });
} }
@ -216,8 +216,8 @@ export default function mustache(parser: Parser) {
type = 'AwaitBlock'; type = 'AwaitBlock';
} else { } else {
parser.error({ parser.error({
code: `expected-block-type`, code: 'expected-block-type',
message: `Expected if, each or await` message: 'Expected if, each or await'
}); });
} }
@ -278,8 +278,8 @@ export default function mustache(parser: Parser) {
parser.allow_whitespace(); parser.allow_whitespace();
block.index = parser.read_identifier(); block.index = parser.read_identifier();
if (!block.index) parser.error({ if (!block.index) parser.error({
code: `expected-name`, code: 'expected-name',
message: `Expected name` message: 'Expected name'
}); });
parser.allow_whitespace(); parser.allow_whitespace();

@ -151,7 +151,7 @@ export default function tag(parser: Parser) {
if (is_closing_tag) { if (is_closing_tag) {
if (is_void(name)) { if (is_void(name)) {
parser.error({ parser.error({
code: `invalid-void-content`, code: 'invalid-void-content',
message: `<${name}> is a void element and cannot have children, or a closing tag` message: `<${name}> is a void element and cannot have children, or a closing tag`
}, start); }, start);
} }
@ -162,7 +162,7 @@ export default function tag(parser: Parser) {
while (parent.name !== name) { while (parent.name !== name) {
if (parent.type !== 'Element') if (parent.type !== 'Element')
parser.error({ parser.error({
code: `invalid-closing-tag`, code: 'invalid-closing-tag',
message: `</${name}> attempted to close an element that was not open` message: `</${name}> attempted to close an element that was not open`
}, start); }, start);
@ -197,16 +197,16 @@ export default function tag(parser: Parser) {
const index = element.attributes.findIndex(attr => attr.type === 'Attribute' && attr.name === 'this'); const index = element.attributes.findIndex(attr => attr.type === 'Attribute' && attr.name === 'this');
if (!~index) { if (!~index) {
parser.error({ parser.error({
code: `missing-component-definition`, code: 'missing-component-definition',
message: `<svelte:component> must have a 'this' attribute` message: '<svelte:component> must have a \'this\' attribute'
}, start); }, start);
} }
const definition = element.attributes.splice(index, 1)[0]; const definition = element.attributes.splice(index, 1)[0];
if (definition.value === true || definition.value.length !== 1 || definition.value[0].type === 'Text') { if (definition.value === true || definition.value.length !== 1 || definition.value[0].type === 'Text') {
parser.error({ parser.error({
code: `invalid-component-definition`, code: 'invalid-component-definition',
message: `invalid component definition` message: 'invalid component definition'
}, definition.start); }, definition.start);
} }
@ -280,8 +280,8 @@ function read_tag_name(parser: Parser) {
if (!legal) { if (!legal) {
parser.error({ parser.error({
code: `invalid-self-placement`, code: 'invalid-self-placement',
message: `<svelte:self> components can only exist inside if-blocks or each-blocks` message: '<svelte:self> components can only exist inside if-blocks or each-blocks'
}, start); }, start);
} }
@ -308,8 +308,8 @@ function read_tag_name(parser: Parser) {
if (!valid_tag_name.test(name)) { if (!valid_tag_name.test(name)) {
parser.error({ parser.error({
code: `invalid-tag-name`, code: 'invalid-tag-name',
message: `Expected valid tag name` message: 'Expected valid tag name'
}, start); }, start);
} }
@ -374,12 +374,12 @@ function read_attribute(parser: Parser, unique_names: Set<string>) {
if (unique_names.has(name)) { if (unique_names.has(name)) {
parser.error({ parser.error({
code: `duplicate-attribute`, code: 'duplicate-attribute',
message: 'Attributes need to be unique' message: 'Attributes need to be unique'
}, start); }, start);
} }
if (type !== "EventHandler") { if (type !== 'EventHandler') {
unique_names.add(name); unique_names.add(name);
} }
@ -390,8 +390,8 @@ function read_attribute(parser: Parser, unique_names: Set<string>) {
end = parser.index; end = parser.index;
} else if (parser.match_regex(/["']/)) { } else if (parser.match_regex(/["']/)) {
parser.error({ parser.error({
code: `unexpected-token`, code: 'unexpected-token',
message: `Expected =` message: 'Expected ='
}, parser.index); }, parser.index);
} }
@ -400,7 +400,7 @@ function read_attribute(parser: Parser, unique_names: Set<string>) {
if (type === 'Ref') { if (type === 'Ref') {
parser.error({ parser.error({
code: `invalid-ref-directive`, code: 'invalid-ref-directive',
message: `The ref directive is no longer supported — use \`bind:this={${directive_name}}\` instead` message: `The ref directive is no longer supported — use \`bind:this={${directive_name}}\` instead`
}, start); }, start);
} }
@ -408,8 +408,8 @@ function read_attribute(parser: Parser, unique_names: Set<string>) {
if (value[0]) { if (value[0]) {
if ((value as any[]).length > 1 || value[0].type === 'Text') { if ((value as any[]).length > 1 || value[0].type === 'Text') {
parser.error({ parser.error({
code: `invalid-directive-value`, code: 'invalid-directive-value',
message: `Directive value must be a JavaScript expression enclosed in curly braces` message: 'Directive value must be a JavaScript expression enclosed in curly braces'
}, value[0].start); }, value[0].start);
} }
} }
@ -462,11 +462,11 @@ function get_directive_type(name: string): DirectiveType {
} }
function read_attribute_value(parser: Parser) { function read_attribute_value(parser: Parser) {
const quote_mark = parser.eat(`'`) ? `'` : parser.eat(`"`) ? `"` : null; const quote_mark = parser.eat('\'') ? '\'' : parser.eat('"') ? '"' : null;
const regex = ( const regex = (
quote_mark === `'` ? /'/ : quote_mark === '\'' ? /'/ :
quote_mark === `"` ? /"/ : quote_mark === '"' ? /"/ :
/(\/>|[\s"'=<>`])/ /(\/>|[\s"'=<>`])/
); );
@ -529,7 +529,7 @@ function read_sequence(parser: Parser, done: () => boolean): Node[] {
} }
parser.error({ parser.error({
code: `unexpected-eof`, code: 'unexpected-eof',
message: `Unexpected end of input` message: 'Unexpected end of input'
}); });
} }

@ -28,7 +28,7 @@ function parse_attributes(str: string) {
if (p === -1) { if (p === -1) {
attrs[attr] = true; attrs[attr] = true;
} else { } else {
attrs[attr.slice(0, p)] = `'"`.includes(attr[p + 1]) ? attrs[attr.slice(0, p)] = '\'"'.includes(attr[p + 1]) ?
attr.slice(p + 2, -1) : attr.slice(p + 2, -1) :
attr.slice(p + 1); attr.slice(p + 1);
} }

@ -200,7 +200,7 @@ export class SvelteComponent {
export class SvelteComponentDev extends SvelteComponent { export class SvelteComponentDev extends SvelteComponent {
constructor(options) { constructor(options) {
if (!options || (!options.target && !options.$$inline)) { if (!options || (!options.target && !options.$$inline)) {
throw new Error(`'target' is a required option`); throw new Error('\'target\' is a required option');
} }
super(); super();
@ -209,7 +209,7 @@ export class SvelteComponentDev extends SvelteComponent {
$destroy() { $destroy() {
super.$destroy(); super.$destroy();
this.$destroy = () => { this.$destroy = () => {
console.warn(`Component was already destroyed`); // eslint-disable-line no-console console.warn('Component was already destroyed'); // eslint-disable-line no-console
}; };
} }
} }

@ -7,7 +7,7 @@ export function set_current_component(component) {
} }
function get_current_component() { function get_current_component() {
if (!current_component) throw new Error(`Function called outside component initialization`); if (!current_component) throw new Error('Function called outside component initialization');
return current_component; return current_component;
} }

@ -14,13 +14,13 @@ export function spread(args) {
const value = attributes[name]; const value = attributes[name];
if (value === undefined) return; if (value === undefined) return;
if (value === true) str += " " + name; if (value === true) str += ' ' + name;
const escaped = String(value) const escaped = String(value)
.replace(/"/g, '&#34;') .replace(/"/g, '&#34;')
.replace(/'/g, '&#39;'); .replace(/'/g, '&#39;');
str += " " + name + "=" + JSON.stringify(escaped); str += ' ' + name + '=' + JSON.stringify(escaped);
}); });
return str; return str;
@ -126,5 +126,5 @@ export function add_attribute(name, value, boolean) {
} }
export function add_classes(classes) { export function add_classes(classes) {
return classes ? ` class="${classes}"` : ``; return classes ? ` class="${classes}"` : '';
} }

@ -38,7 +38,7 @@ export function create_rule(node: Element & ElementCSSInlineStyle, a: number, b:
} }
const animation = node.style.animation || ''; const animation = node.style.animation || '';
node.style.animation = `${animation ? `${animation}, ` : ``}${name} ${duration}ms linear ${delay}ms 1 both`; node.style.animation = `${animation ? `${animation}, ` : ''}${name} ${duration}ms linear ${delay}ms 1 both`;
active += 1; active += 1;
return name; return name;

@ -1,5 +1,5 @@
import { identity as linear, is_function, noop, run_all } from './utils'; import { identity as linear, is_function, noop, run_all } from './utils';
import { now } from "./environment"; import { now } from './environment';
import { loop } from './loop'; import { loop } from './loop';
import { create_rule, delete_rule } from './style_manager'; import { create_rule, delete_rule } from './style_manager';
import { custom_event } from './dom'; import { custom_event } from './dom';

@ -86,7 +86,7 @@ export function slide(node: Element, {
duration, duration,
easing, easing,
css: t => css: t =>
`overflow: hidden;` + 'overflow: hidden;' +
`opacity: ${Math.min(t * 20, 1) * opacity};` + `opacity: ${Math.min(t * 20, 1) * opacity};` +
`height: ${t * height}px;` + `height: ${t * height}px;` +
`padding-top: ${t * padding_top}px;` + `padding-top: ${t * padding_top}px;` +

@ -1,8 +1,8 @@
export default { export default {
warnings: [{ warnings: [{
filename: "SvelteComponent.svelte", filename: 'SvelteComponent.svelte',
code: `css-unused-selector`, code: 'css-unused-selector',
message: "Unused CSS selector", message: 'Unused CSS selector',
start: { start: {
line: 4, line: 4,
column: 1, column: 1,

@ -1,6 +1,6 @@
export default { export default {
warnings: [{ warnings: [{
code: `css-unused-selector`, code: 'css-unused-selector',
message: 'Unused CSS selector', message: 'Unused CSS selector',
start: { start: {
line: 8, line: 8,

@ -1,9 +1,9 @@
export default { export default {
warnings: [ warnings: [
{ {
filename: "SvelteComponent.svelte", filename: 'SvelteComponent.svelte',
code: `css-unused-selector`, code: 'css-unused-selector',
message: "Unused CSS selector", message: 'Unused CSS selector',
start: { start: {
line: 4, line: 4,
column: 1, column: 1,
@ -25,9 +25,9 @@ export default {
}, },
{ {
filename: "SvelteComponent.svelte", filename: 'SvelteComponent.svelte',
code: `css-unused-selector`, code: 'css-unused-selector',
message: "Unused CSS selector", message: 'Unused CSS selector',
start: { start: {
line: 4, line: 4,
column: 13, column: 13,

@ -4,9 +4,9 @@ export default {
}, },
warnings: [{ warnings: [{
filename: "SvelteComponent.svelte", filename: 'SvelteComponent.svelte',
code: `css-unused-selector`, code: 'css-unused-selector',
message: "Unused CSS selector", message: 'Unused CSS selector',
start: { start: {
line: 16, line: 16,
column: 1, column: 1,

@ -1,8 +1,8 @@
export default { export default {
warnings: [{ warnings: [{
filename: "SvelteComponent.svelte", filename: 'SvelteComponent.svelte',
code: `css-unused-selector`, code: 'css-unused-selector',
message: "Unused CSS selector", message: 'Unused CSS selector',
start: { start: {
line: 8, line: 8,
column: 1, column: 1,

@ -8,10 +8,10 @@ export default async function (target) {
const button = counter.shadowRoot.querySelector('button'); const button = counter.shadowRoot.querySelector('button');
assert.equal(counter.count, 0); assert.equal(counter.count, 0);
assert.equal(counter.shadowRoot.innerHTML, `<button>count: 0</button>`); assert.equal(counter.shadowRoot.innerHTML, '<button>count: 0</button>');
await button.dispatchEvent(new MouseEvent('click')); await button.dispatchEvent(new MouseEvent('click'));
assert.equal(counter.count, 1); assert.equal(counter.count, 1);
assert.equal(counter.shadowRoot.innerHTML, `<button>count: 1</button>`); assert.equal(counter.shadowRoot.innerHTML, '<button>count: 1</button>');
} }

@ -12,7 +12,7 @@ export default function (target) {
target.innerHTML = '<my-app foo=yes />'; target.innerHTML = '<my-app foo=yes />';
assert.equal(warnings.length, 1); assert.equal(warnings.length, 1);
assert.equal(warnings[0], `<my-app> was created without expected prop 'bar'`); assert.equal(warnings[0], '<my-app> was created without expected prop \'bar\'');
console.warn = warn; console.warn = warn;
} }

@ -1,6 +1,6 @@
export default { export default {
warnings: [{ warnings: [{
code: "custom-element-no-tag", code: 'custom-element-no-tag',
message: "No custom element 'tag' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag=\"my-thing\"/>. To hide this warning, use <svelte:options tag={null}/>", message: "No custom element 'tag' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag=\"my-thing\"/>. To hide this warning, use <svelte:options tag={null}/>",
pos: 0, pos: 0,
start: { start: {

@ -3,7 +3,7 @@ import CustomElement from './main.svelte';
export default function (target) { export default function (target) {
customElements.define('no-tag', CustomElement); customElements.define('no-tag', CustomElement);
target.innerHTML = `<no-tag name="world"></no-tag>`; target.innerHTML = '<no-tag name="world"></no-tag>';
const el = target.querySelector('no-tag'); const el = target.querySelector('no-tag');
const h1 = el.shadowRoot.querySelector('h1'); const h1 = el.shadowRoot.querySelector('h1');

@ -1,6 +1,6 @@
export default { export default {
warnings: [{ warnings: [{
code: "custom-element-no-tag", code: 'custom-element-no-tag',
message: "No custom element 'tag' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag=\"my-thing\"/>. To hide this warning, use <svelte:options tag={null}/>", message: "No custom element 'tag' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag=\"my-thing\"/>. To hide this warning, use <svelte:options tag={null}/>",
pos: 0, pos: 0,
start: { start: {

@ -3,7 +3,7 @@ import CustomElement from './main.svelte';
export default function (target) { export default function (target) {
customElements.define('no-tag', CustomElement); customElements.define('no-tag', CustomElement);
target.innerHTML = `<no-tag name="world"></no-tag>`; target.innerHTML = '<no-tag name="world"></no-tag>';
const el = target.querySelector('no-tag'); const el = target.querySelector('no-tag');
const h1 = el.shadowRoot.querySelector('h1'); const h1 = el.shadowRoot.querySelector('h1');

@ -3,7 +3,7 @@ import CustomElement from './main.svelte';
export default function (target) { export default function (target) {
customElements.define('no-tag', CustomElement); customElements.define('no-tag', CustomElement);
target.innerHTML = `<no-tag name="world"></no-tag>`; target.innerHTML = '<no-tag name="world"></no-tag>';
const el = target.querySelector('no-tag'); const el = target.querySelector('no-tag');
const h1 = el.shadowRoot.querySelector('h1'); const h1 = el.shadowRoot.querySelector('h1');

@ -19,6 +19,6 @@ export default {
component.foo = false; component.foo = false;
component.bar = true; component.bar = true;
assert.htmlEqual(target.innerHTML, `<p>bar!</p>`); assert.htmlEqual(target.innerHTML, '<p>bar!</p>');
} }
}; };

@ -2,7 +2,7 @@ export default {
skip: true, // existing nodes are blown away skip: true, // existing nodes are blown away
props: { props: {
raw: `<p>this is some html</p> <p>and so is this</p>` raw: '<p>this is some html</p> <p>and so is this</p>'
}, },
snapshot(target) { snapshot(target) {

@ -1,13 +1,13 @@
// this file will replace all the expected.js files with their _actual // this file will replace all the expected.js files with their _actual
// equivalents. Only use it when you're sure that you haven't // equivalents. Only use it when you're sure that you haven't
// broken anything! // broken anything!
const fs = require("fs"); const fs = require('fs');
const glob = require("tiny-glob/sync.js"); const glob = require('tiny-glob/sync.js');
glob("samples/*/_actual.js", { cwd: __dirname }).forEach(file => { glob('samples/*/_actual.js', { cwd: __dirname }).forEach(file => {
const actual = fs.readFileSync(`${__dirname}/${file}`, "utf-8"); const actual = fs.readFileSync(`${__dirname}/${file}`, 'utf-8');
fs.writeFileSync( fs.writeFileSync(
`${__dirname}/${file.replace("_actual.js", "expected.js")}`, `${__dirname}/${file.replace('_actual.js', 'expected.js')}`,
actual actual
); );
}); });

@ -1,13 +1,13 @@
// this file will replace all the output.json files with their _actual.json // this file will replace all the output.json files with their _actual.json
// equivalents. Only use it when you're sure that you haven't // equivalents. Only use it when you're sure that you haven't
// broken anything! // broken anything!
const fs = require("fs"); const fs = require('fs');
const glob = require("tiny-glob/sync.js"); const glob = require('tiny-glob/sync.js');
glob("samples/*/_actual.json", { cwd: __dirname }).forEach(file => { glob('samples/*/_actual.json', { cwd: __dirname }).forEach(file => {
const actual = fs.readFileSync(`${__dirname}/${file}`, "utf-8"); const actual = fs.readFileSync(`${__dirname}/${file}`, 'utf-8');
fs.writeFileSync( fs.writeFileSync(
`${__dirname}/${file.replace("_actual.json", "output.json")}`, `${__dirname}/${file.replace('_actual.json', 'output.json')}`,
actual actual
); );
}); });

@ -1,5 +1,5 @@
export default { export default {
html: `<input>`, html: '<input>',
test({ assert, component, target, window }) { test({ assert, component, target, window }) {
const input = target.querySelector('input'); const input = target.querySelector('input');

@ -3,9 +3,9 @@ export default {
const button = target.querySelector('button'); const button = target.querySelector('button');
const click = new window.MouseEvent('click'); const click = new window.MouseEvent('click');
assert.htmlEqual(target.innerHTML, `<button>1</button>`); assert.htmlEqual(target.innerHTML, '<button>1</button>');
await button.dispatchEvent(click); await button.dispatchEvent(click);
await Promise.resolve(); await Promise.resolve();
assert.htmlEqual(target.innerHTML, `<button>2</button>`); assert.htmlEqual(target.innerHTML, '<button>2</button>');
}, },
}; };

@ -1,3 +1,3 @@
export default { export default {
html: `<div>a</div> <div>b</div> <div>c</div>` html: '<div>a</div> <div>b</div> <div>c</div>'
}; };

@ -1,5 +1,5 @@
export default { export default {
html: `<textarea></textarea>`, html: '<textarea></textarea>',
test({ assert, component, target }) { test({ assert, component, target }) {
const textarea = target.querySelector('textarea'); const textarea = target.querySelector('textarea');
assert.ok(textarea.readOnly === false); assert.ok(textarea.readOnly === false);

@ -1,5 +1,5 @@
export default { export default {
html: `<textarea readonly></textarea>`, html: '<textarea readonly></textarea>',
test({ assert, component, target }) { test({ assert, component, target }) {
const textarea = target.querySelector('textarea'); const textarea = target.querySelector('textarea');
assert.ok(textarea.readOnly); assert.ok(textarea.readOnly);

@ -1,3 +1,3 @@
export default { export default {
html: `<span title='"foo"'>foo</span>` html: '<span title=\'"foo"\'>foo</span>'
}; };

@ -1,8 +1,8 @@
export default { export default {
html: `<div id="foo"></div>`, html: '<div id="foo"></div>',
test({ assert, component, target }) { test({ assert, component, target }) {
component.id = 'bar'; component.id = 'bar';
assert.equal( target.innerHTML, `<div id="bar"></div>` ); assert.equal( target.innerHTML, '<div id="bar"></div>' );
} }
}; };

@ -6,7 +6,7 @@ export default {
inputValue: 42 inputValue: 42
}, },
html: `<input type="text">`, html: '<input type="text">',
test({ assert, component, target }) { test({ assert, component, target }) {
const input = target.querySelector('input'); const input = target.querySelector('input');

@ -1,5 +1,5 @@
export default { export default {
html: `<div style="color: red;">red</div>`, html: '<div style="color: red;">red</div>',
test({ assert, component, target }) { test({ assert, component, target }) {
const div = target.querySelector( 'div' ); const div = target.querySelector( 'div' );
@ -7,7 +7,7 @@ export default {
assert.equal( div.style.color, 'red' ); assert.equal( div.style.color, 'red' );
component.color = 'blue'; component.color = 'blue';
assert.equal( target.innerHTML, `<div style="color: blue;">blue</div>` ); assert.equal( target.innerHTML, '<div style="color: blue;">blue</div>' );
assert.equal( div.style.color, 'blue' ); assert.equal( div.style.color, 'blue' );
} }
}; };

@ -1,3 +1,3 @@
export default { export default {
html: `<div class=""></div>` html: '<div class=""></div>'
}; };

@ -1,3 +1,3 @@
export default { export default {
html: `<div class="false"></div>`, html: '<div class="false"></div>',
}; };

@ -1,9 +1,9 @@
export default { export default {
props: { props: {
testName: "testClassName" testName: 'testClassName'
}, },
html: `<div class="testClassName"></div>`, html: '<div class="testClassName"></div>',
test({ assert, component, target }) { test({ assert, component, target }) {
const div = target.querySelector('div'); const div = target.querySelector('div');

@ -1,5 +1,5 @@
export default { export default {
html: `<div class=" svelte-x1o6ra"></div>`, html: '<div class=" svelte-x1o6ra"></div>',
test({ assert, component, target }) { test({ assert, component, target }) {
const div = target.querySelector('div'); const div = target.querySelector('div');

@ -1,10 +1,10 @@
export default { export default {
props: { props: {
testName1: "test1", testName1: 'test1',
testName2: "test2", testName2: 'test2',
}, },
html: `<div class="test1test2"></div>`, html: '<div class="test1test2"></div>',
test({ assert, component, target }) { test({ assert, component, target }) {
const div = target.querySelector('div'); const div = target.querySelector('div');
@ -15,11 +15,11 @@ export default {
assert.equal(div.className, '0'); assert.equal(div.className, '0');
component.testName1 = null; component.testName1 = null;
component.testName2 = "test"; component.testName2 = 'test';
assert.equal(div.className, 'nulltest'); assert.equal(div.className, 'nulltest');
component.testName1 = undefined; component.testName1 = undefined;
component.testName2 = "test"; component.testName2 = 'test';
assert.equal(div.className, 'undefinedtest'); assert.equal(div.className, 'undefinedtest');
component.testName1 = undefined; component.testName1 = undefined;

@ -1,10 +1,10 @@
export default { export default {
props: { props: {
testName1: "test1", testName1: 'test1',
testName2: "test2", testName2: 'test2',
}, },
html: `<div class="test1test2 svelte-x1o6ra"></div>`, html: '<div class="test1test2 svelte-x1o6ra"></div>',
test({ assert, component, target }) { test({ assert, component, target }) {
const div = target.querySelector('div'); const div = target.querySelector('div');
@ -15,11 +15,11 @@ export default {
assert.equal(div.className, '0 svelte-x1o6ra'); assert.equal(div.className, '0 svelte-x1o6ra');
component.testName1 = null; component.testName1 = null;
component.testName2 = "test"; component.testName2 = 'test';
assert.equal(div.className, 'nulltest svelte-x1o6ra'); assert.equal(div.className, 'nulltest svelte-x1o6ra');
component.testName1 = undefined; component.testName1 = undefined;
component.testName2 = "test"; component.testName2 = 'test';
assert.equal(div.className, 'undefinedtest svelte-x1o6ra'); assert.equal(div.className, 'undefinedtest svelte-x1o6ra');
component.testName1 = undefined; component.testName1 = undefined;

@ -1,9 +1,9 @@
export default { export default {
props: { props: {
testName: "testClassName" testName: 'testClassName'
}, },
html: `<div class="testClassName"></div>`, html: '<div class="testClassName"></div>',
test({ assert, component, target }) { test({ assert, component, target }) {
const div = target.querySelector('div'); const div = target.querySelector('div');

@ -1,9 +1,9 @@
export default { export default {
props: { props: {
testName: "testClassName" testName: 'testClassName'
}, },
html: `<div class="testClassName svelte-x1o6ra"></div>`, html: '<div class="testClassName svelte-x1o6ra"></div>',
test({ assert, component, target }) { test({ assert, component, target }) {
const div = target.querySelector('div'); const div = target.querySelector('div');

@ -1,10 +1,10 @@
export default { export default {
props: { props: {
testName1: "test1", testName1: 'test1',
testName2: "test2", testName2: 'test2',
}, },
html: `<div class="test1test2"></div>`, html: '<div class="test1test2"></div>',
test({ assert, component, target }) { test({ assert, component, target }) {
const div = target.querySelector('div'); const div = target.querySelector('div');
@ -15,11 +15,11 @@ export default {
assert.equal(div.className, '0'); assert.equal(div.className, '0');
component.testName1 = null; component.testName1 = null;
component.testName2 = "test"; component.testName2 = 'test';
assert.equal(div.className, 'nulltest'); assert.equal(div.className, 'nulltest');
component.testName1 = undefined; component.testName1 = undefined;
component.testName2 = "test"; component.testName2 = 'test';
assert.equal(div.className, 'undefinedtest'); assert.equal(div.className, 'undefinedtest');
component.testName1 = undefined; component.testName1 = undefined;

@ -1,10 +1,10 @@
export default { export default {
props: { props: {
testName1: "test1", testName1: 'test1',
testName2: "test2", testName2: 'test2',
}, },
html: `<div class="test1test2 svelte-x1o6ra"></div>`, html: '<div class="test1test2 svelte-x1o6ra"></div>',
test({ assert, component, target }) { test({ assert, component, target }) {
const div = target.querySelector('div'); const div = target.querySelector('div');
@ -15,11 +15,11 @@ export default {
assert.equal(div.className, '0 svelte-x1o6ra'); assert.equal(div.className, '0 svelte-x1o6ra');
component.testName1 = null; component.testName1 = null;
component.testName2 = "test"; component.testName2 = 'test';
assert.equal(div.className, 'nulltest svelte-x1o6ra'); assert.equal(div.className, 'nulltest svelte-x1o6ra');
component.testName1 = undefined; component.testName1 = undefined;
component.testName2 = "test"; component.testName2 = 'test';
assert.equal(div.className, 'undefinedtest svelte-x1o6ra'); assert.equal(div.className, 'undefinedtest svelte-x1o6ra');
component.testName1 = undefined; component.testName1 = undefined;

@ -1,3 +1,3 @@
export default { export default {
html: `<div></div>`, html: '<div></div>',
}; };

@ -1,3 +1,3 @@
export default { export default {
html: `<a href='mailto:hello@example.com'>email</a>` html: '<a href=\'mailto:hello@example.com\'>email</a>'
}; };

@ -1,5 +1,5 @@
export default { export default {
html: `<textarea readonly=""></textarea>`, html: '<textarea readonly=""></textarea>',
test({ assert, component, target }) { test({ assert, component, target }) {
const textarea = target.querySelector( 'textarea' ); const textarea = target.querySelector( 'textarea' );
assert.ok( textarea.readOnly ); assert.ok( textarea.readOnly );

@ -1,3 +1,3 @@
export default { export default {
html: `<span title='"foo"'>foo</span>` html: '<span title=\'"foo"\'>foo</span>'
}; };

@ -1,3 +1,3 @@
export default { export default {
html: `<div class="foo"></div>` html: '<div class="foo"></div>'
}; };

@ -1,3 +1,3 @@
export default { export default {
html: `<div></div>`, html: '<div></div>',
}; };

@ -24,7 +24,7 @@ export default {
`); `);
component.show = false; component.show = false;
assert.htmlEqual(target.innerHTML, `<div></div>`); assert.htmlEqual(target.innerHTML, '<div></div>');
component.show = true; component.show = true;
assert.htmlEqual(target.innerHTML, ` assert.htmlEqual(target.innerHTML, `

@ -9,7 +9,7 @@ export default {
promise promise
}, },
html: ``, html: '',
async test({ assert, component, target }) { async test({ assert, component, target }) {
component.condition = false; component.condition = false;
@ -17,6 +17,6 @@ export default {
fulfil(); fulfil();
await new Promise(f => setTimeout(f, 0)); await new Promise(f => setTimeout(f, 0));
assert.htmlEqual(target.innerHTML, ``); assert.htmlEqual(target.innerHTML, '');
} }
}; };

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save