Skip to content

fix: allow whitespace before an after snippet parameters #12159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions packages/svelte/src/compiler/phases/1-parse/read/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions packages/svelte/src/compiler/phases/1-parse/state/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ function open(parser) {
e.expected_identifier(parser.index);
}

parser.allow_whitespace();

const params_start = parser.index;

parser.eat('(', true);
Expand All @@ -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>>} */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- prettier-ignore -->
{#snippet ok () }
asd
{/snippet}
Loading