Skip to content

Commit 4ccc09c

Browse files
committed
feat: support declarations comment
1 parent 2b33109 commit 4ccc09c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

packages/abell/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "abell",
3-
"version": "1.0.0-alpha.65",
3+
"version": "1.0.0-alpha.66",
44
"description": "Abell is a static-site-generator for JavaScript developers. Powered by Vite, It tries to stay close to fundamentals while providing a great DX",
55
"bin": "./dist/bin.js",
66
"main": "./dist/index.js",

packages/abell/src/vite-plugin-abell/compiler/compiler.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ describe('compile()', () => {
1515
expect(out.declarationsBlock.text).toMatchInlineSnapshot('""');
1616
});
1717

18+
test('should create first block as declaration block with declarations comment', () => {
19+
const abellCode = `
20+
{{
21+
// declarations
22+
const a = 3;
23+
}}
24+
<body>{{ a }}</body>
25+
`;
26+
const out = compile(abellCode, {
27+
filepath: __dirname,
28+
outputType: 'syntax-blocks'
29+
});
30+
expect(out.out.text.trim()).toMatchInlineSnapshot(
31+
'"<body data-abell-heumYD>${e( a )}</body>"'
32+
);
33+
expect(out.declarationsBlock.text.trim()).toMatchInlineSnapshot(`
34+
"// declarations
35+
const a = 3;"
36+
`);
37+
});
38+
1839
test('should successfully compile with declarations', () => {
1940
const abellCode = `
2041
{{

packages/abell/src/vite-plugin-abell/compiler/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export const isDeclarationBlock = (
3737
blockCount: number,
3838
blockContent: string
3939
): boolean => {
40-
if (blockCount < 2 && blockContent.includes('import ')) {
40+
if (
41+
blockCount < 2 &&
42+
(blockContent.includes('import ') ||
43+
blockContent.includes('// declaration'))
44+
) {
4145
return true;
4246
}
4347
return false;

0 commit comments

Comments
 (0)