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

[ES6] Make distinction between * method and * operator #1229

Merged
merged 1 commit into from
Aug 14, 2016

Conversation

avdg
Copy link
Contributor

@avdg avdg commented Jul 22, 2016

No description provided.

@rvanvelzen
Copy link
Collaborator

This supersedes #1227, right?

@avdg
Copy link
Contributor Author

avdg commented Jul 22, 2016

Yes

@kzc
Copy link
Contributor

kzc commented Jul 22, 2016

Run with PR #1229:

$ cat percent.js 
        var foo = {
            "%": "foo",
            get "%"() {
                return "bar";
            },
            *"%"() {
                return "foobar";
            }
        }
        class bar {
            get "%"() {
                return "bar"
            }
            *"%"() {
                return "foobar";
            }
        }
$ bin/uglifyjs percent.js -b
var foo = {
    "%": "foo",
    get %() {
        return "bar";
    },
    *%() {
        return "foobar";
    }
};

class bar {
    get %() {
        return "bar";
    }
    *%() {
        return "foobar";
    }
}
$ bin/uglifyjs percent.js -b | bin/uglifyjs -b
Parse error at -:3,8
SyntaxError: Unexpected token: operator (%)

Edit:

furthermore:

$ node percent.js 
$ echo $?
0
$ bin/uglifyjs percent.js -b | node
[stdin]:3
    get %() {
        ^
SyntaxError: Unexpected token %

@avdg
Copy link
Contributor Author

avdg commented Jul 22, 2016

Errors too soon

@avdg
Copy link
Contributor Author

avdg commented Jul 22, 2016

Better to add an identifier check

@kzc
Copy link
Contributor

kzc commented Jul 22, 2016

I made that example because the PR was special casing "*" and suspected the logic would break for getters/setters with operator-like names.

@avdg
Copy link
Contributor Author

avdg commented Jul 22, 2016

Seems to be a recent breakage

@avdg
Copy link
Contributor Author

avdg commented Jul 22, 2016

Actually we shouldn't need this very special case at all (too many cases that ends up being invalid identifiers)

@kzc
Copy link
Contributor

kzc commented Jul 22, 2016

When you fix it, could you add test cases for % and few other operator-like names, as well as a setter/getter name with a space in it?

For bonus points, test setters/getters using some unprintable unicode names like "\x00\x01" with ascii_only=1 output mode.

@avdg
Copy link
Contributor Author

avdg commented Jul 22, 2016

This issue needs lots of test cases anyway :-)

@avdg
Copy link
Contributor Author

avdg commented Jul 22, 2016

Basically, all the logic we need was there in ObjectKeyVal

@kzc
Copy link
Contributor

kzc commented Jul 22, 2016

@avdg @rvanvelzen Here's an idea for test/run-tests.js - for all passing test/compress/*.js tests, the successful tests' JS output should be (re)parsed and output with the same test compress/mangle/output options to verify that uglify can simply (re)parse and (re)output its own output. It would catch inconsistancies between output and parsing. What do you think?

Edit: the re-parsed output need not necessarily match the original expected test output, which is fine - just as long as it it doesn't error out.

return "bar";
},
*"%"() {
return "foobar";
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need any return statements here at all for the purpose of this test to make the expect_exact string shorter. Or you can just have 1; 2; 3; etc, if you want to easily visually cross reference the specific failing part of the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll replace them with numbers

@avdg
Copy link
Contributor Author

avdg commented Jul 22, 2016

Well, we shouldn't care about ie8 with method naming, but we still have getters that have modified behaviour and don't support ie8.

@avdg
Copy link
Contributor Author

avdg commented Jul 22, 2016

Failing test is due to timeout on node 0.12

@kzc
Copy link
Contributor

kzc commented Jul 22, 2016

  1) bin/uglifyjs should produce a functional build when using --self:
     Error: timeout of 5000ms exceeded. Ensure the done() callback is being called in this test.

Please increase the timeout of this specific mocha test to 15000 to compensate for occasionally slow test machines.

@kzc
Copy link
Contributor

kzc commented Jul 22, 2016

Just add the increased timeout for this unrelated test failure to this PR - don't bother making a new PR.

@avdg
Copy link
Contributor Author

avdg commented Jul 22, 2016

Done, any more test cases?

@kzc
Copy link
Contributor

kzc commented Jul 22, 2016

PR #1230 exposed 4 test failures on the harmony branch. Please test with it.

@kzc
Copy link
Contributor

kzc commented Jul 22, 2016

PR #1230 would have caught the % getter name error before it was corrected.

@avdg
Copy link
Contributor Author

