8000 Treat :import and :export statements as pure. Fixes #21 by fdintino · Pull Request #23 · css-modules/postcss-modules-local-by-default · GitHub
Skip to content

Treat :import and :export statements as pure. Fixes #21 #23

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

Merged
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: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function normalizeNodeArray(nodes) {
function localizeNode(rule, mode, localAliasMap) {
const isScopePseudo = node =>
node.value === ':local' || node.value === ':global';
const isImportExportPseudo = node =>
node.value === ':import' || node.value === ':export';

const transform = (node, context) => {
if (context.ignoreNextSpacing && !isSpacing(node)) {
Expand Down Expand Up @@ -115,9 +117,12 @@ function localizeNode(rule, mode, localAliasMap) {
let childContext;
const isNested = !!node.length;
const isScoped = isScopePseudo(node);
const isImportExport = isImportExportPseudo(node);

if (isImportExport) {
context.hasLocals = true;
// :local(.foo)
if (isNested) {
} else if (isNested) {
if (isScoped) {
if (node.nodes.length === 0) {
throw new Error(`${node.value}() can't be empty`);
Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,18 @@ const tests = [
error: /:global\(\) can't be empty/
},
*/
{
should: 'consider :import statements pure',
input: ':import("~/lol.css") { foo: __foo; }',
options: { mode: 'pure' },
expected: ':import("~/lol.css") { foo: __foo; }',
},
{
should: 'consider :export statements pure',
input: ':export { foo: __foo; }',
options: { mode: 'pure' },
expected: ':export { foo: __foo; }',
},
];

function process(css, options) {
Expand Down