Skip to content

Commit c3535d2

Browse files
committed
couple of fixes
1 parent 4d931ab commit c3535d2

File tree

2 files changed

+37
-26
lines changed
  • packages/svelte
    • src/compiler/phases/1-parse/state
    • tests/parser-modern/samples/snippets

2 files changed

+37
-26
lines changed

packages/svelte/src/compiler/phases/1-parse/state/tag.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ function open(parser) {
269269
e.expected_identifier(parser.index);
270270
}
271271

272+
let slice_end = parser.index;
273+
272274
parser.eat('(', true);
273275

274276
let parentheses = 1;
@@ -280,32 +282,32 @@ function open(parser) {
280282
params += parser.read(/^./);
281283
}
282284

283-
const function_expression = parse_expression_at(`function ${name}(${params}){}`, parser.ts, 0);
285+
let function_expression = /** @type {import('estree').ArrowFunctionExpression} */ (
286+
parse_expression_at(
287+
parser.template.slice(0, slice_end).replace(/\S/g, ' ') + `(${params}) => {}`,
288+
parser.ts,
289+
0
290+
)
291+
);
284292

285293
parser.index += 2;
286294

287-
if (function_expression.type === 'FunctionExpression') {
288-
/** @type {ReturnType<typeof parser.append<import('#compiler').SnippetBlock>>} */
289-
const block = parser.append({
290-
type: 'SnippetBlock',
291-
start,
292-
end: -1,
293-
expression: {
294-
type: 'Identifier',
295-
start: name_start,
296-
end: name_end,
297-
name
298-
},
299-
parameters: function_expression.params.map((param) => {
300-
param.start += start + 1;
301-
param.end += start + 1;
302-
return param;
303-
}),
304-
body: create_fragment()
305-
});
306-
parser.stack.push(block);
307-
parser.fragments.push(block.body);
308-
}
295+
/** @type {ReturnType<typeof parser.append<import('#compiler').SnippetBlock>>} */
296+
const block = parser.append({
297+
type: 'SnippetBlock',
298+
start,
299+
end: -1,
300+
expression: {
301+
type: 'Identifier',
302+
start: name_start,
303+
end: name_end,
304+
name
305+
},
306+
parameters: function_expression.params,
307+
body: create_fragment()
308+
});
309+
parser.stack.push(block);
310+
parser.fragments.push(block.body);
309311

310312
return;
311313
}

packages/svelte/tests/parser-modern/samples/snippets/output.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,29 @@
3232
"loc": {
3333
"start": {
3434
"line": 3,
35-
"column": 14,
36-
"character": 43
35+
"column": 14
3736
},
3837
"end": {
3938
"line": 3,
4039
"column": 25,
4140
"character": 54
4241
}
4342
},
44-
"end": 54,
43+
"end": 46,
4544
"typeAnnotation": {
4645
"type": "TSTypeAnnotation",
4746
"start": 46,
4847
"end": 54,
48+
"loc": {
49+
"start": {
50+
"line": 3,
51+
"column": 17
52+
},
53+
"end": {
54+
"line": 3,
55+
"column": 25
56+
}
57+
},
4958
"typeAnnotation": {
5059
"type": "TSStringKeyword",
5160
"start": 48,

0 commit comments

Comments
 (0)