Repository navigation
Allow private identifiers in optional chains and lower them correctly - #65743
Draft
Ryan Cavanaugh (RyanCavanaugh) wants to merge 4 commits into
Draft
Ryan Cavanaugh (RyanCavanaugh) wants to merge 4 commits into
Ryan Cavanaugh (RyanCavanaugh) wants to merge 4 commits into
Conversation
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This branch has not been deployed
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.
a?.#pis valid ES2022, but the parser reports TS18030 on it. When private names are lowered (targets below ES2022, oruseDefineForClassFields: false), the class fields transform also dropped the short-circuit:a?.#pbecame__classPrivateFieldGet(a, _A_p, "f"), which throws whenais nullish. At ES2020/ES2021 the?.itself is kept, so the class fields transform has to handle the whole chain itself.Parser
parsePropertyAccessExpressionRest. The checker already handles these chains.Class fields transform
x === null || x === void 0 ? void 0 : …. A run is the links from the outermost node back to its?.. Only runs that contain the private name are lowered;a?.#p?.bbecomes(…)?.band is left to the ES2020 transform.thisbinding: a lowered private-name link followed by a call captures its receiver and emits.call(receiver). A receiver that isn't simple to copy goes into a temp. This covers:a?.#m?.(),(a?.#m)(),(a?.#m)!()superreceivers at the start of the chain(a?.#m)!`x`becomes(…).bind(a)followed by the template.delete:delete a?.#p.xbecomesa === null || a === void 0 ? true : delete __classPrivateFieldGet(a, _A_p, "f").x.Tests
privateNameOptionalChain{,Call,Delete,Static,Decorators,Errors}.ts, at es2019/es2020/es2022 (Decorators and Errors at es2019/es2022 only).privateIdentifierChain.1: TS18030 is gone; TS2532 remains.privateNameUncheckedJsOptionalChain:this?.#foonow types aserror, matchingthis.#fooin unchecked JS. The.errors.txtbaseline is removed.