Skip to content

Commit 77ba5e7

Browse files
authored
fix: adjust static attribute regex (#9551)
a `+` was missing Fixes sveltejs/vite-plugin-svelte#804
1 parent 36b2c50 commit 77ba5e7

File tree

5 files changed

+193
-3
lines changed

5 files changed

+193
-3
lines changed

.changeset/khaki-turkeys-hunt.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: adjust static attribute regex

packages/svelte/src/compiler/parse/state/tag.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ function get_directive_type(name) {
437437
if (name === 'in' || name === 'out' || name === 'transition') return 'Transition';
438438
}
439439

440-
const regex_attribute_value = /^(?:"([^"]*)"|'([^'])*'|([^>\s]))/;
440+
const regex_attribute_value = /^(?:"([^"]*)"|'([^'])*'|([^>\s]+))/;
441441

442442
/**
443443
* @param {import('../index.js').Parser} parser

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ function stringify_tag_attributes(attributes) {
253253
}
254254

255255
const regex_style_tags =
256-
/<!--[^]*?-->|<style((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s])|\s+[^=>'"\/]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
256+
/<!--[^]*?-->|<style((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
257257
const regex_script_tags =
258-
/<!--[^]*?-->|<script((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s])|\s+[^=>'"\/]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;
258+
/<!--[^]*?-->|<script((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;
259259

260260
/**
261261
* Calculate the updates required to process all instances of the specified tag.
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>
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)