From 73490bbb8e3c0640ac72151d7e9aa8b5bf6604d6 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 23 Apr 2024 10:39:37 -0400 Subject: [PATCH] chore: markdown errors (#11294) * rename errors.js to errors-tmp.js * start porting errors * generate markdown files for more errors * convert parse errors * convert css errors * convert special_element errors * convert runes errors * convert element errors * more * more * more * more * more * more * fix some tests * fix some tests * more tests * remove unused error * prettierignore * weird * ugh * lint --- .prettierignore | 2 + eslint.config.js | 5 +- .../messages/compile-errors/attributes.md | 59 + .../messages/compile-errors/bindings.md | 35 + .../compile-errors/compiler_options.md | 7 + .../messages/compile-errors/components.md | 3 + .../messages/compile-errors/const_tag.md | 3 + .../svelte/messages/compile-errors/css.md | 51 + .../messages/compile-errors/elements.md | 27 + .../compile-errors/legacy_reactivity.md | 3 + .../svelte/messages/compile-errors/parse.md | 147 ++ .../svelte/messages/compile-errors/runes.md | 95 + .../svelte/messages/compile-errors/slots.md | 31 + .../compile-errors/special_elements.md | 99 + .../messages/compile-errors/variables.md | 19 + .../svelte/scripts/process-messages/index.js | 213 ++ .../templates/compile-errors.js | 74 + packages/svelte/src/compiler/errors.js | 1849 ++++++++++++----- .../src/compiler/phases/1-parse/index.js | 22 +- .../compiler/phases/1-parse/read/context.js | 10 +- .../phases/1-parse/read/expression.js | 4 +- .../compiler/phases/1-parse/read/options.js | 91 +- .../compiler/phases/1-parse/read/script.js | 8 +- .../src/compiler/phases/1-parse/read/style.js | 22 +- .../compiler/phases/1-parse/state/element.js | 74 +- .../src/compiler/phases/1-parse/state/tag.js | 30 +- .../phases/2-analyze/css/css-analyze.js | 27 +- .../src/compiler/phases/2-analyze/index.js | 22 +- .../compiler/phases/2-analyze/validation.js | 267 +-- .../3-transform/client/transform-client.js | 27 +- .../phases/3-transform/client/utils.js | 3 +- .../3-transform/client/visitors/template.js | 7 +- .../3-transform/server/transform-server.js | 18 +- packages/svelte/src/compiler/phases/scope.js | 12 +- packages/svelte/src/compiler/utils/assert.js | 6 +- .../svelte/src/compiler/validate-options.js | 9 +- .../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-before-closing/_config.js | 2 +- .../samples/catch-without-await/_config.js | 2 +- .../class-state-field-static/_config.js | 5 +- .../samples/comment-unclosed/_config.js | 4 +- .../_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 | 4 +- .../samples/dollar-binding-global/_config.js | 4 +- .../samples/dollar-binding-import/_config.js | 2 +- .../_config.js | 4 +- .../samples/else-before-closing-2/_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 +- .../samples/else-if-before-closing/_config.js | 2 +- .../samples/else-if-without-if/_config.js | 2 +- .../empty-attribute-shorthand/_config.js | 2 +- .../empty-classname-binding/_config.js | 2 +- .../samples/empty-directive-name/_config.js | 2 +- .../samples/export-derived-state/_config.js | 2 +- .../samples/export-state-module/_config.js | 2 +- .../samples/export-state/_config.js | 2 +- .../samples/illegal-expression/_config.js | 2 +- .../invalid-snippet-binding/_config.js | 2 +- .../invalid-snippet-mutation/_config.js | 2 +- .../legacy-no-const-assignment/_config.js | 4 +- .../samples/legacy-no-const-update/_config.js | 4 +- .../samples/multiple-styles/_config.js | 4 +- .../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 +- .../samples/runes-duplicate-props/_config.js | 4 +- .../samples/runes-export-let/_config.js | 2 +- .../runes-export-named-state/_config.js | 2 +- .../runes-invalid-each-binding/_config.js | 4 +- .../runes-invalid-each-mutation/_config.js | 4 +- .../runes-no-const-assignment/_config.js | 4 +- .../samples/runes-no-const-update/_config.js | 4 +- .../runes-no-derived-assignment/_config.js | 4 +- .../runes-no-derived-binding/_config.js | 4 +- .../_config.js | 4 +- .../_config.js | 4 +- .../runes-no-derived-update/_config.js | 4 +- .../samples/runes-no-rune-each/_config.js | 4 +- .../runes-prop-export-conflict/_config.js | 2 +- .../runes-wrong-bindable-args/_config.js | 4 +- .../runes-wrong-bindable-placement/_config.js | 4 +- .../runes-wrong-derived-args/_config.js | 4 +- .../runes-wrong-derived-placement/_config.js | 5 +- .../runes-wrong-effect-args/_config.js | 4 +- .../runes-wrong-effect-placement/_config.js | 4 +- .../runes-wrong-host-placement/_config.js | 4 +- .../samples/runes-wrong-props-args/_config.js | 4 +- .../runes-wrong-props-placement/_config.js | 4 +- .../samples/runes-wrong-state-args/_config.js | 4 +- .../runes-wrong-state-placement/_config.js | 4 +- .../_config.js | 4 +- .../samples/script-unclosed-eof/_config.js | 2 +- .../samples/script-unclosed/_config.js | 4 +- .../samples/self-reference/_config.js | 4 +- .../_config.js | 4 +- .../snippet-children-conflict/_config.js | 2 +- .../store-autosub-context-module/_config.js | 4 +- .../samples/store-contextual/_config.js | 2 +- .../store-global-disallowed/_config.js | 4 +- .../_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-eof/_config.js | 2 +- .../samples/style-unclosed/_config.js | 2 +- .../samples/svelte-selfdestructive/_config.js | 4 +- .../samples/then-before-closing/_config.js | 2 +- .../samples/then-without-await/_config.js | 2 +- .../_config.js | 2 +- .../unexpected-end-of-input-b/_config.js | 2 +- .../unexpected-end-of-input-c/_config.js | 2 +- .../unexpected-end-of-input-d/_config.js | 2 +- .../unexpected-end-of-input/_config.js | 4 +- .../_config.js | 2 +- .../_config.js | 2 +- .../samples/unmatched-closing-tag/_config.js | 2 +- .../samples/void-closing/_config.js | 2 +- .../samples/window-children/_config.js | 2 +- .../samples/window-duplicate/_config.js | 2 +- .../samples/window-inside-block/_config.js | 2 +- .../samples/window-inside-element/_config.js | 2 +- .../samples/action-on-component/errors.json | 2 +- .../samples/animation-duplicate/errors.json | 2 +- .../samples/animation-not-in-each/errors.json | 4 +- .../animation-not-in-keyed-each/errors.json | 4 +- .../animation-on-component/errors.json | 2 +- .../samples/animation-siblings/errors.json | 4 +- .../samples/assignment-to-const-2/errors.json | 4 +- .../samples/assignment-to-const-3/errors.json | 4 +- .../samples/assignment-to-const-4/errors.json | 4 +- .../samples/assignment-to-const-5/errors.json | 4 +- .../samples/assignment-to-const-7/errors.json | 4 +- .../samples/assignment-to-const/errors.json | 4 +- .../attribute-expected-equals/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 | 14 +- .../samples/binding-await-then-2/errors.json | 14 +- .../samples/binding-await-then/errors.json | 14 +- .../samples/binding-const/errors.json | 4 +- .../binding-dimensions-svg/errors.json | 4 +- .../samples/binding-input-checked/errors.json | 4 +- .../binding-input-type-boolean/errors.json | 2 +- .../errors.json | 4 +- .../binding-invalid-on-element-2/errors.json | 4 +- .../binding-invalid-on-element/errors.json | 4 +- .../binding-invalid-value-global/errors.json | 2 +- .../samples/binding-invalid-value/errors.json | 2 +- .../samples/binding-invalid/errors.json | 4 +- .../validator/samples/binding-let/errors.json | 4 +- .../errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 12 +- .../errors.json | 4 +- .../errors.json | 2 +- .../component-slot-dynamic/errors.json | 2 +- .../errors.json | 12 +- .../component-slotted-each-block/errors.json | 2 +- .../component-slotted-if-block/errors.json | 2 +- .../samples/const-tag-conflict-1/errors.json | 14 +- .../samples/const-tag-conflict-2/errors.json | 14 +- .../samples/const-tag-placement-1/errors.json | 12 +- .../samples/const-tag-placement-2/errors.json | 12 +- .../samples/const-tag-readonly-1/errors.json | 14 +- .../samples/const-tag-readonly-2/errors.json | 14 +- .../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/css-mismatched-quotes/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 | 4 +- .../errors.json | 4 +- .../dollar-global-in-markup/errors.json | 4 +- .../dollar-global-in-script/errors.json | 4 +- .../dynamic-element-invalid-tag/errors.json | 2 +- .../dynamic-element-missing-tag/errors.json | 4 +- .../samples/dynamic-element-this/errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../each-block-invalid-context/errors.json | 2 +- .../samples/event-attribute/errors.json | 2 +- .../errors.json | 2 +- .../errors.json | 2 +- .../event-modifiers-invalid/errors.json | 2 +- .../html-block-in-attribute/errors.json | 12 +- .../html-block-in-textarea/errors.json | 12 +- .../illegal-variable-declaration/errors.json | 4 +- .../invalid-empty-css-declaration/errors.json | 2 +- .../invalid-node-placement-2/errors.json | 2 +- .../invalid-node-placement/errors.json | 2 +- .../samples/let-directive/errors.json | 14 +- .../logic-block-in-attribute/errors.json | 12 +- .../logic-block-in-textarea/errors.json | 12 +- .../errors.json | 4 +- .../errors.json | 4 +- .../samples/namespace-invalid/errors.json | 4 +- .../samples/namespace-non-literal/errors.json | 4 +- .../reactive-declaration-cyclical/errors.json | 12 +- .../script-invalid-context/errors.json | 2 +- .../slot-attribute-invalid/errors.json | 2 +- .../errors.json | 2 +- .../svelte-fragment-placement-2/errors.json | 14 +- .../svelte-fragment-placement/errors.json | 14 +- .../svelte-head-attributes/errors.json | 14 +- .../validator/samples/tag-invalid/errors.json | 4 +- .../samples/tag-non-string/errors.json | 2 +- .../textarea-value-children/errors.json | 4 +- .../samples/title-no-attributes/errors.json | 4 +- .../samples/title-no-children/errors.json | 4 +- .../errors.json | 4 +- .../transition-duplicate-in/errors.json | 4 +- .../errors.json | 4 +- .../transition-duplicate-out/errors.json | 4 +- .../errors.json | 4 +- .../errors.json | 4 +- .../errors.json | 4 +- .../transition-on-component/errors.json | 2 +- .../errors.json | 4 +- .../window-binding-invalid/errors.json | 4 +- 267 files changed, 3027 insertions(+), 1198 deletions(-) create mode 100644 packages/svelte/messages/compile-errors/attributes.md create mode 100644 packages/svelte/messages/compile-errors/bindings.md create mode 100644 packages/svelte/messages/compile-errors/compiler_options.md create mode 100644 packages/svelte/messages/compile-errors/components.md create mode 100644 packages/svelte/messages/compile-errors/const_tag.md create mode 100644 packages/svelte/messages/compile-errors/css.md create mode 100644 packages/svelte/messages/compile-errors/elements.md create mode 100644 packages/svelte/messages/compile-errors/legacy_reactivity.md create mode 100644 packages/svelte/messages/compile-errors/parse.md create mode 100644 packages/svelte/messages/compile-errors/runes.md create mode 100644 packages/svelte/messages/compile-errors/slots.md create mode 100644 packages/svelte/messages/compile-errors/special_elements.md create mode 100644 packages/svelte/messages/compile-errors/variables.md create mode 100644 packages/svelte/scripts/process-messages/index.js create mode 100644 packages/svelte/scripts/process-messages/templates/compile-errors.js diff --git a/.prettierignore b/.prettierignore index 48d37dc02f..77bdd29cf3 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,6 +2,8 @@ packages/**/dist/*.js packages/**/build/*.js packages/**/npm/**/* packages/**/config/*.js +packages/svelte/messages/**/*.md +packages/svelte/src/compiler/errors.js packages/svelte/tests/**/*.svelte packages/svelte/tests/**/_expected* packages/svelte/tests/**/_actual* diff --git a/eslint.config.js b/eslint.config.js index 75fcc7fa06..a86f724d34 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -33,13 +33,16 @@ export default [ ignores: [ '**/*.d.ts', '**/tests', + 'packages/svelte/scripts/process-messages/templates/*.js', + 'packages/svelte/src/compiler/errors.js', 'packages/svelte/compiler/index.js', // documentation can contain invalid examples 'documentation', // contains a fork of the REPL which doesn't adhere to eslint rules 'sites/svelte-5-preview/**', // wasn't checked previously, reenable at some point - 'sites/svelte.dev/**' + 'sites/svelte.dev/**', + 'tmp/**' ] } ]; diff --git a/packages/svelte/messages/compile-errors/attributes.md b/packages/svelte/messages/compile-errors/attributes.md new file mode 100644 index 0000000000..9501080ee0 --- /dev/null +++ b/packages/svelte/messages/compile-errors/attributes.md @@ -0,0 +1,59 @@ +## 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 diff --git a/packages/svelte/messages/compile-errors/bindings.md b/packages/svelte/messages/compile-errors/bindings.md new file mode 100644 index 0000000000..5e88c5890a --- /dev/null +++ b/packages/svelte/messages/compile-errors/bindings.md @@ -0,0 +1,35 @@ +## 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_invalid_detailed + +`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 new file mode 100644 index 0000000000..761d74c72a --- /dev/null +++ b/packages/svelte/messages/compile-errors/compiler_options.md @@ -0,0 +1,7 @@ +## 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 new file mode 100644 index 0000000000..88a31a81c6 --- /dev/null +++ b/packages/svelte/messages/compile-errors/components.md @@ -0,0 +1,3 @@ +## 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 new file mode 100644 index 0000000000..de8a8ca909 --- /dev/null +++ b/packages/svelte/messages/compile-errors/const_tag.md @@ -0,0 +1,3 @@ +## 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/css.md b/packages/svelte/messages/compile-errors/css.md new file mode 100644 index 0000000000..33331cfac6 --- /dev/null +++ b/packages/svelte/messages/compile-errors/css.md @@ -0,0 +1,51 @@ +## invalid_css_empty_declaration + +Declaration cannot be empty + +## invalid_css_global_block_list + +A :global {...} block cannot be part of a selector list with more than one item + +## invalid_css_global_block_modifier + +A :global {...} block cannot modify an existing selector + +## invalid_css_global_block_combinator + +A :global {...} block cannot follow a %name% combinator + +## invalid_css_global_block_declaration + +A :global {...} block can only contain rules, not declarations + +## invalid_css_global_placement + +:global(...) can be at the start or end of a selector sequence, but not in the middle + +## invalid_css_global_selector + +:global(...) must contain exactly one selector + +## invalid_css_global_selector_list + +:global(...) must not contain type or universal selectors when used in a compound selector + +## invalid_css_type_selector_placement + +:global(...) must not be followed with a type selector + +## invalid_css_selector + +Invalid selector + +## invalid_css_identifier + +Expected a valid CSS identifier + +## invalid_nesting_selector + +Nesting selectors can only be used inside a rule + +## invalid_css_declaration + +Declaration cannot be empty diff --git a/packages/svelte/messages/compile-errors/elements.md b/packages/svelte/messages/compile-errors/elements.md new file mode 100644 index 0000000000..466a26a7ac --- /dev/null +++ b/packages/svelte/messages/compile-errors/elements.md @@ -0,0 +1,27 @@ +## invalid_textarea_content + +A `