Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactor node factory API, use node factory in parser#35282

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
rbuckton merged 20 commits intomasterfromnodeFactory
Jun 16, 2020

Conversation

rbuckton
Copy link
Contributor

@rbucktonrbuckton commentedNov 22, 2019
edited
Loading

This overhauls our node factory API to provide the following benefits:

  • Allows us to leverage the factory API from within the parser.
    • This is intended to help us ensure that the property layout of each kind ofNode is stable between the parser, checker, and transformers to reduce polymorphism, as well as to provide a "single source of truth" with respect to how nodes are created.
  • Allows us to streamline transform flag aggregation into node creation.
    • This allows us to remove transform flag logic frombinder.ts andtransformer.ts and ensures that transform flags willalways be correctly aggregated during transformations.
  • Extracts our auto-parenthesization logic out of the node factories.
    • This allows us to use the new node factories in the parser without the undue overhead incurred by the parenthesizer rules.
  • Allows us to deprecate older node factory APIs and reduce node factory overloads.

In the future, this will also allow us to better isolate which transformer was responsible for creating nodes, as well as to possibly leverage transformers outside of the emit pipeline.

As part of these changes, all of the existingcreate* andupdate* factory functions in thets namespace are being moved to aNodeFactory object that can be created via the internalcreateNodeFactory function. Authors of transformers can access theNodeFactory associated with their transformation via theTransformationContext provided to their transformer:

import*astsfrom"typescript";functionmyTransformer(context:ts.TransformationContext){// old: createIdentifier("foo");// new (option 1):const{ factory}=context;factory.createIdentifier("foo");// new (option 2):const{factory:{ createIdentifier}}=context;createIdentifier("foo");// same as old}

In addition, thets.factory object is a singletonNodeFactory instance, which can be used to create synthetic nodesoutside of a transformer.

So as not to break compatibility with older API consumers, the existingcreate* andupdate* factory functions will also be available to consumers of the TypeScript language service and the TS Server API. However, these functions are considered deprecated, and will be phased out using the following (tentative) plan:

  • 4.0 - Existing factory functions are marked with a@deprecated JSDoc comment and are no longer used by TypeScript internals.
  • 4.1 (?) - The first time a deprecated factory function is called, the Language Service will attempt to write a deprecation warning message (depending on the host and whether a suitableconsole.log-like logger is available).
  • 4.2 (?) - Whenever a deprecated factory function is called, an exception will be thrown.
  • 4.3 (?) - Deprecated factory functions will be removed.

Remaining TODO items:

  • Consider renaming concise functions likecreateParen to a more expressive (and less ambiguous) name such ascreateParenthesizedExpression.
  • Consider making most properties of nodesreadonly, as one goal is to treat a TypeScript AST as immutable (and should be "changed" via visitors).
  • Verify performance of parser use of new API.

@rbuckton
Copy link
ContributorAuthor

@typescript-bot perf test

@typescript-bot
Copy link
Collaborator

typescript-bot commentedNov 22, 2019
edited
Loading

Heya@rbuckton, I've started to run the perf test suite on this PR at922ab41. You can monitor the buildhere. It should now contribute to this PR's status checks.

Update:The results are in!

@typescript-bot
Copy link
Collaborator

@rbuckton
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..35282

Metricmaster35282DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used354,711k (± 0.02%)334,758k (± 0.02%)-19,953k (- 5.63%)334,530k334,897k
Parse Time1.63s (± 0.71%)1.90s (± 0.41%)+0.27s (+16.91%)1.88s1.92s
Bind Time0.86s (± 0.67%)0.75s (± 1.21%)-0.11s (-12.98%)0.74s0.77s
Check Time4.53s (± 0.53%)4.46s (± 0.55%)-0.07s (- 1.44%)4.38s4.50s
Emit Time5.27s (± 0.59%)5.08s (± 0.55%)-0.19s (- 3.60%)5.04s5.15s
Total Time12.29s (± 0.42%)12.20s (± 0.27%)-0.10s (- 0.77%)12.13s12.28s
Monaco - node (v10.16.3, x64)
Memory used365,915k (± 0.01%)340,571k (± 0.03%)-25,344k (- 6.93%)340,328k340,866k
Parse Time1.27s (± 0.51%)1.49s (± 0.60%)+0.23s (+17.90%)1.47s1.51s
Bind Time0.76s (± 0.79%)0.65s (± 0.51%)-0.10s (-13.91%)0.64s0.66s
Check Time4.67s (± 0.26%)4.61s (± 0.41%)-0.06s (- 1.35%)4.57s4.67s
Emit Time2.98s (± 1.47%)2.78s (± 0.57%)-0.20s (- 6.72%)2.74s2.81s
Total Time9.67s (± 0.47%)9.53s (± 0.30%)-0.14s (- 1.49%)9.46s9.58s
TFS - node (v10.16.3, x64)
Memory used321,656k (± 0.02%)299,620k (± 0.02%)-22,036k (- 6.85%)299,542k299,753k
Parse Time0.97s (± 0.87%)1.19s (± 0.69%)+0.22s (+22.25%)1.17s1.21s
Bind Time0.72s (± 1.03%)0.60s (± 1.11%)-0.12s (-16.67%)0.59s0.62s
Check Time4.14s (± 0.53%)4.08s (± 0.36%)-0.06s (- 1.45%)4.04s4.10s
Emit Time3.07s (± 0.85%)2.78s (± 0.76%)-0.29s (- 9.50%)2.72s2.82s
Total Time8.91s (± 0.58%)8.65s (± 0.30%)-0.25s (- 2.86%)8.59s8.70s
Angular - node (v12.1.0, x64)
Memory used330,312k (± 0.04%)312,079k (± 0.02%)-18,232k (- 5.52%)311,933k312,196k
Parse Time1.58s (± 0.74%)1.86s (± 0.83%)+0.28s (+17.92%)1.83s1.89s
Bind Time0.84s (± 0.44%)0.72s (± 0.80%)-0.12s (-14.44%)0.71s0.74s
Check Time4.45s (± 0.58%)4.36s (± 0.66%)-0.10s (- 2.16%)4.31s4.42s
Emit Time5.50s (± 1.08%)5.30s (± 0.58%)-0.20s (- 3.65%)5.25s5.40s
Total Time12.38s (± 0.63%)12.25s (± 0.40%)-0.14s (- 1.10%)12.15s12.35s
Monaco - node (v12.1.0, x64)
Memory used345,639k (± 0.01%)322,985k (± 0.05%)-22,655k (- 6.55%)322,410k323,132k
Parse Time1.23s (± 0.59%)1.47s (± 0.82%)+0.24s (+19.64%)1.45s1.50s
Bind Time0.73s (± 0.68%)0.61s (± 0.65%)-0.11s (-15.84%)0.60s0.62s
Check Time4.49s (± 0.39%)4.49s (± 0.45%)+0.00s (+ 0.04%)4.44s4.54s
Emit Time3.02s (± 0.79%)2.86s (± 0.53%)-0.17s (- 5.49%)2.81s2.89s
Total Time9.47s (± 0.41%)9.43s (± 0.42%)-0.03s (- 0.37%)9.32s9.52s
TFS - node (v12.1.0, x64)
Memory used304,040k (± 0.01%)284,044k (± 0.01%)-19,995k (- 6.58%)283,980k284,106k
Parse Time0.95s (± 0.78%)1.21s (± 1.14%)+0.25s (+26.55%)1.18s1.24s
Bind Time0.68s (± 1.00%)0.57s (± 0.78%)-0.12s (-16.96%)0.56s0.58s
Check Time4.06s (± 0.49%)4.04s (± 0.51%)-0.02s (- 0.52%)4.00s4.08s
Emit Time3.11s (± 1.15%)2.90s (± 0.65%)-0.21s (- 6.75%)2.86s2.95s
Total Time8.81s (± 0.43%)8.71s (± 0.41%)-0.09s (- 1.08%)8.65s8.78s
Angular - node (v8.9.0, x64)
Memory used349,598k (± 0.01%)330,993k (± 0.01%)-18,605k (- 5.32%)330,940k331,111k
Parse Time2.11s (± 0.41%)2.41s (± 0.53%)+0.30s (+14.42%)2.38s2.44s
Bind Time0.91s (± 0.55%)0.79s (± 0.71%)-0.12s (-12.93%)0.78s0.80s
Check Time5.31s (± 0.31%)5.22s (± 0.56%)-0.09s (- 1.75%)5.16s5.30s
Emit Time6.31s (± 0.81%)6.08s (± 1.22%)-0.23s (- 3.68%)5.88s6.23s
Total Time14.63s (± 0.35%)14.49s (± 0.72%)-0.14s (- 0.94%)14.24s14.69s
Monaco - node (v8.9.0, x64)
Memory used363,743k (± 0.01%)341,050k (± 0.01%)-22,694k (- 6.24%)340,920k341,126k
Parse Time1.56s (± 0.52%)1.80s (± 0.61%)+0.24s (+15.16%)1.78s1.83s
Bind Time0.93s (± 0.75%)0.84s (± 0.57%)-0.09s (- 9.90%)0.83s0.85s
Check Time5.56s (± 0.64%)5.28s (± 0.41%)-0.27s (- 4.95%)5.23s5.32s
Emit Time3.05s (± 0.67%)3.30s (± 0.76%)+0.24s (+ 7.86%)3.23s3.35s
Total Time11.10s (± 0.51%)11.21s (± 0.37%)+0.10s (+ 0.95%)11.15s11.30s
TFS - node (v8.9.0, x64)
Memory used320,632k (± 0.01%)300,490k (± 0.01%)-20,142k (- 6.28%)300,422k300,584k
Parse Time1.27s (± 0.53%)1.51s (± 0.60%)+0.24s (+18.54%)1.49s1.53s
Bind Time0.74s (± 0.54%)0.62s (± 0.55%)-0.12s (-16.73%)0.61s0.62s
Check Time4.76s (± 0.43%)4.69s (± 0.46%)-0.07s (- 1.51%)4.66s4.75s
Emit Time3.22s (± 1.09%)3.01s (± 0.65%)-0.21s (- 6.46%)2.97s3.06s
Total Time10.00s (± 0.49%)9.83s (± 0.40%)-0.17s (- 1.71%)9.74s9.91s
Angular - node (v8.9.0, x86)
Memory used198,499k (± 0.02%)189,508k (± 0.03%)-8,991k (- 4.53%)189,394k189,666k
Parse Time2.03s (± 0.58%)2.34s (± 0.85%)+0.31s (+15.26%)2.30s2.38s
Bind Time1.04s (± 1.21%)0.93s (± 0.73%)-0.11s (-10.28%)0.93s0.96s
Check Time4.82s (± 0.72%)4.76s (± 0.41%)-0.06s (- 1.20%)4.72s4.80s
Emit Time6.11s (± 0.66%)5.83s (± 1.23%)-0.28s (- 4.54%)5.65s6.03s
Total Time14.00s (± 0.39%)13.86s (± 0.59%)-0.13s (- 0.96%)13.64s14.10s
Monaco - node (v8.9.0, x86)
Memory used203,768k (± 0.02%)192,720k (± 0.02%)-11,049k (- 5.42%)192,650k192,860k
Parse Time1.61s (± 0.44%)1.86s (± 1.08%)+0.25s (+15.48%)1.82s1.91s
Bind Time0.75s (± 0.99%)0.66s (± 1.38%)-0.09s (-12.48%)0.65s0.68s
Check Time5.42s (± 0.43%)5.37s (± 0.48%)-0.05s (- 0.96%)5.31s5.42s
Emit Time2.88s (± 0.42%)2.70s (± 0.82%)-0.18s (- 6.21%)2.66s2.75s
Total Time10.66s (± 0.25%)10.59s (± 0.51%)-0.07s (- 0.70%)10.46s10.70s
TFS - node (v8.9.0, x86)
Memory used180,595k (± 0.02%)170,821k (± 0.02%)-9,774k (- 5.41%)170,716k170,885k
Parse Time1.30s (± 0.38%)1.55s (± 1.18%)+0.24s (+18.79%)1.52s1.60s
Bind Time0.69s (± 0.53%)0.59s (± 0.84%)-0.11s (-15.68%)0.58s0.60s
Check Time4.48s (± 0.54%)4.44s (± 0.80%)-0.04s (- 0.83%)4.38s4.54s
Emit Time2.97s (± 0.57%)2.79s (± 0.96%)-0.18s (- 6.07%)2.72s2.84s
Total Time9.44s (± 0.36%)9.37s (± 0.65%)-0.08s (- 0.82%)9.25s9.52s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-166-generic
Architecturex64
Available Memory16 GB
Available Memory7 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v8.9.0, x64)
  • node (v8.9.0, x86)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v8.9.0, x64)
  • Angular - node (v8.9.0, x86)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v8.9.0, x64)
  • Monaco - node (v8.9.0, x86)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v8.9.0, x64)
  • TFS - node (v8.9.0, x86)
BenchmarkNameIterations
Current3528210
Baselinemaster10

@rbuckton
Copy link
ContributorAuthor

@typescript-bot perf test

@typescript-bot
Copy link
Collaborator

typescript-bot commentedDec 13, 2019
edited
Loading

Heya@rbuckton, I've started to run the perf test suite on this PR atae7c638. You can monitor the buildhere. It should now contribute to this PR's status checks.

Update:The results are in!

@typescript-bot
Copy link
Collaborator

@rbuckton
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..35282

Metricmaster35282DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used354,603k (± 0.01%)334,788k (± 0.02%)-19,815k (- 5.59%)334,590k334,926k
Parse Time1.63s (± 0.63%)1.98s (± 0.59%)+0.35s (+21.24%)1.95s2.00s
Bind Time0.86s (± 0.72%)0.78s (± 0.64%)-0.09s (- 9.99%)0.77s0.79s
Check Time4.53s (± 1.61%)4.45s (± 0.29%)-0.08s (- 1.88%)4.42s4.48s
Emit Time5.26s (± 1.39%)5.13s (± 1.21%)-0.13s (- 2.55%)5.00s5.33s
Total Time12.29s (± 1.20%)12.32s (± 0.53%)+0.04s (+ 0.28%)12.15s12.51s
Monaco - node (v10.16.3, x64)
Memory used366,191k (± 0.02%)340,557k (± 0.02%)-25,634k (- 7.00%)340,339k340,676k
Parse Time1.27s (± 1.04%)1.57s (± 0.53%)+0.30s (+23.42%)1.55s1.59s
Bind Time0.75s (± 0.59%)0.66s (± 1.21%)-0.09s (-11.97%)0.65s0.68s
Check Time4.65s (± 0.43%)4.61s (± 0.59%)-0.04s (- 0.97%)4.54s4.66s
Emit Time2.93s (± 0.70%)2.80s (± 0.94%)-0.13s (- 4.27%)2.75s2.88s
Total Time9.61s (± 0.48%)9.64s (± 0.45%)+0.04s (+ 0.39%)9.56s9.74s
TFS - node (v10.16.3, x64)
Memory used322,141k (± 0.03%)299,598k (± 0.03%)-22,543k (- 7.00%)299,317k299,745k
Parse Time0.96s (± 0.78%)1.24s (± 0.66%)+0.28s (+29.26%)1.22s1.25s
Bind Time0.73s (± 0.92%)0.61s (± 0.73%)-0.11s (-15.82%)0.61s0.63s
Check Time4.14s (± 0.71%)4.10s (± 0.43%)-0.04s (- 0.94%)4.06s4.14s
Emit Time3.02s (± 1.00%)2.82s (± 0.80%)-0.20s (- 6.69%)2.74s2.86s
Total Time8.84s (± 0.53%)8.77s (± 0.31%)-0.08s (- 0.87%)8.70s8.82s
Angular - node (v12.1.0, x64)
Memory used330,237k (± 0.09%)312,099k (± 0.02%)-18,139k (- 5.49%)311,937k312,258k
Parse Time1.56s (± 0.47%)1.93s (± 0.42%)+0.37s (+23.75%)1.92s1.95s
Bind Time0.84s (± 0.57%)0.74s (± 0.78%)-0.10s (-11.59%)0.73s0.75s
Check Time4.44s (± 0.57%)4.36s (± 0.54%)-0.07s (- 1.67%)4.30s4.42s
Emit Time5.46s (± 1.22%)5.33s (± 0.52%)-0.13s (- 2.38%)5.26s5.39s
Total Time12.29s (± 0.65%)12.36s (± 0.40%)+0.07s (+ 0.54%)12.26s12.45s
Monaco - node (v12.1.0, x64)
Memory used345,874k (± 0.02%)322,943k (± 0.02%)-22,931k (- 6.63%)322,755k323,037k
Parse Time1.23s (± 0.48%)1.54s (± 0.84%)+0.31s (+25.37%)1.51s1.56s
Bind Time0.72s (± 0.97%)0.63s (± 0.47%)-0.09s (-12.66%)0.62s0.63s
Check Time4.50s (± 0.53%)4.46s (± 0.53%)-0.05s (- 1.00%)4.39s4.51s
Emit Time2.99s (± 1.23%)2.90s (± 1.20%)-0.09s (- 3.08%)2.85s3.01s
Total Time9.44s (± 0.55%)9.53s (± 0.58%)+0.09s (+ 0.93%)9.38s9.63s
TFS - node (v12.1.0, x64)
Memory used304,436k (± 0.02%)283,915k (± 0.02%)-20,522k (- 6.74%)283,716k284,049k
Parse Time0.94s (± 0.69%)1.25s (± 1.03%)+0.32s (+33.80%)1.23s1.28s
Bind Time0.68s (± 0.54%)0.58s (± 1.11%)-0.09s (-13.91%)0.57s0.60s
Check Time4.06s (± 0.40%)4.03s (± 0.49%)-0.03s (- 0.76%)3.98s4.07s
Emit Time3.08s (± 1.15%)2.93s (± 1.09%)-0.15s (- 4.88%)2.88s3.02s
Total Time8.75s (± 0.45%)8.79s (± 0.48%)+0.04s (+ 0.41%)8.72s8.92s
Angular - node (v8.9.0, x64)
Memory used349,435k (± 0.01%)330,992k (± 0.02%)-18,444k (- 5.28%)330,896k331,144k
Parse Time2.10s (± 0.36%)2.47s (± 0.70%)+0.37s (+17.49%)2.44s2.52s
Bind Time0.92s (± 0.75%)0.81s (± 0.71%)-0.10s (-11.48%)0.79s0.82s
Check Time5.32s (± 0.86%)5.26s (± 0.38%)-0.05s (- 1.02%)5.22s5.31s
Emit Time6.23s (± 0.53%)6.10s (± 1.15%)-0.13s (- 2.07%)5.95s6.22s
Total Time14.57s (± 0.41%)14.64s (± 0.53%)+0.08s (+ 0.54%)14.46s14.77s
Monaco - node (v8.9.0, x64)
Memory used364,024k (± 0.01%)341,085k (± 0.01%)-22,939k (- 6.30%)341,020k341,147k
Parse Time1.57s (± 0.49%)1.85s (± 0.35%)+0.29s (+18.34%)1.84s1.87s
Bind Time0.93s (± 1.15%)0.84s (± 0.44%)-0.08s (- 8.75%)0.84s0.85s
Check Time5.51s (± 1.64%)5.28s (± 0.29%)-0.24s (- 4.33%)5.24s5.31s
Emit Time3.16s (± 4.52%)3.32s (± 0.75%)+0.16s (+ 5.06%)3.25s3.37s
Total Time11.17s (± 0.84%)11.29s (± 0.25%)+0.13s (+ 1.16%)11.23s11.35s
TFS - node (v8.9.0, x64)
Memory used321,128k (± 0.02%)300,547k (± 0.01%)-20,581k (- 6.41%)300,454k300,613k
Parse Time1.27s (± 0.37%)1.56s (± 0.40%)+0.29s (+22.76%)1.55s1.57s
Bind Time0.74s (± 0.65%)0.63s (± 0.53%)-0.11s (-14.52%)0.62s0.64s
Check Time4.74s (± 0.64%)4.70s (± 0.73%)-0.04s (- 0.87%)4.61s4.79s
Emit Time3.20s (± 0.95%)3.01s (± 0.61%)-0.19s (- 5.91%)2.96s3.04s
Total Time9.95s (± 0.52%)9.89s (± 0.51%)-0.05s (- 0.50%)9.74s10.03s
Angular - node (v8.9.0, x86)
Memory used198,438k (± 0.02%)189,538k (± 0.03%)-8,900k (- 4.49%)189,396k189,664k
Parse Time2.03s (± 1.10%)2.38s (± 0.44%)+0.35s (+17.09%)2.36s2.41s
Bind Time1.02s (± 0.85%)0.95s (± 0.98%)-0.07s (- 7.24%)0.92s0.96s
Check Time4.84s (± 0.52%)4.72s (± 0.95%)-0.12s (- 2.38%)4.65s4.83s
Emit Time6.09s (± 1.36%)5.88s (± 0.40%)-0.21s (- 3.46%)5.83s5.93s
Total Time13.99s (± 0.66%)13.93s (± 0.37%)-0.05s (- 0.39%)13.81s14.07s
Monaco - node (v8.9.0, x86)
Memory used203,977k (± 0.02%)192,792k (± 0.02%)-11,185k (- 5.48%)192,694k192,877k
Parse Time1.61s (± 0.73%)1.89s (± 0.96%)+0.28s (+17.28%)1.86s1.95s
Bind Time0.75s (± 1.26%)0.67s (± 1.30%)-0.08s (-10.58%)0.65s0.69s
Check Time5.41s (± 0.46%)5.39s (± 0.61%)-0.02s (- 0.42%)5.34s5.47s
Emit Time2.89s (± 1.99%)2.70s (± 0.44%)-0.19s (- 6.44%)2.68s2.73s
Total Time10.66s (± 0.51%)10.65s (± 0.50%)-0.01s (- 0.13%)10.55s10.80s
TFS - node (v8.9.0, x86)
Memory used181,023k (± 0.01%)170,863k (± 0.03%)-10,161k (- 5.61%)170,780k170,969k
Parse Time1.32s (± 1.00%)1.58s (± 1.67%)+0.26s (+20.11%)1.53s1.65s
Bind Time0.69s (± 0.72%)0.60s (± 1.14%)-0.10s (-14.24%)0.58s0.61s
Check Time4.49s (± 0.53%)4.43s (± 0.49%)-0.06s (- 1.23%)4.38s4.47s
Emit Time2.93s (± 0.77%)2.81s (± 1.39%)-0.13s (- 4.36%)2.71s2.89s
Total Time9.43s (± 0.38%)9.42s (± 0.56%)-0.02s (- 0.16%)9.24s9.49s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-166-generic
Architecturex64
Available Memory16 GB
Available Memory6 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v8.9.0, x64)
  • node (v8.9.0, x86)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v8.9.0, x64)
  • Angular - node (v8.9.0, x86)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v8.9.0, x64)
  • Monaco - node (v8.9.0, x86)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v8.9.0, x64)
  • TFS - node (v8.9.0, x86)
BenchmarkNameIterations
Current3528210
Baselinemaster10

@ajafff
Copy link
Contributor

What's the benefit of having to usecontext.factory in transforms and how is it different fromts.factory?

@rbuckton
Copy link
ContributorAuthor

What's the benefit of having to usecontext.factory in transforms and how is it different fromts.factory?

The current factory methods mark nodes asSynthesized and do some other work don't make sense for some situations. Since the newNodeFactory API allows for a number of additional hooks for when nodes are created and updated, it is better for a transformer to rely on theNodeFactory provided to it, as that will eventually allow us to be more flexible with transformations in the future.

For example, the parser now utilizes a customNodeFactory that can explicitly set parent pointers as the AST is constructed:

constfactory=createNodeFactory(NodeFactoryFlags.NoParenthesizerRules|NodeFactoryFlags.NoNodeConverters,baseNodeFactory,{
onSetChild(parent,child){
if(setParentNodes){
setParent(child,parent);
}
},
onSetChildren(parent,children){
if(setParentNodes){
setEachParent(children,parent);
}
},
onFinishNode(node){
if(setParentNodes){
if(hasJSDocNodes(node)){
setEachParent(node.jsDoc,node);
}
}
},
onCreateNode(_){
nodeCount++;
}
});

The existing factory methods will still be available for some period of time with deprecations:https://github.com/microsoft/TypeScript/blob/086633f4db521efb6bc25aadaca68f457e56a95b/src/compat/deprecations.ts. This model allows us to introduce deprecations with different levels of aggressiveness:

  • Soft - Deprecations in documentation only.
  • Warn - Deprecations that attempt to warn you when used (usually viaconsole.log if available).
  • Error - Deprecations that throw errors when used.
  • Removed - The deprecated API is completely removed from the package.

@rbucktonrbuckton marked this pull request as ready for reviewMay 8, 2020 02:13
@rbuckton
Copy link
ContributorAuthor

@typescript-bot perf test

@typescript-bot
Copy link
Collaborator

typescript-bot commentedMay 8, 2020
edited
Loading

Heya@rbuckton, I've started to run the perf test suite on this PR at086633f. You can monitor the buildhere.

# Conflicts:#src/compiler/factoryPublic.ts#src/services/codefixes/convertToAsyncFunction.ts#src/services/codefixes/helpers.ts#src/services/codefixes/inferFromUsage.ts#src/services/signatureHelp.ts#tests/baselines/reference/api/tsserverlibrary.d.ts#tests/baselines/reference/api/typescript.d.ts
# Conflicts:#src/compiler/binder.ts#src/compiler/checker.ts#src/compiler/factory.ts#src/compiler/transformers/declarations.ts#src/compiler/transformers/es2015.ts#src/compiler/transformers/module/module.ts#src/compiler/transformers/module/system.ts#src/compiler/transformers/taggedTemplate.ts#src/compiler/transformers/ts.ts#src/compiler/utilities.ts#src/compiler/visitor.ts#src/harness/vfsUtil.ts#src/services/codefixes/addMissingAsync.ts#src/services/codefixes/convertToMappedObjectType.ts#src/services/codefixes/helpers.ts#src/services/completions.ts#src/services/refactors/generateGetAccessorAndSetAccessor.ts
@rbuckton
Copy link
ContributorAuthor

I'm going to merge master into this one more time to make sure there aren't any new changes that need to be captured, then I can merge this to master.

@nonara
Copy link

Nice work! Was a decision made on the renaming proposal?

@rbuckton
Copy link
ContributorAuthor

Yes, we merged#39058 which used the more consistent and clearer names for factory methods.

nonara reacted with thumbs up emoji

@72636c72636c mentioned this pull requestAug 21, 2020
1 task
edsrzf pushed a commit to edsrzf/ts-migrate that referenced this pull requestOct 24, 2020
Most ts.create* and ts.update* functions are deprecated as of TypeScript 4.0. Thecurrent plan is to emit noiser and noisier warnings with each versionuntil the deprecated functions are removed in 4.3.See this pull request for more details:microsoft/TypeScript#35282Some method signatures and names have changed slightly.The easy way to update is to use the global ts.factory object.TypeScript transformations also have access to a NodeFactory in theirtransformation contexts.Note that we still use the deprecate getMutableClone function becauseits replacement is not included in the TypeScript declarations. Seemicrosoft/TypeScript#40507
@ortaorta mentioned this pull requestOct 30, 2020
5 tasks
@jakebaileyjakebailey deleted the nodeFactory branchNovember 7, 2022 17:37
jasonreyes9 added a commit to jasonreyes9/ts-migrate that referenced this pull requestOct 31, 2023
Most ts.create* and ts.update* functions are deprecated as of TypeScript 4.0. Thecurrent plan is to emit noiser and noisier warnings with each versionuntil the deprecated functions are removed in 4.3.See this pull request for more details:microsoft/TypeScript#35282Some method signatures and names have changed slightly.The easy way to update is to use the global ts.factory object.TypeScript transformations also have access to a NodeFactory in theirtransformation contexts.Note that we still use the deprecate getMutableClone function becauseits replacement is not included in the TypeScript declarations. Seemicrosoft/TypeScript#40507
threema-danilo added a commit to threema-ch/threema-desktop that referenced this pull requestDec 18, 2024
Most `ts.create*` and `ts.update*` functions are deprecated as ofTypeScript 4.0.See this pull request for more details:microsoft/TypeScript#35282Additionally, some API calls (especially `createImportClause`) needed tobe updated because apparently the API changed.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@weswighamweswighamweswigham left review comments

@RyanCavanaughRyanCavanaughRyanCavanaugh approved these changes

@sandersnsandersnAwaiting requested review from sandersn

@sheetalkamatsheetalkamatAwaiting requested review from sheetalkamat

@amcaseyamcaseyAwaiting requested review from amcasey

@ahejlsbergahejlsbergAwaiting requested review from ahejlsberg

Assignees

@sheetalkamatsheetalkamat

Labels
Author: TeamFor Milestone BugPRs that fix a bug with a specific milestone
Projects
Archived in project
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

9 participants
@rbuckton@typescript-bot@ajafff@amcasey@nonara@weswigham@RyanCavanaugh@sandersn@sheetalkamat

[8]ページ先頭

©2009-2025 Movatter.jp