GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Adds a simplified pretty printer for tree transformations by rbuckton · Pull Request #6987 · microsoft/TypeScript

Conversation

@rbuckton

@rbuckton Ron Buckton (rbuckton) commented Feb 9, 2016

Copy link
Copy Markdown
Contributor

Unfortunately, we cannot easily leverage our existing emitter to emit transformed nodes. The current emitter often assumes nodes are original source tree nodes, rather than synthesized nodes created during a transformation phase. Transformers are not required to set parent pointers on nodes, as they will often reuse existing source tree nodes and should not change the parent pointers on these nodes.

Instead we will add a new, simpler node printer whose responsibility is to emit the exact node tree provided.

The printFiles function will eventually supplant the existing emitFiles function. When called, this function will get a list of Transformer callbacks based on the provided compiler options, adding the node printer as the last transformer in the list. This gives the node printer access to the TransformationContext, allowing it to process substitutions and track any hoisted declarations added during just-in-time substitution.

The node printer in printFiles is designed for performance, and minimizes the number of conditional branches within the emit for any node. The expectation is that all transformers have finished every non-substitution transformation before the printer is called, and therefore the node printer will print nodes verbatim.

In addition, similarly to how source maps were extracted from emitter.ts and into a SourceMapWriter to support the node printer, comment emit is now also extracted into a CommentWriter.

Related Pull Requests:

  • Adds the visitor API foundation for tree transformations. #6892 - Adds the visitor API foundation for tree transformations.
  • Adds the Transform Flags concept for tree transformations #6983 - Adds the Transform Flags concept for tree transformations.
  • Adds the transformFiles API for tree transformations #6986 - Adds the transformFiles API for tree transformations.
  • Adds a simplified pretty printer for tree transformations #6987 - Adds a simplified pretty printer for tree transformations.
  • Adds the TypeScript transformer #7191 - Adds the TypeScript transformer.
  • Adds the JSX transformer #7192 - Adds the JSX transformer.
  • Adds the ES7 transformer #7193 - Adds the ES7 transformer.
  • Adds the ES6 transformer #7194 - Adds the ES6 transformer.
  • Adds the Module transformers #7206 - Adds the Module transformer.

Review on Reviewable

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Ron Buckton (rbuckton) added 2 commits February 9, 2016 13:43
@rbuckton
Added printer
6b381ec
@rbuckton
Merge branch 'transforms-transformer' into transforms-printer
e545f1b
@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-not-required label Feb 9, 2016
This was referenced Feb 9, 2016
Adds the visitor API foundation for tree transformations. #6892
Merged
Adds the Transform Flags concept for tree transformations #6983
Merged
Adds the transformFiles API for tree transformations #6986
Merged
@rbuckton

Ron Buckton (rbuckton) commented Feb 9, 2016

Copy link
Copy Markdown
Contributor Author

Paging for review: Mohamed Hegazy (@mhegazy), Anders Hejlsberg (@ahejlsberg), Yui (@yuit), Daniel Rosenwasser (@DanielRosenwasser), Ryan Cavanaugh (@RyanCavanaugh), Vladimir Matveev (@vladima)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton
Adds destructuring logic and placeholders for each transformer.
49d2d93
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Feb 11, 2016

Copy link
Copy Markdown
Member

image

image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Feb 11, 2016

Copy link
Copy Markdown
Member

You can get around this by using Reviewable.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Feb 11, 2016

Copy link
Copy Markdown
Member

Review status: 0 of 8 files reviewed at latest revision, 5 unresolved discussions.


src/compiler/comments.ts, line 143 [r1] (raw file):
emitted as

Put some sort of quote demarcation around the emit.


src/compiler/comments.ts, line 148 [r1] (raw file):
same here regarding demarcation and "as"


src/compiler/comments.ts, line 185 [r1] (raw file):
Just use a numeric comparison


src/compiler/utilities.ts, line 115 [r1] (raw file):
I thought it was CommonJS by default but this works too.


src/compiler/factory.ts, line 148 [r1] (raw file):
What's the point of this exactly? Why can't you say this just returns a PrimaryExpression?


Comments from the review on Reviewable.io

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Ron Buckton (rbuckton) added 3 commits February 12, 2016 10:49
@rbuckton
Adds the TypeScript transformer
f948b14
@rbuckton
Merge branch 'transforms-transformer' into transforms-printer
c634a36
@rbuckton
Merge branch 'transforms-transformer' into transforms-printer
8ec3932
@rbuckton

Ron Buckton (rbuckton) commented Feb 17, 2016

Copy link
Copy Markdown
Contributor Author

Review status: 0 of 7 files reviewed at latest revision, 5 unresolved discussions.


src/compiler/comments.ts, line 143 [r1] (raw file):
Copy/paste from emitter, but I'll take a look.


src/compiler/comments.ts, line 148 [r1] (raw file):
Copy/paste from emitter.


src/compiler/comments.ts, line 185 [r1] (raw file):
Copy/paste from emitter.


src/compiler/utilities.ts, line 115 [r1] (raw file):
Not when the target is ES6. It looks like someone else had the same idea though, so I will drop these in favor of getEmitScriptTarget and getEmitModuleKind.


Comments from the review on Reviewable.io

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Ron Buckton (rbuckton) added 6 commits February 16, 2016 16:12
@rbuckton
PR feedback, switched to getEmitScriptTarget/getEmitModuleKind
357171f
@rbuckton
Merge branch 'transforms-transformer' into transforms-transformer-ts
c4dc2ae
@rbuckton
Adds initial jsx transformer
6c0551f
@rbuckton
Added initial ES7 transformer
1ceb02a
@rbuckton
Enables source maps for exceptions thrown in the compiler (when avail…
dd2dc78
…able)
@rbuckton
Adds ES6 transformer
c759b63
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Feb 20, 2016

Copy link
Copy Markdown
Member

Review status: 0 of 7 files reviewed at latest revision, 13 unresolved discussions.


src/compiler/printer.ts, line 184 [r1] (raw file):
Make it explicit withTempFlags.Auto


src/compiler/printer.ts, line 742 [r1] (raw file):
Could we not emit a semicolon as part of emitting a signature list?


src/compiler/printer.ts, line 995 [r1] (raw file):
Does the pretty-printer make no assumptions about the structure? Is it the responsibility of the prior transformers to ensure that an object literal is not the immediate concise body?


src/compiler/printer.ts, line 1106 [r1] (raw file):
Why even do it with a prefix? Or if you do, why not just

emitExpressionWithPrefix(node.asteriskToken ? "yield* " : "yield ", node.expression);·

src/compiler/printer.ts, line 1788 [r1] (raw file):
Cache length


src/compiler/printer.ts, line 1798 [r1] (raw file):
I don't like how the function doesn't document its return value. Can you make the function name more explicit and add a JSDoc comment?


src/compiler/printer.ts, line 1870 [r1] (raw file):
Cache length


src/compiler/printer.ts, line 1984 [r1] (raw file):
What is this condition for?

What about default initializers and optional parameters? Do we have tests for these cases?


Comments from the review on Reviewable.io

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Ron Buckton (rbuckton) added 6 commits February 19, 2016 18:23
@rbuckton
Added CommonJS/AMD/UMD module transformer
39628d7
@rbuckton
Added initial SystemJS transformer.
5564537
@rbuckton
Merge branch 'transforms-transformer' into transforms-printer
90a317f
@rbuckton
Merged some changes from other branches.
6d27336
@rbuckton
Merged some changes from other branches.
f52a30b
@rbuckton
PR Feedback.
64e7aa8
@rbuckton

Ron Buckton (rbuckton) commented Feb 23, 2016

Copy link
Copy Markdown
Contributor Author

Review status: 0 of 12 files reviewed at latest revision, 13 unresolved discussions.


src/compiler/printer.ts, line 742 [r1] (raw file):
This code path won't be used until such a time as we migrate the declaration emitter to use the pretty printer, but in the declaration emitter we always emit a semicolon.


