From 4be593472d240f3b94fbd21ef5f147a99c93a791 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 24 Apr 2024 21:19:09 +0200 Subject: [PATCH 1/4] Version Packages (next) (#11315) Co-authored-by: github-actions[bot] --- .changeset/pre.json | 2 ++ packages/svelte/CHANGELOG.md | 8 ++++++++ packages/svelte/package.json | 2 +- packages/svelte/src/version.js | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.changeset/pre.json b/.changeset/pre.json index b2c7662242..a3c2cd1621 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -215,6 +215,7 @@ "lovely-items-turn", "lovely-rules-eat", "lucky-colts-remember", + "lucky-geckos-swim", "lucky-schools-hang", "lucky-toes-begin", "many-rockets-give", @@ -432,6 +433,7 @@ "tidy-chefs-taste", "tidy-starfishes-allow", "tiny-kings-whisper", + "tiny-meals-deliver", "tough-radios-punch", "twelve-dragons-join", "twelve-onions-juggle", diff --git a/packages/svelte/CHANGELOG.md b/packages/svelte/CHANGELOG.md index ded0371eb1..bceeb209b0 100644 --- a/packages/svelte/CHANGELOG.md +++ b/packages/svelte/CHANGELOG.md @@ -1,5 +1,13 @@ # svelte +## 5.0.0-next.115 + +### Patch Changes + +- fix: remove `bind_prop` in runes mode ([#11321](https://github.com/sveltejs/svelte/pull/11321)) + +- fix: mark `accessors` and `immutable` as deprecated ([#11277](https://github.com/sveltejs/svelte/pull/11277)) + ## 5.0.0-next.114 ### Patch Changes diff --git a/packages/svelte/package.json b/packages/svelte/package.json index fc855d1be2..b6087b6a0f 100644 --- a/packages/svelte/package.json +++ b/packages/svelte/package.json @@ -2,7 +2,7 @@ "name": "svelte", "description": "Cybernetically enhanced web apps", "license": "MIT", - "version": "5.0.0-next.114", + "version": "5.0.0-next.115", "type": "module", "types": "./types/index.d.ts", "engines": { diff --git a/packages/svelte/src/version.js b/packages/svelte/src/version.js index baad214843..1d4da8571b 100644 --- a/packages/svelte/src/version.js +++ b/packages/svelte/src/version.js @@ -6,5 +6,5 @@ * https://svelte.dev/docs/svelte-compiler#svelte-version * @type {string} */ -export const VERSION = '5.0.0-next.114'; +export const VERSION = '5.0.0-next.115'; export const PUBLIC_VERSION = '5'; From 6ad5cd4461878f171b55f1a44d5d0106e84ab941 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 24 Apr 2024 15:45:55 -0400 Subject: [PATCH 2/4] feat: implement message overloads (#11318) --- .../messages/client-warnings/warnings.md | 8 +- .../messages/compile-errors/bindings.md | 4 +- .../svelte/messages/compile-warnings/a11y.md | 6 +- .../messages/compile-warnings/options.md | 4 +- .../svelte/scripts/process-messages/index.js | 157 ++++++++++++------ packages/svelte/src/compiler/errors.js | 16 +- .../src/compiler/phases/2-analyze/a11y.js | 13 +- .../compiler/phases/2-analyze/validation.js | 4 +- packages/svelte/src/compiler/warnings.js | 34 +--- .../src/internal/client/dev/ownership.js | 17 +- .../svelte/src/internal/client/warnings.js | 14 ++ .../non-local-mutation-discouraged/_config.js | 19 +-- .../_config.js | 21 +-- .../_config.js | 21 +-- .../_config.js | 2 +- .../samples/a11y-aria-props/warnings.json | 2 +- .../samples/a11y-aria-role/warnings.json | 4 +- .../errors.json | 2 +- .../errors.json | 2 +- 19 files changed, 163 insertions(+), 187 deletions(-) diff --git a/packages/svelte/messages/client-warnings/warnings.md b/packages/svelte/messages/client-warnings/warnings.md index 643de0ed1d..865d968144 100644 --- a/packages/svelte/messages/client-warnings/warnings.md +++ b/packages/svelte/messages/client-warnings/warnings.md @@ -4,4 +4,10 @@ ## ownership_invalid_binding -> %parent% passed a value to %child% with `bind:`, but the value is owned by %owner%. Consider creating a binding between %owner% and %parent% \ No newline at end of file +> %parent% passed a value to %child% with `bind:`, but the value is owned by %owner%. Consider creating a binding between %owner% and %parent% + +## ownership_invalid_mutation + +> Mutating a value outside the component that created it is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead + +> %component% mutated a value owned by %owner%. This is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead diff --git a/packages/svelte/messages/compile-errors/bindings.md b/packages/svelte/messages/compile-errors/bindings.md index 9afa81d1f2..1a7ef806ac 100644 --- a/packages/svelte/messages/compile-errors/bindings.md +++ b/packages/svelte/messages/compile-errors/bindings.md @@ -14,8 +14,6 @@ > `bind:%name%` is not a valid binding -## bind_invalid_detailed - > `bind:%name%` is not a valid binding. %explanation% ## invalid_type_attribute @@ -32,4 +30,4 @@ ## dynamic_contenteditable_attribute -> 'contenteditable' attribute cannot be dynamic if element uses two-way binding \ No newline at end of file +> 'contenteditable' attribute cannot be dynamic if element uses two-way binding diff --git a/packages/svelte/messages/compile-warnings/a11y.md b/packages/svelte/messages/compile-warnings/a11y.md index feb602344d..e520f01aba 100644 --- a/packages/svelte/messages/compile-warnings/a11y.md +++ b/packages/svelte/messages/compile-warnings/a11y.md @@ -6,8 +6,6 @@ > Unknown aria attribute 'aria-%attribute%' -## a11y_unknown_aria_attribute_suggestion - > Unknown aria attribute 'aria-%attribute%'. Did you mean '%suggestion%'? ## a11y_hidden @@ -62,8 +60,6 @@ > Unknown role '%role%' -## a11y_unknown_role_suggestion - > Unknown role '%role%'. Did you mean '%suggestion%'? ## a11y_no_redundant_roles @@ -168,4 +164,4 @@ ## a11y_missing_content -> <%name%> element should have child content \ No newline at end of file +> <%name%> element should have child content diff --git a/packages/svelte/messages/compile-warnings/options.md b/packages/svelte/messages/compile-warnings/options.md index 5513f05f6e..2bd4d7ca7a 100644 --- a/packages/svelte/messages/compile-warnings/options.md +++ b/packages/svelte/messages/compile-warnings/options.md @@ -1,6 +1,6 @@ ## options_deprecated_accessors -The `accessors` option has been deprecated. It will have no effect in runes mode +> The `accessors` option has been deprecated. It will have no effect in runes mode ## options_deprecated_immutable @@ -24,4 +24,4 @@ The `accessors` option has been deprecated. It will have no effect in runes mode ## options_removed_loop_guard_timeout -> The `loopGuardTimeout` option has been removed \ No newline at end of file +> The `loopGuardTimeout` option has been removed diff --git a/packages/svelte/scripts/process-messages/index.js b/packages/svelte/scripts/process-messages/index.js index ace3a5e66c..fc4ac6ee20 100644 --- a/packages/svelte/scripts/process-messages/index.js +++ b/packages/svelte/scripts/process-messages/index.js @@ -4,6 +4,7 @@ import * as acorn from 'acorn'; import { walk } from 'zimmerframe'; import * as esrap from 'esrap'; +/** @type {Record>} */ const messages = {}; const seen = new Set(); @@ -24,12 +25,21 @@ for (const category of fs.readdirSync('messages')) { throw new Error(`Duplicate message code ${category}/${code}`); } + const sections = text.trim().split('\n\n'); + let details = null; + if (!sections[sections.length - 1].startsWith('> ')) { + details = /** @type {string} */ (sections.pop()); + } + + if (sections.length === 0) { + throw new Error('No message text'); + } + seen.add(code); - messages[category][code] = text - .trim() - .split('\n') - .map((line) => line.slice(2)) - .join('\n'); + messages[category][code] = { + messages: sections.map((section) => section.replace(/^> /gm, '')), + details + }; } } } @@ -102,13 +112,89 @@ function transform(name, dest) { ast.body.splice(index, 1); for (const code in category) { - const message = category[code]; + const { messages } = category[code]; const vars = []; - for (const match of message.matchAll(/%(\w+)%/g)) { - const name = match[1]; - if (!vars.includes(name)) { - vars.push(match[1]); + + const group = messages.map((text, i) => { + for (const match of text.matchAll(/%(\w+)%/g)) { + const name = match[1]; + if (!vars.includes(name)) { + vars.push(match[1]); + } + } + + return { + text, + vars: vars.slice() + }; + }); + + /** @type {import('estree').Expression} */ + let message = { type: 'Literal', value: '' }; + let prev_vars; + + for (let i = 0; i < group.length; i += 1) { + const { text, vars } = group[i]; + + if (vars.length === 0) { + message = { + type: 'Literal', + value: text + }; + continue; } + + const parts = text.split(/(%\w+%)/); + + /** @type {import('estree').Expression[]} */ + const expressions = []; + + /** @type {import('estree').TemplateElement[]} */ + const quasis = []; + + for (let i = 0; i < parts.length; i += 1) { + const part = parts[i]; + if (i % 2 === 0) { + const str = part.replace(/(`|\${)/g, '\\$1'); + quasis.push({ + type: 'TemplateElement', + value: { raw: str, cooked: str }, + tail: i === parts.length - 1 + }); + } else { + expressions.push({ + type: 'Identifier', + name: part.slice(1, -1) + }); + } + } + + /** @type {import('estree').Expression} */ + const expression = { + type: 'TemplateLiteral', + expressions, + quasis + }; + + if (prev_vars) { + if (vars.length === prev_vars.length) { + throw new Error('Message overloads must have new parameters'); + } + + message = { + type: 'ConditionalExpression', + test: { + type: 'Identifier', + name: vars[prev_vars.length] + }, + consequent: expression, + alternate: message + }; + } else { + message = expression; + } + + prev_vars = vars; } const clone = walk(/** @type {import('estree').Node} */ (template_node), null, { @@ -120,14 +206,22 @@ function transform(name, dest) { .split('\n') .map((line) => { if (line === ' * MESSAGE') { - return message + return messages[messages.length - 1] .split('\n') .map((line) => ` * ${line}`) .join('\n'); } if (line.includes('PARAMETER')) { - return vars.map((name) => ` * @param {string} ${name}`).join('\n'); + return vars + .map((name, i) => { + const optional = i >= group[0].vars.length; + + return optional + ? ` * @param {string | undefined | null} [${name}]` + : ` * @param {string} ${name}`; + }) + .join('\n'); } return line; @@ -171,44 +265,7 @@ function transform(name, dest) { }, Identifier(node) { if (node.name !== 'MESSAGE') return; - - if (/%\w+%/.test(message)) { - const parts = message.split(/(%\w+%)/); - - /** @type {import('estree').Expression[]} */ - const expressions = []; - - /** @type {import('estree').TemplateElement[]} */ - const quasis = []; - - for (let i = 0; i < parts.length; i += 1) { - const part = parts[i]; - if (i % 2 === 0) { - const str = part.replace(/(`|\${)/g, '\\$1'); - quasis.push({ - type: 'TemplateElement', - value: { raw: str, cooked: str }, - tail: i === parts.length - 1 - }); - } else { - expressions.push({ - type: 'Identifier', - name: part.slice(1, -1) - }); - } - } - - return { - type: 'TemplateLiteral', - expressions, - quasis - }; - } - - return { - type: 'Literal', - value: message - }; + return message; } }); diff --git a/packages/svelte/src/compiler/errors.js b/packages/svelte/src/compiler/errors.js index 096a2ef97c..810c1582be 100644 --- a/packages/svelte/src/compiler/errors.js +++ b/packages/svelte/src/compiler/errors.js @@ -227,25 +227,15 @@ export function bind_invalid_target(node, name, elements) { e(node, "bind_invalid_target", `\`bind:${name}\` can only be used with ${elements}`); } -/** - * `bind:%name%` is not a valid binding - * @param {null | number | NodeLike} node - * @param {string} name - * @returns {never} - */ -export function bind_invalid(node, name) { - e(node, "bind_invalid", `\`bind:${name}\` is not a valid binding`); -} - /** * `bind:%name%` is not a valid binding. %explanation% * @param {null | number | NodeLike} node * @param {string} name - * @param {string} explanation + * @param {string | undefined | null} [explanation] * @returns {never} */ -export function bind_invalid_detailed(node, name, explanation) { - e(node, "bind_invalid_detailed", `\`bind:${name}\` is not a valid binding. ${explanation}`); +export function bind_invalid(node, name, explanation) { + e(node, "bind_invalid", explanation ? `\`bind:${name}\` is not a valid binding. ${explanation}` : `\`bind:${name}\` is not a valid binding`); } /** diff --git a/packages/svelte/src/compiler/phases/2-analyze/a11y.js b/packages/svelte/src/compiler/phases/2-analyze/a11y.js index 0b54af4b85..91dc7cf8fb 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/a11y.js +++ b/packages/svelte/src/compiler/phases/2-analyze/a11y.js @@ -739,12 +739,7 @@ function check_element(node, state) { const type = name.slice(5); if (!aria_attributes.includes(type)) { const match = fuzzymatch(type, aria_attributes); - if (match) { - // TODO allow 'overloads' in messages, so that we can use the same code with and without suggestions - w.a11y_unknown_aria_attribute_suggestion(attribute, type, match); - } else { - w.a11y_unknown_aria_attribute(attribute, type); - } + w.a11y_unknown_aria_attribute(attribute, type, match); } if (name === 'aria-hidden' && regex_heading_tags.test(node.name)) { @@ -792,11 +787,7 @@ function check_element(node, state) { w.a11y_no_abstract_role(attribute, current_role); } else if (current_role && !aria_roles.includes(current_role)) { const match = fuzzymatch(current_role, aria_roles); - if (match) { - w.a11y_unknown_role_suggestion(attribute, current_role, match); - } else { - w.a11y_unknown_role(attribute, current_role); - } + w.a11y_unknown_role(attribute, current_role, match); } // no-redundant-roles diff --git a/packages/svelte/src/compiler/phases/2-analyze/validation.js b/packages/svelte/src/compiler/phases/2-analyze/validation.js index 55ae8c64d2..eaa486cd21 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/validation.js +++ b/packages/svelte/src/compiler/phases/2-analyze/validation.js @@ -373,7 +373,7 @@ const validation = { parent?.type === 'SvelteBody' ) { if (context.state.options.namespace === 'foreign' && node.name !== 'this') { - e.bind_invalid_detailed(node, node.name, 'Foreign elements only support `bind:this`'); + e.bind_invalid(node, node.name, 'Foreign elements only support `bind:this`'); } if (node.name in binding_properties) { @@ -442,7 +442,7 @@ const validation = { if (match) { const property = binding_properties[match]; if (!property.valid_elements || property.valid_elements.includes(parent.name)) { - e.bind_invalid_detailed(node, node.name, `Did you mean '${match}'?`); + e.bind_invalid(node, node.name, `Did you mean '${match}'?`); } } e.bind_invalid(node, node.name); diff --git a/packages/svelte/src/compiler/warnings.js b/packages/svelte/src/compiler/warnings.js index 2d1d80c403..1dbfcf9705 100644 --- a/packages/svelte/src/compiler/warnings.js +++ b/packages/svelte/src/compiler/warnings.js @@ -49,23 +49,14 @@ export function a11y_aria_attributes(node, name) { w(node, "a11y_aria_attributes", `<${name}> should not have aria-* attributes`); } -/** - * Unknown aria attribute 'aria-%attribute%' - * @param {null | NodeLike} node - * @param {string} attribute - */ -export function a11y_unknown_aria_attribute(node, attribute) { - w(node, "a11y_unknown_aria_attribute", `Unknown aria attribute 'aria-${attribute}'`); -} - /** * Unknown aria attribute 'aria-%attribute%'. Did you mean '%suggestion%'? * @param {null | NodeLike} node * @param {string} attribute - * @param {string} suggestion + * @param {string | undefined | null} [suggestion] */ -export function a11y_unknown_aria_attribute_suggestion(node, attribute, suggestion) { - w(node, "a11y_unknown_aria_attribute_suggestion", `Unknown aria attribute 'aria-${attribute}'. Did you mean '${suggestion}'?`); +export function a11y_unknown_aria_attribute(node, attribute, suggestion) { + w(node, "a11y_unknown_aria_attribute", suggestion ? `Unknown aria attribute 'aria-${attribute}'. Did you mean '${suggestion}'?` : `Unknown aria attribute 'aria-${attribute}'`); } /** @@ -178,23 +169,14 @@ export function a11y_no_abstract_role(node, role) { w(node, "a11y_no_abstract_role", `Abstract role '${role}' is forbidden`); } -/** - * Unknown role '%role%' - * @param {null | NodeLike} node - * @param {string} role - */ -export function a11y_unknown_role(node, role) { - w(node, "a11y_unknown_role", `Unknown role '${role}'`); -} - /** * Unknown role '%role%'. Did you mean '%suggestion%'? * @param {null | NodeLike} node * @param {string} role - * @param {string} suggestion + * @param {string | undefined | null} [suggestion] */ -export function a11y_unknown_role_suggestion(node, role, suggestion) { - w(node, "a11y_unknown_role_suggestion", `Unknown role '${role}'. Did you mean '${suggestion}'?`); +export function a11y_unknown_role(node, role, suggestion) { + w(node, "a11y_unknown_role", suggestion ? `Unknown role '${role}'. Did you mean '${suggestion}'?` : `Unknown role '${role}'`); } /** @@ -545,11 +527,11 @@ export function invalid_self_closing_tag(node, name) { } /** - * e `accessors` option has been deprecated. It will have no effect in runes mode + * The `accessors` option has been deprecated. It will have no effect in runes mode * @param {null | NodeLike} node */ export function options_deprecated_accessors(node) { - w(node, "options_deprecated_accessors", "e `accessors` option has been deprecated. It will have no effect in runes mode"); + w(node, "options_deprecated_accessors", "The `accessors` option has been deprecated. It will have no effect in runes mode"); } /** diff --git a/packages/svelte/src/internal/client/dev/ownership.js b/packages/svelte/src/internal/client/dev/ownership.js index 4fac7837fd..e9fe0f4fb4 100644 --- a/packages/svelte/src/internal/client/dev/ownership.js +++ b/packages/svelte/src/internal/client/dev/ownership.js @@ -225,18 +225,13 @@ export function check_ownership(metadata) { if (component && !has_owner(metadata, component)) { let original = get_owner(metadata); - let message = + // @ts-expect-error + if (original.filename !== component.filename) { // @ts-expect-error - original.filename !== component.filename - ? // @ts-expect-error - `${component.filename} mutated a value owned by ${original.filename}. This is strongly discouraged` - : 'Mutating a value outside the component that created it is strongly discouraged'; - - // TODO get rid of this, but implement message overloads first - // eslint-disable-next-line no-console - console.warn( - `${message}. Consider passing values to child components with \`bind:\`, or use a callback instead.` - ); + w.ownership_invalid_mutation(component.filename, original.filename); + } else { + w.ownership_invalid_mutation(); + } // eslint-disable-next-line no-console console.trace(); diff --git a/packages/svelte/src/internal/client/warnings.js b/packages/svelte/src/internal/client/warnings.js index 66d72758bf..eec28ac1c6 100644 --- a/packages/svelte/src/internal/client/warnings.js +++ b/packages/svelte/src/internal/client/warnings.js @@ -30,4 +30,18 @@ export function ownership_invalid_binding(parent, child, owner) { // TODO print a link to the documentation console.warn("ownership_invalid_binding"); } +} + +/** + * %component% mutated a value owned by %owner%. This is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead + * @param {string | undefined | null} [component] + * @param {string | undefined | null} [owner] + */ +export function ownership_invalid_mutation(component, owner) { + if (DEV) { + console.warn(`%c[svelte] ${"ownership_invalid_mutation"}\n%c${`${component} mutated a value owned by ${owner}. This is strongly discouraged. Consider passing values to child components with \`bind:\`, or use a callback instead`}`, bold, normal); + } else { + // TODO print a link to the documentation + console.warn("ownership_invalid_mutation"); + } } \ No newline at end of file diff --git a/packages/svelte/tests/runtime-runes/samples/non-local-mutation-discouraged/_config.js b/packages/svelte/tests/runtime-runes/samples/non-local-mutation-discouraged/_config.js index 7a78630da5..5cef52a86b 100644 --- a/packages/svelte/tests/runtime-runes/samples/non-local-mutation-discouraged/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/non-local-mutation-discouraged/_config.js @@ -1,14 +1,8 @@ import { test } from '../../test'; -/** @type {typeof console.warn} */ -let warn; - /** @type {typeof console.trace} */ let trace; -/** @type {any[]} */ -let warnings = []; - export default test({ html: ``, @@ -17,31 +11,22 @@ export default test({ }, before_test: () => { - warn = console.warn; trace = console.trace; - - console.warn = (...args) => { - warnings.push(...args); - }; - console.trace = () => {}; }, after_test: () => { - console.warn = warn; console.trace = trace; - - warnings = []; }, - async test({ assert, target }) { + async test({ assert, target, warnings }) { const btn = target.querySelector('button'); await btn?.click(); assert.htmlEqual(target.innerHTML, ``); assert.deepEqual(warnings, [ - '.../samples/non-local-mutation-discouraged/Counter.svelte mutated a value owned by .../samples/non-local-mutation-discouraged/main.svelte. This is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead.' + '.../samples/non-local-mutation-discouraged/Counter.svelte mutated a value owned by .../samples/non-local-mutation-discouraged/main.svelte. This is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead' ]); } }); diff --git a/packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-5/_config.js b/packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-5/_config.js index 0d075cca25..7f0581d6c4 100644 --- a/packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-5/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-5/_config.js @@ -1,31 +1,12 @@ import { tick } from 'svelte'; import { test } from '../../test'; -/** @type {typeof console.warn} */ -let warn; - -/** @type {any[]} */ -let warnings = []; - export default test({ compileOptions: { dev: true }, - before_test: () => { - warn = console.warn; - - console.warn = (...args) => { - warnings.push(...args); - }; - }, - - after_test: () => { - console.warn = warn; - warnings = []; - }, - - async test({ assert, target }) { + async test({ assert, target, warnings }) { const [btn1, btn2] = target.querySelectorAll('button'); await btn1.click(); diff --git a/packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-7/_config.js b/packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-7/_config.js index df3ca08f03..ec8e5ada28 100644 --- a/packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-7/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-7/_config.js @@ -1,31 +1,12 @@ import { tick } from 'svelte'; import { test } from '../../test'; -/** @type {typeof console.warn} */ -let warn; - -/** @type {any[]} */ -let warnings = []; - export default test({ compileOptions: { dev: true }, - before_test: () => { - warn = console.warn; - - console.warn = (...args) => { - warnings.push(...args); - }; - }, - - after_test: () => { - console.warn = warn; - warnings = []; - }, - - async test({ assert, target }) { + async test({ assert, target, warnings }) { const [btn1, btn2] = target.querySelectorAll('button'); btn1.click(); diff --git a/packages/svelte/tests/runtime-runes/samples/non-local-mutation-with-binding-3/_config.js b/packages/svelte/tests/runtime-runes/samples/non-local-mutation-with-binding-3/_config.js index 6fc699efb6..fd0ace4fda 100644 --- a/packages/svelte/tests/runtime-runes/samples/non-local-mutation-with-binding-3/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/non-local-mutation-with-binding-3/_config.js @@ -33,7 +33,7 @@ export default test({ assert.htmlEqual(target.innerHTML, ``); assert.deepEqual(warnings, [ - '.../samples/non-local-mutation-with-binding-3/Counter.svelte mutated a value owned by .../samples/non-local-mutation-with-binding-3/main.svelte. This is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead.' + '.../samples/non-local-mutation-with-binding-3/Counter.svelte mutated a value owned by .../samples/non-local-mutation-with-binding-3/main.svelte. This is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead' ]); } }); diff --git a/packages/svelte/tests/validator/samples/a11y-aria-props/warnings.json b/packages/svelte/tests/validator/samples/a11y-aria-props/warnings.json index cd36ffd42d..bdb7a976a2 100644 --- a/packages/svelte/tests/validator/samples/a11y-aria-props/warnings.json +++ b/packages/svelte/tests/validator/samples/a11y-aria-props/warnings.json @@ -1,6 +1,6 @@ [ { - "code": "a11y_unknown_aria_attribute_suggestion", + "code": "a11y_unknown_aria_attribute", "message": "Unknown aria attribute 'aria-labeledby'. Did you mean 'labelledby'?", "start": { "line": 1, diff --git a/packages/svelte/tests/validator/samples/a11y-aria-role/warnings.json b/packages/svelte/tests/validator/samples/a11y-aria-role/warnings.json index 3b250958b0..a0133cc1bb 100644 --- a/packages/svelte/tests/validator/samples/a11y-aria-role/warnings.json +++ b/packages/svelte/tests/validator/samples/a11y-aria-role/warnings.json @@ -1,6 +1,6 @@ [ { - "code": "a11y_unknown_role_suggestion", + "code": "a11y_unknown_role", "message": "Unknown role 'toooltip'. Did you mean 'tooltip'?", "start": { "line": 6, @@ -12,7 +12,7 @@ } }, { - "code": "a11y_unknown_role_suggestion", + "code": "a11y_unknown_role", "message": "Unknown role 'toooltip'. Did you mean 'tooltip'?", "start": { "line": 7, diff --git a/packages/svelte/tests/validator/samples/binding-invalid-foreign-namespace/errors.json b/packages/svelte/tests/validator/samples/binding-invalid-foreign-namespace/errors.json index de997e5394..aa2d7c1621 100644 --- a/packages/svelte/tests/validator/samples/binding-invalid-foreign-namespace/errors.json +++ b/packages/svelte/tests/validator/samples/binding-invalid-foreign-namespace/errors.json @@ -1,6 +1,6 @@ [ { - "code": "bind_invalid_detailed", + "code": "bind_invalid", "message": "`bind:value` is not a valid binding. Foreign elements only support `bind:this`", "start": { "line": 6, diff --git a/packages/svelte/tests/validator/samples/window-binding-invalid-innerwidth/errors.json b/packages/svelte/tests/validator/samples/window-binding-invalid-innerwidth/errors.json index 99a1c892d3..a63e8a0877 100644 --- a/packages/svelte/tests/validator/samples/window-binding-invalid-innerwidth/errors.json +++ b/packages/svelte/tests/validator/samples/window-binding-invalid-innerwidth/errors.json @@ -1,6 +1,6 @@ [ { - "code": "bind_invalid_detailed", + "code": "bind_invalid", "message": "`bind:innerwidth` is not a valid binding. Did you mean 'innerWidth'?", "start": { "line": 5, From 8e17428316cbad94d21306b75f6ef4d389b6e301 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 25 Apr 2024 08:54:05 -0400 Subject: [PATCH 3/4] chore: tidy up messages (#11327) * start reorganising messages * tidy up * more * more * more * alphabetise * consolidate * more * more * more * more * more * more * alphabetise * more * this is no longer needed * no longer necessary * more * more * fix * regenerate messages * more * more * tighten up rune validation * more * fix * more * tweak a11y messages * add server errors * overhaul runtime errors * regenerate messages * unused * lint * more * more * Update packages/svelte/messages/compile-errors/script.md Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * Update packages/svelte/messages/client-warnings/warnings.md Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * fix --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> --- .prettierignore | 2 + .../svelte/messages/client-errors/effects.md | 3 - .../svelte/messages/client-errors/errors.md | 67 ++ .../messages/client-errors/lifecycle.md | 7 - .../messages/client-warnings/warnings.md | 8 + .../messages/compile-errors/attributes.md | 59 -- .../messages/compile-errors/bindings.md | 33 - .../compile-errors/compiler_options.md | 7 - .../messages/compile-errors/components.md | 3 - .../messages/compile-errors/const_tag.md | 3 - .../messages/compile-errors/elements.md | 27 - .../compile-errors/legacy_reactivity.md | 3 - .../svelte/messages/compile-errors/options.md | 11 + .../svelte/messages/compile-errors/parse.md | 147 --- .../svelte/messages/compile-errors/runes.md | 95 -- .../svelte/messages/compile-errors/script.md | 135 +++ .../svelte/messages/compile-errors/slots.md | 31 - .../compile-errors/special_elements.md | 99 -- .../compile-errors/{css.md => style.md} | 46 +- .../messages/compile-errors/template.md | 365 +++++++ .../messages/compile-errors/variables.md | 19 - .../svelte/messages/compile-warnings/a11y.md | 160 +-- .../messages/compile-warnings/attributes.md | 15 - .../svelte/messages/compile-warnings/block.md | 3 - .../messages/compile-warnings/components.md | 3 - .../svelte/messages/compile-warnings/css.md | 3 - .../messages/compile-warnings/legacy.md | 19 - .../svelte/messages/compile-warnings/misc.md | 3 - .../messages/compile-warnings/options.md | 8 +- .../messages/compile-warnings/performance.md | 7 - .../svelte/messages/compile-warnings/runes.md | 19 - .../messages/compile-warnings/script.md | 35 + .../svelte/messages/compile-warnings/state.md | 7 - .../svelte/messages/compile-warnings/style.md | 3 + .../messages/compile-warnings/template.md | 39 + .../messages/server-errors/lifecycle.md | 3 + .../svelte/messages/shared-errors/errors.md | 19 + .../messages/shared-warnings/warnings.md | 2 +- .../svelte/scripts/process-messages/index.js | 12 + .../templates/server-errors.js | 10 + .../templates/shared-errors.js | 17 + packages/svelte/src/compiler/errors.js | 981 ++++++++---------- .../src/compiler/phases/1-parse/index.js | 6 +- .../compiler/phases/1-parse/read/options.js | 80 +- .../compiler/phases/1-parse/read/script.js | 6 +- .../src/compiler/phases/1-parse/read/style.js | 11 +- .../compiler/phases/1-parse/state/element.js | 50 +- .../src/compiler/phases/1-parse/state/tag.js | 16 +- .../phases/2-analyze/css/css-analyze.js | 18 +- .../src/compiler/phases/2-analyze/index.js | 44 +- .../compiler/phases/2-analyze/validation.js | 251 +++-- packages/svelte/src/compiler/phases/scope.js | 7 +- .../svelte/src/compiler/validate-options.js | 9 +- packages/svelte/src/compiler/warnings.js | 516 +++++---- packages/svelte/src/index-client.js | 13 +- packages/svelte/src/index-server.js | 7 +- .../client/dom/elements/attributes.js | 12 +- .../client/dom/elements/bindings/input.js | 11 +- .../src/internal/client/dom/hydration.js | 3 +- packages/svelte/src/internal/client/errors.js | 233 ++++- packages/svelte/src/internal/client/index.js | 4 +- packages/svelte/src/internal/client/proxy.js | 3 +- .../src/internal/client/reactivity/effects.js | 14 +- .../src/internal/client/reactivity/props.js | 14 +- .../src/internal/client/reactivity/sources.js | 10 +- packages/svelte/src/internal/client/render.js | 12 +- .../svelte/src/internal/client/runtime.js | 9 +- .../svelte/src/internal/client/validate.js | 61 +- .../svelte/src/internal/client/warnings.js | 27 + .../svelte/src/internal/server/context.js | 24 +- packages/svelte/src/internal/server/errors.js | 13 + packages/svelte/src/internal/server/index.js | 24 +- packages/svelte/src/internal/shared/errors.js | 85 ++ .../svelte/src/internal/shared/validate.js | 22 +- .../samples/attribute-empty/_config.js | 2 +- .../_config.js | 2 +- .../attribute-sequence-expression/_config.js | 2 +- .../attribute-unique-binding/_config.js | 2 +- .../attribute-unique-shorthand/_config.js | 2 +- .../samples/attribute-unique/_config.js | 2 +- .../samples/catch-without-await/_config.js | 2 +- .../class-state-field-static/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../component-slot-duplicate-error/_config.js | 2 +- .../component-slot-nested-error-2/_config.js | 2 +- .../component-slot-nested-error-3/_config.js | 2 +- .../component-slot-nested-error/_config.js | 2 +- .../css-global-block-combinator/_config.js | 2 +- .../css-global-block-declaration/_config.js | 2 +- .../css-global-block-modifier/_config.js | 2 +- .../css-global-block-multiple/_config.js | 2 +- .../compiler-errors/samples/css/_config.js | 2 +- .../dollar-binding-declaration/_config.js | 2 +- .../dollar-binding-global-js/_config.js | 2 +- .../samples/dollar-binding-global/_config.js | 2 +- .../samples/dollar-binding-import/_config.js | 2 +- .../samples/else-before-closing-3/_config.js | 2 +- .../samples/else-before-closing/_config.js | 2 +- .../else-if-before-closing-2/_config.js | 2 +- .../empty-attribute-shorthand/_config.js | 2 +- .../empty-classname-binding/_config.js | 6 +- .../samples/empty-directive-name/_config.js | 6 +- .../samples/export-derived-state/_config.js | 2 +- .../samples/export-state-module/_config.js | 2 +- .../samples/export-state/_config.js | 2 +- .../invalid-snippet-binding/_config.js | 2 +- .../invalid-snippet-mutation/_config.js | 2 +- .../legacy-no-const-assignment/_config.js | 2 +- .../samples/legacy-no-const-update/_config.js | 2 +- .../samples/multiple-styles/_config.js | 2 +- .../samples/options-children/_config.js | 2 +- .../raw-mustaches-whitespace/_config.js | 2 +- .../render-tag-invalid-call/_config.js | 2 +- .../runes-before-after-update/_config.js | 2 +- .../runes-bindable-not-called/_config.js | 8 + .../runes-bindable-not-called/main.svelte} | 0 .../samples/runes-duplicate-props/_config.js | 2 +- .../samples/runes-export-let/_config.js | 4 +- .../runes-export-named-state/_config.js | 2 +- .../runes-invalid-each-binding/_config.js | 2 +- .../runes-invalid-each-mutation/_config.js | 2 +- .../runes-no-const-assignment/_config.js | 2 +- .../samples/runes-no-const-update/_config.js | 2 +- .../runes-no-derived-assignment/_config.js | 2 +- .../runes-no-derived-binding/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../runes-no-derived-update/_config.js | 2 +- .../samples/runes-no-rune-each/_config.js | 2 +- .../runes-prop-export-conflict/_config.js | 8 - .../runes-prop-export-conflict/main.svelte | 4 - .../samples/runes-props-not-called/_config.js | 8 + .../runes-props-not-called/main.svelte} | 0 .../runes-wrong-bindable-args/_config.js | 2 +- .../runes-wrong-bindable-placement/_config.js | 2 +- .../runes-wrong-derived-args/_config.js | 2 +- .../runes-wrong-derived-placement/_config.js | 2 +- .../runes-wrong-effect-args/_config.js | 2 +- .../runes-wrong-effect-placement/_config.js | 2 +- .../runes-wrong-host-placement/_config.js | 2 +- .../samples/runes-wrong-props-args/_config.js | 2 +- .../runes-wrong-props-placement/_config.js | 2 +- .../samples/runes-wrong-state-args/_config.js | 2 +- .../runes-wrong-state-placement/_config.js | 2 +- .../_config.js | 2 +- .../samples/script-unclosed/_config.js | 2 +- .../samples/self-reference/_config.js | 4 +- .../_config.js | 2 +- .../snippet-children-conflict/_config.js | 2 +- .../store-autosub-context-module/_config.js | 2 +- .../samples/store-contextual/_config.js | 2 +- .../store-global-disallowed/_config.js | 2 +- .../_config.js | 2 +- .../samples/store-shadow-scope-2/_config.js | 2 +- .../samples/store-shadow-scope-3/_config.js | 2 +- .../samples/store-shadow-scope/_config.js | 2 +- .../_config.js | 2 +- .../samples/style-unclosed/_config.js | 2 +- .../samples/svelte-selfdestructive/_config.js | 2 +- .../samples/then-before-closing/_config.js | 2 +- .../samples/then-without-await/_config.js | 2 +- .../_config.js | 4 +- .../unexpected-end-of-input-d/_config.js | 2 +- .../unexpected-end-of-input/_config.js | 2 +- .../_config.js | 4 +- .../_config.js | 4 +- .../samples/unmatched-closing-tag/_config.js | 4 +- .../samples/void-closing/_config.js | 2 +- .../samples/window-children/_config.js | 2 +- .../samples/window-duplicate/_config.js | 4 +- .../samples/window-inside-block/_config.js | 4 +- .../samples/window-inside-element/_config.js | 4 +- .../samples/ignore-mismatched-href/_config.js | 2 +- packages/svelte/tests/hydration/test.ts | 25 +- .../extended-builtin/_config.js | 2 +- .../component-not-constructor-dev/_config.js | 3 +- .../component-not-constructor2-dev/_config.js | 2 +- .../dynamic-element-invalid-this/_config.js | 4 +- .../each-block-keyed-non-prop/_config.js | 6 +- .../_config.js | 4 +- .../samples/each-block-keyed/_config.js | 4 +- .../samples/keyed-each-dev-unique/_config.js | 3 +- .../samples/store-dev-mode-error/_config.js | 2 +- .../samples/export-binding/_config.js | 4 +- .../samples/props-bound-fallback/_config.js | 2 +- .../props-not-bindable-spread/_config.js | 9 +- .../samples/props-not-bindable/_config.js | 9 +- .../snippet-validation-error-1/_config.js | 3 +- .../snippet-validation-error-2/_config.js | 2 +- .../samples/a11y-alt-text/warnings.json | 8 +- .../a11y-anchor-has-content/warnings.json | 2 +- .../a11y-anchor-in-svg-is-valid/warnings.json | 2 +- .../a11y-anchor-is-valid/warnings.json | 6 +- .../a11y-aria-activedescendant/warnings.json | 2 +- .../samples/a11y-aria-props/warnings.json | 2 +- .../warnings.json | 4 +- .../a11y-autocomplete-valid/warnings.json | 6 +- .../warnings.json | 16 +- .../a11y-heading-has-content/warnings.json | 4 +- .../samples/a11y-html-has-lang/warnings.json | 2 +- .../a11y-iframe-has-title/warnings.json | 2 +- .../a11y-img-redundant-alt/warnings.json | 6 +- .../a11y-media-has-caption/warnings.json | 8 +- .../warnings.json | 4 +- .../warnings.json | 92 +- .../warnings.json | 10 +- .../warnings.json | 96 +- .../warnings.json | 4 +- .../warnings.json | 118 +-- .../samples/a11y-scope/warnings.json | 2 +- .../samples/action-on-component/errors.json | 2 +- .../animation-on-component/errors.json | 2 +- .../samples/assignment-to-const-2/errors.json | 2 +- .../samples/assignment-to-const-3/errors.json | 2 +- .../samples/assignment-to-const-4/errors.json | 2 +- .../samples/assignment-to-const-5/errors.json | 2 +- .../samples/assignment-to-const-7/errors.json | 2 +- .../samples/assignment-to-const/errors.json | 2 +- .../attribute-invalid-name-2/errors.json | 2 +- .../attribute-invalid-name-3/errors.json | 2 +- .../attribute-invalid-name-4/errors.json | 2 +- .../attribute-invalid-name-5/errors.json | 2 +- .../attribute-invalid-name/errors.json | 2 +- .../samples/binding-await-catch/errors.json | 2 +- .../samples/binding-await-then-2/errors.json | 2 +- .../samples/binding-await-then/errors.json | 2 +- .../samples/binding-const/errors.json | 2 +- .../binding-input-type-boolean/errors.json | 2 +- .../errors.json | 2 +- .../binding-invalid-value-global/errors.json | 2 +- .../samples/binding-invalid-value/errors.json | 2 +- .../samples/binding-invalid/errors.json | 2 +- .../validator/samples/binding-let/errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../component-name-lowercase/warnings.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../component-slot-dynamic/errors.json | 2 +- .../errors.json | 2 +- .../component-slotted-each-block/errors.json | 2 +- .../component-slotted-if-block/errors.json | 2 +- .../samples/const-tag-conflict-1/errors.json | 2 +- .../samples/const-tag-conflict-2/errors.json | 2 +- .../samples/const-tag-placement-1/errors.json | 4 +- .../samples/const-tag-placement-2/errors.json | 4 +- .../samples/const-tag-readonly-1/errors.json | 2 +- .../samples/const-tag-readonly-2/errors.json | 2 +- .../contenteditable-dynamic/errors.json | 2 +- .../contenteditable-missing/errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../css-invalid-global-placement/errors.json | 2 +- .../css-invalid-global-selector-2/errors.json | 2 +- .../css-invalid-global-selector-3/errors.json | 2 +- .../css-invalid-global-selector-4/errors.json | 2 +- .../css-invalid-global-selector-5/errors.json | 2 +- .../css-invalid-global-selector-6/errors.json | 2 +- .../errors.json | 2 +- .../css-invalid-global-selector/errors.json | 2 +- .../errors.json | 2 +- .../samples/debug-invalid-args/errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../samples/default-export/errors.json | 2 +- .../directive-non-expression/errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../dollar-global-in-markup/errors.json | 2 +- .../dollar-global-in-script/errors.json | 2 +- .../dynamic-element-invalid-tag/errors.json | 4 +- .../dynamic-element-missing-tag/errors.json | 2 +- .../samples/empty-block/warnings.json | 8 +- .../samples/error-mode-warn/warnings.json | 2 +- .../samples/event-attribute/errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../event-modifiers-invalid/errors.json | 2 +- .../global-event-reference/warnings.json | 8 +- .../html-block-in-attribute/errors.json | 2 +- .../html-block-in-textarea/errors.json | 2 +- .../samples/ignore-warning/warnings.json | 4 +- .../ignore-warnings-cumulative/warnings.json | 2 +- .../ignore-warnings-newline/warnings.json | 2 +- .../ignore-warnings-stacked/warnings.json | 2 +- .../samples/ignore-warnings/warnings.json | 2 +- .../illegal-attribute-character/warnings.json | 4 +- .../illegal-variable-declaration/errors.json | 2 +- .../samples/inline-new-class-2/warnings.json | 2 +- .../samples/inline-new-class-4/warnings.json | 2 +- .../samples/inline-new-class/warnings.json | 2 +- .../invalid-empty-css-declaration/errors.json | 4 +- .../invalid-node-placement-2/errors.json | 2 +- .../invalid-node-placement/errors.json | 2 +- .../invalid-self-closing-tag/warnings.json | 8 +- .../samples/let-directive/errors.json | 2 +- .../logic-block-in-attribute/errors.json | 2 +- .../logic-block-in-textarea/errors.json | 2 +- .../warnings.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../samples/namespace-invalid/errors.json | 4 +- .../samples/namespace-non-literal/errors.json | 4 +- .../reactive-declaration-cyclical/errors.json | 2 +- .../warnings.json | 2 +- .../reactive-module-variable/warnings.json | 2 +- .../rest-eachblock-binding-2/warnings.json | 2 +- .../rest-eachblock-binding-3/warnings.json | 2 +- .../warnings.json | 4 +- .../rest-eachblock-binding/warnings.json | 2 +- .../runes-bindable-not-called/_config.js | 3 - .../runes-bindable-not-called/warnings.json | 14 - .../warnings.json | 12 +- .../samples/runes-props-not-called/_config.js | 3 - .../runes-props-not-called/warnings.json | 14 - .../warnings.json | 2 +- .../runes-referenced-nonstate/warnings.json | 4 +- .../script-invalid-context/errors.json | 2 +- .../samples/silence-warnings-2/input.svelte | 2 +- .../samples/silence-warnings/input.svelte | 2 +- .../slot-attribute-invalid/errors.json | 2 +- .../samples/slot-warning/warnings.json | 2 +- .../samples/slot-warning2/warnings.json | 2 +- .../static-state-reference/warnings.json | 4 +- .../store-runes-conflict/warnings.json | 2 +- .../errors.json | 4 +- .../svelte-fragment-placement-2/errors.json | 2 +- .../svelte-fragment-placement/errors.json | 2 +- .../svelte-head-attributes/errors.json | 2 +- .../validator/samples/tag-invalid/errors.json | 2 +- .../samples/tag-non-string/errors.json | 2 +- .../textarea-value-children/errors.json | 2 +- .../samples/title-no-attributes/errors.json | 2 +- .../samples/title-no-children/errors.json | 2 +- .../transition-on-component/errors.json | 2 +- .../unreferenced-variables-each/warnings.json | 4 +- .../unreferenced-variables/warnings.json | 10 +- .../samples/use-the-platform/warnings.json | 4 +- .../errors.json | 2 +- .../window-binding-invalid/errors.json | 2 +- packages/svelte/tests/validator/test.ts | 2 +- 353 files changed, 2772 insertions(+), 2477 deletions(-) delete mode 100644 packages/svelte/messages/client-errors/effects.md create mode 100644 packages/svelte/messages/client-errors/errors.md delete mode 100644 packages/svelte/messages/client-errors/lifecycle.md delete mode 100644 packages/svelte/messages/compile-errors/attributes.md delete mode 100644 packages/svelte/messages/compile-errors/bindings.md delete mode 100644 packages/svelte/messages/compile-errors/compiler_options.md delete mode 100644 packages/svelte/messages/compile-errors/components.md delete mode 100644 packages/svelte/messages/compile-errors/const_tag.md delete mode 100644 packages/svelte/messages/compile-errors/elements.md delete mode 100644 packages/svelte/messages/compile-errors/legacy_reactivity.md create mode 100644 packages/svelte/messages/compile-errors/options.md delete mode 100644 packages/svelte/messages/compile-errors/parse.md delete mode 100644 packages/svelte/messages/compile-errors/runes.md create mode 100644 packages/svelte/messages/compile-errors/script.md delete mode 100644 packages/svelte/messages/compile-errors/slots.md delete mode 100644 packages/svelte/messages/compile-errors/special_elements.md rename packages/svelte/messages/compile-errors/{css.md => style.md} (60%) create mode 100644 packages/svelte/messages/compile-errors/template.md delete mode 100644 packages/svelte/messages/compile-errors/variables.md delete mode 100644 packages/svelte/messages/compile-warnings/attributes.md delete mode 100644 packages/svelte/messages/compile-warnings/block.md delete mode 100644 packages/svelte/messages/compile-warnings/components.md delete mode 100644 packages/svelte/messages/compile-warnings/css.md delete mode 100644 packages/svelte/messages/compile-warnings/legacy.md delete mode 100644 packages/svelte/messages/compile-warnings/misc.md delete mode 100644 packages/svelte/messages/compile-warnings/performance.md delete mode 100644 packages/svelte/messages/compile-warnings/runes.md create mode 100644 packages/svelte/messages/compile-warnings/script.md delete mode 100644 packages/svelte/messages/compile-warnings/state.md create mode 100644 packages/svelte/messages/compile-warnings/style.md create mode 100644 packages/svelte/messages/compile-warnings/template.md create mode 100644 packages/svelte/messages/server-errors/lifecycle.md create mode 100644 packages/svelte/messages/shared-errors/errors.md create mode 100644 packages/svelte/scripts/process-messages/templates/server-errors.js create mode 100644 packages/svelte/scripts/process-messages/templates/shared-errors.js create mode 100644 packages/svelte/src/internal/server/errors.js create mode 100644 packages/svelte/src/internal/shared/errors.js create mode 100644 packages/svelte/tests/compiler-errors/samples/runes-bindable-not-called/_config.js rename packages/svelte/tests/{validator/samples/runes-bindable-not-called/input.svelte => compiler-errors/samples/runes-bindable-not-called/main.svelte} (100%) delete mode 100644 packages/svelte/tests/compiler-errors/samples/runes-prop-export-conflict/_config.js delete mode 100644 packages/svelte/tests/compiler-errors/samples/runes-prop-export-conflict/main.svelte create mode 100644 packages/svelte/tests/compiler-errors/samples/runes-props-not-called/_config.js rename packages/svelte/tests/{validator/samples/runes-props-not-called/input.svelte => compiler-errors/samples/runes-props-not-called/main.svelte} (100%) delete mode 100644 packages/svelte/tests/validator/samples/runes-bindable-not-called/_config.js delete mode 100644 packages/svelte/tests/validator/samples/runes-bindable-not-called/warnings.json delete mode 100644 packages/svelte/tests/validator/samples/runes-props-not-called/_config.js delete mode 100644 packages/svelte/tests/validator/samples/runes-props-not-called/warnings.json diff --git a/.prettierignore b/.prettierignore index 0e08fae5e9..0567f05cd8 100644 --- a/.prettierignore +++ b/.prettierignore @@ -7,7 +7,9 @@ packages/svelte/src/compiler/errors.js packages/svelte/src/compiler/warnings.js packages/svelte/src/internal/client/errors.js packages/svelte/src/internal/client/warnings.js +packages/svelte/src/internal/shared/errors.js packages/svelte/src/internal/shared/warnings.js +packages/svelte/src/internal/server/errors.js packages/svelte/tests/**/*.svelte packages/svelte/tests/**/_expected* packages/svelte/tests/**/_actual* diff --git a/packages/svelte/messages/client-errors/effects.md b/packages/svelte/messages/client-errors/effects.md deleted file mode 100644 index 88847ea0d5..0000000000 --- a/packages/svelte/messages/client-errors/effects.md +++ /dev/null @@ -1,3 +0,0 @@ -## effect_update_depth_exceeded - -> Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops \ No newline at end of file diff --git a/packages/svelte/messages/client-errors/errors.md b/packages/svelte/messages/client-errors/errors.md new file mode 100644 index 0000000000..aeeb133226 --- /dev/null +++ b/packages/svelte/messages/client-errors/errors.md @@ -0,0 +1,67 @@ +## bind_invalid_checkbox_value + +> Using `bind:value` together with a checkbox input is not allowed. Use `bind:checked` instead + +## bind_invalid_export + +> Component %component% has an export named `%key%` that a consumer component is trying to access using `bind:%key%`, which is disallowed. Instead, use `bind:this` (e.g. `<%name% bind:this={component} />`) and then access the property on the bound component instance (e.g. `component.%key%`) + +## bind_not_bindable + +> A component is attempting to bind to a non-bindable property `%key%` belonging to %component% (i.e. `<%name% bind:%key%={...}>`). To mark a property as bindable: `let { %key% = $bindable() } = $props()` + +## each_key_duplicate + +> Keyed each block has duplicate key at indexes %a% and %b% + +> Keyed each block has duplicate key `%value%` at indexes %a% and %b% + +## effect_in_teardown + +> `%rune%` cannot be used inside an effect cleanup function + +## effect_orphan + +> `%rune%` can only be used inside an effect (e.g. during component initialisation) + +## effect_update_depth_exceeded + +> Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops + +## hydration_missing_marker_close + +> Missing hydration closing marker + +## hydration_missing_marker_open + +> Missing hydration opening marker + +## lifecycle_legacy_only + +> `%name%(...)` cannot be used in runes mode + +## props_invalid_value + +> Cannot do `bind:%key%={undefined}` when `%key%` has a fallback value + +## props_rest_readonly + +> Rest element properties of `$props()` such as `%property%` are readonly + +## rune_outside_svelte + +> The `%rune%` rune is only available inside `.svelte` and `.svelte.js/ts` files + +## state_prototype_fixed + +> Cannot set prototype of `$state` object + +## state_unsafe_mutation + +> Unsafe mutations during Svelte's render or derived phase are not permitted in runes mode. This can lead to unexpected errors and possibly cause infinite loops. +> +> If the object is not meant to be reactive, declare it without `$state` + +## svelte_component_invalid_this_value + +> The `this={...}` property of a `` must be a Svelte component, if defined diff --git a/packages/svelte/messages/client-errors/lifecycle.md b/packages/svelte/messages/client-errors/lifecycle.md deleted file mode 100644 index 98b644d8ec..0000000000 --- a/packages/svelte/messages/client-errors/lifecycle.md +++ /dev/null @@ -1,7 +0,0 @@ -## lifecycle_outside_component - -> `%name%(...)` can only be used during component initialisation - -## lifecycle_legacy_only - -> `%name%(...)` cannot be used in runes mode \ No newline at end of file diff --git a/packages/svelte/messages/client-warnings/warnings.md b/packages/svelte/messages/client-warnings/warnings.md index 865d968144..1f77457f94 100644 --- a/packages/svelte/messages/client-warnings/warnings.md +++ b/packages/svelte/messages/client-warnings/warnings.md @@ -1,3 +1,11 @@ +## hydration_attribute_changed + +> The `%attribute%` attribute on `%html%` changed its value between server and client renders. The client value, `%value%`, will be ignored in favour of the server value + +## hydration_mismatch + +> Hydration failed because the initial UI does not match what was rendered on the server + ## lifecycle_double_unmount > Tried to unmount a component that was not mounted diff --git a/packages/svelte/messages/compile-errors/attributes.md b/packages/svelte/messages/compile-errors/attributes.md deleted file mode 100644 index 8e27e74076..0000000000 --- a/packages/svelte/messages/compile-errors/attributes.md +++ /dev/null @@ -1,59 +0,0 @@ -## empty_attribute_shorthand - -> Attribute shorthand cannot be empty - -## duplicate_attribute - -> Attributes need to be unique - -## invalid_event_attribute_value - -> Event attribute must be a JavaScript expression, not a string - -## invalid_attribute_name - -> '%name%' is not a valid attribute name - -## animation_invalid_placement - -> An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block - -## 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? - -## animation_duplicate - -> An element can only have one 'animate' directive - -## invalid_event_modifier - -> Valid event modifiers are %list% - -## invalid_component_event_modifier - -> Event modifiers other than 'once' can only be used on DOM elements - -## invalid_event_modifier_combination - -> The '%modifier1%' and '%modifier2%' modifiers cannot be used together - -## transition_duplicate - -> Cannot use multiple `%type%:` directives on a single element - -## transition_conflict - -> Cannot use `%type%:` alongside existing `%existing%:` directive - -## invalid_let_directive_placement - -> `let:` directive at invalid position - -## invalid_style_directive_modifier - -> Invalid 'style:' modifier. Valid modifiers are: 'important' - -## invalid_sequence_expression - -> Sequence expressions are not allowed as attribute/directive values in runes mode, unless wrapped in parentheses \ No newline at end of file diff --git a/packages/svelte/messages/compile-errors/bindings.md b/packages/svelte/messages/compile-errors/bindings.md deleted file mode 100644 index 1a7ef806ac..0000000000 --- a/packages/svelte/messages/compile-errors/bindings.md +++ /dev/null @@ -1,33 +0,0 @@ -## invalid_binding_expression - -> Can only bind to an Identifier or MemberExpression - -## invalid_binding_value - -> Can only bind to state or props - -## bind_invalid_target - -> `bind:%name%` can only be used with %elements% - -## bind_invalid - -> `bind:%name%` is not a valid binding - -> `bind:%name%` is not a valid binding. %explanation% - -## invalid_type_attribute - -> 'type' attribute must be a static text value if input uses two-way binding - -## invalid_multiple_attribute - -> 'multiple' attribute must be static if select uses two-way binding - -## missing_contenteditable_attribute - -> 'contenteditable' attribute is required for textContent, innerHTML and innerText two-way bindings - -## dynamic_contenteditable_attribute - -> 'contenteditable' attribute cannot be dynamic if element uses two-way binding diff --git a/packages/svelte/messages/compile-errors/compiler_options.md b/packages/svelte/messages/compile-errors/compiler_options.md deleted file mode 100644 index b2702a1a7e..0000000000 --- a/packages/svelte/messages/compile-errors/compiler_options.md +++ /dev/null @@ -1,7 +0,0 @@ -## invalid_compiler_option - -> Invalid compiler option: %msg% - -## removed_compiler_option - -> Invalid compiler option: %msg% \ No newline at end of file diff --git a/packages/svelte/messages/compile-errors/components.md b/packages/svelte/messages/compile-errors/components.md deleted file mode 100644 index 651c80d733..0000000000 --- a/packages/svelte/messages/compile-errors/components.md +++ /dev/null @@ -1,3 +0,0 @@ -## invalid_component_directive - -> This type of directive is not valid on components \ No newline at end of file diff --git a/packages/svelte/messages/compile-errors/const_tag.md b/packages/svelte/messages/compile-errors/const_tag.md deleted file mode 100644 index 720aba9860..0000000000 --- a/packages/svelte/messages/compile-errors/const_tag.md +++ /dev/null @@ -1,3 +0,0 @@ -## invalid_const_placement - -> {@const} must be the immediate child of {#snippet}, {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, or \ No newline at end of file diff --git a/packages/svelte/messages/compile-errors/elements.md b/packages/svelte/messages/compile-errors/elements.md deleted file mode 100644 index 2686f2370d..0000000000 --- a/packages/svelte/messages/compile-errors/elements.md +++ /dev/null @@ -1,27 +0,0 @@ -## invalid_textarea_content - -> A `