google / google/closure-compiler
Alias for long exported names
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
One of my takeaways from reading the documentation on externs vs exports was that externs are discouraged as a way to prevent mangling of your own api/data model.
It made sense to me that exports via `obj['somePropertyName']` might be more optimized since the compiler can use internal aliases rather than carrying forward the full name everywhere.
I decided to test this out with the example below:
```
function createPersonModel(data) {
var fullName = data['info']['firstNameProperty'] + data['info']['lastNameProperty'];
var fullNameReverse = data['info']['lastNameProperty'] + data['info']['firstNameProperty'];
console.log(fullName);
console.log(fullNameReverse);
}
createPersonModel(anObjectFromAnApi);
```
Let's just assume this is a deep object returned from an api, and I am using `['']` notation to prevent mangling.
Based on what I read in the documentation I was expecting the repeated property references to be aliased?
Instead the code compiled to the following:
```
var a=anObjectFromAnApi.info.lastNameProperty+anObjectFromAnApi.info.firstNameProperty;
console.log(anObjectFromAnApi.info.firstNameProperty+anObjectFromAnApi.info.lastNameProperty);
console.log(a);
```
Isn't there an opportunity here to assign `anObjectFromAnApi.info.lastNameProperty` and `anObjectFromAnApi.info.lastNameProperty` to single character aliases?
I also tried exaggerating this by adding several more references to these properties to see if an alias would be introduced. The behavior was the same though.
Am I misunderstanding the point about aliasing of exports when compared to externs?
Contributor guide
Assessment
This issue has not been assessed yet.