Skip to content

feat: treeshake for optional chaining#4797

Merged
lukastaegert merged 8 commits intorollup:masterfrom
antfu:feat/treeshake-optional-chaining
Jan 12, 2023
Merged

feat: treeshake for optional chaining#4797
lukastaegert merged 8 commits intorollup:masterfrom
antfu:feat/treeshake-optional-chaining

Conversation

@antfu
Copy link
Copy Markdown
Contributor

@antfu antfu commented Jan 9, 2023

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

esbuild treeshakes it as well: https://esbuild.egoist.dev/#W1siaW5kZXgudHMiLHsiY29udGVudCI6ImlmICh1bmRlZmluZWQ/LmEpIHtcbiAgY29uc29sZS5sb2coXCJcIik7XG59XG5cbnVuZGVmaW5lZD8uYSgpO1xuIn1dLFsiZXNidWlsZC5jb25maWcuanNvbiIseyJjb250ZW50Ijoie1xuICBcImZvcm1hdFwiOiBcImVzbVwiLFxuICBcImNkblVybFwiOiBcImh0dHBzOi8vY2RuLnNreXBhY2suZGV2XCIsXG4gIFwibWluaWZ5XCI6IHRydWVcbn0ifV0sWyJzdW0udHMiLHsiY29udGVudCI6ImV4cG9ydCBjb25zdCBzdW0gPSAoYTogbnVtYmVyLCBiOiBudW1iZXIpID0+IGEgKyBiIn1dXQ==

Copy link
Copy Markdown
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, great work!

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 10, 2023

Codecov Report

Merging #4797 (3f66268) into master (b26a37f) will decrease coverage by 0.01%.
The diff coverage is 91.66%.

@@            Coverage Diff             @@
##           master    #4797      +/-   ##
==========================================
- Coverage   99.02%   99.01%   -0.02%     
==========================================
  Files         217      218       +1     
  Lines        7780     7792      +12     
  Branches     2161     2166       +5     
==========================================
+ Hits         7704     7715      +11     
- Misses         24       25       +1     
  Partials       52       52              
Impacted Files Coverage Δ
src/ast/nodes/ChainExpression.ts 91.66% <91.66%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.


getLiteralValueAtPath(): LiteralValueOrUnknown {
if (this.getObjectValue() == null) return undefined;
return UnknownValue;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be easy to cover in a test, I wonder why you current test does not hit this line

private objectValue: LiteralValueOrUnknown | typeof unset = unset;

deoptimizeCache(): void {
this.objectValue = UnknownValue;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is actually hard to cover in a test and I am fine if it is not covered. To hit this, you have to use a variable further up in the chain that is initialized as undefined but later gets another value assigned, invalidating the object.getLiteralValueAtPath in line 46.
The problem is to find a suitable "later". Sometimes it works to do this in a function but as I said, it is tricky.

@antfu
Copy link
Copy Markdown
Contributor Author

antfu commented Jan 10, 2023

Updated. Thanks for the guidance! I will leave the coverage deoptimizeCache as I don't exactly understand the context and how. Feel free to push. Thanks!

Copy link
Copy Markdown
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff, thanks!

@lukastaegert lukastaegert merged commit ffc19b0 into rollup:master Jan 12, 2023
@lukastaegert
Copy link
Copy Markdown
Member

This PR has been released as part of rollup@3.10.0. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants