0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-11-24 16:29:46 +01:00

fix: allow whitespace before an after snippet parameters (#12159)

fixes #12156
Also remove obsolete code
This commit is contained in:
Simon H 2024-06-24 12:22:27 +02:00 committed by GitHub
parent 15246dc612
commit 67422c4334
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 12 deletions

View File

@ -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;

View File

@ -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<typeof parser.append<import('#compiler').SnippetBlock>>} */

View File

@ -0,0 +1,4 @@
<!-- prettier-ignore -->
{#snippet ok () }
asd
{/snippet}