Skip to content

Commit 6f04b6a

Browse files
Timothy Lindvalltimlindvall
Timothy Lindvall
authored andcommitted
fix: Address PR feedback.
- Throw if header comment in compiled css file is after footer. - cssContents should be a string. Also add blockId as a property to the ImportedCompiledCssFile interface. - Fix comment for getBlockRelative().
1 parent 68271ad commit 6f04b6a

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

packages/@css-blocks/core/src/BlockParser/BlockFactory.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,8 @@ export class BlockFactory {
296296
}
297297

298298
/**
299-
* Similar to getBlockFromPath(), this imports and parses a block data file. However,
300-
* this method can accept relative paths using a FileIdentifier (generated by an Importer)
301-
* as the base location for the relative path.
299+
* Similar to getBlock(), this imports and parses a block data file. However, this
300+
* method parses a block relative to another block.
302301
*
303302
* @param fromIdentifier - The FileIdentifier that references the base location that the
304303
* import path is relative to.

packages/@css-blocks/core/src/importing/BaseImporter.ts

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ export abstract class BaseImporter implements Importer {
8686
}
8787
const footerEndIndex = footerStartIndex + footerFullMatch.length;
8888

89+
if (headerStartIndex > footerStartIndex) {
90+
throw new Error("Header must exist before footer in imported content.");
91+
}
92+
8993
// Break the file into segments.
9094
const pre = contents.slice(0, headerStartIndex);
9195
const post = contents.slice(footerEndIndex + 1);

packages/@css-blocks/core/src/importing/Importer.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ export interface ImportedCompiledCssFile {
108108
syntax: Syntax.css;
109109

110110
/**
111-
* The contents of the imported pre-compiled CSS file, sliced into segments based
112-
* on the presence and location of CSS Blocks comments.
111+
* The CSS rules imported from the pre-compiled CSS file.
113112
*/
114-
cssContents: ImportedCompiledCssFileContents;
113+
cssContents: string;
114+
115+
/**
116+
* The Block ID as declared in the header comment. This is expected
117+
* to match the `block-id` declaration for the `:scope` selector
118+
* in the definition.
119+
*/
120+
blockId: string;
115121

116122
/**
117123
* The contents of the block definition. If this was embedded base64 data, it will

0 commit comments

Comments
 (0)