mirror of https://github.com/sveltejs/svelte
parent
903d27e1ed
commit
77310c320b
@ -1,178 +1,192 @@
|
|||||||
// All parser errors should be listed and accessed from here
|
// All parser errors should be listed and accessed from here
|
||||||
|
|
||||||
|
import list from '../utils/list';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export default {
|
export default {
|
||||||
unexpected_eof: {
|
css_syntax_error: (message) => ({
|
||||||
code: 'unexpected-eof',
|
code: 'css-syntax-error',
|
||||||
message: 'Unexpected end of input'
|
message
|
||||||
},
|
}),
|
||||||
attribute_duplicate: {
|
duplicate_attribute: {
|
||||||
code: 'duplicate-attribute',
|
code: 'duplicate-attribute',
|
||||||
message: 'Attributes need to be unique'
|
message: 'Attributes need to be unique'
|
||||||
},
|
},
|
||||||
expected_token_equal: {
|
duplicate_element: (slug: string, name: string) => ({
|
||||||
code: 'unexpected-token',
|
code: `duplicate-${slug}`,
|
||||||
message: 'Expected ='
|
message: `A component can only have one <${name}> tag`
|
||||||
},
|
}),
|
||||||
directive_value_invalid: {
|
|
||||||
code: 'invalid-directive-value',
|
|
||||||
message: 'Directive value must be a JavaScript expression enclosed in curly braces'
|
|
||||||
},
|
|
||||||
duplicate_style: {
|
duplicate_style: {
|
||||||
code: 'duplicate-style',
|
code: 'duplicate-style',
|
||||||
message: 'You can only have one top-level <style> tag per component'
|
message: 'You can only have one top-level <style> tag per component'
|
||||||
},
|
},
|
||||||
duplicate_instance_script: () => ({
|
empty_attribute_shorthand: {
|
||||||
code: 'invalid-script',
|
code: 'empty-attribute-shorthand',
|
||||||
message: 'A component can only have one instance-level <script> element'
|
message: 'Attribute shorthand cannot be empty'
|
||||||
|
},
|
||||||
|
empty_directive_name: (type: string) => ({
|
||||||
|
code: 'empty-directive-name',
|
||||||
|
message: `${type} name cannot be empty`
|
||||||
}),
|
}),
|
||||||
duplicate_module_script: () => ({
|
empty_global_selector: {
|
||||||
code: 'invalid-script',
|
code: 'css-syntax-error',
|
||||||
message: 'A component can only have one <script context="module"> element'
|
message: ':global() must contain a selector'
|
||||||
|
},
|
||||||
|
expected_block_type: {
|
||||||
|
code: 'expected-block-type',
|
||||||
|
message: 'Expected if, each or await'
|
||||||
|
},
|
||||||
|
expected_name: {
|
||||||
|
code: 'expected-name',
|
||||||
|
message: 'Expected name'
|
||||||
|
},
|
||||||
|
invalid_catch_placement_unclosed_block: (block) => ({
|
||||||
|
code: 'invalid-catch-placement',
|
||||||
|
message: `Expected to close ${block} before seeing {:catch} block`
|
||||||
}),
|
}),
|
||||||
dynamic_context_attribute: () => ({
|
invalid_catch_placement_without_await: {
|
||||||
code: 'invalid-script',
|
code: 'invalid-catch-placement',
|
||||||
message: 'context attribute must be static'
|
message: 'Cannot have an {:catch} block outside an {#await ...} block'
|
||||||
|
},
|
||||||
|
invalid_component_definition: {
|
||||||
|
code: 'invalid-component-definition',
|
||||||
|
message: 'invalid component definition'
|
||||||
|
},
|
||||||
|
invalid_closing_tag_unopened: (name: string) => ({
|
||||||
|
code: 'invalid-closing-tag',
|
||||||
|
message: `</${name}> attempted to close an element that was not open`
|
||||||
}),
|
}),
|
||||||
fixed_context_attribute: () => ({
|
invalid_closing_tag_autoclosed: (name: string, reason: string) => ({
|
||||||
code: 'invalid-script',
|
code: 'invalid-closing-tag',
|
||||||
message: 'If the context attribute is supplied, its value must be "module"'
|
message: `</${name}> attempted to close <${name}> that was already automatically closed by <${reason}>`
|
||||||
}),
|
}),
|
||||||
|
invalid_debug_args: {
|
||||||
|
code: 'invalid-debug-args',
|
||||||
|
message:
|
||||||
|
'{@debug ...} arguments must be identifiers, not arbitrary expressions'
|
||||||
|
},
|
||||||
|
invalid_declaration: {
|
||||||
|
code: 'invalid-declaration',
|
||||||
|
message: 'Declaration cannot be empty'
|
||||||
|
},
|
||||||
|
invalid_directive_value: {
|
||||||
|
code: 'invalid-directive-value',
|
||||||
|
message: 'Directive value must be a JavaScript expression enclosed in curly braces'
|
||||||
|
},
|
||||||
invalid_elseif: {
|
invalid_elseif: {
|
||||||
code: 'invalid-elseif',
|
code: 'invalid-elseif',
|
||||||
message: '\'elseif\' should be \'else if\''
|
message: '\'elseif\' should be \'else if\''
|
||||||
},
|
},
|
||||||
else_if_without_if: {
|
invalid_elseif_placement_outside_if: {
|
||||||
code: 'invalid-elseif-placement',
|
code: 'invalid-elseif-placement',
|
||||||
message: 'Cannot have an {:else if ...} block outside an {#if ...} block'
|
message: 'Cannot have an {:else if ...} block outside an {#if ...} block'
|
||||||
},
|
},
|
||||||
else_if_before_block_close: (block) => ({
|
invalid_elseif_placement_unclosed_block: (block) => ({
|
||||||
code: 'invalid-elseif-placement',
|
code: 'invalid-elseif-placement',
|
||||||
message: `Expected to close ${block} before seeing {:else if ...} block`
|
message: `Expected to close ${block} before seeing {:else if ...} block`
|
||||||
}),
|
}),
|
||||||
else_without_if_each: () => ({
|
invalid_else_placement_outside_if: {
|
||||||
code: 'invalid-else-placement',
|
code: 'invalid-else-placement',
|
||||||
message: 'Cannot have an {:else} block outside an {#if ...} or {#each ...} block'
|
message: 'Cannot have an {:else} block outside an {#if ...} or {#each ...} block'
|
||||||
}),
|
},
|
||||||
else_before_block_close: (block) => ({
|
invalid_else_placement_unclosed_block: (block) => ({
|
||||||
code: 'invalid-else-placement',
|
code: 'invalid-else-placement',
|
||||||
message: `Expected to close ${block} before seeing {:else} block`
|
message: `Expected to close ${block} before seeing {:else} block`
|
||||||
}),
|
}),
|
||||||
then_before_close_block: (block) => ({
|
invalid_element_content: (slug: string, name: string) => ({
|
||||||
code: 'invalid-then-placement',
|
code: `invalid-${slug}-content`,
|
||||||
message: `Expected to close ${block} before seeing {:then} block`
|
message: `<${name}> cannot have children`
|
||||||
}),
|
}),
|
||||||
then_without_await: {
|
invalid_element_placement: (slug: string, name: string) => ({
|
||||||
code: 'invalid-then-placement',
|
code: `invalid-${slug}-placement`,
|
||||||
message: 'Cannot have an {:then} block outside an {#await ...} block'
|
message: `<${name}> tags cannot be inside elements or blocks`
|
||||||
},
|
|
||||||
catch_before_close_block: (block) => ({
|
|
||||||
code: 'invalid-catch-placement',
|
|
||||||
message: `Expected to close ${block} before seeing {:catch} block`
|
|
||||||
}),
|
}),
|
||||||
catch_without_await: {
|
invalid_ref_directive: (name: string) => ({
|
||||||
code: 'invalid-catch-placement',
|
code: 'invalid-ref-directive',
|
||||||
message: 'Cannot have an {:catch} block outside an {#await ...} block'
|
message: `The ref directive is no longer supported — use \`bind:this={${name}}\` instead`
|
||||||
|
}),
|
||||||
|
invalid_ref_selector: {
|
||||||
|
code: 'invalid-ref-selector',
|
||||||
|
message: 'ref selectors are no longer supported'
|
||||||
},
|
},
|
||||||
component_definition_invalid: {
|
invalid_self_placement: {
|
||||||
code: 'invalid-component-definition',
|
code: 'invalid-self-placement',
|
||||||
message: 'invalid component definition'
|
message: '<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components'
|
||||||
},
|
},
|
||||||
component_definition_missing: {
|
invalid_script_instance: {
|
||||||
code: 'missing-component-definition',
|
code: 'invalid-script',
|
||||||
message: '<svelte:component> must have a \'this\' attribute'
|
message: 'A component can only have one instance-level <script> element'
|
||||||
},
|
},
|
||||||
expected_block_type: {
|
invalid_script_module: {
|
||||||
code: 'expected-block-type',
|
code: 'invalid-script',
|
||||||
message: 'Expected if, each or await'
|
message: 'A component can only have one <script context="module"> element'
|
||||||
},
|
},
|
||||||
expected_name: {
|
invalid_script_context_attribute: {
|
||||||
code: 'expected-name',
|
code: 'invalid-script',
|
||||||
message: 'Expected name'
|
message: 'context attribute must be static'
|
||||||
},
|
},
|
||||||
unexpected_block_close: {
|
invalid_script_context_value: {
|
||||||
code: 'unexpected-block-close',
|
code: 'invalid-script',
|
||||||
message: 'Unexpected block closing tag'
|
message: 'If the context attribute is supplied, its value must be "module"'
|
||||||
},
|
},
|
||||||
debug_args: () => ({
|
invalid_tag_name: {
|
||||||
code: 'invalid-debug-args',
|
|
||||||
message:
|
|
||||||
'{@debug ...} arguments must be identifiers, not arbitrary expressions'
|
|
||||||
}),
|
|
||||||
element_unopened: (name) => ({
|
|
||||||
code: 'invalid-closing-tag',
|
|
||||||
message: `</${name}> attempted to close an element that was not open`
|
|
||||||
}),
|
|
||||||
element_autoclosed: (name, reason) => ({
|
|
||||||
code: 'invalid-closing-tag',
|
|
||||||
message: `</${name}> attempted to close <${name}> that was already automatically closed by <${reason}>`
|
|
||||||
}),
|
|
||||||
element_tag_name_invalid: {
|
|
||||||
code: 'invalid-tag-name',
|
code: 'invalid-tag-name',
|
||||||
message: 'Expected valid tag name'
|
message: 'Expected valid tag name'
|
||||||
},
|
},
|
||||||
meta_no_children: (slug, name) => ({
|
invalid_tag_name_svelte_element: (tags: string[], match: string) => ({
|
||||||
code: `invalid-${slug}-content`,
|
|
||||||
message: `<${name}> cannot have children`
|
|
||||||
}),
|
|
||||||
meta_duplicate: (slug, name) => ({
|
|
||||||
code: `duplicate-${slug}`,
|
|
||||||
message: `A component can only have one <${name}> tag`
|
|
||||||
}),
|
|
||||||
meta_top_level: (slug, name) => ({
|
|
||||||
code: `invalid-${slug}-placement`,
|
|
||||||
message: `<${name}> tags cannot be inside elements or blocks`
|
|
||||||
}),
|
|
||||||
self_placement_invalid: {
|
|
||||||
code: 'invalid-self-placement',
|
|
||||||
message: '<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components'
|
|
||||||
},
|
|
||||||
meta_tag_name_invalid: (tags, match) => ({
|
|
||||||
code: 'invalid-tag-name',
|
code: 'invalid-tag-name',
|
||||||
message: `Valid <svelte:...> tag names are ${tags}${
|
message: `Valid <svelte:...> tag names are ${list(tags)}${
|
||||||
match ? ' (did you mean ' + match + '?)' : ''
|
match ? ' (did you mean ' + match + '?)' : ''
|
||||||
}`
|
}`
|
||||||
}),
|
}),
|
||||||
ref_directive_invalid: (name) => ({
|
invalid_then_placement_unclosed_block: (block) => ({
|
||||||
code: 'invalid-ref-directive',
|
code: 'invalid-then-placement',
|
||||||
message: `The ref directive is no longer supported — use \`bind:this={${name}}\` instead`
|
message: `Expected to close ${block} before seeing {:then} block`
|
||||||
}),
|
}),
|
||||||
void_no_children: (name) => ({
|
invalid_then_placement_without_await: {
|
||||||
|
code: 'invalid-then-placement',
|
||||||
|
message: 'Cannot have an {:then} block outside an {#await ...} block'
|
||||||
|
},
|
||||||
|
invalid_void_content: (name: string) => ({
|
||||||
code: 'invalid-void-content',
|
code: 'invalid-void-content',
|
||||||
message: `<${name}> is a void element and cannot have children, or a closing tag`
|
message: `<${name}> is a void element and cannot have children, or a closing tag`
|
||||||
}),
|
}),
|
||||||
unclosed_script: () => ({
|
missing_component_definition: {
|
||||||
|
code: 'missing-component-definition',
|
||||||
|
message: '<svelte:component> must have a \'this\' attribute'
|
||||||
|
},
|
||||||
|
unclosed_script: {
|
||||||
code: 'unclosed-script',
|
code: 'unclosed-script',
|
||||||
message: '<script> must have a closing tag'
|
message: '<script> must have a closing tag'
|
||||||
}),
|
},
|
||||||
unclosed_style: () => ({
|
unclosed_style: {
|
||||||
code: 'unclosed-style',
|
code: 'unclosed-style',
|
||||||
message: '<style> must have a closing tag'
|
message: '<style> must have a closing tag'
|
||||||
}),
|
},
|
||||||
unclosed_comment: () => ({
|
unclosed_comment: {
|
||||||
code: 'unclosed-comment',
|
code: 'unclosed-comment',
|
||||||
message: 'comment was left open, expected -->'
|
message: 'comment was left open, expected -->'
|
||||||
|
},
|
||||||
|
unexpected_block_close: {
|
||||||
|
code: 'unexpected-block-close',
|
||||||
|
message: 'Unexpected block closing tag'
|
||||||
|
},
|
||||||
|
unexpected_eof: {
|
||||||
|
code: 'unexpected-eof',
|
||||||
|
message: 'Unexpected end of input'
|
||||||
|
},
|
||||||
|
unexpected_eof_token: (token: string) => ({
|
||||||
|
code: 'unexpected-eof',
|
||||||
|
message: `Unexpected ${token}`
|
||||||
}),
|
}),
|
||||||
unexpected_token: () => ({
|
unexpected_token: (token: string) => ({
|
||||||
code: 'unexpected-token',
|
code: 'unexpected-token',
|
||||||
message: 'Expected )'
|
message: `Expected ${token}`
|
||||||
}),
|
|
||||||
invalid_ref_selector: () => ({
|
|
||||||
code: 'invalid-ref-selector',
|
|
||||||
message: 'ref selectors are no longer supported'
|
|
||||||
}),
|
}),
|
||||||
invalid_declaration: () => ({
|
unexpected_token_destructure: {
|
||||||
code: 'invalid-declaration',
|
code: 'unexpected-token',
|
||||||
message: 'Declaration cannot be empty'
|
message: 'Expected identifier or destructure pattern'
|
||||||
}),
|
}
|
||||||
empty_global_selector: () => ({
|
|
||||||
code: 'css-syntax-error',
|
|
||||||
message: ':global() must contain a selector'
|
|
||||||
}),
|
|
||||||
syntax_error: (message) => ({
|
|
||||||
code: 'css-syntax-error',
|
|
||||||
message
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in new issue