Skip to content

Commit

Permalink
Merge pull request #130 from postcss/custom-syntax
Browse files Browse the repository at this point in the history
Add custom syntax and parser support
  • Loading branch information
MoOx committed Jan 4, 2016
2 parents 0216fa3 + 9c6e7dc commit dd4c160
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/imports/inline-comment.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// inline comment
1 change: 1 addition & 0 deletions test/fixtures/scss-parser.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "inline-comment.scss";
1 change: 1 addition & 0 deletions test/fixtures/scss-parser.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* inline comment*/
1 change: 1 addition & 0 deletions test/fixtures/scss-syntax.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "inline-comment.scss";
1 change: 1 addition & 0 deletions test/fixtures/scss-syntax.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// inline comment
13 changes: 13 additions & 0 deletions test/plugins.js
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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,
})
})

0 comments on commit dd4c160

Please sign in to comment.