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

Guidelines for supporting ADVANCED compile #305

Open
pcj opened this issue Dec 15, 2016 · 6 comments
Open

Guidelines for supporting ADVANCED compile #305

pcj opened this issue Dec 15, 2016 · 6 comments

Comments

@pcj
Copy link

pcj commented Dec 15, 2016

Given a typescript codebase with no prior knowledge of Closure, what steps need to be taken to make it safe for advanced closure compilation (through tsickle)?

@evmar
Copy link
Contributor

evmar commented Dec 15, 2016

It would be great for us to document this, thanks for filing the bug!

To start with, https://developers.google.com/closure/compiler/docs/api-tutorial3 is a good read.

It is my ultimate goal with tsickle that it always just does the right thing and you don't need to worry about what the compiler will do. See this bug label:
https://github.com/angular/tsickle/issues?q=is%3Aopen+is%3Aissue+label%3A%22prevent+closure+antipatterns%22

@pcj
Copy link
Author

pcj commented Dec 15, 2016

Thanks @evmar, sounds like tsickle won't be able to insulate the user (in this case a generic typescript author) from knowing about what patterns to avoid to use ADVANCED compile.

I'm coming into a project that has a medium'ish sized existing typescript codebase, probably overly optimistic / naiive to expect that it will work with advanced compilation without some serious examination of the codebase.

Is that your sense as well?

@evmar
Copy link
Contributor

evmar commented Dec 15, 2016

In practice it boils down to a few things:

  • never access both foo.bar and foo["bar"] on the same object
  • be careful around JSON

@evmar
Copy link
Contributor

evmar commented Dec 15, 2016

And yes, it's likely you'll compile your project and discover some problems. However, usually it's not super hard to debug, though you will have to squint at some optimized code.

@pcj
Copy link
Author

pcj commented Dec 15, 2016

Does tsickle convert foo["bar"] to foo.bar, which would become $foo$.$bar$ and then a.b?

@evmar
Copy link
Contributor

evmar commented Dec 15, 2016

No. It's important to be able to write foo["bar"] and have it make it into Closure, as it supports code patterns like:

let obj = JSON.parse(someText);
console.log(obj["foo"]);  // should use "foo" in the output, as that's what the JSON has
// note that Closure might actually compile that into obj.foo as that's fewer characters

My current thinking is we should warn people away from it in the case where you're using a string to access a property:
#23

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