Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fat arrow Unexpected token in the Class #909

Closed
iterion-mikehit opened this issue Apr 15, 2021 · 14 comments
Closed

fat arrow Unexpected token in the Class #909

iterion-mikehit opened this issue Apr 15, 2021 · 14 comments

Comments

@iterion-mikehit
Copy link

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 = () => {...

@sanex3339
Copy link
Member

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

@BlackYuzia
Copy link
Contributor

BlackYuzia commented Apr 15, 2021

@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
}
}

@iterion-mikehit
Copy link
Author

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

@sanex3339 sanex3339 reopened this Apr 26, 2021
@sanex3339
Copy link
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.

@sanex3339 sanex3339 removed the stage 3 label Apr 26, 2021
@sanex3339
Copy link
Member

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

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

@sanex3339
Copy link
Member

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

@sanex3339
Copy link
Member

WIP PR to the obfuscator:
#916

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

will be finished.

@Bdethloff
Copy link

Bdethloff commented May 7, 2021

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/espree#486
eslint/eslint-scope#69

Sorry to hassle you

@sanex3339
Copy link
Member

PR to the @types/estree
DefinitelyTyped/DefinitelyTyped#52832

@Bdethloff
Copy link

Any update on this?

@sanex3339
Copy link
Member

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

@regnaio
Copy link

regnaio commented Jul 21, 2021

Could we please merge the PR: #916?

Thank you!

@sanex3339
Copy link
Member

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

@sanex3339
Copy link
Member

Released as 2.18.0

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

No branches or pull requests

5 participants