Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behaviour on undefined raws.before #60

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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