Skip to content

Commit e8463ff

Browse files
committed
fix: always consume terminator if it is preceded by an operator
1 parent be73442 commit e8463ff

File tree

6 files changed

+103
-24
lines changed

6 files changed

+103
-24
lines changed

.changeset/tall-moons-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"htmljs-parser": patch
3+
---
4+
5+
Always consume next character of expression if terminator was preceded by an operator.

src/__tests__/fixtures/attr-complex-unary/__snapshots__/attr-complex-unary.expected.txt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
╰─ ╰─ tagName "tag"
66
2╭─
77
╰─ ╰─ openTagEnd
8-
3╭─ tag a = class, b
9-
│ │ │ │ │ ╰─ attrName
10-
│ │ │ │ ╰─ attrValue.value "class"
11-
│ │ │ ╰─ attrValue "= class"
8+
3╭─ tag a = class {}, b
9+
│ │ │ │ │ ╰─ attrName
10+
│ │ │ │ ╰─ attrValue.value "class {}"
11+
│ │ │ ╰─ attrValue "= class {}"
1212
│ │ ╰─ attrName
1313
│ ├─ closeTagEnd(tag)
1414
╰─ ╰─ tagName "tag"
1515
4╭─
1616
╰─ ╰─ openTagEnd
17-
5╭─ <tag a = class></tag>
18-
│ ││ │ │ │ ││ │ ╰─ closeTagEnd(tag)
19-
│ ││ │ │ │ ││ ╰─ closeTagName "tag"
20-
│ ││ │ │ │ │╰─ closeTagStart "</"
21-
│ ││ │ │ │ ╰─ openTagEnd
22-
│ ││ │ │ ╰─ attrValue.value "class"
23-
│ ││ │ ╰─ attrValue "= class"
17+
5╭─ <tag a = class {}></tag>
18+
│ ││ │ │ │ ││ │ ╰─ closeTagEnd(tag)
19+
│ ││ │ │ │ ││ ╰─ closeTagName "tag"
20+
│ ││ │ │ │ │╰─ closeTagStart "</"
21+
│ ││ │ │ │ ╰─ openTagEnd
22+
│ ││ │ │ ╰─ attrValue.value "class {}"
23+
│ ││ │ ╰─ attrValue "= class {}"
2424
│ ││ ╰─ attrName
2525
│ │╰─ tagName "tag"
2626
│ ├─ closeTagEnd(tag)
2727
╰─ ╰─ openTagStart
2828
6├─
29-
7╭─ <tag a = class/>
30-
│ ││ │ │ │ ╰─ openTagEnd:selfClosed "/>"
31-
│ ││ │ │ ╰─ attrValue.value "class"
32-
│ ││ │ ╰─ attrValue "= class"
29+
7╭─ <tag a = class {}/>
30+
│ ││ │ │ │ ╰─ openTagEnd:selfClosed "/>"
31+
│ ││ │ │ ╰─ attrValue.value "class {}"
32+
│ ││ │ ╰─ attrValue "= class {}"
3333
│ ││ ╰─ attrName
3434
│ │╰─ tagName "tag"
3535
╰─ ╰─ openTagStart
@@ -69,9 +69,9 @@
6969
╰─ ╰─ tagName "tag"
7070
16╭─
7171
╰─ ╰─ openTagEnd
72-
17╭─ tag a = test+class b
73-
│ │ │ │ ╰─ attrValue.value "test+class b"
74-
│ │ │ ╰─ attrValue "= test+class b"
72+
17╭─ tag a = test+class b {}
73+
│ │ │ │ ╰─ attrValue.value "test+class b {}"
74+
│ │ │ ╰─ attrValue "= test+class b {}"
7575
│ │ ╰─ attrName
7676
│ ├─ closeTagEnd(tag)
7777
╰─ ╰─ tagName "tag"
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
tag a = class b {}
22

3-
tag a = class, b
3+
tag a = class {}, b
44

5-
<tag a = class></tag>
5+
<tag a = class {}></tag>
66

