From 1fe66eb3047872ca330971d48be3e5e054d3949c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 24 Apr 2024 17:34:57 -0400 Subject: [PATCH] more --- .../compile-errors/special_elements.md | 26 +++++----- packages/svelte/src/compiler/errors.js | 52 +++++++++---------- .../compiler/phases/1-parse/state/element.js | 16 +++--- .../src/compiler/phases/2-analyze/index.js | 2 +- .../compiler/phases/2-analyze/validation.js | 6 +-- .../samples/self-reference/_config.js | 2 +- .../_config.js | 2 +- .../samples/svelte-selfdestructive/_config.js | 2 +- .../samples/window-duplicate/_config.js | 2 +- .../samples/window-inside-block/_config.js | 2 +- .../samples/window-inside-element/_config.js | 2 +- .../dynamic-element-invalid-tag/errors.json | 2 +- .../dynamic-element-missing-tag/errors.json | 2 +- .../svelte-fragment-placement-2/errors.json | 2 +- .../svelte-fragment-placement/errors.json | 2 +- .../svelte-head-attributes/errors.json | 2 +- 16 files changed, 62 insertions(+), 62 deletions(-) diff --git a/packages/svelte/messages/compile-errors/special_elements.md b/packages/svelte/messages/compile-errors/special_elements.md index 7693dc17cc..cfca9e55c9 100644 --- a/packages/svelte/messages/compile-errors/special_elements.md +++ b/packages/svelte/messages/compile-errors/special_elements.md @@ -30,54 +30,54 @@ > `` unknown attribute '%name%' -## illegal_svelte_head_attribute +## svelte_head_illegal_attribute > `` cannot have attributes nor directives -## invalid_svelte_fragment_attribute +## svelte_fragment_invalid_attribute > `` can only have a slot attribute and (optionally) a let: directive -## invalid_svelte_fragment_slot +## svelte_fragment_invalid_slot > `` slot attribute must have a static value -## invalid_svelte_fragment_placement +## svelte_fragment_invalid_placement > `` must be the direct child of a component -## invalid_svelte_element_placement +## svelte_meta_invalid_placement > <%name%> tags cannot be inside elements or blocks -## duplicate_svelte_element +## svelte_meta_duplicate > A component can only have one <%name%> element -## invalid_self_placement +## svelte_self_invalid_placement > `` components can only exist inside {#if} blocks, {#each} blocks, {#snippet} blocks or slots passed to components -## missing_svelte_element_definition +## svelte_element_missing_this > `` must have a 'this' attribute -## missing_svelte_component_definition +## svelte_component_missing_this > `` must have a 'this' attribute -## invalid_svelte_element_definition +## svelte_element_invalid_this > Invalid element definition — must be an {expression} -## invalid_svelte_component_definition +## svelte_component_invalid_this > Invalid component definition — must be an {expression} -## invalid_svelte_tag +## svelte_meta_invalid_tag > Valid `` tag names are %list% -## conflicting_slot_usage +## slot_snippet_conflict > Cannot use `` syntax and `{@render ...}` tags in the same component. Migrate towards `{@render ...}` tags completely. diff --git a/packages/svelte/src/compiler/errors.js b/packages/svelte/src/compiler/errors.js index 2675afe306..e4d6f7a7ca 100644 --- a/packages/svelte/src/compiler/errors.js +++ b/packages/svelte/src/compiler/errors.js @@ -1154,8 +1154,8 @@ export function svelte_options_unknown_attribute(node, name) { * @param {null | number | NodeLike} node * @returns {never} */ -export function illegal_svelte_head_attribute(node) { - e(node, "illegal_svelte_head_attribute", "`` cannot have attributes nor directives"); +export function svelte_head_illegal_attribute(node) { + e(node, "svelte_head_illegal_attribute", "`` cannot have attributes nor directives"); } /** @@ -1163,8 +1163,8 @@ export function illegal_svelte_head_attribute(node) { * @param {null | number | NodeLike} node * @returns {never} */ -export function invalid_svelte_fragment_attribute(node) { - e(node, "invalid_svelte_fragment_attribute", "`` can only have a slot attribute and (optionally) a let: directive"); +export function svelte_fragment_invalid_attribute(node) { + e(node, "svelte_fragment_invalid_attribute", "`` can only have a slot attribute and (optionally) a let: directive"); } /** @@ -1172,8 +1172,8 @@ export function invalid_svelte_fragment_attribute(node) { * @param {null | number | NodeLike} node * @returns {never} */ -export function invalid_svelte_fragment_slot(node) { - e(node, "invalid_svelte_fragment_slot", "`` slot attribute must have a static value"); +export function svelte_fragment_invalid_slot(node) { + e(node, "svelte_fragment_invalid_slot", "`` slot attribute must have a static value"); } /** @@ -1181,8 +1181,8 @@ export function invalid_svelte_fragment_slot(node) { * @param {null | number | NodeLike} node * @returns {never} */ -export function invalid_svelte_fragment_placement(node) { - e(node, "invalid_svelte_fragment_placement", "`` must be the direct child of a component"); +export function svelte_fragment_invalid_placement(node) { + e(node, "svelte_fragment_invalid_placement", "`` must be the direct child of a component"); } /** @@ -1191,8 +1191,8 @@ export function invalid_svelte_fragment_placement(node) { * @param {string} name * @returns {never} */ -export function invalid_svelte_element_placement(node, name) { - e(node, "invalid_svelte_element_placement", `<${name}> tags cannot be inside elements or blocks`); +export function svelte_meta_invalid_placement(node, name) { + e(node, "svelte_meta_invalid_placement", `<${name}> tags cannot be inside elements or blocks`); } /** @@ -1201,8 +1201,8 @@ export function invalid_svelte_element_placement(node, name) { * @param {string} name * @returns {never} */ -export function duplicate_svelte_element(node, name) { - e(node, "duplicate_svelte_element", `A component can only have one <${name}> element`); +export function svelte_meta_duplicate(node, name) { + e(node, "svelte_meta_duplicate", `A component can only have one <${name}> element`); } /** @@ -1210,8 +1210,8 @@ export function duplicate_svelte_element(node, name) { * @param {null | number | NodeLike} node * @returns {never} */ -export function invalid_self_placement(node) { - e(node, "invalid_self_placement", "`` components can only exist inside {#if} blocks, {#each} blocks, {#snippet} blocks or slots passed to components"); +export function svelte_self_invalid_placement(node) { + e(node, "svelte_self_invalid_placement", "`` components can only exist inside {#if} blocks, {#each} blocks, {#snippet} blocks or slots passed to components"); } /** @@ -1219,8 +1219,8 @@ export function invalid_self_placement(node) { * @param {null | number | NodeLike} node * @returns {never} */ -export function missing_svelte_element_definition(node) { - e(node, "missing_svelte_element_definition", "`` must have a 'this' attribute"); +export function svelte_element_missing_this(node) { + e(node, "svelte_element_missing_this", "`` must have a 'this' attribute"); } /** @@ -1228,8 +1228,8 @@ export function missing_svelte_element_definition(node) { * @param {null | number | NodeLike} node * @returns {never} */ -export function missing_svelte_component_definition(node) { - e(node, "missing_svelte_component_definition", "`` must have a 'this' attribute"); +export function svelte_component_missing_this(node) { + e(node, "svelte_component_missing_this", "`` must have a 'this' attribute"); } /** @@ -1237,8 +1237,8 @@ export function missing_svelte_component_definition(node) { * @param {null | number | NodeLike} node * @returns {never} */ -export function invalid_svelte_element_definition(node) { - e(node, "invalid_svelte_element_definition", "Invalid element definition — must be an {expression}"); +export function svelte_element_invalid_this(node) { + e(node, "svelte_element_invalid_this", "Invalid element definition — must be an {expression}"); } /** @@ -1246,8 +1246,8 @@ export function invalid_svelte_element_definition(node) { * @param {null | number | NodeLike} node * @returns {never} */ -export function invalid_svelte_component_definition(node) { - e(node, "invalid_svelte_component_definition", "Invalid component definition — must be an {expression}"); +export function svelte_component_invalid_this(node) { + e(node, "svelte_component_invalid_this", "Invalid component definition — must be an {expression}"); } /** @@ -1256,8 +1256,8 @@ export function invalid_svelte_component_definition(node) { * @param {string} list * @returns {never} */ -export function invalid_svelte_tag(node, list) { - e(node, "invalid_svelte_tag", `Valid \`\` tag names are ${list}`); +export function svelte_meta_invalid_tag(node, list) { + e(node, "svelte_meta_invalid_tag", `Valid \`\` tag names are ${list}`); } /** @@ -1265,8 +1265,8 @@ export function invalid_svelte_tag(node, list) { * @param {null | number | NodeLike} node * @returns {never} */ -export function conflicting_slot_usage(node) { - e(node, "conflicting_slot_usage", "Cannot use `` syntax and `{@render ...}` tags in the same component. Migrate towards `{@render ...}` tags completely."); +export function slot_snippet_conflict(node) { + e(node, "slot_snippet_conflict", "Cannot use `` syntax and `{@render ...}` tags in the same component. Migrate towards `{@render ...}` tags completely."); } /** diff --git a/packages/svelte/src/compiler/phases/1-parse/state/element.js b/packages/svelte/src/compiler/phases/1-parse/state/element.js index 7696b23a66..ce6a0805a7 100644 --- a/packages/svelte/src/compiler/phases/1-parse/state/element.js +++ b/packages/svelte/src/compiler/phases/1-parse/state/element.js @@ -108,11 +108,11 @@ export default function tag(parser) { } } else { if (name in parser.meta_tags) { - e.duplicate_svelte_element(start, name); + e.svelte_meta_duplicate(start, name); } if (parent.type !== 'Root') { - e.invalid_svelte_element_placement(start, name); + e.svelte_meta_invalid_placement(start, name); } parser.meta_tags[name] = true; @@ -233,7 +233,7 @@ export default function tag(parser) { (attr) => attr.type === 'Attribute' && attr.name === 'this' ); if (index === -1) { - e.missing_svelte_component_definition(start); + e.svelte_component_missing_this(start); } const definition = /** @type {import('#compiler').Attribute} */ ( @@ -244,7 +244,7 @@ export default function tag(parser) { definition.value.length !== 1 || definition.value[0].type === 'Text' ) { - e.invalid_svelte_component_definition(definition.start); + e.svelte_component_invalid_this(definition.start); } element.expression = definition.value[0].expression; @@ -256,14 +256,14 @@ export default function tag(parser) { (attr) => attr.type === 'Attribute' && attr.name === 'this' ); if (index === -1) { - e.missing_svelte_element_definition(start); + e.svelte_element_missing_this(start); } const definition = /** @type {import('#compiler').Attribute} */ ( element.attributes.splice(index, 1)[0] ); if (definition.value === true || definition.value.length !== 1) { - e.invalid_svelte_element_definition(definition.start); + e.svelte_element_invalid_this(definition.start); } const chunk = definition.value[0]; element.tag = @@ -387,7 +387,7 @@ function read_tag_name(parser) { } if (!legal) { - e.invalid_self_placement(start); + e.svelte_self_invalid_placement(start); } return 'svelte:self'; @@ -404,7 +404,7 @@ function read_tag_name(parser) { if (name.startsWith('svelte:')) { const list = `${valid_meta_tags.slice(0, -1).join(', ')} or ${valid_meta_tags[valid_meta_tags.length - 1]}`; - e.invalid_svelte_tag(start, list); + e.svelte_meta_invalid_tag(start, list); } if (!valid_tag_name.test(name)) { diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index bac63eab45..1c283979fc 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -507,7 +507,7 @@ export function analyze_component(root, source, options) { } if (analysis.uses_render_tags && (analysis.uses_slots || analysis.slot_names.size > 0)) { - e.conflicting_slot_usage(analysis.slot_names.values().next().value); + e.slot_snippet_conflict(analysis.slot_names.values().next().value); } // warn on any nonstate declarations that are a) reassigned and b) referenced in the template diff --git a/packages/svelte/src/compiler/phases/2-analyze/validation.js b/packages/svelte/src/compiler/phases/2-analyze/validation.js index 3875fa7098..b20b90f353 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/validation.js +++ b/packages/svelte/src/compiler/phases/2-analyze/validation.js @@ -646,7 +646,7 @@ const validation = { SvelteHead(node) { const attribute = node.attributes[0]; if (attribute) { - e.illegal_svelte_head_attribute(attribute); + e.svelte_head_illegal_attribute(attribute); } }, SvelteElement(node, context) { @@ -659,7 +659,7 @@ const validation = { SvelteFragment(node, context) { const parent = context.path.at(-2); if (parent?.type !== 'Component' && parent?.type !== 'SvelteComponent') { - e.invalid_svelte_fragment_placement(node); + e.svelte_fragment_invalid_placement(node); } for (const attribute of node.attributes) { @@ -668,7 +668,7 @@ const validation = { validate_slot_attribute(context, attribute); } } else if (attribute.type !== 'LetDirective') { - e.invalid_svelte_fragment_attribute(attribute); + e.svelte_fragment_invalid_attribute(attribute); } } }, diff --git a/packages/svelte/tests/compiler-errors/samples/self-reference/_config.js b/packages/svelte/tests/compiler-errors/samples/self-reference/_config.js index be27484ce6..292dbf92d2 100644 --- a/packages/svelte/tests/compiler-errors/samples/self-reference/_config.js +++ b/packages/svelte/tests/compiler-errors/samples/self-reference/_config.js @@ -2,7 +2,7 @@ import { test } from '../../test'; export default test({ error: { - code: 'invalid_self_placement', + code: 'svelte_self_invalid_placement', message: '`` components can only exist inside {#if} blocks, {#each} blocks, {#snippet} blocks or slots passed to components', position: [1, 1] diff --git a/packages/svelte/tests/compiler-errors/samples/slot-conflicting-with-render-tag/_config.js b/packages/svelte/tests/compiler-errors/samples/slot-conflicting-with-render-tag/_config.js index d85305d319..c46640e663 100644 --- a/packages/svelte/tests/compiler-errors/samples/slot-conflicting-with-render-tag/_config.js +++ b/packages/svelte/tests/compiler-errors/samples/slot-conflicting-with-render-tag/_config.js @@ -2,7 +2,7 @@ import { test } from '../../test'; export default test({ error: { - code: 'conflicting_slot_usage', + code: 'slot_snippet_conflict', message: 'Cannot use `` syntax and `{@render ...}` tags in the same component. Migrate towards `{@render ...}` tags completely.', position: [71, 84] diff --git a/packages/svelte/tests/compiler-errors/samples/svelte-selfdestructive/_config.js b/packages/svelte/tests/compiler-errors/samples/svelte-selfdestructive/_config.js index f5ff354027..bc995db523 100644 --- a/packages/svelte/tests/compiler-errors/samples/svelte-selfdestructive/_config.js +++ b/packages/svelte/tests/compiler-errors/samples/svelte-selfdestructive/_config.js @@ -2,7 +2,7 @@ import { test } from '../../test'; export default test({ error: { - code: 'invalid_svelte_tag', + code: 'svelte_meta_invalid_tag', message: 'Valid `` tag names are svelte:head, svelte:options, svelte:window, svelte:document, svelte:body, svelte:element, svelte:component, svelte:self or svelte:fragment', position: [10, 10] diff --git a/packages/svelte/tests/compiler-errors/samples/window-duplicate/_config.js b/packages/svelte/tests/compiler-errors/samples/window-duplicate/_config.js index fed30e9475..4ca827914d 100644 --- a/packages/svelte/tests/compiler-errors/samples/window-duplicate/_config.js +++ b/packages/svelte/tests/compiler-errors/samples/window-duplicate/_config.js @@ -2,7 +2,7 @@ import { test } from '../../test'; export default test({ error: { - code: 'duplicate_svelte_element', + code: 'svelte_meta_duplicate', message: 'A component can only have one element', position: [17, 17] } diff --git a/packages/svelte/tests/compiler-errors/samples/window-inside-block/_config.js b/packages/svelte/tests/compiler-errors/samples/window-inside-block/_config.js index 36bda11a77..bca18f6fe9 100644 --- a/packages/svelte/tests/compiler-errors/samples/window-inside-block/_config.js +++ b/packages/svelte/tests/compiler-errors/samples/window-inside-block/_config.js @@ -2,7 +2,7 @@ import { test } from '../../test'; export default test({ error: { - code: 'invalid_svelte_element_placement', + code: 'svelte_meta_invalid_placement', message: ' tags cannot be inside elements or blocks', position: [11, 11] } diff --git a/packages/svelte/tests/compiler-errors/samples/window-inside-element/_config.js b/packages/svelte/tests/compiler-errors/samples/window-inside-element/_config.js index 844353ac1b..1752fdf009 100644 --- a/packages/svelte/tests/compiler-errors/samples/window-inside-element/_config.js +++ b/packages/svelte/tests/compiler-errors/samples/window-inside-element/_config.js @@ -2,7 +2,7 @@ import { test } from '../../test'; export default test({ error: { - code: 'invalid_svelte_element_placement', + code: 'svelte_meta_invalid_placement', message: ' tags cannot be inside elements or blocks', position: [7, 7] } diff --git a/packages/svelte/tests/validator/samples/dynamic-element-invalid-tag/errors.json b/packages/svelte/tests/validator/samples/dynamic-element-invalid-tag/errors.json index ccd34029d2..d34ea60271 100644 --- a/packages/svelte/tests/validator/samples/dynamic-element-invalid-tag/errors.json +++ b/packages/svelte/tests/validator/samples/dynamic-element-invalid-tag/errors.json @@ -1,6 +1,6 @@ [ { - "code": "invalid_svelte_element_definition", + "code": "svelte_element_invalid_this", "message": "Invalid element definition — must be an {expression}", "start": { "line": 2, diff --git a/packages/svelte/tests/validator/samples/dynamic-element-missing-tag/errors.json b/packages/svelte/tests/validator/samples/dynamic-element-missing-tag/errors.json index d31bd1964c..60062d5aa6 100644 --- a/packages/svelte/tests/validator/samples/dynamic-element-missing-tag/errors.json +++ b/packages/svelte/tests/validator/samples/dynamic-element-missing-tag/errors.json @@ -1,6 +1,6 @@ [ { - "code": "missing_svelte_element_definition", + "code": "svelte_element_missing_this", "message": "`` must have a 'this' attribute", "start": { "line": 2, diff --git a/packages/svelte/tests/validator/samples/svelte-fragment-placement-2/errors.json b/packages/svelte/tests/validator/samples/svelte-fragment-placement-2/errors.json index cf34adc56b..ded3b1d69f 100644 --- a/packages/svelte/tests/validator/samples/svelte-fragment-placement-2/errors.json +++ b/packages/svelte/tests/validator/samples/svelte-fragment-placement-2/errors.json @@ -1,6 +1,6 @@ [ { - "code": "invalid_svelte_fragment_placement", + "code": "svelte_fragment_invalid_placement", "message": "`` must be the direct child of a component", "start": { "line": 5, diff --git a/packages/svelte/tests/validator/samples/svelte-fragment-placement/errors.json b/packages/svelte/tests/validator/samples/svelte-fragment-placement/errors.json index 195b0fca19..303a85e8e8 100644 --- a/packages/svelte/tests/validator/samples/svelte-fragment-placement/errors.json +++ b/packages/svelte/tests/validator/samples/svelte-fragment-placement/errors.json @@ -1,6 +1,6 @@ [ { - "code": "invalid_svelte_fragment_placement", + "code": "svelte_fragment_invalid_placement", "message": "`` must be the direct child of a component", "start": { "line": 7, diff --git a/packages/svelte/tests/validator/samples/svelte-head-attributes/errors.json b/packages/svelte/tests/validator/samples/svelte-head-attributes/errors.json index f230f20788..5db7d529db 100644 --- a/packages/svelte/tests/validator/samples/svelte-head-attributes/errors.json +++ b/packages/svelte/tests/validator/samples/svelte-head-attributes/errors.json @@ -1,6 +1,6 @@ [ { - "code": "illegal_svelte_head_attribute", + "code": "svelte_head_illegal_attribute", "message": "`` cannot have attributes nor directives", "start": { "line": 1,