Skip to content

Commit e38b29e

Browse files
committed
fix: expression parsing improvements
1 parent b7f3d3e commit e38b29e

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1╭─ a=x * y
2+
│ ││╰─ attrValue.value "x * y"
3+
│ │├─ attrValue "=x * y"
4+
│ │╰─ attrName
5+
╰─ ╰─ tagName
6+
2╭─ b=x ** y
7+
│ ││╰─ attrValue.value "x ** y"
8+
│ │├─ attrValue "=x ** y"
9+
│ │╰─ attrName
10+
│ ├─ closeTag(a)
11+
│ ├─ openTagEnd(a)
12+
╰─ ╰─ tagName
13+
3╭─ c=x &&
14+
│ ││╰─ attrValue.value "x &&\ny"
15+
│ │├─ attrValue "=x &&\ny"
16+
│ │╰─ attrName
17+
│ ├─ closeTag(b)
18+
│ ├─ openTagEnd(b)
19+
╰─ ╰─ tagName
20+
4╭─ y
21+
│ ├─ closeTag(c)
22+
╰─ ╰─ openTagEnd(c)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a=x * y
2+
b=x ** y
3+
c=x &&
4+
y

src/states/EXPRESSION.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,28 +224,28 @@ export const EXPRESSION: StateDefinition<ExpressionMeta> = {
224224

225225
function buildOperatorPattern(isConcise: boolean) {
226226
const binary =
227-
"[*%<&^|?:]" + // Any of these characters can always continue an expression
228-
"|=[=>]" + // We only continue after an equals if it is => or ==
227+
"[!*%<&^|?:]+" + // Any of these characters can always continue an expression
228+
"|=[=>]+" + // We only continue after an equals if it is => or ==
229229
"|/(?:\\b|\\s)" + // We only continue after a forward slash if it isn't //, /* or />
230230
"|\\.(?=\\s)" + // We only continue after a period if it's followed by a space
231231
"|\\bin(?:stanceof)(?=\\s+[^=/,;:>])"; // We only continue after word operators (instanceof/in) when they are not followed by a terminator
232232
const unary =
233-
"!" +
234-
"|a(?:sync|wait)" +
233+
"\\b(?:" +
234+
"a(?:sync|wait)" +
235235
"|class" +
236236
"|function" +
237237
"|new" +
238238
"|typeof" +
239-
"|void";
239+
"|void" +
240+
")\\b";
240241
const lookAheadPattern =
241242
"\\s*(?:" +
242243
binary +
243-
"|\\+" + // any number of plus signs are ok.
244-
`|-${isConcise ? "[^-]" : ""}` + // in concise mode only consume minus signs if not --
245-
`|>${isConcise ? "" : "[>=]"}` + // in html mode only consume closing angle brackets if it is >= or >>
244+
"|\\++" + // any number of plus signs are ok.
245+
`|-${isConcise ? "[^-]" : "+"}` + // in concise mode only consume minus signs if not --
246+
`|>+${isConcise ? "" : "[>=]"}` + // in html mode only consume closing angle brackets if it is >= or >>
246247
")\\s*" +
247248
`|\\s+(?=[${isConcise ? "" : "["}{(])`; // if we have spaces followed by an opening bracket, we'll consume the spaces and let the expression state handle the brackets
248-
249249
const lookBehindPattern = `(?<=${unary}|${binary}|[^-]-|[^+]\\+)`;
250250
return new RegExp(`${lookAheadPattern}|${lookBehindPattern}`, "y");
251251
}

0 commit comments

Comments
 (0)