{"record":{"id":"007a3a504ec8521e","repo":"karatelabs/karate","slug":"constructor-is-a-reserved-private-name","errorCode":null,"errorMessage":"#constructor is a reserved private name","messagePattern":"#constructor is a reserved private name","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":355,"sourceCode":"                if (c.token.type == PRIVATE_NAME) {\n                    key = c;\n                    break;\n                }\n                String t = c.getText();\n                if (\"get\".equals(t)) {\n                    kind = 1;\n                } else if (\"set\".equals(t)) {\n                    kind = 2;\n                } else if (\"static\".equals(t)) {\n                    kind |= 8;\n                }\n            }\n            if (key == null) {\n                continue;\n            }\n            String name = key.getText();\n            if (\"#constructor\".equals(name)) {\n                throw new ParserException(\"#constructor is a reserved private name\");\n            }\n            if (names == null) {\n                names = new HashSet<>(4);\n                kinds = new HashMap<>(4);\n            }\n            Integer prior = kinds.put(name, kind);\n            // a get/set pair at the same placement is the sole legal duplicate\n            boolean accessorPair = prior != null && (prior & 8) == (kind & 8)\n                    && (prior & 4) == 0 && (kind & 4) == 0 && ((prior & 3) | (kind & 3)) == 3;\n            if (prior != null && !accessorPair) {\n                throw new ParserException(\"duplicate private name \" + name + \" in class body\");\n            }\n            names.add(name);\n        }\n        return names == null ? parent : new PrivateScope(parent, names);\n    }\n\n    /**","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L337-L373","documentation":"`constructor` is reserved by the spec and cannot be used as a private class member name. While building the class's PrivateScope, classPrivateScand checks each member key and immediately rejects the literal name `#constructor`, regardless of member kind (field, method, getter, setter, static).","triggerScenarios":"Declaring any class member named `#constructor` — e.g. `class C { #constructor() {} }` or `class C { static #constructor = 1; }` — triggers this during privateNodeChecks.","commonSituations":"Confusion between the public `constructor` method and private naming schemes; generated/transformed code that prefixed all members with `#`; attempts to hide the constructor via privacy.","solutions":["Rename the member, e.g. `#ctor` or `#init`, and update references","Use the normal public `constructor(...)` method for construction logic — it cannot and should not be private","If a private helper should run at construction, call it from the public constructor"],"exampleFix":"// before\nclass C { #constructor() { ... } }\n// after\nclass C { #ctor() { ... } constructor() { this.#ctor(); } }","handlingStrategy":"validation","validationCode":"// Reject #constructor anywhere in class source:\nconst hasReserved = /#constructor\\b/.test(src);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never name private members after reserved slots (constructor, prototype)","Use conventional names like #ctor/#init for private construction helpers","Run a quick grep for `#constructor` before shipping class code"],"tags":["javascript","parser","classes","reserved-names"],"backgroundTag":"reserved-word-usage","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"}