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: namespace import referencing via value aliases #965

Merged
merged 4 commits into from
Aug 8, 2023
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
7 changes: 7 additions & 0 deletions .changeset/tidy-papayas-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@modular-css/processor": patch
---

Fix namespace import referencing via value aliases #964

Updating internal `values` map after importing new values, which was missing previously.
11 changes: 11 additions & 0 deletions packages/processor/plugins/values-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ module.exports = () => ({
throw rule.error(`Unknown @value type, unable to process`);
},
},

RootExit() {
// Update any references that might've been affected by imports
for(const name of Object.keys(values)) {
const { value } = values[name];

if(value in values) {
values[name] = values[value];
}
}
},
};
},
});
Expand Down
9 changes: 9 additions & 0 deletions packages/processor/test/__snapshots__/values.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ exports[`/processor.js values should support importing variables from a file 1`]
"
`;

exports[`/processor.js values should support layers of namespaced value references 1`] = `
"/* packages/processor/test/specimens/deep-namespace/c.css */
/* packages/processor/test/specimens/deep-namespace/b.css */
/* packages/processor/test/specimens/deep-namespace/a.css */
.mc_a {
color: cyan;
}"
`;

exports[`/processor.js values should support local values in value composition 1`] = `
"/* packages/processor/test/specimens/folder/folder.css */
.mc_folder { margin: 2px; }
Expand Down
5 changes: 5 additions & 0 deletions packages/processor/test/specimens/deep-namespace/a.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@value b from "./b.css";

.a {
color: b;
}
3 changes: 3 additions & 0 deletions packages/processor/test/specimens/deep-namespace/b.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@value * as values from "./c.css";

@value b: values.c;
1 change: 1 addition & 0 deletions packages/processor/test/specimens/deep-namespace/c.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@value c: cyan;
8 changes: 8 additions & 0 deletions packages/processor/test/values.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,13 @@ describe("/processor.js", () => {

expect(css).toMatchSnapshot();
});

it("should support layers of namespaced value references", async () => {
await processor.file(require.resolve("./specimens/deep-namespace/a.css"));

const { css } = await processor.output();

expect(css).toMatchSnapshot();
});
});
});