Skip to content

Commit b2ea6ad

Browse files
committed
feat: no idea what I'm doing
1 parent 9dc140a commit b2ea6ad

46 files changed

Lines changed: 2895 additions & 563 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/oxlint/src-js/generated/deserialize.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ export function resetBuffer() {
5252
astId++;
5353
}
5454

55+
function deserializeAstroScript(pos) {
56+
let start,
57+
end,
58+
previousParent = parent,
59+
node = (parent = {
60+
__proto__: NodeProto,
61+
type: "AstroScript",
62+
program: null,
63+
start: (start = deserializeU32(pos)),
64+
end: (end = deserializeU32(pos + 4)),
65+
range: [start, end],
66+
parent,
67+
});
68+
node.program = deserializeProgram(pos + 8);
69+
parent = previousParent;
70+
return node;
71+
}
72+
5573
function deserializeProgram(pos) {
5674
let localAstId = astId,
5775
end = deserializeU32(pos + 4),
@@ -3820,6 +3838,8 @@ function deserializeJSXChild(pos) {
38203838
return deserializeBoxJSXExpressionContainer(pos + 8);
38213839
case 4:
38223840
return deserializeBoxJSXSpreadChild(pos + 8);
3841+
case 5:
3842+
return deserializeBoxAstroScript(pos + 8);
38233843
default:
38243844
throw Error(`Unexpected discriminant ${uint8[pos]} for JSXChild`);
38253845
}
@@ -5745,6 +5765,8 @@ function deserializeCommentKind(pos) {
57455765
return "Block";
57465766
case 2:
57475767
return "Block";
5768+
case 3:
5769+
return "Html";
57485770
default:
57495771
throw Error(`Unexpected discriminant ${uint8[pos]} for CommentKind`);
57505772
}
@@ -5920,6 +5942,18 @@ function deserializeU8(pos) {
59205942
return uint8[pos];
59215943
}
59225944

5945+
function deserializeVecJSXChild(pos) {
5946+
let arr = [],
5947+
pos32 = pos >> 2;
5948+
pos = uint32[pos32];
5949+
let endPos = pos + uint32[pos32 + 2] * 16;
5950+
for (; pos !== endPos; ) {
5951+
arr.push(deserializeJSXChild(pos));
5952+
pos += 16;
5953+
}
5954+
return arr;
5955+
}
5956+
59235957
function deserializeStr(pos) {
59245958
let pos32 = pos >> 2,
59255959
len = uint32[pos32 + 2];
@@ -6771,18 +6805,6 @@ function deserializeBoxJSXOpeningElement(pos) {
67716805
return deserializeJSXOpeningElement(uint32[pos >> 2]);
67726806
}
67736807

6774-
function deserializeVecJSXChild(pos) {
6775-
let arr = [],
6776-
pos32 = pos >> 2;
6777-
pos = uint32[pos32];
6778-
let endPos = pos + uint32[pos32 + 2] * 16;
6779-
for (; pos !== endPos; ) {
6780-
arr.push(deserializeJSXChild(pos));
6781-
pos += 16;
6782-
}
6783-
return arr;
6784-
}
6785-
67866808
function deserializeBoxJSXClosingElement(pos) {
67876809
return deserializeJSXClosingElement(uint32[pos >> 2]);
67886810
}
@@ -6841,6 +6863,10 @@ function deserializeBoxJSXSpreadChild(pos) {
68416863
return deserializeJSXSpreadChild(uint32[pos >> 2]);
68426864
}
68436865

6866+
function deserializeBoxAstroScript(pos) {
6867+
return deserializeAstroScript(uint32[pos >> 2]);
6868+
}
6869+
68446870
function deserializeVecTSEnumMember(pos) {
68456871
let arr = [],
68466872
pos32 = pos >> 2;

apps/oxlint/src-js/generated/types.d.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ import { Token } from "../plugins/tokens.ts";
66
import { Comment } from "../plugins/types.ts";
77
export { Span, Comment, Token };
88

9+
export interface AstroRoot extends Span {
10+
type: "AstroRoot";
11+
frontmatter: AstroFrontmatter | null;
12+
body: Array<JSXChild>;
13+
parent: Node;
14+
}
15+
16+
export interface AstroFrontmatter extends Span {
17+
type: "AstroFrontmatter";
18+
program: Program;
19+
parent: Node;
20+
}
21+
22+
export interface AstroScript extends Span {
23+
type: "AstroScript";
24+
program: Program;
25+
parent: Node;
26+
}
27+
928
export interface Program extends Span {
1029
type: "Program";
1130
body: Array<Directive | Statement>;
@@ -1068,7 +1087,13 @@ export interface JSXIdentifier extends Span {
10681087
parent: Node;
10691088
}
10701089

1071-
export type JSXChild = JSXText | JSXElement | JSXFragment | JSXExpressionContainer | JSXSpreadChild;
1090+
export type JSXChild =
1091+
| JSXText
1092+
| JSXElement
1093+
| JSXFragment
1094+
| JSXExpressionContainer
1095+
| JSXSpreadChild
1096+
| AstroScript;
10721097

10731098
export interface JSXSpreadChild extends Span {
10741099
type: "JSXSpreadChild";
@@ -1728,6 +1753,9 @@ export type UpdateOperator = "++" | "--";
17281753
export type ModuleKind = "script" | "module" | "commonjs";
17291754

17301755
export type Node =
1756+
| AstroRoot
1757+
| AstroFrontmatter
1758+
| AstroScript
17311759
| Program
17321760
| IdentifierName
17331761
| IdentifierReference

crates/oxc_ast/src/ast/comment.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ pub enum CommentKind {
2121
/// Multi-line block comment (contains line breaks)
2222
#[estree(rename = "Block")]
2323
MultiLineBlock = 2,
24+
/// HTML comment `<!-- ... -->`
25+
/// Used in Astro files
26+
#[estree(rename = "Html")]
27+
Html = 3,
2428
}
2529

2630
/// Information about a comment's position relative to a token.
@@ -179,6 +183,8 @@ impl Comment {
179183
CommentKind::SingleLineBlock | CommentKind::MultiLineBlock => {
180184
Span::new(self.span.start + 2, self.span.end - 2)
181185
}
186+
// HTML comments: `<!-- content -->` - skip 4 chars at start, 3 at end
187+
CommentKind::Html => Span::new(self.span.start + 4, self.span.end - 3),
182188
}
183189
}
184190

@@ -200,6 +206,12 @@ impl Comment {
200206
self.kind == CommentKind::MultiLineBlock
201207
}
202208

209+
/// Returns `true` if this is an HTML comment (`<!-- -->`).
210+
#[inline]
211+
pub fn is_html(self) -> bool {
212+
self.kind == CommentKind::Html
213+
}
214+
203215
/// Returns `true` if this comment is before a token.
204216
#[inline]
205217
pub fn is_leading(self) -> bool {

crates/oxc_ast/src/generated/derive_estree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,7 @@ impl ESTree for CommentKind {
32553255
Self::Line => JsonSafeString("Line").serialize(serializer),
32563256
Self::SingleLineBlock => JsonSafeString("Block").serialize(serializer),
32573257
Self::MultiLineBlock => JsonSafeString("Block").serialize(serializer),
3258+
Self::Html => JsonSafeString("Html").serialize(serializer),
32583259
}
32593260
}
32603261
}

crates/oxc_codegen/src/comment.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ impl Codegen<'_> {
161161
}
162162
}
163163
}
164+
CommentKind::Html => {
165+
// HTML comments: print as-is
166+
self.print_str(comment_source);
167+
}
164168
}
165169
}
166170

0 commit comments

Comments
 (0)