avdg commented Jul 22, 2016

2 errors related to surrogated identifiers
2 errors related to export (which I don't work on yet)

@kzc
Copy link
Contributor

kzc commented Jul 22, 2016

Yeah, they are unrelated issues to this PR. But test was inspired by error in this PR.

@kzc
Copy link
Contributor

kzc commented Jul 22, 2016

property_with_operator_value and property_with_unprintable were only testing getters. To exercise the new function _print_getter_setter could you put a couple of setters in those tests?

*"\x00\x01"() {
return "foobar";
}
}
}
expect_exact: 'var foo={"\\0\x01":"foo",get"\\0\x01"(){return"bar"},*"\\0\x01"(){return"foobar"}};class bar{get"\\0\x01"(){return"bar"}*"\\0\x01"(){return"foobar"}}'
expect_exact: 'var foo={"\\0\x01":"foo",get"\\0\x01"(){return"bar"},set"\\0\x01"(foo){save(foo)},*"\\0\x01"(){return"foobar"}};class bar{get"\\0\x01"(){return"bar"}set"\\0\x01"(foo){save(foo)}*"\\0\x01"(){return"foobar"}}'
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make a new test that's a copy of the test property_with_unprintable except using ascii_only=true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@avdg avdg changed the title Make distinction between * method and * operator [ES6] Make distinction between * method and * operator Jul 26, 2016
@avdg
Copy link
Contributor Author

avdg commented Jul 26, 2016

Uh, we do have to store these quotes no? (keep quotes option)

@kzc kzc mentioned this pull request Jul 28, 2016
@kzc
Copy link
Contributor

kzc commented Jul 28, 2016

Uh, we do have to store these quotes no? (keep quotes option)

Probably should store the quote but not emit them by default if not required. It should respect output.option("quote_keys")

@avdg
Copy link
Contributor Author

avdg commented Jul 28, 2016

Normal properties seems fine, just the getters and setters not

@avdg
Copy link
Contributor Author

avdg commented Jul 29, 2016

Current progress: property shortcut not quoted properly yet as I do have to find out a printing strategy yet when I have more time.

avdg/UglifyJS2@generator-symbol...avdg:generator-symbol-tmp

@avdg
Copy link
Contributor Author

avdg commented Jul 29, 2016

@kzc I better squash the commits for now since the fix for the star alone seems to be important. There are other broken stuff, but they aren't regressions just yet.

Also add quotes to properties when necessary,
this might be the case if the name isn't a valid
identifier
@avdg
Copy link
Contributor Author

avdg commented Jul 29, 2016

done

@avdg
Copy link
Contributor Author

avdg commented Jul 29, 2016

I've added more tests on the generator-symbol-tmp branch. avdg/UglifyJS2@generator-symbol...avdg:generator-symbol-tmp

Edit: since the merge, this should now be avdg/UglifyJS2@harmony...avdg:generator-symbol-tmp

@avdg
Copy link
Contributor Author

avdg commented Jul 30, 2016

(note on additional optional patches) I might move the concise method thing to an AST_ObjectProperty, given the getters are functions as well and doing fine there.

Edit; AST move should be done there, I still have issues with computed properties as concise method, which seems to make the scope analyzer complain a lot. Still investigating cause, but it has something to do with things like [Symbol.iterator](){/* do stuff */} where doing some stuff on Symbol makes uglify complain.

Edit2: Seems that is solved by adapting the walker, maybe this can be generalized in such a way we don't need AST_ObjectComputedKeyVal anymore.

@kzc
Copy link
Contributor

kzc commented Jul 30, 2016

You may just want get this one merged to address the regression and wait to add features in other PRs.

@avdg
Copy link
Contributor Author

avdg commented Jul 30, 2016

Yes yes, that's what I'm doing right now. I want to prevent any more unnecessary blockages.

Although I can go a step further by opening a separate issue/pr.

@Hypercubed
Copy link

Just a note, jspm often generates output like:

System.registerDynamic("npm:core-js@2.4.1.json", [], false, function() {
  return {
    "main": "index.js",
    "format": "cjs",
    "meta": {
      "*": {
        "globals": {
          "process": "process"
        }
      },
      "*.json": {
        "format": "json"
      }
    }
  };
});

This PR prevents the harmony branch from crashing at the "*" key.

@rvanvelzen rvanvelzen merged commit 110a1ac into mishoo:harmony Aug 14, 2016
@rvanvelzen
Copy link
Collaborator

Awesome, thanks!

@avdg avdg deleted the generator-symbol branch August 15, 2016 18:30
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.

4 participants