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

Renaming causes bug to occur on iOS device #3164

Closed
leidegre opened this issue Dec 5, 2018 · 10 comments
Closed

Renaming causes bug to occur on iOS device #3164

leidegre opened this issue Dec 5, 2018 · 10 comments
Assignees
Labels
internal-issue-created An internal Google issue has been created to track this GitHub issue triage-done Has been reviewed by someone on triage rotation.

Comments

@leidegre
Copy link

leidegre commented Dec 5, 2018

The following JavaScript

"use strict";
const selectors_1 = require("../../../shared/selectors");
module.exports = async (dispatch, getState, { match, serverRes, appContext }) => {
    const { fetchProjectDetails } = await appContext.import('../actions', __filename, __dirname);
    await dispatch(fetchProjectDetails(match.params.projectHId));
    if (typeof process !== 'undefined') {
        if (selectors_1.getRequestErrorCode(getState(), { operationId: `/projects/${match.params.projectHId}` }) === 'NOT_FOUND') {
            serverRes && serverRes.status(404);
        }
    }
};

Compiled like this

java -jar closure-compiler-v20181125.jar --language_in ECMASCRIPT_2017 --language_out ECMASCRIPT_2017 --js x.js --formatting PRETTY_PRINT

Results in the following code

'use strict';
const selectors_1 = require("../../../shared/selectors");
module.exports = async(d, e, {match:b, serverRes:c, appContext:a}) => {
  var {fetchProjectDetails:a} = await a.import("../actions", __filename, __dirname);
  await d(a(b.params.projectHId));
  "undefined" !== typeof process && "NOT_FOUND" === selectors_1.getRequestErrorCode(e(), {operationId:`/projects/${b.params.projectHId}`}) && c && c.status(404);
};

This line

var {fetchProjectDetails:a} = await a.import("../actions", __filename, __dirname);

Both appContext and fetchProjectDetails was renamed to a which appears to confuse iOS. The error we get is undefined is not an object (evaluating 'a.import'). This is a consistent issue across all iOS devices we've been able to test with and I'm wondering whether there's a way to get around this issue without switching to WHITESPACE_ONLY.

@EatingW EatingW added the triage-done Has been reviewed by someone on triage rotation. label Dec 5, 2018
@EatingW
Copy link
Contributor

EatingW commented Dec 5, 2018

Created Google internal issue b/120558057

@EatingW
Copy link
Contributor

EatingW commented Dec 6, 2018

This doesn't seem specific to iOS. The code will cause the same error in any environment.

It might be a destructuring-related bug in the CoalesceVariableNames pass.

@leidegre
Copy link
Author

leidegre commented Dec 7, 2018

@EatingW we did not experience any problems with V8 (Node.js/Chrome/Chromium). I don't know the language spec well enough to say whether this construction is legal or not but it is definitely not ideal from my point of view because it's confusing.

I don't think the Closure Compiler should repurpose any variable name in scope. I don't think the trade off is worth it. But this is just my opinion.

@lauraharker
Copy link
Contributor

Sorry, Yiting's earlier comment was my mistake. This code is valid in the language. You can workaround this by with options.setCoalesceVariableNames(false) in the Java API.

Here's a smaller repro that fails in Safari v12.0.1 for me on MacOS, but works in other browsers:
(async (x) => { var x; x.y })({})
The var x declaration seems to cause the parameter x to be put in a separate scope from the body. For me, this is only happen with async arrows, so maybe we could update the pass to not rename variables in async arrow fns only. I'll see if there's an existing WebKit bug for this.

Could you explain what trade offs of variable name repurposing you're referring to? Just this one bug, or have you run into other issues with the pass?

@lauraharker
Copy link
Contributor

@leidegre
Copy link
Author

leidegre commented Dec 9, 2018

Sorry, Yiting's earlier comment was my mistake. This code is valid in the language. You can workaround this by with options.setCoalesceVariableNames(false) in the Java API.

Great, I'll use this for now.

@leidegre
Copy link
Author

leidegre commented Dec 9, 2018

Could you explain what trade offs of variable name repurposing you're referring to? Just this one bug, or have you run into other issues with the pass?

I was thinking about the space saving of minification trade off. That while reusing a here is legal, b would be equally good and not as confusing. If I ever have to debug the minified output overly aggressive compact naming does make that harder. I understand that there are situations where this probably is warranted but that was what I had in mind, when I wrote that.

@lauraharker lauraharker self-assigned this Dec 18, 2018
@lauraharker
Copy link
Contributor

I'm implementing a workaround for the Safari bug.

Re debugging minified code - I agree that this makes debugging harder. Since it benefits code size it still seems worth having on by default to me. (As long as the source map information is corret.)

@leidegre
Copy link
Author

I agree that this makes debugging harder. Since it benefits code size it still seems worth having on by default to me. (As long as the source map information is corret.)

Agreed.

@brad4d brad4d added the internal-issue-created An internal Google issue has been created to track this GitHub issue label Dec 19, 2018
@lauraharker
Copy link
Contributor

One more debugging item I forgot about earlier:

If you enable options.generatePseudoNames = true, the compiler will generate a new name that fuses the two combined variable names, instead of just using the first name. Something like:
function f(a) { let b = 3; return b; } -> function f(a_b) { let a_b = 3; return a_b; }

@brad4d brad4d closed this as completed in 4e7b71f Dec 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal-issue-created An internal Google issue has been created to track this GitHub issue triage-done Has been reviewed by someone on triage rotation.
Projects
None yet
Development

No branches or pull requests

4 participants