Skip to content

Commit

Permalink
fix: Correct replacements of css.<key> values (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
tivac committed Jun 22, 2018
1 parent f413732 commit b4de308
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 67 deletions.
4 changes: 2 additions & 2 deletions packages/svelte/src/markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ function updateCss({ content, result }) {
code : content
// Replace simple {css.<key>} values first
.replace(
new RegExp(`{css.(${Object.keys(exported).join("|")})}`, "gm"),
new RegExp(`{css\\.(${Object.keys(exported).join("|")})}`, "gm"),
(match, key) => exported[key].join(" ")
)
// Then any remaining bare css.<key> values
.replace(
new RegExp(`(\\b)css.(${Object.keys(exported).join("|")})(\\b)`, "gm"),
new RegExp(`(\\b)css\\.(${Object.keys(exported).join("|")})(\\b)`, "gm"),
(match, prefix, key, suffix) => `${prefix}"${exported[key].join(" ")}"${suffix}`
)
};
Expand Down
63 changes: 0 additions & 63 deletions packages/svelte/src/methods.js

This file was deleted.

10 changes: 9 additions & 1 deletion packages/svelte/test/__snapshots__/svelte.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ exports[`/svelte.js should extract CSS from a <link> tag (existing script) 1`] =
export default {
data : () => ({
bool : true
})
}),
oncreate() {
const bd = {
flex : \\"flex\\"
};
const style = css[bd.flex];
}
};</script>
"
`;
Expand Down
10 changes: 9 additions & 1 deletion packages/svelte/test/specimens/external-script.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ <h1 class="{css.hd}">Head</h1>
export default {
data : () => ({
bool : true
})
}),

oncreate() {
const bd = {
flex : "flex"
};

const style = css[bd.flex];
}
};
</script>

0 comments on commit b4de308

Please sign in to comment.