src/compiler/printer.ts, line 995 [r1] (raw file):
That is correct, although I am adding some support to automatically parenthesize expressions to ensure the correct output. One reason for this is to make sure we have the right parentheses around nodes without having to know about the parent node during an individual transformation.


src/compiler/printer.ts, line 1106 [r1] (raw file):
Because yield; is legal in JavaScript, and we don't want to emit yield ;.


src/compiler/printer.ts, line 1788 [r1] (raw file):
I've discussed this with Vladimir Matveev (@vladima) in the past. V8 still does an array length lookup on every iteration to perform a bounds check, so caching the length doesn't necessarily have a real benefit.


src/compiler/printer.ts, line 1798 [r1] (raw file):
I'll fix this, though the equivalent function in emitter.ts is also undocumented.


src/compiler/printer.ts, line 1870 [r1] (raw file):
See above.


src/compiler/printer.ts, line 1984 [r1] (raw file):
These are effectively the same conditions as in emitSignatureParametersForArrow in emitter.ts, with some additional restrictions.


Comments from the review on Reviewable.io

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton
Merge branch 'transforms-printer' into transforms-transformer-ts
0a325ee
Ron Buckton (rbuckton) and others added 25 commits March 2, 2016 12:32
@rbuckton
Merge branch 'transforms-transformer-es6' into transforms-transformer…
70cbb9b
…-module
@rbuckton
Switch from onBefore/onAfterEmitNode to onEmitNode
ebb4764
@rbuckton
Merge branch 'transforms-printer' into transforms-transformer-ts
e66e51d
@rbuckton
Switched to onEmitNode
8b35af4
@rbuckton
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
1fdaf74
@rbuckton
Merge branch 'transforms-transformer-jsx' into transforms-transformer…
593fbd4
…-es7
@rbuckton
Merge branch 'transforms-transformer-es7' into transforms-transformer…
7b28b48
…-es6
@rbuckton
Switched to onEmitNode
1c73818
@rbuckton
Merge branch 'transforms-transformer-es6' into transforms-transformer…
c4a75ba
…-module
@rbuckton
Switched to onEmitNode
72eebdb
@rbuckton
Fixed invalid assertion in ts transformer
1cf183b
@rbuckton
General fixes and cleanup
d89e21a
@rbuckton
Moved modifier related flags to separate enum
5b8cf96
@rbuckton
Removed ModifiersArray
99e6ad8
@rbuckton
Add support for array return values from visitors
47cdfbe
@rbuckton
Removed NodeArrayNode in favor of arrays
2699bf9
@rbuckton
cleaned up assertions and removed flattenNodes.
94018a1
@rbuckton
Fixed perf issue in binder, plus PR feedback
ad0dd4e
@rbuckton
Updated baselines
44ca7d4
@rbuckton
PR Feedback
ae7843d
@rbuckton
Merge pull request #7206 from Microsoft/transforms-transformer-module
3c5f170
Adds the Module transformers
@rbuckton
Merge pull request #7194 from Microsoft/transforms-transformer-es6
07a3d18
Adds the ES6 transformer
@rbuckton
Merge pull request #7193 from Microsoft/transforms-transformer-es7
cc00f4c
Adds the ES7 transformer
@rbuckton
Merge pull request #7192 from Microsoft/transforms-transformer-jsx
829a9df
Adds the JSX transformer
@rbuckton
Merge pull request #7191 from Microsoft/transforms-transformer-ts
ca9148e
Adds the TypeScript transformer
Ron Buckton (rbuckton) added a commit that referenced this pull request Mar 18, 2016
@rbuckton
Merge pull request #6987 from Microsoft/transforms-printer
85ae53d
Adds a simplified pretty printer for tree transformations
@rbuckton
Ron Buckton (rbuckton) merged commit 85ae53d into transforms-transformer Mar 18, 2016
@rbuckton
Ron Buckton (rbuckton) deleted the transforms-printer branch March 18, 2016 23:39
@unional Homa Wong (unional) mentioned this pull request Nov 21, 2016
Support for other JSX factories #6146
Merged
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@rbuckton @DanielRosenwasser @sandersn @msftclas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.