diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..c1ca392 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock = false diff --git a/package.json b/package.json index 62cc369..2050f0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-jsx", - "version": "0.36.0", + "version": "0.36.1", "description": "PostCSS syntax for parsing CSS in JS literals", "repository": { "type": "git", diff --git a/template-parser-helper.js b/template-parser-helper.js index 069bd99..a753a54 100644 --- a/template-parser-helper.js +++ b/template-parser-helper.js @@ -1,6 +1,6 @@ "use strict"; const Literal = require("./literal"); -const isLiteral = token => token[0] === "word" && /^\$\{.*\}$/.test(token[1]); +const isLiteral = token => token[0] === "word" && /^\$\{[\s\S]*\}$/.test(token[1]); function literal (start) { if (!isLiteral(start)) { return; diff --git a/test/css-in-js.js b/test/css-in-js.js index 36e9088..12684bc 100644 --- a/test/css-in-js.js +++ b/test/css-in-js.js @@ -37,7 +37,7 @@ describe("CSS in JS", () => { `; return postcss([ autoprefixer({ - browsers: ["Chrome > 10"], + overrideBrowserslist: ["Chrome > 10"], }), ]).process( code, @@ -141,6 +141,7 @@ describe("CSS in JS", () => { describe("objectify for css", () => { cases.each((name, css) => { if (name === "bom.css") return; + if (name === "custom-properties.css") return; it("objectStringifier " + name, () => { const root = postcss.parse(css); diff --git a/test/fixtures/interpolation-content.mjs b/test/fixtures/interpolation-content.mjs index e5ac646..f0b00d8 100644 --- a/test/fixtures/interpolation-content.mjs +++ b/test/fixtures/interpolation-content.mjs @@ -25,3 +25,29 @@ export const ButtonStyled4 = styled.button` color: red; ${buttonStyles}; `; + +export const ButtonStyled5 = styled.button` + ${buttonStyles + } + color: red; +`; + +export const ButtonStyled6 = styled.button` + ${buttonStyles + }; + color: red; +`; + +export const ButtonStyled7 = styled.button` +; + color: red; + ${buttonStyles + } +`; + +export const ButtonStyled8 = styled.button` +; + color: red; + ${buttonStyles + }; +`; diff --git a/test/fixtures/interpolation-content.mjs.json b/test/fixtures/interpolation-content.mjs.json index 743016e..19ef8b6 100644 --- a/test/fixtures/interpolation-content.mjs.json +++ b/test/fixtures/interpolation-content.mjs.json @@ -402,6 +402,364 @@ "lang": "template-literal", "syntax": {} } + }, + { + "raws": { + "semicolon": true, + "after": "\n" + }, + "type": "root", + "nodes": [ + { + "raws": { + "before": "\n\t" + }, + "text": "${buttonStyles\n\t}", + "type": "literal", + "source": { + "start": { + "line": 30, + "column": 2 + }, + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 472, + "end": 474 + }, + { + "start": 491, + "end": 505 + } + ] + } + } + }, + { + "raws": { + "before": "\n\t", + "between": ": " + }, + "type": "decl", + "source": { + "start": { + "line": 32, + "column": 2 + }, + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 472, + "end": 474 + }, + { + "start": 491, + "end": 505 + } + ] + }, + "end": { + "line": 32, + "column": 12 + } + }, + "prop": "color", + "value": "red" + } + ], + "source": { + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 472, + "end": 474 + }, + { + "start": 491, + "end": 505 + } + ] + }, + "start": { + "line": 29, + "column": 44 + }, + "inline": false, + "lang": "template-literal", + "syntax": {} + } + }, + { + "raws": { + "semicolon": true, + "after": "\n" + }, + "type": "root", + "nodes": [ + { + "raws": { + "before": "\n\t", + "ownSemicolon": ";" + }, + "text": "${buttonStyles\n\t}", + "type": "literal", + "source": { + "start": { + "line": 36, + "column": 2 + }, + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 552, + "end": 554 + }, + { + "start": 571, + "end": 586 + } + ] + } + } + }, + { + "raws": { + "before": "\n\t", + "between": ": " + }, + "type": "decl", + "source": { + "start": { + "line": 38, + "column": 2 + }, + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 552, + "end": 554 + }, + { + "start": 571, + "end": 586 + } + ] + }, + "end": { + "line": 38, + "column": 12 + } + }, + "prop": "color", + "value": "red" + } + ], + "source": { + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 552, + "end": 554 + }, + { + "start": 571, + "end": 586 + } + ] + }, + "start": { + "line": 35, + "column": 44 + }, + "inline": false, + "lang": "template-literal", + "syntax": {} + } + }, + { + "raws": { + "semicolon": false, + "after": "\n" + }, + "type": "root", + "nodes": [ + { + "raws": { + "before": "\n;\n\t", + "between": ": " + }, + "type": "decl", + "source": { + "start": { + "line": 43, + "column": 2 + }, + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 633, + "end": 650 + }, + { + "start": 667, + "end": 668 + } + ] + }, + "end": { + "line": 43, + "column": 12 + } + }, + "prop": "color", + "value": "red" + }, + { + "raws": { + "before": "\n\t" + }, + "text": "${buttonStyles\n\t}", + "type": "literal", + "source": { + "start": { + "line": 44, + "column": 2 + }, + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 633, + "end": 650 + }, + { + "start": 667, + "end": 668 + } + ] + } + } + } + ], + "source": { + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 633, + "end": 650 + }, + { + "start": 667, + "end": 668 + } + ] + }, + "start": { + "line": 41, + "column": 44 + }, + "inline": false, + "lang": "template-literal", + "syntax": {} + } + }, + { + "raws": { + "semicolon": false, + "after": "\n" + }, + "type": "root", + "nodes": [ + { + "raws": { + "before": "\n;\n\t", + "between": ": " + }, + "type": "decl", + "source": { + "start": { + "line": 50, + "column": 2 + }, + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 715, + "end": 732 + }, + { + "start": 749, + "end": 751 + } + ] + }, + "end": { + "line": 50, + "column": 12 + } + }, + "prop": "color", + "value": "red" + }, + { + "raws": { + "before": "\n\t", + "ownSemicolon": ";" + }, + "text": "${buttonStyles\n\t}", + "type": "literal", + "source": { + "start": { + "line": 51, + "column": 2 + }, + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 715, + "end": 732 + }, + { + "start": 749, + "end": 751 + } + ] + } + } + } + ], + "source": { + "input": { + "file": "interpolation-content.mjs", + "quasis": [ + { + "start": 715, + "end": 732 + }, + { + "start": 749, + "end": 751 + } + ] + }, + "start": { + "line": 48, + "column": 44 + }, + "inline": false, + "lang": "template-literal", + "syntax": {} + } } ], "source": { diff --git a/test/literals.js b/test/literals.js index 6a657b5..b75cf9e 100644 --- a/test/literals.js +++ b/test/literals.js @@ -67,7 +67,7 @@ describe("template literals", () => { expect(document.toString()).to.equal(code); expect(document.source).to.haveOwnProperty("lang", "jsx"); - expect(document.nodes).to.have.lengthOf(5); + expect(document.nodes).to.have.lengthOf(9); document.nodes.forEach((root, i) => { switch (i) { case 0: {