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

test-helpers.js: unusual code is blocking closure-compiler improvement #85

Closed
brad4d opened this issue Apr 10, 2017 · 5 comments
Closed

Comments

@brad4d
Copy link

brad4d commented Apr 10, 2017

This closure-compiler issue is related to the unusual way methods are being defined in test-helpers.js.
google/closure-compiler#2409

Could @fejesjoco or someone else help me understand the purpose of this arrangement?
I suspect it's trying to work around something for which there's a better solution.

@fejesjoco
Copy link
Contributor

This code is annotated to work with Closure Compiler (without externs). But it didn't work because the compiler didn't see the methods inside the IIFE. I changed that in #69, indeed the code looked a bit weird, but this seemed the easiest way to work around the compiler limitation.

There's a requirement that makes this harder: we cannot add goog statements, like goog.scope, because this code also has to work without Closure. So that's why an IIFE with this layout was chosen.

We started adding code that calls these methods. So if you roll this back, that code will break if the compiler again will not see the signatures of these methods.

The code can be changed of course, in order not to break anything you'd have to make sure that Closure Compiler can see and validate the method signatures and it stays free of goog statemets.

@brad4d
Copy link
Author

brad4d commented Apr 10, 2017

The version you have is still broken if it's ever executed in a strict environment, since this will be undefined.

I notice that the code is in fact using window.
If you require window be defined in your environment, you just do this?

window.TestHelpers = {};
window.TestHelpers.flushAsynchronousObjects = ...

@fejesjoco
Copy link
Contributor

fejesjoco commented Apr 11, 2017

If a method is defined on window, will the compiler still see that method as a global one?

Also I think I forgot to mention that probably the main reason for an IIFE was that some methods are considered private.

Note that I'm not part of the Polymer team, so whatever the plan, I won't be able to approve it.

@brad4d
Copy link
Author

brad4d commented Apr 12, 2017

Thanks for the explanation.
I got what I needed to understand from this, so I'm closing it.

@brad4d
Copy link
Author

brad4d commented Apr 19, 2017

@fejesjoco
Yes, closure-compiler will recognize things defined on window as globals.
I filed #86 to suggest simplifying this stuff.

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

No branches or pull requests

2 participants