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

fix: Refactor evented to make mincompatable with Chrome 53 #8810

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mister-ben
Copy link
Contributor

Description

Chrome 53 doesn't like the minified output. Specifically, it throws Uncaught SyntaxError: Unexpected token ( on the ternary in the minified version of normalizeListenArgs()

const normalizeListenArgs = (self, args, fnName) => {
// If the number of arguments is less than 3, the target is always the
// evented object itself.
const isTargetingSelf = args.length < 3 || args[0] === self || args[0] === self.eventBusEl_;
let target;
let type;
let listener;
if (isTargetingSelf) {
target = self.eventBusEl_;
// Deal with cases where we got 3 arguments, but we are still listening to
// the evented object itself.
if (args.length >= 3) {
args.shift();
}
[type, listener] = args;
} else {
[target, type, listener] = args;
}
validateTarget(target, self, fnName);
validateEventType(type, self, fnName);
validateListener(listener, self, fnName);
listener = Fn.bind_(self, listener);
return {isTargetingSelf, target, type, listener};
};

Line breaks added for clarify

Tt = (e, t, s) => {
  var i = t.length < 3 || t[0] === e || t[0] === e.eventBusEl_;
  let r, n, a;
  return i ? (r = e.eventBusEl_, 3 <= t.length && t.shift(), [n, a] = t) : [r, n, a] = t, ft(r, e, s), yt(n, e, s), bt(a, e, s), a = _(e, a), {
    isTargetingSelf: I,
    target: r,
    type: n,
    listener: a
  }
},

Chrome would be happy with this if [r, n, a] = t were ([r, n, a] = t).

Specific Changes proposed

Refactor normalizeListenArgs() slightly to use multiple statements to coerce uglify-js to include parentheses.
Also updates uglify-js, but that in itself isn't the fix.

#8783

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • Change has been verified in an actual browser - Browserstack Chrome 53
    • Unit Tests updated or fixed
    • Docs/guides updated
    • Example created (starter template on JSBin)
    • Has no DOM changes which impact accessiblilty or trigger warnings (e.g. Chrome issues tab)
    • Has no changes to JSDoc which cause npm run docs:api to error
  • Reviewed by Two Core Contributors

Copy link

codecov bot commented Jul 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.07%. Comparing base (e78bcc7) to head (7418bc2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8810   +/-   ##
=======================================
  Coverage   83.07%   83.07%           
=======================================
  Files         120      120           
  Lines        8022     8024    +2     
  Branches     1925     1925           
=======================================
+ Hits         6664     6666    +2     
  Misses       1358     1358           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -182,7 +182,10 @@ const normalizeListenArgs = (self, args, fnName) => {

[type, listener] = args;
} else {
[target, type, listener] = args;
target = args[0];
Copy link
Member

Choose a reason for hiding this comment

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

We should add a comment here with a link to this PR so that folks will be less likely to refactor it away.

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.

None yet

2 participants