Skip to content

Commit 0607f19

Browse files
authored
fix support for stylelint (#45)
1 parent 5fd1e72 commit 0607f19

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/parser.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@ const docFixer = require("./parse-style");
66
const htmlParser = require("./html-parser");
77

88
function parser (source, opts) {
9+
function filenameMatch (reg) {
10+
return opts.from && reg.test(opts.from);
11+
}
912
// Skip known style sheet and script files.
10-
if (opts.from && /\.(?:(?:\w*c|wx|le|sa|s)ss|styl(?:us)?|m?[jt]sx?|es\d*|pac)(?:\?.*)?$/i.test(opts.from)) {
13+
if (filenameMatch(/\.(?:(?:\w*c|wx|le|sa|s)ss|styl(?:us)?|m?[jt]sx?|es\d*|pac)(?:\?.*)?$/i)) {
1114
return;
1215
}
1316

1417
source = source && source.toString();
1518

1619
const styleHtm = htmlParser(source, opts);
20+
if (!styleHtm && !filenameMatch(/\.(?:[sx]?html?|[sx]ht|vue|ux|php)(?:\?.*)?$/i)) {
21+
return;
22+
}
1723
const document = new Document();
18-
const parseStyle = docFixer(source, opts);
24+
1925
let index = 0;
2026
if (styleHtm) {
27+
const parseStyle = docFixer(source, opts);
2128
styleHtm.sort((a, b) => {
2229
return a.startIndex - b.startIndex;
2330
}).forEach(style => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-html",
3-
"version": "0.20.0",
3+
"version": "0.20.1",
44
"description": "PostCSS syntax for parsing HTML (and HTML-like)",
55
"main": "lib/index.js",
66
"scripts": {

test/html.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ describe("html tests", () => {
420420
from: undefined,
421421
}
422422
).then(result => {
423-
expect(result.root.nodes).to.have.lengthOf(0);
423+
expect(result.root.nodes).to.have.lengthOf(1);
424+
expect(result.root.nodes[0]).to.have.property("type").to.equal("comment");
424425
});
425426
});
426427
});

0 commit comments

Comments
 (0)