{"record":{"id":"7c7cc8bbd75e02a5","repo":"karatelabs/karate","slug":"invalid-sitename-comma-expression","errorCode":null,"errorMessage":"invalid ${siteName}: comma expression","messagePattern":"invalid (.+?): comma expression","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":1697,"sourceCode":"        }\n        // Top-level Object/Array literal refines into a destructuring pattern.\n        if (n.type == NodeType.LIT_EXPR && n.size() >= 1) {\n            NodeType lit = n.getFirst().type;\n            if (lit == NodeType.LIT_ARRAY || lit == NodeType.LIT_OBJECT) {\n                return;\n            }\n        }\n        // Peel any layers of parens. Per spec, a ParenthesizedExpression around an\n        // ObjectLiteral or ArrayLiteral does NOT refine to a destructuring pattern,\n        // so it becomes invalid; everything else falls through to the simple check.\n        while (n.type == NodeType.PAREN_EXPR) {\n            // PAREN_EXPR shape: [(, body, )]\n            Node body = n.size() >= 2 ? n.get(1) : null;\n            if (body == null) {\n                throw new ParserException(\"invalid \" + siteName);\n            }\n            if (body.type == NodeType.EXPR_LIST && body.size() != 1) {\n                throw new ParserException(\"invalid \" + siteName + \": comma expression\");\n            }\n            Node inner = stripExprWrappers(body);\n            if (inner == null) {\n                throw new ParserException(\"invalid \" + siteName);\n            }\n            if (inner.type == NodeType.LIT_EXPR && inner.size() >= 1) {\n                NodeType lit = inner.getFirst().type;\n                if (lit == NodeType.LIT_ARRAY || lit == NodeType.LIT_OBJECT) {\n                    throw new ParserException(\"invalid \" + siteName + \": parenthesized destructuring pattern\");\n                }\n            }\n            n = inner;\n        }\n        switch (n.type) {\n            case REF_EXPR -> {\n                // REF_EXPR is single-arg arrow `x => ...` when its first child is an\n                // FN_ARROW_EXPR rather than the IDENT token; that form is invalid.\n                if (n.size() >= 1 && !n.getFirst().isToken()","sourceCodeStart":1679,"sourceCodeEnd":1715,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L1679-L1715","documentation":"Karate's parser rejects a parenthesized comma expression used where a destructuring pattern or assignment target is required, e.g. `(a, b) = arr`. Parentheses do not turn a comma-separated list into a valid target; only a single expression may appear. The parser detects an EXPR_LIST with more than one element inside the PAREN_EXPR and fails with the site name included.","triggerScenarios":"Parsing `(a, b) = [1, 2];` or similar where the parenthesized body's EXPR_LIST has size != 1 — the check fires before the target is refined further.","commonSituations":"Expecting parentheses to enable tuple-style assignment like in Python; converting array-destructuring code by wrapping it in parens; hand-written code confusing sequence expressions with destructuring.","solutions":["Remove the parentheses and use plain array destructuring: `[a, b] = [1, 2]`","Split into separate assignment statements, one per variable","Remove the comma if only one of the targets was intended"],"exampleFix":"// before\n(a, b) = pair; // comma expression not a target\n// after\n[a, b] = pair;","handlingStrategy":"validation","validationCode":"// detect comma-separated parenthesized assignment targets\nif (/^\\(\\s*[A-Za-z_$][\\w$]*\\s*,\\s*[A-Za-z_$][\\w$]*\\s*\\)\\s*=[^=]/.test(src.trim())) {\n  throw new Error('parenthesized comma expression is not a valid assignment target');\n}","typeGuard":null,"tryCatchPattern":"try {\n  runScript(src);\n} catch (e) {\n  if (String(e).includes('comma expression')) {\n    // convert to array destructuring\n  }\n  throw e;\n}","preventionTips":["Use [a, b] = pair, never (a, b) = pair, for tuple assignment","Remember JavaScript has no tuple assignment syntax","Test patterns borrowed from other languages before relying on them"],"tags":["javascript","parser","syntax","comma-expression"],"backgroundTag":"invalid-argument-format","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}