Add Doc[] as Doc (#9733)

Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com>
This commit is contained in:
fisker CheungandGeorgii Dolzhykov authored and GitHub committed 2021-01-04 10:04:30 +08:00
1 parent 23521ded6c
commit 9d9c0e2b6f
22 files changed
+332 -93

No files matched your search

+1 -1
View File
@@ -170,7 +170,7 @@ export const printers = {
Prettier uses an intermediate representation, called a Doc, which Prettier then turns into a string (based on options like `printWidth`). A _printer_'s job is to take the AST generated by `parsers[<parser name>].parse` and return a Doc. A Doc is constructed using [builder commands](https://github.com/prettier/prettier/blob/master/commands.md):
```js
const { concat, join, line, ifBreak, group } = require("prettier").doc.builders;
const { join, line, ifBreak, group } = require("prettier").doc.builders;
```
The printing process works as follows:
+1 -1
View File
@@ -7,6 +7,6 @@ This printer is a fork of [recast](https://github.com/benjamn/recast)’s printe
The basic idea is that the printer takes an AST and returns an intermediate representation of the output, and the printer uses that to generate a string. The advantage is that the printer can "measure" the IR and see if the output is going to fit on a line, and break if not.
This means that most of the logic of printing an AST involves generating an abstract representation of the output involving certain commands. For example, `concat(["(", line, arg, line, ")"])` would represent a concatenation of opening parens, an argument, and closing parens. But if that doesn’t fit on one line, the printer can break where `line` is specified.
This means that most of the logic of printing an AST involves generating an abstract representation of the output involving certain commands. For example, `["(", line, arg, line, ")"]` would represent a concatenation of opening parens, an argument, and closing parens. But if that doesn’t fit on one line, the printer can break where `line` is specified.
More (rough) details can be found in [commands.md](https://github.com/prettier/prettier/blob/master/commands.md).