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,