Skip to content

Commit d48ac67

Browse files
authored
fix: replace multiple missing values (#576)
* test: failing specimens & snapshot for #575 * fix: add g flag to missing key regex Fixes #575
1 parent 0fc5403 commit d48ac67

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

packages/svelte/svelte.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = (config = false) => {
2929
if(!missed) {
3030
return source;
3131
}
32-
32+
3333
const { strict } = processor.options;
3434

3535
const classes = missed.map((reference) => reference.replace("css.", ""));
@@ -45,7 +45,7 @@ module.exports = (config = false) => {
4545

4646
// Turn all missing values into strings so nothing explodes
4747
return source.replace(
48-
new RegExp(`(${missed.map((ref) => escape(ref)).join("|")})`),
48+
new RegExp(`(${missed.map((ref) => escape(ref)).join("|")})`, "g"),
4949
(match) => JSON.stringify(match)
5050
);
5151
};
@@ -82,13 +82,13 @@ module.exports = (config = false) => {
8282

8383
if(style) {
8484
log("extract <style>", html);
85-
85+
8686
css = "<style>";
87-
87+
8888
if(processor.has(html)) {
8989
processor.invalidate(html);
9090
}
91-
91+
9292
result = await processor.string(
9393
html,
9494
style[1]
@@ -194,7 +194,7 @@ module.exports = (config = false) => {
194194
new RegExp(`(\\b)css\\.(${selectors})(\\b)`, "gm"),
195195
(match, prefix, key, suffix) => {
196196
const replacement = Array.isArray(exported[key]) ? exported[key].join(" ") : exported[key];
197-
197+
198198
return `${prefix}"${replacement}"${suffix}`;
199199
}
200200
);

packages/svelte/test/__snapshots__/svelte.test.js.snap

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ Array [
254254
exports[`/svelte.js should handle errors: empty css file - <link> 3`] = `
255255
"
256256
<div class=\\"{\\"css.nope\\"}\\">NOPE</div>
257-
<div class=\\"{css.alsonope}\\">STILL NOPE</div>
257+
<div class=\\"{\\"css.alsonope\\"}\\">STILL NOPE</div>
258258
"
259259
`;
260260
@@ -273,19 +273,22 @@ Array [
273273
274274
exports[`/svelte.js should handle errors: empty css file - <style> 3`] = `
275275
"<div class=\\"{\\"css.nope\\"}\\">NOPE</div>
276-
<div class=\\"{css.alsonope}\\">STILL NOPE</div>
276+
<div class=\\"{\\"css.alsonope\\"}\\">STILL NOPE</div>
277277
278278
<style>/* replaced by modular-css */</style>
279279
"
280280
`;
281281
282-
exports[`/svelte.js should handle errors: invalid reference <script> - <link> 1`] = `"@modular-css/svelte: Unable to find .nuhuh in \\"./invalid.css\\""`;
282+
exports[`/svelte.js should handle errors: invalid reference <script> - <link> 1`] = `"@modular-css/svelte: Unable to find .nuhuh, .alsono in \\"./invalid.css\\""`;
283283
284284
exports[`/svelte.js should handle errors: invalid reference <script> - <link> 2`] = `
285285
Array [
286286
Array [
287287
"@modular-css/svelte: Unable to find .nuhuh in \\"./invalid.css\\"",
288288
],
289+
Array [
290+
"@modular-css/svelte: Unable to find .alsono in \\"./invalid.css\\"",
291+
],
289292
]
290293
`;
291294
@@ -298,17 +301,21 @@ import css from \\"./invalid.css\\";
298301
299302
300303
console.log(\\"css.nuhuh\\");
304+
console.log(\\"css.alsono\\");
301305
</script>
302306
"
303307
`;
304308
305-
exports[`/svelte.js should handle errors: invalid reference <script> - <style> 1`] = `"@modular-css/svelte: Unable to find .nuhuh in \\"<style>\\""`;
309+
exports[`/svelte.js should handle errors: invalid reference <script> - <style> 1`] = `"@modular-css/svelte: Unable to find .nuhuh, .alsono in \\"<style>\\""`;
306310
307311
exports[`/svelte.js should handle errors: invalid reference <script> - <style> 2`] = `
308312
Array [
309313
Array [
310314
"@modular-css/svelte: Unable to find .nuhuh in \\"<style>\\"",
311315
],
316+
Array [
317+
"@modular-css/svelte: Unable to find .alsono in \\"<style>\\"",
318+
],
312319
]
313320
`;
314321
@@ -319,40 +326,49 @@ exports[`/svelte.js should handle errors: invalid reference <script> - <style> 3
319326
320327
<script>
321328
console.log(\\"css.nuhuh\\");
329+
console.log(\\"css.alsono\\");
322330
</script>
323331
"
324332
`;
325333
326-
exports[`/svelte.js should handle errors: invalid reference template - <link> 1`] = `"@modular-css/svelte: Unable to find .nope in \\"./invalid.css\\""`;
334+
exports[`/svelte.js should handle errors: invalid reference template - <link> 1`] = `"@modular-css/svelte: Unable to find .nope, .stillnope in \\"./invalid.css\\""`;
327335
328336
exports[`/svelte.js should handle errors: invalid reference template - <link> 2`] = `
329337
Array [
330338
Array [
331339
"@modular-css/svelte: Unable to find .nope in \\"./invalid.css\\"",
332340
],
341+
Array [
342+
"@modular-css/svelte: Unable to find .stillnope in \\"./invalid.css\\"",
343+
],
333344
]
334345
`;
335346
336347
exports[`/svelte.js should handle errors: invalid reference template - <link> 3`] = `
337348
"
338349
<h1 class=\\"{\\"css.nope\\"}\\">Nope</h1>
339350
<h2 class=\\"yup\\">Yup</h2>
351+
<h3 class=\\"{\\"css.stillnope\\"}\\">Still Nope</h3>
340352
"
341353
`;
342354
343-
exports[`/svelte.js should handle errors: invalid reference template - <style> 1`] = `"@modular-css/svelte: Unable to find .nope in \\"<style>\\""`;
355+
exports[`/svelte.js should handle errors: invalid reference template - <style> 1`] = `"@modular-css/svelte: Unable to find .nope, .alsonope in \\"<style>\\""`;
344356
345357
exports[`/svelte.js should handle errors: invalid reference template - <style> 2`] = `
346358
Array [
347359
Array [
348360
"@modular-css/svelte: Unable to find .nope in \\"<style>\\"",
349361
],
362+
Array [
363+
"@modular-css/svelte: Unable to find .alsonope in \\"<style>\\"",
364+
],
350365
]
351366
`;
352367
353368
exports[`/svelte.js should handle errors: invalid reference template - <style> 3`] = `
354369
"<h1 class=\\"{\\"css.nope\\"}\\">Nope</h1>
355370
<h2 class=\\"yup\\">Yup</h2>
371+
<h3 class=\\"{\\"css.alsonope\\"}\\">Also Nope</h3>
356372
357373
<style>/* replaced by modular-css */</style>
358374
"

packages/svelte/test/specimens/invalid-external-script.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ <h2 class="{css.yup}">Yup</h2>
44

55
<script>
66
console.log(css.nuhuh);
7+
console.log(css.alsono);
78
</script>

packages/svelte/test/specimens/invalid-external-template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
<h1 class="{css.nope}">Nope</h1>
44
<h2 class="{css.yup}">Yup</h2>
5+
<h3 class="{css.stillnope}">Still Nope</h3>

packages/svelte/test/specimens/invalid-inline-script.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ <h2 class="{css.yup}">Yup</h2>
66

77
<script>
88
console.log(css.nuhuh);
9+
console.log(css.alsono);
910
</script>

packages/svelte/test/specimens/invalid-inline-template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<h1 class="{css.nope}">Nope</h1>
22
<h2 class="{css.yup}">Yup</h2>
3+
<h3 class="{css.alsonope}">Also Nope</h3>
34

45
<style>
56
.yup { color: red; }

0 commit comments

Comments
 (0)