Skip to content

Commit 6e3c991

Browse files
committed
Add custom syntax and parser support
1 parent 2ec41ac commit 6e3c991

8 files changed

+33
-2
lines changed

index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ function AtImport(options) {
3434
})
3535

3636
return function(styles, result) {
37+
options.parser = postcss.parse
38+
if (result.opts.syntax) {
39+
options.parser = result.opts.syntax.parse
40+
}
41+
if (result.opts.parser) {
42+
options.parser = result.opts.parser
43+
}
44+
if (options.parser.parse) {
45+
options.parser = options.parser.parse
46+
}
47+
3748
var state = {
3849
importedFiles: {},
3950
hashFiles: {},
@@ -252,7 +263,8 @@ function readImportedContent(
252263
return
253264
}
254265

255-
var newStyles = postcss.parse(fileContent, options)
266+
var newStyles = options.parser(fileContent, options)
267+
256268
if (options.skipDuplicates) {
257269
var hasImport = newStyles.some(function(child) {
258270
return child.type === "atrule" && child.name === "import"

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"devDependencies": {
2727
"ava": "^0.8.0",
2828
"css-whitespace": "^1.1.1",
29-
"eslint": "^1.1.0"
29+
"eslint": "^1.1.0",
30+
"postcss-scss": "^0.1.3"
3031
},
3132
"scripts": {
3233
"lint": "eslint .",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// inline comment

test/fixtures/scss-parser.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "inline-comment.scss";
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* inline comment*/

test/fixtures/scss-syntax.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "inline-comment.scss";
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// inline comment

test/plugins.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test from "ava"
22
import postcss from "postcss"
3+
import scss from "postcss-scss"
34
import atImport from ".."
45
import compareFixtures from "./lib/compare-fixtures"
56

@@ -42,3 +43,15 @@ test("should remain silent when value is an empty array", () => {
4243
}))
4344
.process("")
4445
})
46+
47+
test("should process custom syntax", t => {
48+
return compareFixtures(t, "scss-syntax", null, {
49+
syntax: scss,
50+
})
51+
})
52+
53+
test("should process custom syntax by parser", t => {
54+
return compareFixtures(t, "scss-parser", null, {
55+
parser: scss,
56+
})
57+
})

0 commit comments

Comments
 (0)