diff --git a/packages/svelte/src/compiler/phases/1-parse/read/context.js b/packages/svelte/src/compiler/phases/1-parse/read/context.js index 1188fb8eb4..0ae8eab512 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/context.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/context.js @@ -14,17 +14,16 @@ import { locator } from '../../../state.js'; /** * @param {import('../index.js').Parser} parser - * @param {boolean} [optional_allowed] * @returns {import('estree').Pattern} */ -export default function read_pattern(parser, optional_allowed = false) { +export default function read_pattern(parser) { const start = parser.index; let i = parser.index; const code = full_char_code_at(parser.template, i); if (isIdentifierStart(code, true)) { const name = /** @type {string} */ (parser.read_identifier()); - const annotation = read_type_annotation(parser, optional_allowed); + const annotation = read_type_annotation(parser); return { type: 'Identifier', @@ -84,7 +83,7 @@ export default function read_pattern(parser, optional_allowed = false) { parse_expression_at(`${space_with_newline}(${pattern_string} = 1)`, parser.ts, start - 1) ).left; - expression.typeAnnotation = read_type_annotation(parser, optional_allowed); + expression.typeAnnotation = read_type_annotation(parser); if (expression.typeAnnotation) { expression.end = expression.typeAnnotation.end; } @@ -97,19 +96,12 @@ export default function read_pattern(parser, optional_allowed = false) { /** * @param {import('../index.js').Parser} parser - * @param {boolean} [optional_allowed] * @returns {any} */ -function read_type_annotation(parser, optional_allowed = false) { +function read_type_annotation(parser) { const start = parser.index; parser.allow_whitespace(); - if (optional_allowed && parser.eat('?')) { - // Acorn-TS puts the optional info as a property on the surrounding node. - // We spare the work here because it doesn't matter for us anywhere else. - parser.allow_whitespace(); - } - if (!parser.eat(':')) { parser.index = start; return undefined; diff --git a/packages/svelte/src/compiler/phases/1-parse/state/tag.js b/packages/svelte/src/compiler/phases/1-parse/state/tag.js index 762dab69bb..0dc7b9709e 100644 --- a/packages/svelte/src/compiler/phases/1-parse/state/tag.js +++ b/packages/svelte/src/compiler/phases/1-parse/state/tag.js @@ -269,6 +269,8 @@ function open(parser) { e.expected_identifier(parser.index); } + parser.allow_whitespace(); + const params_start = parser.index; parser.eat('(', true); @@ -289,6 +291,7 @@ function open(parser) { parse_expression_at(prelude + `${params} => {}`, parser.ts, params_start) ); + parser.allow_whitespace(); parser.eat('}', true); /** @type {ReturnType>} */ diff --git a/packages/svelte/tests/validator/samples/snippet-whitespace-ok/errors.json b/packages/svelte/tests/validator/samples/snippet-whitespace-ok/errors.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/packages/svelte/tests/validator/samples/snippet-whitespace-ok/errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/svelte/tests/validator/samples/snippet-whitespace-ok/input.svelte b/packages/svelte/tests/validator/samples/snippet-whitespace-ok/input.svelte new file mode 100644 index 0000000000..60174d3d56 --- /dev/null +++ b/packages/svelte/tests/validator/samples/snippet-whitespace-ok/input.svelte @@ -0,0 +1,4 @@ + +{#snippet ok () } + asd +{/snippet}