Skip to content

Commit 90bfbff

Browse files
committed
fix: Improve Block ref parser.
1 parent fc35f1c commit 90bfbff

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

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

+7-9
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,19 @@ export async function importBlocks(block: Block, factory: BlockFactory, file: st
3737
// For each `@block` expression, read in the block file, parse and
3838
// push to block references Promise array.
3939
root.walkAtRules(BLOCK_IMPORT, (atRule: postcss.AtRule) => {
40-
// <blocks-list> from <block-path>
40+
// imports: `<blocks-list> from <block-path>`
41+
// blockList: `<default-block> | <named-blocks> | <default-block> " , " <named-blocks> | <named-blocks> " , " <default-block>`
42+
// blockPath: `' " ' <any-value> ' " ' | " ' " <any-value> " ' "`
4143
let imports = atRule.params;
42-
43-
// <default-block> | <named-blocks> | <default-block> " , " <named-blocks> | <named-blocks> " , " <default-block>
44-
let blockList = imports.split(FROM_EXPR)[0];
45-
46-
// ' " ' <any-value> ' " ' | " ' " <any-value> " ' ", then strip quotes.
47-
let blockPath = stripQuotes(imports.split(FROM_EXPR)[1] || "");
44+
let [blockList = "", blockPath = ""] = imports.split(FROM_EXPR);
45+
blockPath = stripQuotes(blockPath);
4846

4947
if (!blockList || !blockPath) {
5048
throw new errors.InvalidBlockSyntax(
5149
`Malformed block reference: \`@block ${atRule.params}\``,
5250
sourceLocation(file, atRule),
53-
);
54-
}
51+
);
52+
}
5553

5654
// Import file, then parse file, then save block reference.
5755
let blockPromise: Promise<Block> = factory.getBlockRelative(block.identifier, blockPath);

0 commit comments

Comments
 (0)