diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d58883d..a0a70a11 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,10 @@ See [resolve option](https://github.com/postcss/postcss-import#resolve) for more ([#120](https://github.com/postcss/postcss-import/pull/120)) - Changed: custom resolve should include glob resolver ([#121](https://github.com/postcss/postcss-import/pull/121)) +- Added: custom syntax in imported files support +([#130](https://github.com/postcss/postcss-import/pull/130)) - Changed: glob resolver do not add `moduleDirectories` and parse all uri as glob patterns +([#131](https://github.com/postcss/postcss-import/pull/131)) # 7.1.3 - 2015-11-05 diff --git a/index.js b/index.js index fdfebc17..efbca8bb 100755 --- a/index.js +++ b/index.js @@ -34,6 +34,17 @@ function AtImport(options) { }) return function(styles, result) { + options.parser = postcss.parse + if (result.opts.syntax) { + options.parser = result.opts.syntax.parse + } + if (result.opts.parser) { + options.parser = result.opts.parser + } + if (options.parser.parse) { + options.parser = options.parser.parse + } + var state = { importedFiles: {}, hashFiles: {}, @@ -252,7 +263,8 @@ function readImportedContent( return } - var newStyles = postcss.parse(fileContent, options) + var newStyles = options.parser(fileContent, options) + if (options.skipDuplicates) { var hasImport = newStyles.some(function(child) { return child.type === "atrule" && child.name === "import" diff --git a/package.json b/package.json index 774c2485..7923d47d 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "devDependencies": { "ava": "^0.8.0", "css-whitespace": "^1.1.1", - "eslint": "^1.1.0" + "eslint": "^1.1.0", + "postcss-scss": "^0.1.3" }, "scripts": { "lint": "eslint .", diff --git a/test/fixtures/imports/inline-comment.scss b/test/fixtures/imports/inline-comment.scss new file mode 100644 index 00000000..bdf8f0f7 --- /dev/null +++ b/test/fixtures/imports/inline-comment.scss @@ -0,0 +1 @@ +// inline comment diff --git a/test/fixtures/scss-parser.css b/test/fixtures/scss-parser.css new file mode 100644 index 00000000..dd521736 --- /dev/null +++ b/test/fixtures/scss-parser.css @@ -0,0 +1 @@ +@import "inline-comment.scss"; diff --git a/test/fixtures/scss-parser.expected.css b/test/fixtures/scss-parser.expected.css new file mode 100644 index 00000000..87791d5c --- /dev/null +++ b/test/fixtures/scss-parser.expected.css @@ -0,0 +1 @@ +/* inline comment*/ diff --git a/test/fixtures/scss-syntax.css b/test/fixtures/scss-syntax.css new file mode 100644 index 00000000..dd521736 --- /dev/null +++ b/test/fixtures/scss-syntax.css @@ -0,0 +1 @@ +@import "inline-comment.scss"; diff --git a/test/fixtures/scss-syntax.expected.css b/test/fixtures/scss-syntax.expected.css new file mode 100644 index 00000000..bdf8f0f7 --- /dev/null +++ b/test/fixtures/scss-syntax.expected.css @@ -0,0 +1 @@ +// inline comment diff --git a/test/plugins.js b/test/plugins.js index 51c15add..d5b8bd8c 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -1,5 +1,6 @@ import test from "ava" import postcss from "postcss" +import scss from "postcss-scss" import atImport from ".." import compareFixtures from "./lib/compare-fixtures" @@ -42,3 +43,15 @@ test("should remain silent when value is an empty array", () => { })) .process("") }) + +test("should process custom syntax", t => { + return compareFixtures(t, "scss-syntax", null, { + syntax: scss, + }) +}) + +test("should process custom syntax by parser", t => { + return compareFixtures(t, "scss-parser", null, { + parser: scss, + }) +})