{"record":{"id":"408ac2233e406034","repo":"karatelabs/karate","slug":"await-is-a-reserved-word-in-a-class-static-initialization","errorCode":null,"errorMessage":"'await' is a reserved word in a class static initialization block","messagePattern":"'await' is a reserved word in a class static initialization block","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":685,"sourceCode":"     *       check is on the token — skipping the positions where it is a property name\n     *       rather than a reference.</li>\n     * </ul>\n     * {@code arguments} is equally illegal per spec but is not rejected here: telling a\n     * reference from the many legal {@code x.arguments} / {@code {arguments: …}} spellings\n     * costs more than the rule is worth.\n     */\n    private void checkStaticBlockBody(Node node, int flags) {\n        boolean keepAwait = (flags & SB_AWAIT_OK) == 0 && !isPropertyNameHolder(node);\n        int last = node.size() - 1;\n        TokenType prev = null;\n        for (int i = 0; i <= last; i++) {\n            Node child = node.get(i);\n            if (child.isToken()) {\n                TokenType type = child.token.type;\n                // `x.await` / `x?.await` name a member, they do not reference one\n                if (keepAwait && type == IDENT && prev != DOT && prev != QUES_DOT\n                        && isIdentText(child.token, \"await\")) {\n                    throw new ParserException(\"'await' is a reserved word in a class static initialization block\");\n                }\n                prev = type;\n                continue;\n            }\n            prev = null;\n            int childFlags = flags;\n            switch (child.type) {\n                case RETURN_STMT -> {\n                    if ((flags & SB_FN) == 0) {\n                        throw new ParserException(\"'return' is not allowed in a class static initialization block\");\n                    }\n                }\n                case BREAK_STMT -> {\n                    if ((flags & (SB_FN | SB_LOOP | SB_SWITCH)) == 0 && child.size() == 1) {\n                        throw new ParserException(\"'break' may not cross a class static initialization block\");\n                    }\n                }\n                case CONTINUE_STMT -> {","sourceCodeStart":667,"sourceCodeEnd":703,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L667-L703","documentation":"Inside a class static initialization block, `await` is a reserved word and cannot be used as an identifier (the block is implicitly an async-like context). The Karate JS parser throws this when `await` appears in identifier position, except as a member name after `.` or `?.` (e.g. `x.await` is allowed). Rename the identifier.","triggerScenarios":"Parsing a class `static { ... }` block whose body uses `await` as a variable name or property shorthand (`{ await }`, `let await = ...`), detected by the static-block body walker with keepAwait member-access exemption.","commonSituations":"Code using `await` as a variable (legal in sloppy non-module scripts) being moved into a static block; minified/generated code that picked `await` as a name; upgrading class fields to static blocks during refactoring.","solutions":["Rename the identifier from `await` to something else (e.g. `awaitResult`, `aWait`).","Access members via dot syntax (`obj.await`) which remains legal, instead of destructuring/shorthand using the bare word.","Move the code out of the static block into a regular static method if the identifier cannot be renamed."],"exampleFix":"// before\nclass C { static { let await = fetchCfg(); } }\n// after\nclass C { static { let cfg = fetchCfg(); } }","handlingStrategy":"validation","validationCode":"// flag `await` used as a bare identifier inside static block sources\nfunction awaitSafe(src) { return !/(?<![\\w$.])await(?![\\w$])(?!\\s*:)/.test(src.replace(/\\.await|\\?\\.await/g, '')); }","typeGuard":null,"tryCatchPattern":"try { karate.eval(blockSrc); } catch (e) { if (String(e).includes(\"'await' is a reserved word\")) { /* rename identifier */ } }","preventionTips":["Never use reserved words (`await`, `yield`, `let`) as identifiers.","When migrating code into class static blocks, rename legacy `await` variables.","Configure linters to disallow reserved-word identifiers."],"tags":["javascript","parser","syntax-error","reserved-word","static-block"],"backgroundTag":"javascript-syntax-error","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"}