Skip to content

Commit 9926347

Browse files
authored
fix: adjust static attribute regex (#9552)
Svelte 5 version of #9551
1 parent 550cecf commit 9926347

File tree

4 files changed

+188
-3
lines changed

4 files changed

+188
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ function read_tag_name(parser) {
382382
// eslint-disable-next-line no-useless-escape
383383
const regex_token_ending_character = /[\s=\/>"']/;
384384
const regex_starts_with_quote_characters = /^["']/;
385-
const regex_attribute_value = /^(?:"([^"]*)"|'([^'])*'|([^>\s]))/;
385+
const regex_attribute_value = /^(?:"([^"]*)"|'([^'])*'|([^>\s]+))/;
386386

387387
/**
388388
* @param {import('../index.js').Parser} parser

packages/svelte/src/compiler/preprocess/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ function stringify_tag_attributes(attributes) {
254254
}
255255

256256
const regex_style_tags =
257-
/<!--[^]*?-->|<style((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s])|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
257+
/<!--[^]*?-->|<style((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
258258
const regex_script_tags =
259-
/<!--[^]*?-->|<script((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s])|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;
259+
/<!--[^]*?-->|<script((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;
260260

261261
/**
262262
* Calculate the updates required to process all instances of the specified tag.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script context=module>
2+
export const foo = 'bar';
3+
</script>
4+
5+
<script>
6+
foo;
7+
</script>
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
{
2+
"html": {
3+
"start": 62,
4+
"end": 60,
5+
"type": "Fragment",
6+
"children": [
7+
{
8+
"start": 60,
9+
"end": 62,
10+
"type": "Text",
11+
"raw": "\n\n",
12+
"data": "\n\n"
13+
}
14+
]
15+
},
16+
"instance": {
17+
"type": "Script",
18+
"start": 62,
19+
"end": 86,
20+
"context": "default",
21+
"content": {
22+
"type": "Program",
23+
"start": 70,
24+
"end": 77,
25+
"loc": {
26+
"start": {
27+
"line": 1,
28+
"column": 0
29+
},
30+
"end": {
31+
"line": 7,
32+
"column": 0
33+
}
34+
},
35+
"body": [
36+
{
37+
"type": "ExpressionStatement",
38+
"start": 72,
39+
"end": 76,
40+
"loc": {
41+
"start": {
42+
"line": 6,
43+
"column": 1
44+
},
45+
"end": {
46+
"line": 6,
47+
"column": 5
48+
}
49+
},
50+
"expression": {
51+
"type": "Identifier",
52+
"start": 72,
53+
"end": 75,
54+
"loc": {
55+
"start": {
56+
"line": 6,
57+
"column": 1
58+
},
59+
"end": {
60+
"line": 6,
61+
"column": 4
62+
}
63+
},
64+
"name": "foo"
65+
}
66+
}
67+
],
68+
"sourceType": "module"
69+
}
70+
},
71+
"module": {
72+
"type": "Script",
73+
"start": 0,
74+
"end": 60,
75+
"context": "module",
76+
"content": {
77+
"type": "Program",
78+
"start": 23,
79+
"end": 51,
80+
"loc": {
81+
"start": {
82+
"line": 1,
83+
"column": 0
84+
},
85+
"end": {
86+
"line": 3,
87+
"column": 0
88+
}
89+
},
90+
"body": [
91+
{
92+
"type": "ExportNamedDeclaration",
93+
"start": 25,
94+
"end": 50,
95+
"loc": {
96+
"start": {
97+
"line": 2,
98+
"column": 1
99+
},
100+
"end": {
101+
"line": 2,
102+
"column": 26
103+
}
104+
},
105+
"declaration": {
106+
"type": "VariableDeclaration",
107+
"start": 32,
108+
"end": 50,
109+
"loc": {
110+
"start": {
111+
"line": 2,
112+
"column": 8
113+
},
114+
"end": {
115+
"line": 2,
116+
"column": 26
117+
}
118+
},
119+
"declarations": [
120+
{
121+
"type": "VariableDeclarator",
122+
"start": 38,
123+
"end": 49,
124+
"loc": {
125+
"start": {
126+
"line": 2,
127+
"column": 14
128+
},
129+
"end": {
130+
"line": 2,
131+
"column": 25
132+
}
133+
},
134+
"id": {
135+
"type": "Identifier",
136+
"start": 38,
137+
"end": 41,
138+
"loc": {
139+
"start": {
140+
"line": 2,
141+
"column": 14
142+
},
143+
"end": {
144+
"line": 2,
145+
"column": 17
146+
}
147+
},
148+
"name": "foo"
149+
},
150+
"init": {
151+
"type": "Literal",
152+
"start": 44,
153+
"end": 49,
154+
"loc": {
155+
"start": {
156+
"line": 2,
157+
"column": 20
158+
},
159+
"end": {
160+
"line": 2,
161+
"column": 25
162+
}
163+
},
164+
"value": "bar",
165+
"raw": "'bar'"
166+
}
167+
}
168+
],
169+
"kind": "const"
170+
},
171+
"specifiers": [],
172+
"source": null
173+
}
174+
],
175+
"sourceType": "module"
176+
}
177+
}
178+
}

0 commit comments

Comments
 (0)