Skip to content

Commit

Permalink
fix: don't crash when raws.before is undefined (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-sodzawiczny authored and evilebottnawi committed Feb 26, 2019
1 parent 2bfed2e commit 43168ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/extractICSS.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const importPattern = /^:import\(("[^"]*"|'[^']*'|[^"']+)\)$/;
const getDeclsObject = rule => {
const object = {};
rule.walkDecls(decl => {
object[decl.raws.before.trim() + decl.prop] = decl.value;
const before = decl.raws.before ? decl.raws.before.trim() : "";
object[before + decl.prop] = decl.value;
});
return object;
};
Expand Down
21 changes: 20 additions & 1 deletion test/extractICSS.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test("extract :import statements with single quoted path", () => {
});
});

test("extract :import statements with double quoted path", () => {
test("extract manually added :import", () => {
expect(runExtract(':import("./colors.css") {}')).toEqual({
icssImports: {
"./colors.css": {}
Expand All @@ -50,6 +50,25 @@ test("not extract :import with values", () => {
});
});

test("extract :import statements manually created in postcss", () => {
const root = postcss.parse("");
root.append(
postcss
.rule({ selector: ":import(./colors.css)" })
.append(postcss.decl({ prop: "i__blue", value: "blue" }))
.append(postcss.decl({ prop: "i__red", value: "red" }))
);
expect(extractICSS(root)).toEqual({
icssImports: {
"./colors.css": {
i__blue: "blue",
i__red: "red"
}
},
icssExports: {}
});
});

test("not extract invalid :import", () => {
expect(runExtract(":import(\\'./colors.css) {}")).toEqual({
icssImports: {},
Expand Down

0 comments on commit 43168ab

Please sign in to comment.