7-
<tag a = class/>
7+
<tag a = class {}/>
88

99
tag a = classthing b
1010

@@ -14,4 +14,4 @@ tag a = test_class b
1414

1515
tag a = test$class b
1616

17-
tag a = test+class b
17+
tag a = test+class b {}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
1╭─ let/a:(B | C) = D
2+
│ │ ││ │ ╰─ attrValue.value
3+
│ │ ││ ├─ attrValue "= D"
4+
│ │ ││ ╰─ attrName
5+
│ │ │╰─ tagVar.value "a:(B | C)"
6+
│ │ ╰─ tagVar "/a:(B | C)"
7+
╰─ ╰─ tagName "let"
8+
2╭─
9+
╰─ ╰─ openTagEnd
10+
3╭─ let/a: (B | C) = D
11+
│ │ ││ │ ╰─ attrValue.value
12+
│ │ ││ ├─ attrValue "= D"
13+
│ │ ││ ╰─ attrName
14+
│ │ │╰─ tagVar.value "a: (B | C)"
15+
│ │ ╰─ tagVar "/a: (B | C)"
16+
│ ├─ closeTagEnd(let)
17+
╰─ ╰─ tagName "let"
18+
4╭─
19+
╰─ ╰─ openTagEnd
20+
5╭─ let/a : (B | C) = D
21+
│ │ ││ │ ╰─ attrValue.value
22+
│ │ ││ ├─ attrValue "= D"
23+
│ │ ││ ╰─ attrName
24+
│ │ │╰─ tagVar.value "a : (B | C)"
25+
│ │ ╰─ tagVar "/a : (B | C)"
26+
│ ├─ closeTagEnd(let)
27+
╰─ ╰─ tagName "let"
28+
6╭─
29+
╰─ ╰─ openTagEnd
30+
7╭─ let/a :(B | C) = D
31+
│ │ ││ │ ╰─ attrValue.value
32+
│ │ ││ ├─ attrValue "= D"
33+
│ │ ││ ╰─ attrName
34+
│ │ │╰─ tagVar.value "a :(B | C)"
35+
│ │ ╰─ tagVar "/a :(B | C)"
36+
│ ├─ closeTagEnd(let)
37+
╰─ ╰─ tagName "let"
38+
8╭─
39+
╰─ ╰─ openTagEnd
40+
9╭─ let/a: B & (C | D) = D
41+
│ │ ││ │ ╰─ attrValue.value
42+
│ │ ││ ├─ attrValue "= D"
43+
│ │ ││ ╰─ attrName
44+
│ │ │╰─ tagVar.value "a: B & (C | D)"
45+
│ │ ╰─ tagVar "/a: B & (C | D)"
46+
│ ├─ closeTagEnd(let)
47+
╰─ ╰─ tagName "let"
48+
10╭─
49+
│ ├─ openTagEnd
50+
╰─ ╰─ closeTagEnd(let)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let/a:(B | C) = D
2+
3+
let/a: (B | C) = D
4+
5+
let/a : (B | C) = D
6+
7+
let/a :(B | C) = D
8+
9+
let/a: B & (C | D) = D

src/states/EXPRESSION.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,23 @@ export const EXPRESSION: StateDefinition<ExpressionMeta> = {
6161
}
6262

6363
if (expression.shouldTerminate(code, this.data, this.pos)) {
64-
this.exitState();
65-
return;
64+
let wasExpression = false;
65+
if (expression.operators) {
66+
const prevNonWhitespacePos = lookBehindWhile(
67+
isWhitespaceCode,
68+
this.data,
69+
this.pos - 1
70+
);
71+
if (prevNonWhitespacePos > expression.start) {
72+
wasExpression =
73+
lookBehindForOperator(this.data, prevNonWhitespacePos) !== -1;
74+
}
75+
}
76+
77+
if (!wasExpression) {
78+
this.exitState();
79+
return;
80+
}
6681
}
6782
}
6883

0 commit comments

Comments
 (0)