mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-04 22:31:33 +09:00
fix: validate unexpected closing paren in expressions (#4803)
User found syntax error which was accepted by linter. Turns out parseExpressionAt allows something like this ```js (a + b)) ``` Switched back to `parse` which actually gives proper result when expression is wrapped with parens.
This commit is contained in:
1 parent
a0189c1b72
commit
5546301aeb
2 files changed
+10
-3
No files matched your search
@@ -40,6 +40,9 @@ describe("lint expression", () => {
|
||||
expect(lintExpression({ expression: `a + ` })).toEqual([
|
||||
error(4, 4, "Unexpected token"),
|
||||
]);
|
||||
expect(lintExpression({ expression: `"string" + a)` })).toEqual([
|
||||
error(13, 13, "Unexpected token"),
|
||||
]);
|
||||
});
|
||||
|
||||
test("restrict expression syntax", () => {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { type Expression, type Identifier, parseExpressionAt } from "acorn";
|
||||
import {
|
||||
type Expression,
|
||||
type Identifier,
|
||||
parse,
|
||||
parseExpressionAt,
|
||||
} from "acorn";
|
||||
import { simple } from "acorn-walk";
|
||||
import type { DataSources } from "./schema/data-sources";
|
||||
import type { Scope } from "./scope";
|
||||
@@ -51,8 +56,7 @@ export const lintExpression = ({
|
||||
try {
|
||||
// wrap expression with parentheses to force acorn parse whole expression
|
||||
// instead of just first valid part
|
||||
// https://github.com/acornjs/acorn/tree/master/acorn
|
||||
const root = parseExpressionAt(`(${expression})`, 0, {
|
||||
const root = parse(`(${expression})`, {
|
||||
ecmaVersion: "latest",
|
||||
// support parsing import to forbid explicitly
|
||||
sourceType: "module",
|
||||
|
||||
Reference in new issue
Block a user