|
|
|
@ -1,12 +1,11 @@
|
|
|
|
// 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';
|
|
|
|
import list from '../utils/list';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export default {
|
|
|
|
export default {
|
|
|
|
css_syntax_error: (message) => ({
|
|
|
|
css_syntax_error: /**
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: any; }} */ (message) => ({
|
|
|
|
code: 'css-syntax-error',
|
|
|
|
code: 'css-syntax-error',
|
|
|
|
message
|
|
|
|
message
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -14,7 +13,11 @@ export default {
|
|
|
|
code: 'duplicate-attribute',
|
|
|
|
code: 'duplicate-attribute',
|
|
|
|
message: 'Attributes need to be unique'
|
|
|
|
message: 'Attributes need to be unique'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
duplicate_element: (slug: string, name: string) => ({
|
|
|
|
duplicate_element: /**
|
|
|
|
|
|
|
|
* @param {string} slug
|
|
|
|
|
|
|
|
* @param {string} name
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (slug, name) => ({
|
|
|
|
code: `duplicate-${slug}`,
|
|
|
|
code: `duplicate-${slug}`,
|
|
|
|
message: `A component can only have one <${name}> tag`
|
|
|
|
message: `A component can only have one <${name}> tag`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -26,7 +29,10 @@ export default {
|
|
|
|
code: 'empty-attribute-shorthand',
|
|
|
|
code: 'empty-attribute-shorthand',
|
|
|
|
message: 'Attribute shorthand cannot be empty'
|
|
|
|
message: 'Attribute shorthand cannot be empty'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
empty_directive_name: (type: string) => ({
|
|
|
|
empty_directive_name: /**
|
|
|
|
|
|
|
|
* @param {string} type
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (type) => ({
|
|
|
|
code: 'empty-directive-name',
|
|
|
|
code: 'empty-directive-name',
|
|
|
|
message: `${type} name cannot be empty`
|
|
|
|
message: `${type} name cannot be empty`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -42,7 +48,8 @@ export default {
|
|
|
|
code: 'expected-name',
|
|
|
|
code: 'expected-name',
|
|
|
|
message: 'Expected name'
|
|
|
|
message: 'Expected name'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
invalid_catch_placement_unclosed_block: (block) => ({
|
|
|
|
invalid_catch_placement_unclosed_block: /**
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }} */ (block) => ({
|
|
|
|
code: 'invalid-catch-placement',
|
|
|
|
code: 'invalid-catch-placement',
|
|
|
|
message: `Expected to close ${block} before seeing {:catch} block`
|
|
|
|
message: `Expected to close ${block} before seeing {:catch} block`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -54,11 +61,18 @@ export default {
|
|
|
|
code: 'invalid-component-definition',
|
|
|
|
code: 'invalid-component-definition',
|
|
|
|
message: 'invalid component definition'
|
|
|
|
message: 'invalid component definition'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
invalid_closing_tag_unopened: (name: string) => ({
|
|
|
|
invalid_closing_tag_unopened: /**
|
|
|
|
|
|
|
|
* @param {string} name
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (name) => ({
|
|
|
|
code: 'invalid-closing-tag',
|
|
|
|
code: 'invalid-closing-tag',
|
|
|
|
message: `</${name}> attempted to close an element that was not open`
|
|
|
|
message: `</${name}> attempted to close an element that was not open`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
invalid_closing_tag_autoclosed: (name: string, reason: string) => ({
|
|
|
|
invalid_closing_tag_autoclosed: /**
|
|
|
|
|
|
|
|
* @param {string} name
|
|
|
|
|
|
|
|
* @param {string} reason
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (name, reason) => ({
|
|
|
|
code: 'invalid-closing-tag',
|
|
|
|
code: 'invalid-closing-tag',
|
|
|
|
message: `</${name}> attempted to close <${name}> that was already automatically closed by <${reason}>`
|
|
|
|
message: `</${name}> attempted to close <${name}> that was already automatically closed by <${reason}>`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -82,7 +96,8 @@ export default {
|
|
|
|
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'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
invalid_elseif_placement_unclosed_block: (block) => ({
|
|
|
|
invalid_elseif_placement_unclosed_block: /**
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }} */ (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`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -90,11 +105,16 @@ export default {
|
|
|
|
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'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
invalid_else_placement_unclosed_block: (block) => ({
|
|
|
|
invalid_else_placement_unclosed_block: /**
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }} */ (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`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
invalid_element_content: (slug: string, name: string) => ({
|
|
|
|
invalid_element_content: /**
|
|
|
|
|
|
|
|
* @param {string} slug
|
|
|
|
|
|
|
|
* @param {string} name
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (slug, name) => ({
|
|
|
|
code: `invalid-${slug}-content`,
|
|
|
|
code: `invalid-${slug}-content`,
|
|
|
|
message: `<${name}> cannot have children`
|
|
|
|
message: `<${name}> cannot have children`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -102,19 +122,34 @@ export default {
|
|
|
|
code: 'invalid-element-definition',
|
|
|
|
code: 'invalid-element-definition',
|
|
|
|
message: 'Invalid element definition'
|
|
|
|
message: 'Invalid element definition'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
invalid_element_placement: (slug: string, name: string) => ({
|
|
|
|
invalid_element_placement: /**
|
|
|
|
|
|
|
|
* @param {string} slug
|
|
|
|
|
|
|
|
* @param {string} name
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (slug, name) => ({
|
|
|
|
code: `invalid-${slug}-placement`,
|
|
|
|
code: `invalid-${slug}-placement`,
|
|
|
|
message: `<${name}> tags cannot be inside elements or blocks`
|
|
|
|
message: `<${name}> tags cannot be inside elements or blocks`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
invalid_logic_block_placement: (location: string, name: string) => ({
|
|
|
|
invalid_logic_block_placement: /**
|
|
|
|
|
|
|
|
* @param {string} location
|
|
|
|
|
|
|
|
* @param {string} name
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (location, name) => ({
|
|
|
|
code: 'invalid-logic-block-placement',
|
|
|
|
code: 'invalid-logic-block-placement',
|
|
|
|
message: `{#${name}} logic block cannot be ${location}`
|
|
|
|
message: `{#${name}} logic block cannot be ${location}`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
invalid_tag_placement: (location: string, name: string) => ({
|
|
|
|
invalid_tag_placement: /**
|
|
|
|
|
|
|
|
* @param {string} location
|
|
|
|
|
|
|
|
* @param {string} name
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (location, name) => ({
|
|
|
|
code: 'invalid-tag-placement',
|
|
|
|
code: 'invalid-tag-placement',
|
|
|
|
message: `{@${name}} tag cannot be ${location}`
|
|
|
|
message: `{@${name}} tag cannot be ${location}`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
invalid_ref_directive: (name: string) => ({
|
|
|
|
invalid_ref_directive: /**
|
|
|
|
|
|
|
|
* @param {string} name
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (name) => ({
|
|
|
|
code: 'invalid-ref-directive',
|
|
|
|
code: 'invalid-ref-directive',
|
|
|
|
message: `The ref directive is no longer supported — use \`bind:this={${name}}\` instead`
|
|
|
|
message: `The ref directive is no longer supported — use \`bind:this={${name}}\` instead`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -124,8 +159,7 @@ export default {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
invalid_self_placement: {
|
|
|
|
invalid_self_placement: {
|
|
|
|
code: 'invalid-self-placement',
|
|
|
|
code: 'invalid-self-placement',
|
|
|
|
message:
|
|
|
|
message: '<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components'
|
|
|
|
'<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components'
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
invalid_script_instance: {
|
|
|
|
invalid_script_instance: {
|
|
|
|
code: 'invalid-script',
|
|
|
|
code: 'invalid-script',
|
|
|
|
@ -147,13 +181,16 @@ export default {
|
|
|
|
code: 'invalid-tag-name',
|
|
|
|
code: 'invalid-tag-name',
|
|
|
|
message: 'Expected valid tag name'
|
|
|
|
message: 'Expected valid tag name'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
invalid_tag_name_svelte_element: (tags: string[], match: string) => ({
|
|
|
|
invalid_tag_name_svelte_element: /**
|
|
|
|
|
|
|
|
* @param {string[]} tags
|
|
|
|
|
|
|
|
* @param {string} match
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (tags, match) => ({
|
|
|
|
code: 'invalid-tag-name',
|
|
|
|
code: 'invalid-tag-name',
|
|
|
|
message: `Valid <svelte:...> tag names are ${list(tags)}${
|
|
|
|
message: `Valid <svelte:...> tag names are ${list(tags)}${match ? ' (did you mean ' + match + '?)' : ''}`
|
|
|
|
match ? ' (did you mean ' + match + '?)' : ''
|
|
|
|
|
|
|
|
}`
|
|
|
|
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
invalid_then_placement_unclosed_block: (block) => ({
|
|
|
|
invalid_then_placement_unclosed_block: /**
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }} */ (block) => ({
|
|
|
|
code: 'invalid-then-placement',
|
|
|
|
code: 'invalid-then-placement',
|
|
|
|
message: `Expected to close ${block} before seeing {:then} block`
|
|
|
|
message: `Expected to close ${block} before seeing {:then} block`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -161,7 +198,10 @@ export default {
|
|
|
|
code: 'invalid-then-placement',
|
|
|
|
code: 'invalid-then-placement',
|
|
|
|
message: 'Cannot have an {:then} block outside an {#await ...} block'
|
|
|
|
message: 'Cannot have an {:then} block outside an {#await ...} block'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
invalid_void_content: (name: string) => ({
|
|
|
|
invalid_void_content: /**
|
|
|
|
|
|
|
|
* @param {string} name
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (name) => ({
|
|
|
|
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`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -189,7 +229,10 @@ export default {
|
|
|
|
code: 'unclosed-comment',
|
|
|
|
code: 'unclosed-comment',
|
|
|
|
message: 'comment was left open, expected -->'
|
|
|
|
message: 'comment was left open, expected -->'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
unclosed_attribute_value: (token: string) => ({
|
|
|
|
unclosed_attribute_value: /**
|
|
|
|
|
|
|
|
* @param {string} token
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (token) => ({
|
|
|
|
code: 'unclosed-attribute-value',
|
|
|
|
code: 'unclosed-attribute-value',
|
|
|
|
message: `Expected to close the attribute value with ${token}`
|
|
|
|
message: `Expected to close the attribute value with ${token}`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -201,11 +244,17 @@ export default {
|
|
|
|
code: 'unexpected-eof',
|
|
|
|
code: 'unexpected-eof',
|
|
|
|
message: 'Unexpected end of input'
|
|
|
|
message: 'Unexpected end of input'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
unexpected_eof_token: (token: string) => ({
|
|
|
|
unexpected_eof_token: /**
|
|
|
|
|
|
|
|
* @param {string} token
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (token) => ({
|
|
|
|
code: 'unexpected-eof',
|
|
|
|
code: 'unexpected-eof',
|
|
|
|
message: `Unexpected ${token}`
|
|
|
|
message: `Unexpected ${token}`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
unexpected_token: (token: string) => ({
|
|
|
|
unexpected_token: /**
|
|
|
|
|
|
|
|
* @param {string} token
|
|
|
|
|
|
|
|
* @returns {{ code: string; message: string; }}
|
|
|
|
|
|
|
|
*/ (token) => ({
|
|
|
|
code: 'unexpected-token',
|
|
|
|
code: 'unexpected-token',
|
|
|
|
message: `Expected ${token}`
|
|
|
|
message: `Expected ${token}`
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -214,3 +263,7 @@ export default {
|
|
|
|
message: 'Expected identifier or destructure pattern'
|
|
|
|
message: 'Expected identifier or destructure pattern'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|