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

enable typeof "undefined" for general use #1446

Closed
wants to merge 1 commit into from

Conversation

alexlamsl
Copy link
Collaborator

Based on #1443 (comment)

/cc @kzc

@kzc
Copy link
Contributor

kzc commented Jan 28, 2017

Can you please add the test from #1443 (comment) to see if it still performs correctly if undefined is redefined? If not, we must keep this transform under the "unsafe" flag.

function f(undefined) {
    return function() {
        var n = 1;
        return typeof n == "undefined";
    };
}
console.log( f(1)() );

It should be tested with and without mangle.

@alexlamsl
Copy link
Collaborator Author

@kzc added your test case (took liberty to remove console.log()) with only comparisons and without mangle.

In terms of code, AST_Undefined seems to always output as void 0.

@kzc
Copy link
Contributor

kzc commented Jan 28, 2017

Could you please add another test undefined_redefined_mangle with mangle enabled?

@kzc
Copy link
Contributor

kzc commented Jan 28, 2017

Regarding void 0 and undefined, all these tests should use expect_exact instead of expect because the test result is subject to parsing which may not be in the form you think it is in. It's hard to explain.

@alexlamsl
Copy link
Collaborator Author

@kzc I missed the "with or" bit in your previous comment - sorry about that!

As for expect_exact instead of expect - are you worried that the parser might get in the way and confuses us with undefined and void 0 being interpreted as the same thing?

@kzc
Copy link
Contributor

kzc commented Jan 28, 2017

Exactly. This has happened in the past. parse.js and output.js do some transforms of their own. Sometimes the form you see in ascii is not the same as you'd expect in the AST. It's a clever trick using the same parse/output code to check itself, but sometimes it can lead to problems. For example, string literals with "different" 'quote' characters can lead to the same AST. As can quoted and unquoted property names with various quoting styles. You may think you have a successful test when in fact you do not. expect_exact removes any doubt.

@alexlamsl
Copy link
Collaborator Author

@kzc thanks for the explanation 👍

Is there anything else that needs testing and/or changing? If not, I shall remove [wip] in the title.

}
input: {
function f(undefined) {
return function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the superfluous inner function so that undefined and var n are in the same scope.

mangle = {}
input: {
function f(undefined) {
return function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the superfluous inner function so that undefined and var n are in the same scope.

Copy link
Contributor

Choose a reason for hiding this comment

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

Both tests should look like this:

        function f(undefined) {
                var n = 1;
                return typeof n == "undefined";
        }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated both tests.

move out of unsafe, guard corner case with screw_id8 instead
@kzc
Copy link
Contributor

kzc commented Jan 28, 2017

LGTM

@alexlamsl alexlamsl changed the title [wip] enable typeof "undefined" for general use enable typeof "undefined" for general use Jan 28, 2017
@alexlamsl alexlamsl closed this in e5badb9 Feb 23, 2017
@alexlamsl alexlamsl deleted the typeof-undefined branch February 24, 2017 00:18
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