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

support dumping AST #1879

Merged
merged 4 commits into from
May 7, 2017
Merged

support dumping AST #1879

merged 4 commits into from
May 7, 2017

Conversation

alexlamsl
Copy link
Collaborator

bin/uglifyjs Outdated

function skip_key(key) {
switch (key) {
case "cname":
Copy link
Contributor

@kzc kzc May 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please change this to:

var skip_keys = [ "cname", "enclosed", ... ];
function skip_key(key) { return skip_keys.indexOf(key) >= 0; }

as it's more efficient.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you meant function skip_key(...? 😮

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed. corrected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 4116731

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect.

@kzc
Copy link
Contributor

kzc commented May 7, 2017

Wow - nice. Far simpler implementation than the dump AST patch.

@alexlamsl
Copy link
Collaborator Author

Wow - nice. Far simpler implementation than the dump AST patch.

I cheat by utilising the recursive nature of JSON.stringify()'s replacer 👻

@kzc
Copy link
Contributor

kzc commented May 7, 2017

This will make debugging infinitely easier.

@alexlamsl
Copy link
Collaborator Author

@kzc reading your patch at #769 (comment) again, I noticed I've missed reordering of AST_Binary's properties.

Improve readability of JSON dump.
@kzc
Copy link
Contributor

kzc commented May 7, 2017

I noticed I've missed reordering of AST_Binary's properties.

Thanks. Makes it much easier to read the AST output.

@kzc
Copy link
Contributor

kzc commented May 7, 2017

Something is not quite right with the latest version of this PR:

$ bin/uglifyjs --self -mc passes=3 -o ast
bin/uglifyjs:380
    return skip_keys.indexOf(key) >= 0;
                    ^

TypeError: Cannot read property 'indexOf' of undefined

Would you mind adding at least one AST dump mocha test?

@kzc
Copy link
Contributor

kzc commented May 7, 2017

This is a workaround for the bug above:

bin/uglifyjs --self -mc passes=3 | bin/uglifyjs -o ast

@alexlamsl
Copy link
Collaborator Author

alexlamsl commented May 7, 2017

That's one strange bug indeed - let me investigate, then put in a quick mocha test.

Edit: yeah, I'm being an idiot...

@alexlamsl
Copy link
Collaborator Author

Something is not quite right with the latest version of this PR:

Should be fixed by 1040110, alongside a mocha test.

@kzc
Copy link
Contributor

kzc commented May 7, 2017

Odd - why would moving the skip_keys array to the top fix the problem for some cases?

@alexlamsl
Copy link
Collaborator Author

Reading from process.stdin is asynchronous, i.e. run() gets called within the event loop, which means the rest of bin/uglifyjs gets to be evaluated before it.

The previous version of this PR also works because it does not contain var skip_keys, so there wasn't any issue with execution order.

@kzc
Copy link
Contributor

kzc commented May 7, 2017

Reading from process.stdin is asynchronous

Thanks. It's obvious in hindsight.

@kzc
Copy link
Contributor

kzc commented May 7, 2017

This feature works great - best thing since sliced bread.

@alexlamsl alexlamsl merged commit da295de into mishoo:master May 7, 2017
@alexlamsl alexlamsl deleted the dump-ast branch May 7, 2017 22:23
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.

2 participants