Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use useDefineForClassFields in ts-config #4224

Merged
merged 4 commits into from Sep 19, 2021

Conversation

dnalborczyk
Copy link
Contributor

@dnalborczyk dnalborczyk commented Sep 7, 2021

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

emits ecmascript standard compliant class fields.

it's the default setting for ES2022 and above, including ESNext.

https://www.typescriptlang.org/tsconfig#useDefineForClassFields

more thorough explainer: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier

-> the first commit is expected to fail the tests as some of the classes are not ecmascript compliant.

@codecov
Copy link

codecov bot commented Sep 8, 2021

Codecov Report

Merging #4224 (3cf248c) into master (2ff8fc1) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4224   +/-   ##
=======================================
  Coverage   98.37%   98.37%           
=======================================
  Files         202      202           
  Lines        7260     7260           
  Branches     2119     2119           
=======================================
  Hits         7142     7142           
  Misses         58       58           
  Partials       60       60           
Impacted Files Coverage Δ
src/Module.ts 100.00% <ø> (ø)
src/ast/nodes/ArrayExpression.ts 100.00% <ø> (ø)
src/ast/nodes/ArrayPattern.ts 90.00% <ø> (ø)
src/ast/nodes/ArrowFunctionExpression.ts 100.00% <ø> (ø)
src/ast/nodes/AssignmentExpression.ts 100.00% <ø> (ø)
src/ast/nodes/AssignmentPattern.ts 100.00% <ø> (ø)
src/ast/nodes/AwaitExpression.ts 100.00% <ø> (ø)
src/ast/nodes/BinaryExpression.ts 97.43% <ø> (ø)
src/ast/nodes/BlockStatement.ts 100.00% <ø> (ø)
src/ast/nodes/BreakStatement.ts 100.00% <ø> (ø)
... and 68 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ff8fc1...3cf248c. Read the comment docs.

@dnalborczyk dnalborczyk marked this pull request as ready for review September 8, 2021 02:47
@lukastaegert
Copy link
Member

lukastaegert commented Sep 11, 2021

I am a little undecided on this one. While it definitely makes sense, it makes the minified(!) browser bundle 25kB(!) or 6% larger—all of which are defineProperty calls. All of which to catch some edge cases which would not be part of the external API anyway. Also, we do not use setters in class fields. The second issue does apply to us, as evidenced by your changes, but I still do not see the value of those 25kB. As we are only testing the generated output, I wonder if we should rather not use this option deliberately and revisit this topic once we actually ship class fields in our code to end users.

Still, your changes in the code itself make sense to me and should work even with this option disabled.

@@ -3,6 +3,8 @@ import { MISSING_EXPORT_SHIM_VARIABLE } from '../../utils/variableNames';
import Variable from './Variable';

export default class ExportShimVariable extends Variable {
module: Module;

constructor(module: Module) {
Copy link
Member

Choose a reason for hiding this comment

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

One thing we could use more is to use constructor argument declarations for fields, i.e. here

constructor(public readonly module: Module) {...}

We are already using it in some places like Chunk where it saves us quite a bit of mindless copying

Copy link
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.

I have disabled the flag for now and would like to merge the branch as it is as I find the changes useful but I am not yet sold 100% on the benefits of the flag. That way, your work is not lost and we can reevaluate later.

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.

None yet

2 participants