get all remaining validator tests passing except the event modifier stuff

pull/1866/head
Rich Harris 7 years ago
parent b5513497a1
commit 68464ca94f

@ -3,7 +3,7 @@ import { walk, childKeys } from 'estree-walker';
import { getLocator } from 'locate-character'; import { getLocator } from 'locate-character';
import Stats from '../Stats'; import Stats from '../Stats';
import reservedNames from '../utils/reservedNames'; import reservedNames from '../utils/reservedNames';
import namespaces from '../utils/namespaces'; import { namespaces, validNamespaces } from '../utils/namespaces';
import { removeNode } from '../utils/removeNode'; import { removeNode } from '../utils/removeNode';
import wrapModule from './wrapModule'; import wrapModule from './wrapModule';
import { createScopes, extractNames, Scope } from '../utils/annotateWithScopes'; import { createScopes, extractNames, Scope } from '../utils/annotateWithScopes';
@ -18,6 +18,7 @@ import flattenReference from '../utils/flattenReference';
import addToSet from '../utils/addToSet'; import addToSet from '../utils/addToSet';
import isReference from 'is-reference'; import isReference from 'is-reference';
import TemplateScope from './nodes/shared/TemplateScope'; import TemplateScope from './nodes/shared/TemplateScope';
import fuzzymatch from '../utils/fuzzymatch';
type Meta = { type Meta = {
namespace?: string; namespace?: string;
@ -602,42 +603,62 @@ function process_meta(component, nodes) {
const meta: Meta = {}; const meta: Meta = {};
const node = nodes.find(node => node.name === 'svelte:meta'); const node = nodes.find(node => node.name === 'svelte:meta');
function get_value(attribute, message) {
const { name, value } = attribute;
if (value.length > 1 || (value[0] && value[0].type !== 'Text')) {
component.error(attribute, {
code: `invalid-${name}-attribute`,
message
});
}
return value[0].data;
}
if (node) { if (node) {
node.attributes.forEach(attribute => { node.attributes.forEach(attribute => {
if (attribute.type === 'Attribute') { if (attribute.type === 'Attribute') {
const { name, value } = attribute; const { name } = attribute;
if (value.length > 1 || (value[0] && value[0].type !== 'Text')) {
component.error(attribute, {
code: `invalid-meta-attribute`,
message: `<svelte:meta> cannot have dynamic attributes`
});
}
const { data } = value[0];
switch (name) { switch (name) {
case 'tag': case 'tag':
case 'namespace': const tag = get_value(attribute, `'tag' must be a string literal`);
if (!data) {
if (!/^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/.test(tag)) {
component.error(attribute, { component.error(attribute, {
code: `invalid-${name}-attribute`, code: `invalid-tag-property`,
message: `<svelte:meta> ${name} attribute must have a string value` message: `tag name must be two or more words joined by the '-' character`
}); });
} }
meta[name] = data; meta.tag = tag;
break; break;
case 'immutable': case 'namespace':
if (data && (data !== 'true' && data !== 'false')) { const ns = get_value(attribute, `The 'namespace' attribute must be a string literal representing a valid namespace`);
component.error(attribute, {
code: `invalid-immutable-attribute`, if (validNamespaces.indexOf(ns) === -1) {
message: `<svelte:meta> immutable attribute must be true or false` const match = fuzzymatch(ns, validNamespaces);
}); if (match) {
component.error(attribute, {
code: `invalid-namespace-property`,
message: `Invalid namespace '${ns}' (did you mean '${match}'?)`
});
} else {
component.error(attribute, {
code: `invalid-namespace-property`,
message: `Invalid namespace '${ns}'`
});
}
} }
meta.immutable = data !== 'false'; meta.namespace = ns;
break;
case 'immutable':
meta.immutable = get_value(attribute, `immutable attribute must be true or false`) !== 'false';
break;
default: default:
component.error(attribute, { component.error(attribute, {
@ -668,8 +689,6 @@ function process_meta(component, nodes) {
message: `<svelte:meta> can only have static 'tag', 'namespace' and 'immutable' attributes, or a bind:props directive` message: `<svelte:meta> can only have static 'tag', 'namespace' and 'immutable' attributes, or a bind:props directive`
}); });
} }
}); });
} }

@ -9,7 +9,7 @@ import Animation from './Animation';
import Action from './Action'; import Action from './Action';
import Class from './Class'; import Class from './Class';
import Text from './Text'; import Text from './Text';
import * as namespaces from '../../utils/namespaces'; import { namespaces } from '../../utils/namespaces';
import mapChildren from './shared/mapChildren'; import mapChildren from './shared/mapChildren';
import { dimensions } from '../../utils/patterns'; import { dimensions } from '../../utils/patterns';
import fuzzymatch from '../../utils/fuzzymatch'; import fuzzymatch from '../../utils/fuzzymatch';

@ -10,7 +10,7 @@ import { stringify, escapeHTML, escape } from '../../../../utils/stringify';
import TextWrapper from '../Text'; import TextWrapper from '../Text';
import fixAttributeCasing from '../../../../utils/fixAttributeCasing'; import fixAttributeCasing from '../../../../utils/fixAttributeCasing';
import deindent from '../../../../utils/deindent'; import deindent from '../../../../utils/deindent';
import namespaces from '../../../../utils/namespaces'; import { namespaces } from '../../../../utils/namespaces';
import AttributeWrapper from './Attribute'; import AttributeWrapper from './Attribute';
import StyleAttributeWrapper from './StyleAttribute'; import StyleAttributeWrapper from './StyleAttribute';
import { dimensions } from '../../../../utils/patterns'; import { dimensions } from '../../../../utils/patterns';

@ -20,6 +20,4 @@ export const validNamespaces = [
xmlns, xmlns,
]; ];
const namespaces: Record<string, string> = { html, mathml, svg, xlink, xml, xmlns }; export const namespaces: Record<string, string> = { html, mathml, svg, xlink, xml, xmlns };
export default namespaces;

@ -1,15 +1,15 @@
[{ [{
"code": "invalid-namespace-property", "code": "invalid-namespace-property",
"message": "Invalid namespace 'lol'", "message": "Invalid namespace 'lol'",
"pos": 29, "pos": 13,
"start": { "start": {
"line": 3, "line": 1,
"column": 2, "column": 13,
"character": 29 "character": 13
}, },
"end": { "end": {
"line": 3, "line": 1,
"column": 18, "column": 28,
"character": 45 "character": 28
} }
}] }]

@ -1,15 +1,15 @@
[{ [{
"code": "invalid-namespace-property", "code": "invalid-namespace-property",
"message": "Invalid namespace 'http://www.w3.org/1999/svg' (did you mean 'http://www.w3.org/2000/svg'?)", "message": "Invalid namespace 'http://www.w3.org/1999/svg' (did you mean 'http://www.w3.org/2000/svg'?)",
"pos": 29, "pos": 13,
"start": { "start": {
"line": 3, "line": 1,
"column": 2, "column": 13,
"character": 29 "character": 13
}, },
"end": { "end": {
"line": 3, "line": 1,
"column": 41, "column": 51,
"character": 68 "character": 51
} }
}] }]

@ -1,15 +1,15 @@
[{ [{
"code": "invalid-namespace-attribute", "code": "invalid-namespace-attribute",
"message": "The 'namespace' attribute must be a string literal representing a valid namespace", "message": "The 'namespace' attribute must be a string literal representing a valid namespace",
"pos": 79, "pos": 13,
"start": { "start": {
"line": 5, "line": 1,
"column": 2, "column": 13,
"character": 79 "character": 13
}, },
"end": { "end": {
"line": 5, "line": 1,
"column": 11, "column": 27,
"character": 88 "character": 27
} }
}] }]

@ -2,14 +2,14 @@
"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",
"start": { "start": {
"line": 3, "line": 1,
"column": 7, "column": 13,
"character": 34 "character": 13
}, },
"end": { "end": {
"line": 3, "line": 1,
"column": 16, "column": 26,
"character": 43 "character": 26
}, },
"pos": 34 "pos": 13
}] }]

@ -2,14 +2,14 @@
"code": "invalid-tag-attribute", "code": "invalid-tag-attribute",
"message": "'tag' must be a string literal", "message": "'tag' must be a string literal",
"start": { "start": {
"line": 3, "line": 1,
"column": 7, "column": 13,
"character": 34 "character": 13
}, },
"end": { "end": {
"line": 3, "line": 1,
"column": 9, "column": 21,
"character": 36 "character": 21
}, },
"pos": 34 "pos": 13
}] }]
Loading…
Cancel
Save