Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 1986b22

Browse files
committed
fix: sass indentedSyntax and add tests for indentedSyntax
1 parent e6aa6ef commit 1986b22

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const sass = require('node-sass');
2-
const path = require('path');
2+
const stripIndent = require('strip-indent');
33

44
module.exports = (css, settings) => {
55
const cssWithPlaceholders = css
@@ -12,7 +12,10 @@ module.exports = (css, settings) => {
1212

1313
// Prepend option data to cssWithPlaceholders
1414
const optionData = settings.sassOptions && settings.sassOptions.data || "";
15-
const data = optionData + "\n" + cssWithPlaceholders;
15+
let data = optionData + "\n" + cssWithPlaceholders;
16+
17+
// clean up extra indent if we are using indentedSyntax
18+
if(settings.sassOptions && settings.sassOptions.indentedSyntax) data = stripIndent(data);
1619

1720
const preprocessed = sass.renderSync(
1821
Object.assign(

test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,38 @@ describe('styled-jsx-plugin-sass', () => {
150150
`)
151151
)
152152
})
153+
154+
it('works with indentedSyntax', () => {
155+
assert.equal(
156+
plugin('body\n\tdisplay: block\n\tmargin: 0', {
157+
sassOptions: {
158+
indentedSyntax: true
159+
}
160+
}).trim(),
161+
cleanup(`
162+
body {
163+
display: block;
164+
margin: 0; }
165+
`)
166+
)
167+
})
168+
169+
it('cleans up extra indent with indentedSyntax', () => {
170+
assert.equal(
171+
plugin(`
172+
body
173+
display: block
174+
margin: 0
175+
`, {
176+
sassOptions: {
177+
indentedSyntax: true
178+
}
179+
}).trim(),
180+
cleanup(`
181+
body {
182+
display: block;
183+
margin: 0; }
184+
`)
185+
)
186+
})
153187
})

0 commit comments

Comments
 (0)