Skip to content

Error on class static field #116

Closed
Closed
@fgeorges

Description

@fgeorges

Describe the bug:

When the code to confuse contains a class with a static field, an error is thrown and code generation does not complete.

Config and Small code sample

Repro:

require("js-confuser").obfuscate(`
  class C {
    static v = 42;
  }
`, {
  target: "node",
  preset: "low",
}).then(obfuscated => {
  console.log(obfuscated)
})

Expected behavior

This example should pass and generate the corresponding, confused code.

Actual behavior

It throws an error:

xxx/node_modules/escodegen/escodegen.js:2525
        result = this[type](expr, precedence, flags);
                           ^

TypeError: this[type] is not a function
    at CodeGenerator.generateExpression (xxx/node_modules/escodegen/escodegen.js:2525:28)
    at xxx/node_modules/escodegen/escodegen.js:1133:38
    at withIndent (xxx/node_modules/escodegen/escodegen.js:581:9)
    at CodeGenerator.ClassBody (xxx/node_modules/escodegen/escodegen.js:1128:13)
    at CodeGenerator.generateStatement (xxx/node_modules/escodegen/escodegen.js:2538:33)
    at CodeGenerator.ClassDeclaration (xxx/node_modules/escodegen/escodegen.js:1159:30)
    at CodeGenerator.generateStatement xxx/node_modules/escodegen/escodegen.js:2538:33)
    at CodeGenerator.Program (xxx/node_modules/escodegen/escodegen.js:1718:43)
    at CodeGenerator.generateStatement (xxx/node_modules/escodegen/escodegen.js:2538:33)
    at generateInternal (xxx/node_modules/escodegen/escodegen.js:2559:28)

Additional context

It seems that in CodeGenerator.prototype.generateExpression(), the expression this[type] is undefined when type is PropertyDefinition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions