From 24880201031e892170e3e70adc1899765a1ff935 Mon Sep 17 00:00:00 2001 From: Efremov Alexey Date: Fri, 1 May 2020 18:18:16 +0300 Subject: [PATCH 1/2] Write fail test --- package.json | 1 + test/sass.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/sass.js diff --git a/package.json b/package.json index 0fe7e63..3459961 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "postcss-less": "^3.1.0", "postcss-markdown": ">=0.36.0", "postcss-safe-parser": "^4.0.1", + "postcss-sass": "^0.4.4", "postcss-scss": "^2.0.0", "proxyquire": "^2.1.0", "sugarss": "^2.0.0" diff --git a/test/sass.js b/test/sass.js new file mode 100644 index 0000000..557f171 --- /dev/null +++ b/test/sass.js @@ -0,0 +1,29 @@ +"use strict"; +const postcss = require("postcss"); +const expect = require("chai").expect; +const syntax = require("../")({ + css: "sass", +}); + +describe("sass", () => { + it("test", () => { + const sass = ` + $sizes: 40px, 50px, 80px + @each $size in $sizes + .icon-#{$size} + font-size: $size + `.trim(); + return postcss([ + function (root) { + root.nodes.forEach(node => { + node.toString(); + }); + } + ]).process(sass, { + syntax, + from: 'style.sass', + }).then(result => { + expect(result.css).to.equal(sass); + }); + }); +}) From 08e6839f00922266142e0ebdffe72a35ed64a4a6 Mon Sep 17 00:00:00 2001 From: Efremov Alexey Date: Fri, 1 May 2020 18:19:32 +0300 Subject: [PATCH 2/2] Fix sass.js test --- patch-postcss.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/patch-postcss.js b/patch-postcss.js index 0018f69..3150b9c 100644 --- a/patch-postcss.js +++ b/patch-postcss.js @@ -35,7 +35,14 @@ function patchNode (Node) { Node = Node.prototype; const NodeToString = Node.toString; Node.toString = function toString (stringifier) { - return NodeToString.call(this, stringifier || this.root().source.syntax); + let arg = stringifier; + if (!arg) { + const source = this.root().source; + if (source) { + arg = source.syntax; + } + } + return NodeToString.call(this, arg); }; }