File tree Expand file tree Collapse file tree 4 files changed +91
-1
lines changed
src/compiler/phases/1-parse/read Expand file tree Collapse file tree 4 files changed +91
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: allow trailing comments on functions
Original file line number Diff line number Diff line change @@ -18,7 +18,12 @@ export default function read_expression(parser) {
18
18
19
19
let index = /** @type {number } */ ( node . end ) ;
20
20
if ( node . trailingComments !== undefined && node . trailingComments . length > 0 ) {
21
- index = node . trailingComments . at ( - 1 ) . end ;
21
+ // in simple expressions like {true/*this is literal*/} trailing comments are not included
22
+ // in the node end so we need them added to the index to keep the parser in check.
23
+ // but for arrow functions trailing comments are actually already included in the end
24
+ // and doesn't include whitespace in the end so if we set the parse index to that we
25
+ // will loose chars that we already read.
26
+ index = Math . max ( node . trailingComments . at ( - 1 ) . end , index ) ;
22
27
}
23
28
24
29
while ( num_parens > 0 ) {
Original file line number Diff line number Diff line change
1
+ <button
2
+ onclick ={() => {
3
+ /* some comment */
4
+ }}
5
+ ></button >
Original file line number Diff line number Diff line change
1
+ {
2
+ "html" : {
3
+ "type" : " Fragment" ,
4
+ "start" : 0 ,
5
+ "end" : 61 ,
6
+ "children" : [
7
+ {
8
+ "type" : " Element" ,
9
+ "start" : 0 ,
10
+ "end" : 61 ,
11
+ "name" : " button" ,
12
+ "attributes" : [
13
+ {
14
+ "type" : " Attribute" ,
15
+ "start" : 9 ,
16
+ "end" : 50 ,
17
+ "name" : " onclick" ,
18
+ "value" : [
19
+ {
20
+ "type" : " MustacheTag" ,
21
+ "start" : 17 ,
22
+ "end" : 50 ,
23
+ "expression" : {
24
+ "type" : " ArrowFunctionExpression" ,
25
+ "start" : 18 ,
26
+ "end" : 49 ,
27
+ "loc" : {
28
+ "start" : {
29
+ "line" : 2 ,
30
+ "column" : 10
31
+ },
32
+ "end" : {
33
+ "line" : 4 ,
34
+ "column" : 2
35
+ }
36
+ },
37
+ "id" : null ,
38
+ "expression" : false ,
39
+ "generator" : false ,
40
+ "async" : false ,
41
+ "params" : [],
42
+ "body" : {
43
+ "type" : " BlockStatement" ,
44
+ "start" : 24 ,
45
+ "end" : 49 ,
46
+ "loc" : {
47
+ "start" : {
48
+ "line" : 2 ,
49
+ "column" : 16
50
+ },
51
+ "end" : {
52
+ "line" : 4 ,
53
+ "column" : 2
54
+ }
55
+ },
56
+ "body" : []
57
+ },
58
+ "trailingComments" : [
59
+ {
60
+ "type" : " Block" ,
61
+ "value" : " some comment " ,
62
+ "start" : 28 ,
63
+ "end" : 46
64
+ }
65
+ ]
66
+ }
67
+ }
68
+ ]
69
+ }
70
+ ],
71
+ "children" : []
72
+ }
73
+ ]
74
+ }
75
+ }
You can’t perform that action at this time.
0 commit comments