From b8bfcd95c900e9b013510499576c4f879e6365cb Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Tue, 26 Jul 2022 10:44:04 -0700 Subject: [PATCH] fix: comma will now always terminate a tag variable (#123) --- .changeset/cuddly-carrots-compete.md | 5 +++ .../comma-after-tag-variable.expected.txt | 37 +++++++++++++++++++ .../comma-after-tag-variable/input.marko | 4 ++ src/states/OPEN_TAG.ts | 2 + 4 files changed, 48 insertions(+) create mode 100644 .changeset/cuddly-carrots-compete.md create mode 100644 src/__tests__/fixtures/comma-after-tag-variable/__snapshots__/comma-after-tag-variable.expected.txt create mode 100644 src/__tests__/fixtures/comma-after-tag-variable/input.marko diff --git a/.changeset/cuddly-carrots-compete.md b/.changeset/cuddly-carrots-compete.md new file mode 100644 index 00000000..374f6632 --- /dev/null +++ b/.changeset/cuddly-carrots-compete.md @@ -0,0 +1,5 @@ +--- +"htmljs-parser": patch +--- + +Comma will now always terminate a tag variable. diff --git a/src/__tests__/fixtures/comma-after-tag-variable/__snapshots__/comma-after-tag-variable.expected.txt b/src/__tests__/fixtures/comma-after-tag-variable/__snapshots__/comma-after-tag-variable.expected.txt new file mode 100644 index 00000000..11e04080 --- /dev/null +++ b/src/__tests__/fixtures/comma-after-tag-variable/__snapshots__/comma-after-tag-variable.expected.txt @@ -0,0 +1,37 @@ +1╭─ + │ ││ ││ │││╰─ openTagEnd:selfClosed "/>" + │ ││ ││ ││╰─ attrValue.value + │ ││ ││ │╰─ attrValue "=1" + │ ││ ││ ╰─ attrName + │ ││ │╰─ tagVar.value + │ ││ ╰─ tagVar "/x" + │ │╰─ tagName "let" + ╰─ ╰─ openTagStart +2╭─ + │ ││ ││ │││╰─ openTagEnd:selfClosed "/>" + │ ││ ││ ││╰─ attrValue.value + │ ││ ││ │╰─ attrValue "=1" + │ ││ ││ ╰─ attrName + │ ││ │╰─ tagVar.value + │ ││ ╰─ tagVar "/x" + │ │╰─ tagName "let" + ╰─ ╰─ openTagStart +3╭─ + │ ││ ││ │││╰─ openTagEnd:selfClosed "/>" + │ ││ ││ ││╰─ attrValue.value + │ ││ ││ │╰─ attrValue "=1" + │ ││ ││ ╰─ attrName + │ ││ │╰─ tagVar.value + │ ││ ╰─ tagVar "/x" + │ │╰─ tagName "let" + ╰─ ╰─ openTagStart +4╭─ + │ ││ ││ │││╰─ openTagEnd:selfClosed "/>" + │ ││ ││ ││╰─ attrValue.value + │ ││ ││ │╰─ attrValue "=1" + │ ││ ││ ╰─ attrName + │ ││ │╰─ tagVar.value + │ ││ ╰─ tagVar "/x" + │ │╰─ tagName "let" + ╰─ ╰─ openTagStart +5╰─ \ No newline at end of file diff --git a/src/__tests__/fixtures/comma-after-tag-variable/input.marko b/src/__tests__/fixtures/comma-after-tag-variable/input.marko new file mode 100644 index 00000000..d513219b --- /dev/null +++ b/src/__tests__/fixtures/comma-after-tag-variable/input.marko @@ -0,0 +1,4 @@ + + + + diff --git a/src/states/OPEN_TAG.ts b/src/states/OPEN_TAG.ts index 34048783..e8ae3d0d 100644 --- a/src/states/OPEN_TAG.ts +++ b/src/states/OPEN_TAG.ts @@ -37,6 +37,7 @@ const CONCISE_TAG_VAR_TERMINATORS = [ CODE.OPEN_PAREN, CODE.PIPE, CODE.EQUAL, + CODE.COMMA, [CODE.COLON, CODE.EQUAL], ]; @@ -45,6 +46,7 @@ const HTML_TAG_VAR_TERMINATORS = [ CODE.OPEN_PAREN, CODE.PIPE, CODE.EQUAL, + CODE.COMMA, [CODE.COLON, CODE.EQUAL], [CODE.FORWARD_SLASH, CODE.CLOSE_ANGLE_BRACKET], ];