Skip to content

Commit aabf1f1

Browse files
committed
fix: arrow function parsing in type expressions
1 parent c195d2f commit aabf1f1

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

.changeset/nine-dragons-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"htmljs-parser": patch
3+
---
4+
5+
Fix arrow function parsing in type expressions.

src/__tests__/fixtures/ts-type-statement/__snapshots__/ts-type-statement.expected.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@
2828
21├─ 2
2929
22├─ > = baz;
3030
23╭─
31+
╰─ ╰─ openTagEnd
32+
24╭─ export interface Foo {
33+
╰─ ╰─ tagName "export"
34+
25├─ bar: () => Baz;
35+
26├─ }
36+
27╭─
3137
╰─ ╰─ openTagEnd

src/__tests__/fixtures/ts-type-statement/input.marko

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ static const x: Foo<
2020
1,
2121
2
2222
> = baz;
23+
24+
export interface Foo {
25+
bar: () => Baz;
26+
}

src/states/EXPRESSION.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ export const EXPRESSION: StateDefinition<ExpressionMeta> = {
144144
}
145145
break;
146146
case CODE.EQUAL:
147-
if (expression.operators && !expression.groupStack.length) {
147+
if (expression.operators) {
148148
if (this.lookAtCharCodeAhead(1) === CODE.CLOSE_ANGLE_BRACKET) {
149149
this.pos++;
150-
} else if (!expression.forceType) {
150+
} else if (!(expression.forceType || expression.groupStack.length)) {
151151
expression.inType = false;
152152
}
153153

0 commit comments

Comments
 (0)