Skip to content

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