{"record":{"id":"e7f036e71ac91698","repo":"karatelabs/karate","slug":"super-keyword-is-only-valid-inside-a-class-method","errorCode":null,"errorMessage":"'super' keyword is only valid inside a class method","messagePattern":"'super' keyword is only valid inside a class method","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/Interpreter.java","lineNumber":1573,"sourceCode":"            Object value = evalFieldInitializer(f.initializer, thisObj, context);\n            if (context.isError()) {\n                return;\n            }\n            if (f.privateName == null) {\n                obj.putMember(f.key, value); // public fields are enumerable own properties\n            } else {\n                obj.putPrivate(f.privateName, value);\n            }\n        }\n    }\n\n    // Resolves the property-lookup target for `super.x` / `super[x]`: the\n    // [[Prototype]] of the active method's home object (the parent class's\n    // prototype, or the parent constructor for a static method).\n    static ObjectLike evalSuperBase(CoreContext context) {\n        JsFunctionNode active = context.activeFunction;\n        if (active == null || active.homeObject == null) {\n            throw JsErrorException.syntaxError(\"'super' keyword is only valid inside a class method\");\n        }\n        ObjectLike home = active.homeObject;\n        Object proto = home.getPrototype();\n        return proto instanceof ObjectLike ol ? ol : null;\n    }\n\n    // Resolved shape of a CLASS_METHOD node. Methods/accessors end in FN_EXPR;\n    // fields have no FN_EXPR (optional trailing [EQ, EXPR] initializer):\n    //   [modifier tokens...] <key (1 name token | L_BRACKET EXPR R_BRACKET)>\n    //       ( FN_EXPR | [EQ EXPR]? )\n    private static final class ClassMember {\n        boolean isStatic;\n        boolean isAccessor;\n        boolean isField;\n        boolean isPrivate;  // key was a `#name` token\n        PrivateName privateName; // resolved identity, when private\n        String kind;        // \"get\" / \"set\" / null\n        boolean computed;","sourceCodeStart":1555,"sourceCodeEnd":1591,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/Interpreter.java#L1555-L1591","documentation":"Thrown as a syntax error when `super.x` / `super[x]` is evaluated in a context with no active class function or no home object. `super.x` resolves via the [[Prototype]] of the enclosing method's home object; without a class method context there is nothing to resolve against.","triggerScenarios":"Using `super.someMethod()` inside a plain function, arrow function defined outside a class method, object-literal method, or top-level code.","commonSituations":"Moving a class method body into a standalone helper while keeping its `super.` calls; destructuring a method off a class and calling it elsewhere.","solutions":["Keep `super.x` calls inside class methods (or object-literal shorthand methods bound to a home object).","Capture the parent reference explicitly (e.g. `const parent = Parent.prototype`) and call `parent.method.call(this)` when extracting code.","Assign the extracted function as a class method if super-property access is required."],"exampleFix":"// before\nfunction describe() { return super.describe(); }\n// after\nclass Child extends Parent {\n  describe() { return super.describe(); }\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { obj.copiedMethod(); } catch (e) { if (String(e).includes(\"'super' keyword\")) { /* rebind as class method */ } }","preventionTips":["Don't destructure or detach class methods that use super.x","Use explicit Parent.prototype references when extracting code","Keep super-property access inside class method bodies"],"tags":["javascript","super","class","syntax-error"],"backgroundTag":"invalid-super-usage","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}