From 6857cdf722842894ab3e3d0b3395b627ed8bd1f7 Mon Sep 17 00:00:00 2001 From: dpiercey Date: Thu, 14 Aug 2025 16:07:28 -0700 Subject: [PATCH] fix: arrow fn in type args/params --- .changeset/tired-results-taste.md | 5 +++++ .../tag-type-argument-arrow-function.expected.txt | 7 +++++++ .../tag-type-argument-arrow-function/input.marko | 1 + src/states/EXPRESSION.ts | 11 ++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .changeset/tired-results-taste.md create mode 100644 src/__tests__/fixtures/tag-type-argument-arrow-function/__snapshots__/tag-type-argument-arrow-function.expected.txt create mode 100644 src/__tests__/fixtures/tag-type-argument-arrow-function/input.marko diff --git a/.changeset/tired-results-taste.md b/.changeset/tired-results-taste.md new file mode 100644 index 00000000..9c858aee --- /dev/null +++ b/.changeset/tired-results-taste.md @@ -0,0 +1,5 @@ +--- +"htmljs-parser": patch +--- + +Fix issue with arrow functions in type args/params. diff --git a/src/__tests__/fixtures/tag-type-argument-arrow-function/__snapshots__/tag-type-argument-arrow-function.expected.txt b/src/__tests__/fixtures/tag-type-argument-arrow-function/__snapshots__/tag-type-argument-arrow-function.expected.txt new file mode 100644 index 00000000..4b59b40d --- /dev/null +++ b/src/__tests__/fixtures/tag-type-argument-arrow-function/__snapshots__/tag-type-argument-arrow-function.expected.txt @@ -0,0 +1,7 @@ +1╭─ void }>/> + │ ││ ││ ╰─ openTagEnd:selfClosed "/>" + │ ││ │╰─ tagTypeArgs.value "{ bar: () => void }" + │ ││ ╰─ tagTypeArgs "<{ bar: () => void }>" + │ │╰─ tagName "foo" + ╰─ ╰─ openTagStart +2╰─ \ No newline at end of file diff --git a/src/__tests__/fixtures/tag-type-argument-arrow-function/input.marko b/src/__tests__/fixtures/tag-type-argument-arrow-function/input.marko new file mode 100644 index 00000000..0bc3d3f8 --- /dev/null +++ b/src/__tests__/fixtures/tag-type-argument-arrow-function/input.marko @@ -0,0 +1 @@ + void }>/> diff --git a/src/states/EXPRESSION.ts b/src/states/EXPRESSION.ts index 08bfc43f..6e02e694 100644 --- a/src/states/EXPRESSION.ts +++ b/src/states/EXPRESSION.ts @@ -212,7 +212,16 @@ export const EXPRESSION: StateDefinition = { case CODE.CLOSE_PAREN: case CODE.CLOSE_SQUARE_BRACKET: case CODE.CLOSE_CURLY_BRACE: - case expression.inType && CODE.CLOSE_ANGLE_BRACKET: { + case CODE.CLOSE_ANGLE_BRACKET: { + if (code === CODE.CLOSE_ANGLE_BRACKET) { + if ( + !expression.inType || + this.lookAtCharCodeAhead(-1) === CODE.EQUAL + ) { + break; + } + } + if (!expression.groupStack.length) { return this.emitError( expression,