pull/11327/head
Rich Harris 2 years ago
parent 0e5632fb12
commit ea42b08036

@ -1,31 +1,15 @@
## invalid_svelte_option_attribute
## svelte_options_invalid_attribute
> `<svelte:options>` can only receive static attributes
## invalid_svelte_option_namespace
## svelte_options_invalid_attribute_value
> Unsupported `<svelte:option>` value for "namespace". Valid values are "html", "svg" or "foreign"
> Valid values are %list%
## tag_option_deprecated
> "tag" option is deprecated — use "customElement" instead
## invalid_svelte_option_runes
> Unsupported `<svelte:option>` value for "runes". Valid values are true or false
## invalid_svelte_option_accessors
> Unsupported `<svelte:option>` value for "accessors". Valid values are true or false
## invalid_svelte_option_preserveWhitespace
> Unsupported `<svelte:option>` value for "preserveWhitespace". Valid values are true or false
## invalid_svelte_option_immutable
> Unsupported `<svelte:option>` value for "immutable". Valid values are true or false
## invalid_tag_property
> Tag name must be two or more words joined by the "-" character
@ -96,4 +80,4 @@
## conflicting_slot_usage
> Cannot use `<slot>` syntax and `{@render ...}` tags in the same component. Migrate towards `{@render ...}` tags completely.
> Cannot use `<slot>` syntax and `{@render ...}` tags in the same component. Migrate towards `{@render ...}` tags completely.

@ -56,33 +56,6 @@ function e(node, code, message) {
throw new CompileError(code, message, start !== undefined && end !== undefined ? [start, end] : undefined);
}
/**
* An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function animation_invalid_placement(node) {
e(node, "animation_invalid_placement", "An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block");
}
/**
* An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block. Did you forget to add a key to your each block?
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function animation_missing_key(node) {
e(node, "animation_missing_key", "An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block. Did you forget to add a key to your each block?");
}
/**
* An element can only have one 'animate' directive
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function animation_duplicate(node) {
e(node, "animation_duplicate", "An element can only have one 'animate' directive");
}
/**
* Attribute shorthand cannot be empty
* @param {null | number | NodeLike} node
@ -445,36 +418,6 @@ export function invalid_title_content(node) {
e(node, "invalid_title_content", "`<title>` can only contain text and {tags}");
}
/**
* Valid event modifiers are %list%
* @param {null | number | NodeLike} node
* @param {string} list
* @returns {never}
*/
export function invalid_event_modifier(node, list) {
e(node, "invalid_event_modifier", `Valid event modifiers are ${list}`);
}
/**
* Event modifiers other than 'once' can only be used on DOM elements
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_component_event_modifier(node) {
e(node, "invalid_component_event_modifier", "Event modifiers other than 'once' can only be used on DOM elements");
}
/**
* The '%modifier1%' and '%modifier2%' modifiers cannot be used together
* @param {null | number | NodeLike} node
* @param {string} modifier1
* @param {string} modifier2
* @returns {never}
*/
export function invalid_event_modifier_combination(node, modifier1, modifier2) {
e(node, "invalid_event_modifier_combination", `The '${modifier1}' and '${modifier2}' modifiers cannot be used together`);
}
/**
* Cyclical dependency detected: %cycle%
* @param {null | number | NodeLike} node
@ -1137,17 +1080,18 @@ export function conflicting_children_snippet(node) {
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_svelte_option_attribute(node) {
e(node, "invalid_svelte_option_attribute", "`<svelte:options>` can only receive static attributes");
export function svelte_options_invalid_attribute(node) {
e(node, "svelte_options_invalid_attribute", "`<svelte:options>` can only receive static attributes");
}
/**
* Unsupported `<svelte:option>` value for "namespace". Valid values are "html", "svg" or "foreign"
* Valid values are %list%
* @param {null | number | NodeLike} node
* @param {string} list
* @returns {never}
*/
export function invalid_svelte_option_namespace(node) {
e(node, "invalid_svelte_option_namespace", "Unsupported `<svelte:option>` value for \"namespace\". Valid values are \"html\", \"svg\" or \"foreign\"");
export function svelte_options_invalid_attribute_value(node, list) {
e(node, "svelte_options_invalid_attribute_value", `Valid values are ${list}`);
}
/**
@ -1361,6 +1305,63 @@ export function conflicting_slot_usage(node) {
e(node, "conflicting_slot_usage", "Cannot use `<slot>` syntax and `{@render ...}` tags in the same component. Migrate towards `{@render ...}` tags completely.");
}
/**
* An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function animation_invalid_placement(node) {
e(node, "animation_invalid_placement", "An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block");
}
/**
* An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block. Did you forget to add a key to your each block?
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function animation_missing_key(node) {
e(node, "animation_missing_key", "An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block. Did you forget to add a key to your each block?");
}
/**
* An element can only have one 'animate' directive
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function animation_duplicate(node) {
e(node, "animation_duplicate", "An element can only have one 'animate' directive");
}
/**
* Valid event modifiers are %list%
* @param {null | number | NodeLike} node
* @param {string} list
* @returns {never}
*/
export function event_handler_invalid_modifier(node, list) {
e(node, "event_handler_invalid_modifier", `Valid event modifiers are ${list}`);
}
/**
* The '%modifier1%' and '%modifier2%' modifiers cannot be used together
* @param {null | number | NodeLike} node
* @param {string} modifier1
* @param {string} modifier2
* @returns {never}
*/
export function event_handler_invalid_modifier_combination(node, modifier1, modifier2) {
e(node, "event_handler_invalid_modifier_combination", `The '${modifier1}' and '${modifier2}' modifiers cannot be used together`);
}
/**
* Event modifiers other than 'once' can only be used on DOM elements
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function event_handler_invalid_component_modifier(node) {
e(node, "event_handler_invalid_component_modifier", "Event modifiers other than 'once' can only be used on DOM elements");
}
/**
* Cannot use multiple `%type%:` directives on a single element
* @param {null | number | NodeLike} node

@ -22,14 +22,14 @@ export default function read_options(node) {
for (const attribute of node.attributes) {
if (attribute.type !== 'Attribute') {
e.invalid_svelte_option_attribute(attribute);
e.svelte_options_invalid_attribute(attribute);
}
const { name } = attribute;
switch (name) {
case 'runes': {
component_options.runes = get_boolean_value(attribute, e.invalid_svelte_option_runes);
component_options.runes = get_boolean_value(attribute);
break;
}
case 'tag': {
@ -44,7 +44,7 @@ export default function read_options(node) {
if (value === true) {
e.invalid_svelte_option_customElement(attribute);
} else if (value[0].type === 'Text') {
const tag = get_static_value(attribute, () => e.invalid_tag_property(attribute));
const tag = get_static_value(attribute);
validate_tag(attribute, tag);
ce.tag = tag;
component_options.customElement = ce;
@ -151,42 +151,28 @@ export default function read_options(node) {
break;
}
case 'namespace': {
const value = get_static_value(attribute, () =>
e.invalid_svelte_option_namespace(attribute)
);
if (typeof value !== 'string') {
e.invalid_svelte_option_namespace(attribute);
}
const value = get_static_value(attribute);
if (value === namespace_svg) {
component_options.namespace = 'svg';
} else if (value === 'html' || value === 'svg' || value === 'foreign') {
component_options.namespace = value;
} else {
e.invalid_svelte_option_namespace(attribute);
e.svelte_options_invalid_attribute_value(attribute, `"html", "svg" or "foreign"`);
}
break;
}
case 'immutable': {
component_options.immutable = get_boolean_value(
attribute,
e.invalid_svelte_option_immutable
);
component_options.immutable = get_boolean_value(attribute);
break;
}
case 'preserveWhitespace': {
component_options.preserveWhitespace = get_boolean_value(
attribute,
e.invalid_svelte_option_preserveWhitespace
);
component_options.preserveWhitespace = get_boolean_value(attribute);
break;
}
case 'accessors': {
component_options.accessors = get_boolean_value(
attribute,
e.invalid_svelte_option_accessors
);
component_options.accessors = get_boolean_value(attribute);
break;
}
default:
@ -199,41 +185,39 @@ export default function read_options(node) {
/**
* @param {any} attribute
* @param {(attribute: any) => never} error
*/
function get_static_value(attribute, error) {
function get_static_value(attribute) {
const { value } = attribute;
const chunk = value[0];
if (!chunk) return true;
if (value.length > 1) {
error(attribute);
return null;
}
if (chunk.type === 'Text') return chunk.data;
if (chunk.expression.type !== 'Literal') {
error(attribute);
return null;
}
return chunk.expression.value;
}
/**
* @param {any} attribute
* @param {(attribute: any) => never} error
*/
function get_boolean_value(attribute, error) {
const value = get_static_value(attribute, () => error(attribute));
function get_boolean_value(attribute) {
const value = get_static_value(attribute);
if (typeof value !== 'boolean') {
error(attribute);
e.svelte_options_invalid_attribute_value(attribute, 'true or false');
}
return value;
}
/**
* @param {any} attribute
* @param {string} tag
* @param {string | null} tag
* @returns {asserts tag is string}
*/
function validate_tag(attribute, tag) {
if (typeof tag !== 'string' && tag !== null) {
if (typeof tag !== 'string') {
e.invalid_tag_property(attribute);
}
if (tag && !regex_valid_tag_name.test(tag)) {

@ -1,7 +1,7 @@
[
{
"code": "invalid_svelte_option_namespace",
"message": "Unsupported `<svelte:option>` value for \"namespace\". Valid values are \"html\", \"svg\" or \"foreign\"",
"code": "svelte_options_invalid_attribute_value",
"message": "Valid values are \"html\", \"svg\" or \"foreign\"",
"start": {
"line": 1,
"column": 16

@ -1,7 +1,7 @@
[
{
"code": "invalid_svelte_option_namespace",
"message": "Unsupported `<svelte:option>` value for \"namespace\". Valid values are \"html\", \"svg\" or \"foreign\"",
"code": "svelte_options_invalid_attribute_value",
"message": "Valid values are \"html\", \"svg\" or \"foreign\"",
"start": {
"line": 1,
"column": 16

Loading…
Cancel
Save