Skip to content

Commit e82f636

Browse files
committed
fix: Cannot export a block as a reserved namespace identifier.
1 parent 457e08c commit e82f636

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/@css-blocks/core/src/BlockParser/features/export-blocks.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { postcss } from "opticss";
22

3-
import { BLOCK_EXPORT, CLASS_NAME_IDENT, DEFAULT_EXPORT } from "../../BlockSyntax";
3+
import { BLOCK_EXPORT, CLASS_NAME_IDENT, DEFAULT_EXPORT, RESERVED_BLOCK_NAMES } from "../../BlockSyntax";
44
import { Block } from "../../BlockTree";
55
import * as errors from "../../errors";
66
import { sourceRange } from "../../SourceLocation";
@@ -77,7 +77,8 @@ export async function exportBlocks(block: Block, factory: BlockFactory, file: st
7777
sourceRange(factory.configuration, block.stylesheet, file, atRule),
7878
);
7979
}
80-
if (remoteName === DEFAULT_EXPORT) {
80+
81+
if (RESERVED_BLOCK_NAMES.has(remoteName)) {
8182
throw new errors.InvalidBlockSyntax(
8283
`Cannot export "${localName}" as reserved word "${remoteName}"`,
8384
sourceRange(factory.configuration, block.stylesheet, file, atRule),

packages/@css-blocks/core/test/BlockParser/import-export-test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,25 @@ export class BlockImportExport extends BEMProcessor {
612612
);
613613
}
614614

615+
@test async "svg is a reserved word – bare exports"() {
616+
let imports = new MockImportRegistry();
617+
imports.registerSource(
618+
"images.block.css",
619+
`:scope { color: red; }`,
620+
);
621+
622+
623+
let inputCSS = `
624+
@export (default as svg) from "./images.block.css";
625+
`;
626+
627+
return assertError(
628+
InvalidBlockSyntax,
629+
`Cannot export "default" as reserved word "svg" (test.css:2:7)`,
630+
this.process("test.css", inputCSS, {importer: imports.importer()}),
631+
);
632+
}
633+
615634
@test async "default is a reserved word – named exports"() {
616635
let imports = new MockImportRegistry();
617636
imports.registerSource(

0 commit comments

Comments
 (0)