Skip to content

Commit 847bf92

Browse files
committed
fix: lint and napi tests
1 parent 9a401c1 commit 847bf92

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

crates/oxc_parser/src/astro/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{ParseOptions, ParserImpl, parser_parse::UniquePromise};
99

1010
use super::parse_astro_scripts;
1111

12-
/// Return value of [`Parser::parse_astro`] for Astro files.
12+
/// Return value of [`parse_astro`] for Astro files.
1313
///
1414
/// ## AST Validity
1515
///

napi/parser/test/astro.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ const name = "World";
3434

3535
const root = ret.root as AstroRoot;
3636
expect(root.type).toBe("AstroRoot");
37-
expect(root.frontmatter).toBeNull();
37+
// When no frontmatter exists, a synthetic empty frontmatter is created
38+
// for semantic analysis to have a Program root node
39+
expect(root.frontmatter).not.toBeNull();
40+
expect(root.frontmatter?.program.body.length).toBe(0);
3841
expect(root.body.length).toBeGreaterThan(0);
3942
});
4043

@@ -71,10 +74,16 @@ const name = "World";
7174
const root = ret.root as AstroRoot;
7275
expect(root.type).toBe("AstroRoot");
7376

74-
// Find the AstroScript in the body
75-
const astroScript = root.body.find((child: any) => child.type === "AstroScript") as
76-
| AstroScript
77-
| undefined;
77+
// Find the script JSXElement in the body
78+
const scriptElement = root.body.find(
79+
(child: any) => child.type === "JSXElement" && child.openingElement?.name?.name === "script",
80+
) as any;
81+
expect(scriptElement).toBeDefined();
82+
83+
// The AstroScript is inside the script element's children
84+
const astroScript = scriptElement?.children?.find(
85+
(child: any) => child.type === "AstroScript",
86+
) as AstroScript | undefined;
7887
expect(astroScript).toBeDefined();
7988
expect(astroScript?.type).toBe("AstroScript");
8089
expect(astroScript?.program).toBeDefined();

0 commit comments

Comments
 (0)