Skip to content

Commit 62f14a9

Browse files
maxmiltonjonathantneal
authored andcommitted
Fix parsing the contents of imported stylesheets
1 parent bf62f87 commit 62f14a9

6 files changed

+61
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules
22
package-lock.json
33
*.log*
44
*.result.css
5+
*.result.scss
56
.*
67
!.editorconfig
78
!.gitignore

.tape.js

+9
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ module.exports = {
8989
syntax: require('postcss-scss')
9090
}
9191
},
92+
'import-scss': {
93+
message: 'supports @import with scss syntax',
94+
source: 'imports-scss.scss',
95+
expect: 'imports-scss.expect.scss',
96+
result: 'imports-scss.result.scss',
97+
processOptions: {
98+
syntax: require('postcss-scss')
99+
}
100+
},
92101
'unresolved:ignore': {
93102
message: 'supports { unresolved: "ignore" } option',
94103
expect: 'unresolved.expect.css',

src/lib/transform-import-atrule.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export default function transformImportAtrule(rule, opts) {
1212
// @import options
1313
const { id, media, cwf, cwd } = getImportOpts(rule, opts);
1414

15+
// PostCSS options
16+
const options = opts.result.opts;
17+
const parser = options.parser || options.syntax && options.syntax.parse || null;
18+
1519
if (
1620
opts.importFilter instanceof Function && opts.importFilter(id, media) ||
1721
opts.importFilter instanceof RegExp && opts.importFilter.test(id)
@@ -28,7 +32,7 @@ export default function transformImportAtrule(rule, opts) {
2832

2933
return importPromise.then(
3034
// promise the processed file
31-
({ file, contents }) => processor.process(contents, { from: file }).then(
35+
({ file, contents }) => processor.process(contents, { from: file, parser: parser }).then(
3236
({ root }) => {
3337
// push a dependency message
3438
opts.result.messages.push({ type: 'dependency', file: file, parent: cwf });

test/imports-scss.expect.scss

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.scss {
2+
.nested {
3+
// inline comment
4+
content: "pass";
5+
}
6+
7+
.name {
8+
content: "pass";
9+
10+
.mixin {
11+
-webkit-border-radius: 1em;
12+
-moz-border-radius: 1em;
13+
-ms-border-radius: 1em;
14+
border-radius: 1em;
15+
}
16+
}
17+
}
18+
19+
.imported {
20+
content: "name";
21+
}

test/imports-scss.scss

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$pass: "pass";
2+
3+
@import "imports/scss";
4+
5+
.imported {
6+
content: "$(name)";
7+
}

test/imports/scss.scss

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@import "./mixins";
2+
3+
$name: name;
4+
5+
.scss {
6+
.nested {
7+
// inline comment
8+
content: $pass;
9+
}
10+
11+
.#{$name} {
12+
content: $pass;
13+
14+
.mixin {
15+
@include mixin-test-1;
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)