🏗🚮 Inline private const class properties#24027
Closed
jridgewell wants to merge 2 commits intoampproject:masterfrom
Closed
🏗🚮 Inline private const class properties#24027jridgewell wants to merge 2 commits intoampproject:masterfrom
jridgewell wants to merge 2 commits intoampproject:masterfrom
Conversation
Since we've [disabled](https://github.com/ampproject/amphtml/blob/33ca73f014a388cca2d94ec19cd868d62334de2a/build-system/runner/src/org/ampproject/AmpCommandLineRunner.java#L78) closure's `inlineProperties` transform, we lose the ability to DCE based on constant properties: ```js class Ex { constructor() { /** @Private @const {boolean} */ this.foo_ = false; } test() { if (this.foo_) { // We expect this to be DCE'd (since foo_ is always false) // But closure won't do it. alert('foo'); } } } ``` This inlines the private const properties _before_ closure sees them, so that they can be DCE'd: ```js // Input class Ex { constructor() { /** @Private @const {boolean} */ this.foo_ = false; } test() { if (this.foo_) { alert('foo'); } } } // Output class Ex { constructor() { } test() { if (false) { alert('foo'); } } } ```
dreamofabear
left a comment
There was a problem hiding this comment.
Why not enable inlineProperties in Closure instead of adding yet another Babel transform?
jridgewell
added a commit
to jridgewell/amphtml
that referenced
this pull request
Aug 19, 2019
Supersedes ampproject#24027. This allows Closure to inline known-constant properties into any accesses, which allows it to DCE if-statement branches that are known to never run.
jridgewell
added a commit
that referenced
this pull request
Aug 20, 2019
* Enable property inlining Supersedes #24027. This allows Closure to inline known-constant properties into any accesses, which allows it to DCE if-statement branches that are known to never run. * Use constant split comment
Contributor
Author
|
Agh, it's still needed. |
Contributor
Author
|
Not needed for #23968 anymore. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since we've disabled closure's
inlinePropertiestransform, we lose the ability to DCE based on constant properties:This inlines the private const properties before closure sees them, so that they can be DCE'd: