Replies: 2 comments 2 replies
-
It sounds like you're trying to interact with third-party code without compiling that code along with your application? If so, I encourage you to explore "externs" and "exports". Externs serve the purpose of describing externally defined names/APIs so that the compiler knows what to not rewrite, what types will be returned, etc. I had remembered that "exports" were the tool for defining your own API, but now that I'm re-reading documentation at https://developers.google.com/closure/compiler/docs/externs-and-exports, it appears that externs instead should be used to declare what symbols should be exported:
So, you likely need to document the library you are using in an I've used https://github.com/angular/tsickle/ with some limited success to auto-generate externs for .d.ts files, but it makes some assumptions that might be difficult (such as using tsickle itself to also transpile your ts into js?). I'm not sure if there are other tools that can do this for you. |
Beta Was this translation helpful? Give feedback.
-
Closure Compiler used to have a property renaming mode called "heuristic property renaming" that was deleted back in 2015, that isn't exactly what you're proposing but was deprecated for reasons I think would also show up in your proposal. So I don't think this is a change we can merge into the main repo. The primary issue with heuristic property renaming was that medium/large projects using it found various encounter hard-to-resolve bugs caused by a change in one file affecting renaming in completely unrelated files. e.g. deleting some code For your project, one other thing to consider if you continue with this patch, is that more optimizations besides just RenameProperties have special handling for extern properties. See everything that uses |
Beta Was this translation helpful? Give feedback.
-
Hello, I'm working with several third-party libraries in TypeScript, particularly those utilizing enums, and I'm facing challenges in maintaining consistent property names when using Google Closure Compiler (GCC) in advanced compilation mode.
My current understanding is that GCC, designed for whole-application optimization, tends to rename variables and object properties unless they are specified in an externs file. However, given the nature of my project involving multiple external libraries, it's impractical to manage an externs file for every potential variable or property.
I've explored a potential workaround and would like to get feedback on its viability. The idea is to modify the GCC source code to prevent the renaming of properties that have quoted usage. Specifically, updating the condition in RenameProperties.java to:
if (p != null && p.newName != null && !quotedNames.contains(oldName)) {
This modification seems to work in my initial tests, but I'm concerned about its broader implications and compatibility with GCC's optimization goals. I understand that modifying the GCC source could lead to unexpected behaviors.
Has anyone faced a similar challenge or has insights into this approach? Are there better alternatives or practices I should consider to maintain property consistency without compromising the advanced optimization features of GCC?
PS: 4 tests failing after mentions changes, but most of failed test are expected "incorrect" behavior. For example IntegrationTest#testConvertToDottedProperties where
failed with an error:
Beta Was this translation helpful? Give feedback.
All reactions