add codes to errors

pull/1340/head
Rich Harris 7 years ago
parent b86a1edb52
commit 35f4a1f063

@ -71,11 +71,19 @@ export class Parser {
const current = this.current();
const type = current.type === 'Element' ? `<${current.name}>` : 'Block';
this.error(`${type} was left open`, current.start);
const slug = current.type === 'Element' ? 'element' : 'block';
this.error({
code: `unclosed-${slug}`,
message: `${type} was left open`
}, current.start);
}
if (state !== fragment) {
this.error('Unexpected end of input');
this.error({
code: `unexpected-eof`,
message: 'Unexpected end of input'
});
}
if (this.html.children.length) {
@ -97,12 +105,16 @@ export class Parser {
}
acornError(err: any) {
this.error(err.message.replace(/ \(\d+:\d+\)$/, ''), err.pos);
this.error({
code: `parse-error`,
message: err.message.replace(/ \(\d+:\d+\)$/, '')
}, err.pos);
}
error(message: string, index = this.index) {
error({ code, message }: { code: string, message: string }, index = this.index) {
error(message, {
name: 'ParseError',
code,
source: this.template,
start: index,
filename: this.filename
@ -116,7 +128,10 @@ export class Parser {
}
if (required) {
this.error(message || `Expected ${str}`);
this.error({
code: `unexpected-${this.index === this.template.length ? 'eof' : 'token'}`,
message: message || `Expected ${str}`
});
}
return false;
@ -164,7 +179,10 @@ export class Parser {
const identifier = this.template.slice(this.index, this.index = i);
if (reservedNames.has(identifier)) {
this.error(`'${identifier}' is a reserved word in JavaScript and cannot be used here`, start);
this.error({
code: `unexpected-reserved-word`,
message: `'${identifier}' is a reserved word in JavaScript and cannot be used here`
}, start);
}
return identifier;
@ -172,7 +190,10 @@ export class Parser {
readUntil(pattern: RegExp) {
if (this.index >= this.template.length)
this.error('Unexpected end of input');
this.error({
code: `unexpected-eof`,
message: 'Unexpected end of input'
});
const start = this.index;
const match = pattern.exec(this.template.slice(start));
@ -192,7 +213,10 @@ export class Parser {
requireWhitespace() {
if (!whitespace.test(this.template[this.index])) {
this.error(`Expected whitespace`);
this.error({
code: `missing-whitespace`,
message: `Expected whitespace`
});
}
this.allowWhitespace();

@ -2,7 +2,19 @@ import { parseExpressionAt } from 'acorn';
import repeat from '../../utils/repeat';
import { Parser } from '../index';
const DIRECTIVES = {
const DIRECTIVES: Record<string, {
names: string[];
attribute: (
start: number,
end: number,
type: string,
name: string,
expression?: any,
directiveName?: string
) => { start: number, end: number, type: string, name: string, value?: any, expression?: any };
allowedExpressionTypes: string[];
error: string;
}> = {
Ref: {
names: ['ref'],
attribute(start, end, type, name) {
@ -143,7 +155,10 @@ export function readDirective(
try {
expression = readExpression(parser, expressionStart, quoteMark);
if (directive.allowedExpressionTypes.indexOf(expression.type) === -1) {
parser.error(directive.error, expressionStart);
parser.error({
code: `invalid-directive-value`,
message: directive.error
}, expressionStart);
}
} catch (err) {
if (parser.template[expressionStart] === '{') {
@ -155,7 +170,10 @@ export function readDirective(
const value = parser.template.slice(expressionStart + (parser.v2 ? 1 : 2), expressionEnd);
message += ` — use '${value}', not '${parser.v2 ? `{${value}}` : `{{${value}}}`}'`;
}
parser.error(message, expressionStart);
parser.error({
code: `invalid-directive-value`,
message
}, expressionStart);
}
throw err;

@ -12,7 +12,10 @@ export default function readScript(parser: Parser, start: number, attributes: No
const scriptStart = parser.index;
const scriptEnd = parser.template.indexOf(scriptClosingTag, scriptStart);
if (scriptEnd === -1) parser.error(`<script> must have a closing tag`);
if (scriptEnd === -1) parser.error({
code: `unclosed-script`,
message: `<script> must have a closing tag`
});
const source =
repeat(' ', scriptStart) + parser.template.slice(scriptStart, scriptEnd);

@ -17,7 +17,10 @@ export default function readStyle(parser: Parser, start: number, attributes: Nod
});
} catch (err) {
if (err.name === 'CssSyntaxError') {
parser.error(err.message, err.offset);
parser.error({
code: `css-syntax-error`,
message: err.message
}, err.offset);
} else {
throw err;
}

@ -56,7 +56,10 @@ export default function mustache(parser: Parser) {
} else if (block.type === 'AwaitBlock') {
expected = 'await';
} else {
parser.error(`Unexpected block closing tag`);
parser.error({
code: `unexpected-block-close`,
message: `Unexpected block closing tag`
});
}
parser.eat(expected, true);
@ -86,9 +89,10 @@ export default function mustache(parser: Parser) {
} else if (parser.eat(parser.v2 ? ':elseif' : 'elseif')) {
const block = parser.current();
if (block.type !== 'IfBlock')
parser.error(
'Cannot have an {{elseif ...}} block outside an {{#if ...}} block'
);
parser.error({
code: `invalid-elseif-placement`,
message: 'Cannot have an {{elseif ...}} block outside an {{#if ...}} block'
});
parser.requireWhitespace();
@ -117,9 +121,10 @@ export default function mustache(parser: Parser) {
} else if (parser.eat(parser.v2 ? ':else' : 'else')) {
const block = parser.current();
if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
parser.error(
'Cannot have an {{else}} block outside an {{#if ...}} or {{#each ...}} block'
);
parser.error({
code: `invalid-else-placement`,
message: 'Cannot have an {{else}} block outside an {{#if ...}} or {{#each ...}} block'
});
}
parser.allowWhitespace();
@ -191,7 +196,10 @@ export default function mustache(parser: Parser) {
} else if (parser.eat('await')) {
type = 'AwaitBlock';
} else {
parser.error(`Expected if, each or await`);
parser.error({
code: `expected-block-type`,
message: `Expected if, each or await`
});
}
parser.requireWhitespace();
@ -249,20 +257,30 @@ export default function mustache(parser: Parser) {
parser.allowWhitespace();
const destructuredContext = parser.readIdentifier();
if (!destructuredContext) parser.error(`Expected name`);
if (!destructuredContext) parser.error({
code: `expected-name`,
message: `Expected name`
});
block.destructuredContexts.push(destructuredContext);
parser.allowWhitespace();
} while (parser.eat(','));
if (!block.destructuredContexts.length) parser.error(`Expected name`);
if (!block.destructuredContexts.length) parser.error({
code: `expected-name`,
message: `Expected name`
});
block.context = block.destructuredContexts.join('_');
parser.allowWhitespace();
parser.eat(']', true);
} else {
block.context = parser.readIdentifier();
if (!block.context) parser.error(`Expected name`);
if (!block.context) parser.error({
code: `expected-name`,
message: `Expected name`
});
}
parser.allowWhitespace();
@ -270,7 +288,11 @@ export default function mustache(parser: Parser) {
if (parser.eat(',')) {
parser.allowWhitespace();
block.index = parser.readIdentifier();
if (!block.index) parser.error(`Expected name`);
if (!block.index) parser.error({
code: `expected-name`,
message: `Expected name`
});
parser.allowWhitespace();
}
@ -287,7 +309,10 @@ export default function mustache(parser: Parser) {
expression.property.computed ||
expression.property.type !== 'Identifier'
) {
parser.error('invalid key', expression.start);
parser.error({
code: `invalid-key`,
message: 'invalid key'
}, expression.start);
}
block.key = expression.property.name;
@ -296,7 +321,10 @@ export default function mustache(parser: Parser) {
parser.allowWhitespace();
} else if (parser.eat('@')) {
block.key = parser.readIdentifier();
if (!block.key) parser.error(`Expected name`);
if (!block.key) parser.error({
code: `expected-name`,
message: `Expected name`
});
parser.allowWhitespace();
}
}

@ -83,21 +83,27 @@ export default function tag(parser: Parser) {
const name = readTagName(parser);
if (metaTags.has(name)) {
const slug = metaTags.get(name).toLowerCase();
if (isClosingTag) {
if ((name === ':Window' || name === 'svelte:window') && parser.current().children.length) {
parser.error(
`<${name}> cannot have children`,
parser.current().children[0].start
);
parser.error({
code: `invalid-window-content`,
message: `<${name}> cannot have children`
}, parser.current().children[0].start);
}
} else {
if (name in parser.metaTags) {
parser.error(`A component can only have one <${name}> tag`, start);
parser.error({
code: `duplicate-${slug}`,
message: `A component can only have one <${name}> tag`
}, start);
}
if (parser.stack.length > 1) {
console.log(parser.stack);
parser.error(`<${name}> tags cannot be inside elements or blocks`, start);
parser.error({
code: `invalid-${slug}-placement`,
message: `<${name}> tags cannot be inside elements or blocks`
}, start);
}
parser.metaTags[name] = true;
@ -121,21 +127,21 @@ export default function tag(parser: Parser) {
if (isClosingTag) {
if (isVoidElementName(name)) {
parser.error(
`<${name}> is a void element and cannot have children, or a closing tag`,
start
);
parser.error({
code: `invalid-void-content`,
message: `<${name}> is a void element and cannot have children, or a closing tag`
}, start);
}
if (!parser.eat('>')) parser.error(`Expected '>'`);
parser.eat('>', true);
// close any elements that don't have their own closing tags, e.g. <div><p></div>
while (parent.name !== name) {
if (parent.type !== 'Element')
parser.error(
`</${name}> attempted to close an element that was not open`,
start
);
parser.error({
code: `invalid-closing-tag`,
message: `</${name}> attempted to close an element that was not open`
}, start);
parent.end = start;
parser.stack.pop();
@ -161,10 +167,10 @@ export default function tag(parser: Parser) {
while (i--) {
const item = parser.stack[i];
if (item.type === 'EachBlock') {
parser.error(
`<slot> cannot be a child of an each-block`,
start
);
parser.error({
code: `invalid-slot-placement`,
message: `<slot> cannot be a child of an each-block`
}, start);
}
}
}
@ -182,7 +188,10 @@ export default function tag(parser: Parser) {
let attribute;
while ((attribute = readAttribute(parser, uniqueNames))) {
if (attribute.type === 'Binding' && !parser.allowBindings) {
parser.error(`Two-way binding is disabled`, attribute.start);
parser.error({
code: `binding-disabled`,
message: `Two-way binding is disabled`
}, attribute.start);
}
element.attributes.push(attribute);
@ -193,12 +202,18 @@ export default function tag(parser: Parser) {
// TODO post v2, treat this just as any other attribute
const index = element.attributes.findIndex(attr => attr.name === 'this');
if (!~index) {
parser.error(`<svelte:component> must have a 'this' attribute`, start);
parser.error({
code: `missing-component-definition`,
message: `<svelte:component> must have a 'this' attribute`
}, start);
}
const definition = element.attributes.splice(index, 1)[0];
if (definition.value === true || definition.value.length !== 1 || definition.value[0].type === 'Text') {
parser.error(`invalid component definition`, definition.start);
parser.error({
code: `invalid-component-definition`,
message: `invalid component definition`
}, definition.start);
}
element.expression = definition.value[0].expression;
@ -210,9 +225,10 @@ export default function tag(parser: Parser) {
if (parser[special.property]) {
parser.index = start;
parser.error(
`You can only have one top-level <${name}> tag per component`
);
parser.error({
code: `duplicate-${name}`,
message: `You can only have one top-level <${name}> tag per component`
});
}
parser.eat('>', true);
@ -282,10 +298,10 @@ function readTagName(parser: Parser) {
}
if (!legal) {
parser.error(
`<${SELF}> components can only exist inside if-blocks or each-blocks`,
start
);
parser.error({
code: `invalid-self-placement`,
message: `<${SELF}> components can only exist inside if-blocks or each-blocks`
}, start);
}
return SELF;
@ -298,7 +314,10 @@ function readTagName(parser: Parser) {
if (metaTags.has(name)) return name;
if (!validTagName.test(name)) {
parser.error(`Expected valid tag name`, start);
parser.error({
code: `invalid-tag-name`,
message: `Expected valid tag name`
}, start);
}
return name;
@ -324,7 +343,10 @@ function readAttribute(parser: Parser, uniqueNames: Set<string>) {
};
} else {
if (!parser.v2) {
parser.error('Expected spread operator (...)');
parser.error({
code: `expected-spread`,
message: 'Expected spread operator (...)'
});
}
const valueStart = parser.index;
@ -356,7 +378,10 @@ function readAttribute(parser: Parser, uniqueNames: Set<string>) {
let name = parser.readUntil(/(\s|=|\/|>)/);
if (!name) return null;
if (uniqueNames.has(name)) {
parser.error('Attributes need to be unique', start);
parser.error({
code: `duplicate-attribute`,
message: 'Attributes need to be unique'
}, start);
}
uniqueNames.add(name);
@ -444,5 +469,8 @@ function readSequence(parser: Parser, done: () => boolean) {
}
}
parser.error(`Unexpected end of input`);
parser.error({
code: `unexpected-eof`,
message: `Unexpected end of input`
});
}

@ -7,7 +7,7 @@ import { Node } from '../../../interfaces';
export default function components(validator: Validator, prop: Node) {
if (prop.value.type !== 'ObjectExpression') {
validator.error(prop, {
code: `invalid-property`,
code: `invalid-components-property`,
message: `The 'components' property must be an object literal`
});
}

@ -16,7 +16,7 @@ const isFunctionExpression = new Set([
export default function computed(validator: Validator, prop: Node) {
if (prop.value.type !== 'ObjectExpression') {
validator.error(prop, {
code: `invalid-property`,
code: `invalid-computed-property`,
message: `The 'computed' property must be an object literal`
});
}

@ -8,7 +8,7 @@ export default function data(validator: Validator, prop: Node) {
if (disallowed.has(prop.value.type)) {
validator.error(prop.value, {
code: `invalid-property`,
code: `invalid-data-property`,
message: `'data' must be a function`
});
}

@ -6,7 +6,7 @@ import { Node } from '../../../interfaces';
export default function events(validator: Validator, prop: Node) {
if (prop.value.type !== 'ObjectExpression') {
validator.error(prop, {
code: `invalid-property`,
code: `invalid-events-property`,
message: `The 'events' property must be an object literal`
});
}

@ -9,7 +9,7 @@ import isThisGetCallExpression from '../../../utils/isThisGetCallExpression';
export default function helpers(validator: Validator, prop: Node) {
if (prop.value.type !== 'ObjectExpression') {
validator.error(prop, {
code: `invalid-property`,
code: `invalid-helpers-property`,
message: `The 'helpers' property must be an object literal`
});
}

@ -4,7 +4,7 @@ import { Node } from '../../../interfaces';
export default function immutable(validator: Validator, prop: Node) {
if (prop.value.type !== 'Literal' || typeof prop.value.value !== 'boolean') {
validator.error(prop.value, {
code: `invalid-property`,
code: `invalid-immutable-property`,
message: `'immutable' must be a boolean literal`
});
}

@ -11,7 +11,7 @@ const builtin = new Set(['set', 'get', 'on', 'fire', 'observe', 'destroy']);
export default function methods(validator: Validator, prop: Node) {
if (prop.value.type !== 'ObjectExpression') {
validator.error(prop, {
code: `invalid-property`,
code: `invalid-methods-property`,
message: `The 'methods' property must be an object literal`
});
}

@ -11,7 +11,7 @@ export default function namespace(validator: Validator, prop: Node) {
if (typeof ns !== 'string') {
validator.error(prop, {
code: `invalid-property`,
code: `invalid-namespace-property`,
message: `The 'namespace' property must be a string literal representing a valid namespace`
});
}
@ -20,12 +20,12 @@ export default function namespace(validator: Validator, prop: Node) {
const match = fuzzymatch(ns, namespaces.validNamespaces);
if (match) {
validator.error(prop, {
code: `invalid-property`,
code: `invalid-namespace-property`,
message: `Invalid namespace '${ns}' (did you mean '${match}'?)`
});
} else {
validator.error(prop, {
code: `invalid-property`,
code: `invalid-namespace-property`,
message: `Invalid namespace '${ns}'`
});
}

@ -6,7 +6,7 @@ export default function oncreate(validator: Validator, prop: Node) {
if (prop.value.type === 'ArrowFunctionExpression') {
if (usesThisOrArguments(prop.value.body)) {
validator.error(prop, {
code: `invalid-property`,
code: `invalid-oncreate-property`,
message: `'oncreate' should be a function expression, not an arrow function expression`
});
}

@ -6,7 +6,7 @@ export default function ondestroy(validator: Validator, prop: Node) {
if (prop.value.type === 'ArrowFunctionExpression') {
if (usesThisOrArguments(prop.value.body)) {
validator.error(prop, {
code: `invalid-property`,
code: `invalid-ondestroy-property`,
message: `'ondestroy' should be a function expression, not an arrow function expression`
});
}

@ -5,7 +5,7 @@ import nodeToString from '../../../utils/nodeToString';
export default function props(validator: Validator, prop: Node) {
if (prop.value.type !== 'ArrayExpression') {
validator.error(prop.value, {
code: `invalid-property`,
code: `invalid-props-property`,
message: `'props' must be an array expression, if specified`
});
}
@ -13,7 +13,7 @@ export default function props(validator: Validator, prop: Node) {
prop.value.elements.forEach((element: Node) => {
if (typeof nodeToString(element) !== 'string') {
validator.error(element, {
code: `invalid-property`,
code: `invalid-props-property`,
message: `'props' must be an array of string literals`
});
}

@ -8,7 +8,7 @@ export default function setup(validator: Validator, prop: Node) {
if (disallowed.has(prop.value.type)) {
validator.error(prop.value, {
code: `invalid-property`,
code: `invalid-setup-property`,
message: `'setup' must be a function`
});
}

@ -6,14 +6,14 @@ export default function tag(validator: Validator, prop: Node) {
const tag = nodeToString(prop.value);
if (typeof tag !== 'string') {
validator.error(prop.value, {
code: `invalid-property`,
code: `invalid-tag-property`,
message: `'tag' must be a string literal`
});
}
if (!/^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/.test(tag)) {
validator.error(prop.value, {
code: `invalid-property`,
code: `invalid-tag-property`,
message: `tag name must be two or more words joined by the '-' character`
});
}

@ -6,7 +6,7 @@ import { Node } from '../../../interfaces';
export default function transitions(validator: Validator, prop: Node) {
if (prop.value.type !== 'ObjectExpression') {
validator.error(prop, {
code: `invalid-property`,
code: `invalid-transitions-property`,
message: `The 'transitions' property must be an object literal`
});
}

@ -32,6 +32,7 @@ describe('parse', () => {
if (!expectedError) throw err;
try {
assert.equal(err.code, expectedError.code);
assert.equal(err.message, expectedError.message);
assert.deepEqual(err.loc, expectedError.loc);
assert.equal(err.pos, expectedError.pos);

@ -1,4 +1,5 @@
{
"code": "duplicate-attribute",
"message": "Attributes need to be unique",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "duplicate-attribute",
"message": "Attributes need to be unique",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "binding-disabled",
"message": "Two-way binding is disabled",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "binding-disabled",
"message": "Two-way binding is disabled",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-directive-value",
"message": "directive values should not be wrapped — use 'foo', not '{foo}'",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-directive-value",
"message": "directive values should not be wrapped — use 'foo', not '{{foo}}'",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-directive-value",
"message": "Can only bind to an identifier (e.g. `foo`) or a member expression (e.g. `foo.bar` or `foo[baz]`)",
"pos": 19,
"loc": {

@ -1,4 +1,5 @@
{
"code": "invalid-directive-value",
"message": "Can only bind to an identifier (e.g. `foo`) or a member expression (e.g. `foo.bar` or `foo[baz]`)",
"pos": 19,
"loc": {

@ -1,4 +1,5 @@
{
"code": "unexpected-eof",
"message": "comment was left open, expected -->",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "unexpected-eof",
"message": "comment was left open, expected -->",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "css-syntax-error",
"message": "LeftCurlyBracket is expected",
"loc": {
"line": 2,

@ -1,4 +1,5 @@
{
"code": "css-syntax-error",
"message": "LeftCurlyBracket is expected",
"loc": {
"line": 2,

@ -1,4 +1,5 @@
{
"code": "invalid-directive-value",
"message": "Expected a method call",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-directive-value",
"message": "Expected a method call",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "parse-error",
"message": "Assigning to rvalue",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "parse-error",
"message": "Assigning to rvalue",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "duplicate-style",
"message": "You can only have one top-level <style> tag per component",
"loc": {
"line": 9,

@ -1,4 +1,5 @@
{
"code": "duplicate-style",
"message": "You can only have one top-level <style> tag per component",
"loc": {
"line": 9,

@ -1,4 +1,5 @@
{
"code": "invalid-directive-value",
"message": "ref directives cannot have a value",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-directive-value",
"message": "ref directives cannot have a value",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "unclosed-script",
"message": "<script> must have a closing tag",
"loc": {
"line": 3,

@ -1,4 +1,5 @@
{
"code": "unclosed-script",
"message": "<script> must have a closing tag",
"loc": {
"line": 3,

@ -1,4 +1,5 @@
{
"code": "invalid-self-placement",
"message": "<svelte:self> components can only exist inside if-blocks or each-blocks",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-self-placement",
"message": "<:Self> components can only exist inside if-blocks or each-blocks",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "unexpected-eof",
"message": "Unexpected end of input",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "unexpected-eof",
"message": "Unexpected end of input",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "unexpected-eof",
"message": "Unexpected end of input",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "unexpected-eof",
"message": "Unexpected end of input",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "unclosed-block",
"message": "Block was left open",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "unclosed-block",
"message": "Block was left open",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "unclosed-element",
"message": "<div> was left open",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "unclosed-element",
"message": "<div> was left open",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-closing-tag",
"message": "</div> attempted to close an element that was not open",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-closing-tag",
"message": "</div> attempted to close an element that was not open",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-void-content",
"message": "<input> is a void element and cannot have children, or a closing tag",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-void-content",
"message": "<input> is a void element and cannot have children, or a closing tag",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-window-content",
"message": "<svelte:window> cannot have children",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "invalid-window-content",
"message": "<:Window> cannot have children",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
{
"code": "duplicate-window",
"message": "A component can only have one <svelte:window> tag",
"loc": {
"line": 2,

@ -1,4 +1,5 @@
{
"code": "duplicate-window",
"message": "A component can only have one <:Window> tag",
"loc": {
"line": 2,

@ -1,4 +1,5 @@
{
"code": "invalid-window-placement",
"message": "<svelte:window> tags cannot be inside elements or blocks",
"loc": {
"line": 2,

@ -1,4 +1,5 @@
{
"code": "invalid-window-placement",
"message": "<:Window> tags cannot be inside elements or blocks",
"loc": {
"line": 2,

@ -1,4 +1,5 @@
{
"code": "invalid-window-placement",
"message": "<svelte:window> tags cannot be inside elements or blocks",
"loc": {
"line": 2,

@ -1,4 +1,5 @@
{
"code": "invalid-window-placement",
"message": "<:Window> tags cannot be inside elements or blocks",
"loc": {
"line": 2,

@ -2,7 +2,7 @@ import * as fs from "fs";
import assert from "assert";
import { svelte, loadConfig, tryToLoadJson } from "../helpers.js";
describe.only("validate", () => {
describe("validate", () => {
fs.readdirSync("test/validator/samples").forEach(dir => {
if (dir[0] === ".") return;

@ -1,4 +1,5 @@
[{
"code": "unexpected-reserved-word",
"message": "'case' is a reserved word in JavaScript and cannot be used here",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
[{
"code": "unexpected-reserved-word",
"message": "'case' is a reserved word in JavaScript and cannot be used here",
"loc": {
"line": 1,

@ -1,4 +1,5 @@
[{
"code": "parse-error",
"message": "Duplicate export 'default'",
"pos": 37,
"loc": {

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-namespace-property",
"message": "Invalid namespace 'lol'",
"pos": 29,
"loc": {

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-namespace-property",
"message": "Invalid namespace 'http://www.w3.org/1999/svg' (did you mean 'http://www.w3.org/2000/svg'?)",
"pos": 29,
"loc": {

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-namespace-property",
"message": "The 'namespace' property must be a string literal representing a valid namespace",
"pos": 79,
"loc": {

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-components-property",
"message": "The 'components' property must be an object literal",
"loc": {
"line": 3,

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-events-property",
"message": "The 'events' property must be an object literal",
"loc": {
"line": 3,

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-helpers-property",
"message": "The 'helpers' property must be an object literal",
"loc": {
"line": 3,

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-methods-property",
"message": "The 'methods' property must be an object literal",
"loc": {
"line": 3,

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-transitions-property",
"message": "The 'transitions' property must be an object literal",
"loc": {
"line": 3,

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-oncreate-property",
"message": "'oncreate' should be a function expression, not an arrow function expression",
"pos": 29,
"loc": {

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-ondestroy-property",
"message": "'ondestroy' should be a function expression, not an arrow function expression",
"pos": 29,
"loc": {

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-computed-property",
"message": "The 'computed' property must be an object literal",
"loc": {
"line": 5,

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-data-property",
"message": "'data' must be a function",
"loc": {
"line": 5,

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-props-property",
"message": "'props' must be an array expression, if specified",
"loc": {
"line": 5,

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-props-property",
"message": "'props' must be an array of string literals",
"loc": {
"line": 5,

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-tag-property",
"message": "tag name must be two or more words joined by the '-' character",
"loc": {
"line": 3,

@ -1,5 +1,5 @@
[{
"code": "invalid-property",
"code": "invalid-tag-property",
"message": "'tag' must be a string literal",
"loc": {
"line": 3,

Loading…
Cancel
Save