Skip to content

fat arrow Unexpected token in the Class #909

Description

@iterion-mikehit

Hi, try this to obfuscatge with online obfuscator. Any idea why error is raising?
class alfaTest{
constructor() {
let test = {}
}
setScreen = () => {
console.log('test');
}
}

Raise an error

Error: ERROR at line 5: Unexpected token (5:14)

...setScreen = () => {...

Activity

  1. sanex3339 commented on Apr 15, 2021

    @sanex3339
    Member

    This is because of class properties that are currently on stage 3 of ECMA proposal and does not support by acorn and escodegen

  2. BlackYuzia commented on Apr 15, 2021

    @BlackYuzia
    Contributor

    @iterion-mikehit you should use methods, like:

    class Kruzya {
     // ...
     
     test() {console.log("test")}
    }

    second way:

    class Kruzya {
    constructor() {
      this.setScreen = () => {console.log("test")}; // typo but should work
    }
    }
  3. iterion-mikehit commented on Apr 15, 2021

    @iterion-mikehit
    Author

    Thank you I have a more complex JS code unfortunately rewrite it

  4. sanex3339 commented on Apr 26, 2021

    @sanex3339
    Member

    Now this proposal in stage 4. Acorn just has added the support of this feature, but estraverse/escodegen still does not support it. I'll keep this issue open.

  5. sanex3339 commented on May 6, 2021

    @sanex3339
    Member

    I forked estraverse too, but as the first step we have to wait until these PRs will be merged:
    eslint/js#486
    eslint/eslint-scope#69

    After that, I'll try to implement this feature in my fork of escodegen

  6. sanex3339 commented on May 6, 2021

    @sanex3339
    Member

    PR with the support of this feature in my fork of escodegen
    javascript-obfuscator/escodegen#3

  7. sanex3339 commented on May 6, 2021

    @sanex3339
    Member

    WIP PR to the obfuscator:
    #916

    Still need to wait until
    eslint/js#486
    eslint/eslint-scope#69

    will be finished.

  8. Bdethloff commented on May 7, 2021

    @Bdethloff

    I'm having the same problem.

    I'm trying to obfuscate several classes all of which have arrow function methods. In each file, the obfuscator reaches the first arrow function and throws this Error: ERROR at line 24: Unexpected token (24:18)

    An example of the smallest class

    import { xInit, yInit } from "../functions/displaySVG.js";
    import { createSvgText} from "../functions/drawSVG.js";
    import { currentUser } from "../script.js";
    
    export default class Label {
        constructor(text, position) {
            this.text = text;
            this.coordinates = {x: xInit, y: yInit};
            this.position = position;
        }
    
        drawLabel = () => {
            let matrixGroup = document.getElementById("matrixGroup");
            let label = createSvgText(
                this.text, 13, "#333639",
                this.coordinates.x, this.coordinates.y,
                `mapLabel labl-${this.position} draggable`
            );
            label.setAttribute("id", `labl-${this.position}`)
            label.setAttributeNS(null, "font-weight", "bold");
            label.setAttributeNS(null, "text-decoration", "underline");
    
            label.addEventListener("dblclick", currentUser.maps[0].deleteLabel);
    
            matrixGroup.appendChild(label);
        }
    
        setCoordinates = (x, y) => {
            this.coordinates.x = x;
            this.coordinates.y = y;
        }
    }
    

    Is the message here, we're waiting on...?
    eslint/js#486
    eslint/eslint-scope#69

    Sorry to hassle you

  9. sanex3339 commented on May 9, 2021

    @sanex3339
    Member
  10. Bdethloff commented on May 18, 2021

    @Bdethloff

    Any update on this?

  11. sanex3339 commented on May 18, 2021

    @sanex3339
    Member

    I linked all related PR's. We have to wait until they all will be merged.

  12. regnaio commented on Jul 21, 2021

    @regnaio

    Could we please merge the PR: #916?

    Thank you!

  13. sanex3339 commented on Jul 21, 2021

    @sanex3339
    Member

    This PR cannot be merged right now. Wait until eslint/eslint-scope#71 will be merged

  14. sanex3339 commented on Jul 23, 2021

    @sanex3339
    Member

    Released as 2.18.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions