Repository navigation
Allow private identifiers in optional chains and lower them correctly - #65743
Ryan Cavanaugh (RyanCavanaugh) wants to merge 5 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>
|
Copilot you're duplicating code here with the es2020 transform, try to refactor this so it's not so duplicative |
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Done in 7eb94d9. The ES2020 lowering engine is now No existing baselines changed. One ES2020 emit change has no test coverage: |
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.