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

rewrite the constructor for ast #2318

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

rewrite the constructor for ast #2318

wants to merge 5 commits into from

Conversation

yimi0
Copy link

@yimi0 yimi0 commented Sep 18, 2017

We can add custom properties to SELF_PROPS to ensure that the properties can be cloned.

@rvanvelzen
Copy link
Collaborator

What concrete problem does this solve?

@yimi0
Copy link
Author

yimi0 commented Sep 18, 2017

No problem, just to improve the extensibility. is useful when calling node.clone(true).

@alexlamsl
Copy link
Collaborator

Is there any examples that illustrates said improvement, e.g. some mocha tests?

@yimi0
Copy link
Author

yimi0 commented Sep 25, 2017

UglifyJS.AST_Node.SELF_PROPS.push("skip");
UglifyJS.AST_Lambda.SELF_PROPS.push("id", "level");

let id = 0;
ast.walk(new UglifyJS.TreeWalker(node => {
    if (node instanceof UglifyJS.AST_Lambda) {
        node.id = id++;
        node.level = getScopeLevel(node);
        ...
    }
    ...
    node.skip = canSkip(node);
});

...

let oldAst = ast, newAst = ast.clone(true);

newAst.walk(new UglifyJS.TreeWalker(node => {
    if (node.skip) return;
    if (node instanceof UglifyJS.AST_Lambda) {
        switch (node.level) {
             case 0:
                 // toplevel
                 ...
                 break;
             case 1:
             ...
             default:
                 ...
        }
    }
    ...
});

@alexlamsl alexlamsl force-pushed the master branch 2 times, most recently from 7d1c0a7 to b468103 Compare July 5, 2018 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants