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

Update typescript to 4.8 #14880

Merged
merged 5 commits into from Aug 30, 2022
Merged

Update typescript to 4.8 #14880

merged 5 commits into from Aug 30, 2022

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Aug 26, 2022

Q                       A
Any Dependency Changes? Bump TS to 4.8 and fix new typing errors
License MIT

Also removed babel-parser's tsconfig now that we have converted the parser to TS.

@JLHwung JLHwung added PR: Internal 🏠 A type of pull request used for our changelog categories PR: Dependency ⬆️ labels Aug 26, 2022
@@ -10,7 +10,9 @@ export function finalize<T>(deepArr: DeepArray<T>): ReadonlyDeepArray<T> {
return Object.freeze(deepArr) as ReadonlyDeepArray<T>;
}

export function flattenToSet<T>(arr: ReadonlyDeepArray<T>): Set<T> {
export function flattenToSet<T extends string>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

T is constrained to string so that Array.isArray(el) can effectively differentiate between ReadonlyDeepArray<T> and T.

@babel-bot
Copy link
Collaborator

babel-bot commented Aug 26, 2022

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52822/

nicolo-ribaudo
nicolo-ribaudo previously approved these changes Aug 26, 2022
@nicolo-ribaudo nicolo-ribaudo dismissed their stale review August 26, 2022 03:28

There is the OOM error you mentioned :/

@liuxingbaoyu
Copy link
Member

This should be a new bug, not even enabling strictNullCheck. :)

@liuxingbaoyu
Copy link
Member

liuxingbaoyu commented Aug 26, 2022

ts4.7

PS F:\babel> yarn tsc --extendedDiagnostics --incremental false
Files:                          714
Lines of Library:             27958
Lines of Definitions:         48613
Lines of TypeScript:         109737
Lines of JavaScript:              0
Lines of JSON:                 4198
Lines of Other:                   0
Nodes of Library:            119371
Nodes of Definitions:        127849
Nodes of TypeScript:         416262
Nodes of JavaScript:              0
Nodes of JSON:                11813
Nodes of Other:                   0
Identifiers:                 230675
Symbols:                     959380
Types:                       380554
Instantiations:            42135598
Memory used:               1117681K
Assignability cache size:    262472
Identity cache size:          16941
Subtype cache size:          100724
Strict subtype cache size:     8524
I/O Read time:                0.08s
Parse time:                   0.75s
ResolveModule time:           0.18s
ResolveTypeReference time:    0.01s
Program time:                 1.11s
Bind time:                    0.42s
Check time:                  19.77s
transformTime time:           1.32s
Source Map time:              0.05s
commentTime time:             0.08s
I/O Write time:               0.26s
printTime time:               2.18s
Emit time:                    2.19s
Total time:                  23.49s

ts4.8

PS F:\babel> yarn tsc --extendedDiagnostics --incremental false
Files:                          715
Lines of Library:             28146
Lines of Definitions:         48613
Lines of TypeScript:         109741
Lines of JavaScript:              0
Lines of JSON:                 4198
Lines of Other:                   0
Nodes of Library:            118224
Nodes of Definitions:        126241
Nodes of TypeScript:         413313
Nodes of JavaScript:              0
Nodes of JSON:                11813
Nodes of Other:                   0
Identifiers:                 230557
Symbols:                    2992041
Types:                      1556880
Instantiations:            42130595
Memory used:               3987979K
Assignability cache size:    260473
Identity cache size:          16941
Subtype cache size:           99375
Strict subtype cache size:     9253
I/O Read time:                0.08s
Parse time:                   0.73s
ResolveModule time:           0.20s
ResolveTypeReference time:    0.01s
Program time:                 1.11s
Bind time:                    0.42s
Check time:                  57.65s
transformTime time:           1.84s
Source Map time:              0.05s
commentTime time:             0.09s
I/O Write time:               0.32s
printTime time:               2.84s
Emit time:                    2.84s
Total time:                  62.02s

This should be a regression.
Memory usage increased from 1gb to 4gb and time increased from 23s to 62s.
Chief among them is a suspicious increase in the number of Symbols and Types.

But I personally don't mind letting it merge first to avoid blocking our development progress.

@JLHwung JLHwung marked this pull request as draft August 26, 2022 14:14
@nstepien
Copy link
Contributor

@liuxingbaoyu might be related microsoft/TypeScript#50290 (comment)

@liuxingbaoyu
Copy link
Member

@nstepien
Thank you for your reminder!
I've seen that one, and it shows up as a massive increase in Assignability cache size, but here it's Symbols and Types.

@liuxingbaoyu
Copy link
Member

I'm sure I don't know what's going on.😅

@liuxingbaoyu
Copy link
Member

Yes, as you can see, the CI turns green after adding a magic any.

This might have something to do with this across files.
When I extract Scope to the same file, it throws error.
image

packages/babel-traverse/src/path/index.ts:157:24 - error TS2345: Argument of type 'this' is not assignable to parameter of type 'NodePath<Scopable | Pattern>'.
  Type 'NodePath<T>' is not assignable to type 'NodePath<Scopable | Pattern>'.
    Type 'T' is not assignable to type 'Scopable | Pattern'.
      Type 'Node' is not assignable to type 'Scopable | Pattern'.
        Type 'ArrayExpression' is not assignable to type 'Scopable | Pattern'.
          Type 'ArrayExpression' is not assignable to type 'ArrayPattern'.
            Types of property 'type' are incompatible.
              Type '"ArrayExpression"' is not assignable to type '"ArrayPattern"'.
                Type 'T' is not assignable to type 'WhileStatement'.
                  Type 'Node' is not assignable to type 'WhileStatement'.
                    Type 'ArrayExpression' is missing the following properties from type 'WhileStatement': test, body

157     let a = new Scope2(this);

I think we can merge first, since our NodePath is so complex, it's not trivial to make even a minimal reproduction.

This works, too, without any other side effects.

   getScope(scope: Scope): Scope {
     return this.isScope()
       ? new Scope(this as NodePath<t.Pattern | t.Scopable>)
       : scope;
   }

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
@JLHwung
Copy link
Contributor Author

JLHwung commented Aug 29, 2022

When I extract Scope to the same file, it throws error.

Yeah the error is expected, new Scope must be guarded by the isScope check.

@liuxingbaoyu liuxingbaoyu marked this pull request as ready for review August 29, 2022 13:55
@liuxingbaoyu
Copy link
Member

You're right, I seem to be closer to making a repo that reproduces, albeit just as complicated. 😂

@JLHwung
Copy link
Contributor Author

JLHwung commented Aug 29, 2022

@liuxingbaoyu A smaller reproduction will be great! I am drafting an issue to the TS repo. If you come up with a smaller reproduction, please let me know and I can update the issue.

@liuxingbaoyu
Copy link
Member

https://github.com/liuxingbaoyu/babel-ts4.8-bug
To be honest, this might not be small enough for a human, but it's much more convenient for debugging and binary search.

@nicolo-ribaudo nicolo-ribaudo merged commit 2626f18 into babel:main Aug 30, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the ts-4-8 branch August 30, 2022 09:47
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Nov 30, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Dependency ⬆️ PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants