Skip to content

Commit

Permalink
fix: treat :import and :export statements as pure
Browse files Browse the repository at this point in the history
  • Loading branch information
fdintino committed Jul 24, 2020
1 parent 446dd71 commit 298fd99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit 298fd99

Please sign in to comment.