diff --git a/.changeset/tall-moons-enjoy.md b/.changeset/tall-moons-enjoy.md new file mode 100644 index 0000000..040019d --- /dev/null +++ b/.changeset/tall-moons-enjoy.md @@ -0,0 +1,5 @@ +--- +"htmljs-parser": patch +--- + +Always consume next character of expression if terminator was preceded by an operator. diff --git a/src/__tests__/fixtures/attr-complex-unary/__snapshots__/attr-complex-unary.expected.txt b/src/__tests__/fixtures/attr-complex-unary/__snapshots__/attr-complex-unary.expected.txt index 75c9de4..e7d3319 100644 --- a/src/__tests__/fixtures/attr-complex-unary/__snapshots__/attr-complex-unary.expected.txt +++ b/src/__tests__/fixtures/attr-complex-unary/__snapshots__/attr-complex-unary.expected.txt @@ -5,31 +5,31 @@ ╰─ ╰─ tagName "tag" 2╭─ ╰─ ╰─ openTagEnd -3╭─ tag a = class, b - │ │ │ │ │ ╰─ attrName - │ │ │ │ ╰─ attrValue.value "class" - │ │ │ ╰─ attrValue "= class" +3╭─ tag a = class {}, b + │ │ │ │ │ ╰─ attrName + │ │ │ │ ╰─ attrValue.value "class {}" + │ │ │ ╰─ attrValue "= class {}" │ │ ╰─ attrName │ ├─ closeTagEnd(tag) ╰─ ╰─ tagName "tag" 4╭─ ╰─ ╰─ openTagEnd -5╭─ - │ ││ │ │ │ ││ │ ╰─ closeTagEnd(tag) - │ ││ │ │ │ ││ ╰─ closeTagName "tag" - │ ││ │ │ │ │╰─ closeTagStart " + │ ││ │ │ │ ││ │ ╰─ closeTagEnd(tag) + │ ││ │ │ │ ││ ╰─ closeTagName "tag" + │ ││ │ │ │ │╰─ closeTagStart " - │ ││ │ │ │ ╰─ openTagEnd:selfClosed "/>" - │ ││ │ │ ╰─ attrValue.value "class" - │ ││ │ ╰─ attrValue "= class" +7╭─ + │ ││ │ │ │ ╰─ openTagEnd:selfClosed "/>" + │ ││ │ │ ╰─ attrValue.value "class {}" + │ ││ │ ╰─ attrValue "= class {}" │ ││ ╰─ attrName │ │╰─ tagName "tag" ╰─ ╰─ openTagStart @@ -69,9 +69,9 @@ ╰─ ╰─ tagName "tag" 16╭─ ╰─ ╰─ openTagEnd -17╭─ tag a = test+class b - │ │ │ │ ╰─ attrValue.value "test+class b" - │ │ │ ╰─ attrValue "= test+class b" +17╭─ tag a = test+class b {} + │ │ │ │ ╰─ attrValue.value "test+class b {}" + │ │ │ ╰─ attrValue "= test+class b {}" │ │ ╰─ attrName │ ├─ closeTagEnd(tag) ╰─ ╰─ tagName "tag" diff --git a/src/__tests__/fixtures/attr-complex-unary/input.marko b/src/__tests__/fixtures/attr-complex-unary/input.marko index e9e73b2..e913441 100644 --- a/src/__tests__/fixtures/attr-complex-unary/input.marko +++ b/src/__tests__/fixtures/attr-complex-unary/input.marko @@ -1,10 +1,10 @@ tag a = class b {} -tag a = class, b +tag a = class {}, b - + - + tag a = classthing b @@ -14,4 +14,4 @@ tag a = test_class b tag a = test$class b -tag a = test+class b +tag a = test+class b {} diff --git a/src/__tests__/fixtures/tag-var-type-with-parens/__snapshots__/tag-var-type-with-parens.expected.txt b/src/__tests__/fixtures/tag-var-type-with-parens/__snapshots__/tag-var-type-with-parens.expected.txt new file mode 100644 index 0000000..50f744d --- /dev/null +++ b/src/__tests__/fixtures/tag-var-type-with-parens/__snapshots__/tag-var-type-with-parens.expected.txt @@ -0,0 +1,50 @@ +1╭─ let/a:(B | C) = D + │ │ ││ │ ╰─ attrValue.value + │ │ ││ ├─ attrValue "= D" + │ │ ││ ╰─ attrName + │ │ │╰─ tagVar.value "a:(B | C)" + │ │ ╰─ tagVar "/a:(B | C)" + ╰─ ╰─ tagName "let" +2╭─ + ╰─ ╰─ openTagEnd +3╭─ let/a: (B | C) = D + │ │ ││ │ ╰─ attrValue.value + │ │ ││ ├─ attrValue "= D" + │ │ ││ ╰─ attrName + │ │ │╰─ tagVar.value "a: (B | C)" + │ │ ╰─ tagVar "/a: (B | C)" + │ ├─ closeTagEnd(let) + ╰─ ╰─ tagName "let" +4╭─ + ╰─ ╰─ openTagEnd +5╭─ let/a : (B | C) = D + │ │ ││ │ ╰─ attrValue.value + │ │ ││ ├─ attrValue "= D" + │ │ ││ ╰─ attrName + │ │ │╰─ tagVar.value "a : (B | C)" + │ │ ╰─ tagVar "/a : (B | C)" + │ ├─ closeTagEnd(let) + ╰─ ╰─ tagName "let" +6╭─ + ╰─ ╰─ openTagEnd +7╭─ let/a :(B | C) = D + │ │ ││ │ ╰─ attrValue.value + │ │ ││ ├─ attrValue "= D" + │ │ ││ ╰─ attrName + │ │ │╰─ tagVar.value "a :(B | C)" + │ │ ╰─ tagVar "/a :(B | C)" + │ ├─ closeTagEnd(let) + ╰─ ╰─ tagName "let" +8╭─ + ╰─ ╰─ openTagEnd +9╭─ let/a: B & (C | D) = D + │ │ ││ │ ╰─ attrValue.value + │ │ ││ ├─ attrValue "= D" + │ │ ││ ╰─ attrName + │ │ │╰─ tagVar.value "a: B & (C | D)" + │ │ ╰─ tagVar "/a: B & (C | D)" + │ ├─ closeTagEnd(let) + ╰─ ╰─ tagName "let" +10╭─ + │ ├─ openTagEnd + ╰─ ╰─ closeTagEnd(let) \ No newline at end of file diff --git a/src/__tests__/fixtures/tag-var-type-with-parens/input.marko b/src/__tests__/fixtures/tag-var-type-with-parens/input.marko new file mode 100644 index 0000000..146c2e5 --- /dev/null +++ b/src/__tests__/fixtures/tag-var-type-with-parens/input.marko @@ -0,0 +1,9 @@ +let/a:(B | C) = D + +let/a: (B | C) = D + +let/a : (B | C) = D + +let/a :(B | C) = D + +let/a: B & (C | D) = D diff --git a/src/states/EXPRESSION.ts b/src/states/EXPRESSION.ts index a0e91bf..cd86619 100644 --- a/src/states/EXPRESSION.ts +++ b/src/states/EXPRESSION.ts @@ -61,8 +61,23 @@ export const EXPRESSION: StateDefinition = { } if (expression.shouldTerminate(code, this.data, this.pos)) { - this.exitState(); - return; + let wasExpression = false; + if (expression.operators) { + const prevNonWhitespacePos = lookBehindWhile( + isWhitespaceCode, + this.data, + this.pos - 1 + ); + if (prevNonWhitespacePos > expression.start) { + wasExpression = + lookBehindForOperator(this.data, prevNonWhitespacePos) !== -1; + } + } + + if (!wasExpression) { + this.exitState(); + return; + } } }