Skip to content
This repository was archived by the owner on Oct 14, 2026. It is now read-only.

Commit 125602e

Browse files
author
James Kolce
committed
[fix: #12] Add support for inline comments
1 parent d92b002 commit 125602e

7 files changed

Lines changed: 108 additions & 7 deletions

File tree

‎dist/index.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ const postcss = require("postcss");
55
const autoprefixer = require("autoprefixer");
66
const nested = require("postcss-nested");
77
const ifMedia = require("postcss-if-media");
8+
const scssSyntax = require("postcss-scss");
9+
const stripComments = require("postcss-strip-inline-comments");
810
const lh_1 = require("./lib/lh");
911
const custom_media_1 = require("./lib/custom-media");
1012
const media_minmax_1 = require("./lib/media-minmax");
1113
exports.default = file => {
1214
const ccss = fs.readFileSync(file, 'utf8');
1315
return postcss([
16+
stripComments,
1417
ifMedia,
1518
nested,
1619
custom_media_1.default,
1720
media_minmax_1.default,
1821
lh_1.default,
1922
autoprefixer
20-
]).process(ccss).css;
23+
]).process(ccss, { parser: scssSyntax }).css;
2124
};

‎package-lock.json‎

Lines changed: 77 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
"autoprefixer": "^7.1.6",
2727
"postcss": "^6.0.13",
2828
"postcss-if-media": "^1.0.3",
29-
"postcss-nested": "^2.1.2"
29+
"postcss-nested": "^2.1.2",
30+
"postcss-scss": "^1.0.2",
31+
"postcss-strip-inline-comments": "^0.1.5"
3032
},
3133
"devDependencies": {
3234
"@types/node": "^8.0.47",

‎src/index.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as postcss from 'postcss';
33
import * as autoprefixer from 'autoprefixer';
44
import * as nested from 'postcss-nested';
55
import * as ifMedia from 'postcss-if-media';
6+
import * as scssSyntax from 'postcss-scss';
7+
import * as stripComments from 'postcss-strip-inline-comments';
68

79
import lh from './lib/lh';
810
import customMedia from './lib/custom-media';
@@ -12,11 +14,12 @@ export default file => {
1214
const ccss = fs.readFileSync(file, 'utf8');
1315

1416
return postcss([
17+
stripComments,
1518
ifMedia,
1619
nested,
1720
customMedia,
1821
mediaMinMax,
1922
lh,
2023
autoprefixer
21-
]).process(ccss).css;
24+
]).process(ccss, { parser: scssSyntax }).css;
2225
}

‎test/index.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,12 @@ test('if-media', t => {
141141

142142
t.end();
143143
});
144+
145+
test('strip-comments', t => {
146+
t.equal(
147+
actual('strip-comments/input'),
148+
expected('strip-comments/output'),
149+
'should remove inline comments');
150+
151+
t.end();
152+
});

‎test/strip-comments/input.ccss‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* This comment will remain */
2+
// This comment will be removed
3+
body {
4+
// This comment will also be removed
5+
background-color: black;
6+
}
7+
// And so will this one

‎test/strip-comments/output.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* This comment will remain */
2+
body {
3+
background-color: black;
4+
}

0 commit comments

Comments
 (0)