Skip to content

Commit 442e7cc

Browse files
committed
fix: arrow functions content was being parsed as types
1 parent 091999f commit 442e7cc

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

.changeset/chubby-glasses-read.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 issue where arrow functions content was being parsed as types.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
1╭─ static const a = (a: number, b: number): string => {
2+
╰─ ╰─ tagName "static"
3+
2├─ if (a < b) {
4+
3├─ return "foo";
5+
4├─ } else {
6+
5├─ return "bar";
7+
6├─ }
8+
7├─ };
9+
8╭─
10+
╰─ ╰─ openTagEnd
11+
9╭─ static const b = (a: number, b: number): () => string => () => {
12+
╰─ ╰─ tagName "static"
13+
10├─ if (a < b) {
14+
11├─ return "foo";
15+
12├─ } else {
16+
13├─ return "bar";
17+
14├─ }
18+
15├─ };
19+
16╭─
20+
╰─ ╰─ openTagEnd
21+
17╭─ static const c = (a: number, b: number): string => a < b ? "foo" : "bar";
22+
╰─ ╰─ tagName "static"
23+
18╭─
24+
╰─ ╰─ openTagEnd
25+
19╭─ static const d = (a: number, b: number): () => string => () => a < b ? "foo" : "bar";
26+
╰─ ╰─ tagName "static"
27+
20╭─
28+
╰─ ╰─ openTagEnd
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
static const a = (a: number, b: number): string => {
2+
if (a < b) {
3+
return "foo";
4+
} else {
5+
return "bar";
6+
}
7+
};
8+
9+
static const b = (a: number, b: number): () => string => () => {
10+
if (a < b) {
11+
return "foo";
12+
} else {
13+
return "bar";
14+
}
15+
};
16+
17+
static const c = (a: number, b: number): string => a < b ? "foo" : "bar";
18+
19+
static const d = (a: number, b: number): () => string => () => a < b ? "foo" : "bar";

src/states/EXPRESSION.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ export const EXPRESSION: StateDefinition<ExpressionMeta> = {
150150
case CODE.EQUAL:
151151
if (expression.operators) {
152152
if (this.lookAtCharCodeAhead(1) === CODE.CLOSE_ANGLE_BRACKET) {
153+
if (
154+
expression.inType &&
155+
!expression.forceType &&
156+
this.getPreviousNonWhitespaceCharCode() !== CODE.CLOSE_PAREN
157+
) {
158+
expression.inType = false;
159+
}
153160
this.pos++;
154161
} else if (!(expression.forceType || expression.groupStack.length)) {
155162
expression.inType = false;

0 commit comments

Comments
 (0)