Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chubby-glasses-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"htmljs-parser": patch
---

Fix issue where arrow functions content was being parsed as types.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
1╭─ static const a = (a: number, b: number): string => {
╰─ ╰─ tagName "static"
2├─ if (a < b) {
3├─ return "foo";
4├─ } else {
5├─ return "bar";
6├─ }
7├─ };
8╭─
╰─ ╰─ openTagEnd
9╭─ static const b = (a: number, b: number): () => string => () => {
╰─ ╰─ tagName "static"
10├─ if (a < b) {
11├─ return "foo";
12├─ } else {
13├─ return "bar";
14├─ }
15├─ };
16╭─
╰─ ╰─ openTagEnd
17╭─ static const c = (a: number, b: number): string => a < b ? "foo" : "bar";
╰─ ╰─ tagName "static"
18╭─
╰─ ╰─ openTagEnd
19╭─ static const d = (a: number, b: number): () => string => () => a < b ? "foo" : "bar";
╰─ ╰─ tagName "static"
20╭─
╰─ ╰─ openTagEnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
static const a = (a: number, b: number): string => {
if (a < b) {
return "foo";
} else {
return "bar";
}
};

static const b = (a: number, b: number): () => string => () => {
if (a < b) {
return "foo";
} else {
return "bar";
}
};

static const c = (a: number, b: number): string => a < b ? "foo" : "bar";

static const d = (a: number, b: number): () => string => () => a < b ? "foo" : "bar";
7 changes: 7 additions & 0 deletions src/states/EXPRESSION.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ export const EXPRESSION: StateDefinition<ExpressionMeta> = {
case CODE.EQUAL:
if (expression.operators) {
if (this.lookAtCharCodeAhead(1) === CODE.CLOSE_ANGLE_BRACKET) {
if (
expression.inType &&
!expression.forceType &&
this.getPreviousNonWhitespaceCharCode() !== CODE.CLOSE_PAREN
) {
expression.inType = false;
}
this.pos++;
} else if (!(expression.forceType || expression.groupStack.length)) {
expression.inType = false;
Expand Down
Loading