Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace multiple missing values #576

Merged
merged 2 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/svelte/svelte.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = (config = false) => {
if(!missed) {
return source;
}

const { strict } = processor.options;

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

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

if(style) {
log("extract <style>", html);

css = "<style>";

if(processor.has(html)) {
processor.invalidate(html);
}

result = await processor.string(
html,
style[1]
Expand Down Expand Up @@ -194,7 +194,7 @@ module.exports = (config = false) => {
new RegExp(`(\\b)css\\.(${selectors})(\\b)`, "gm"),
(match, prefix, key, suffix) => {
const replacement = Array.isArray(exported[key]) ? exported[key].join(" ") : exported[key];

return `${prefix}"${replacement}"${suffix}`;
}
);
Expand Down
28 changes: 22 additions & 6 deletions packages/svelte/test/__snapshots__/svelte.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ Array [
exports[`/svelte.js should handle errors: empty css file - <link> 3`] = `
"
<div class=\\"{\\"css.nope\\"}\\">NOPE</div>
<div class=\\"{css.alsonope}\\">STILL NOPE</div>
<div class=\\"{\\"css.alsonope\\"}\\">STILL NOPE</div>
"
`;

Expand All @@ -273,19 +273,22 @@ Array [

exports[`/svelte.js should handle errors: empty css file - <style> 3`] = `
"<div class=\\"{\\"css.nope\\"}\\">NOPE</div>
<div class=\\"{css.alsonope}\\">STILL NOPE</div>
<div class=\\"{\\"css.alsonope\\"}\\">STILL NOPE</div>

<style>/* replaced by modular-css */</style>
"
`;

exports[`/svelte.js should handle errors: invalid reference <script> - <link> 1`] = `"@modular-css/svelte: Unable to find .nuhuh in \\"./invalid.css\\""`;
exports[`/svelte.js should handle errors: invalid reference <script> - <link> 1`] = `"@modular-css/svelte: Unable to find .nuhuh, .alsono in \\"./invalid.css\\""`;

exports[`/svelte.js should handle errors: invalid reference <script> - <link> 2`] = `
Array [
Array [
"@modular-css/svelte: Unable to find .nuhuh in \\"./invalid.css\\"",
],
Array [
"@modular-css/svelte: Unable to find .alsono in \\"./invalid.css\\"",
],
]
`;

Expand All @@ -298,17 +301,21 @@ import css from \\"./invalid.css\\";


console.log(\\"css.nuhuh\\");
console.log(\\"css.alsono\\");
</script>
"
`;

exports[`/svelte.js should handle errors: invalid reference <script> - <style> 1`] = `"@modular-css/svelte: Unable to find .nuhuh in \\"<style>\\""`;
exports[`/svelte.js should handle errors: invalid reference <script> - <style> 1`] = `"@modular-css/svelte: Unable to find .nuhuh, .alsono in \\"<style>\\""`;

exports[`/svelte.js should handle errors: invalid reference <script> - <style> 2`] = `
Array [
Array [
"@modular-css/svelte: Unable to find .nuhuh in \\"<style>\\"",
],
Array [
"@modular-css/svelte: Unable to find .alsono in \\"<style>\\"",
],
]
`;

Expand All @@ -319,40 +326,49 @@ exports[`/svelte.js should handle errors: invalid reference <script> - <style> 3

<script>
console.log(\\"css.nuhuh\\");
console.log(\\"css.alsono\\");
</script>
"
`;

exports[`/svelte.js should handle errors: invalid reference template - <link> 1`] = `"@modular-css/svelte: Unable to find .nope in \\"./invalid.css\\""`;
exports[`/svelte.js should handle errors: invalid reference template - <link> 1`] = `"@modular-css/svelte: Unable to find .nope, .stillnope in \\"./invalid.css\\""`;

exports[`/svelte.js should handle errors: invalid reference template - <link> 2`] = `
Array [
Array [
"@modular-css/svelte: Unable to find .nope in \\"./invalid.css\\"",
],
Array [
"@modular-css/svelte: Unable to find .stillnope in \\"./invalid.css\\"",
],
]
`;

exports[`/svelte.js should handle errors: invalid reference template - <link> 3`] = `
"
<h1 class=\\"{\\"css.nope\\"}\\">Nope</h1>
<h2 class=\\"yup\\">Yup</h2>
<h3 class=\\"{\\"css.stillnope\\"}\\">Still Nope</h3>
"
`;

exports[`/svelte.js should handle errors: invalid reference template - <style> 1`] = `"@modular-css/svelte: Unable to find .nope in \\"<style>\\""`;
exports[`/svelte.js should handle errors: invalid reference template - <style> 1`] = `"@modular-css/svelte: Unable to find .nope, .alsonope in \\"<style>\\""`;

exports[`/svelte.js should handle errors: invalid reference template - <style> 2`] = `
Array [
Array [
"@modular-css/svelte: Unable to find .nope in \\"<style>\\"",
],
Array [
"@modular-css/svelte: Unable to find .alsonope in \\"<style>\\"",
],
]
`;

exports[`/svelte.js should handle errors: invalid reference template - <style> 3`] = `
"<h1 class=\\"{\\"css.nope\\"}\\">Nope</h1>
<h2 class=\\"yup\\">Yup</h2>
<h3 class=\\"{\\"css.alsonope\\"}\\">Also Nope</h3>

<style>/* replaced by modular-css */</style>
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ <h2 class="{css.yup}">Yup</h2>

<script>
console.log(css.nuhuh);
console.log(css.alsono);
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

<h1 class="{css.nope}">Nope</h1>
<h2 class="{css.yup}">Yup</h2>
<h3 class="{css.stillnope}">Still Nope</h3>
1 change: 1 addition & 0 deletions packages/svelte/test/specimens/invalid-inline-script.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ <h2 class="{css.yup}">Yup</h2>

<script>
console.log(css.nuhuh);
console.log(css.alsono);
</script>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<h1 class="{css.nope}">Nope</h1>
<h2 class="{css.yup}">Yup</h2>
<h3 class="{css.alsonope}">Also Nope</h3>

<style>
.yup { color: red; }
Expand Down