RFC: label doc (#10275)

* RFC: label doc

* Update functions in doc-utils
This commit is contained in:
Georgii Dolzhykov authored and GitHub committed 2021-02-10 17:08:54 +02:00
1 parent 91c0d58c4a
commit 662cdb04db
7 files changed
+57 -10

No files matched your search

+12
View File
@@ -271,6 +271,18 @@ With `negate: true`, corresponds to `ifBreak(doc, indent(doc), { groupId })`
It doesn't make sense to apply `indentIfBreak` to the current group because "indent if the current group is broken" is the normal behavior of `indent`. That's why `groupId` is required.
### `label`
_Added in v2.3.0_
```ts
declare function label(label: string, doc: Doc): Doc;
```
Mark a doc with a string label. This doesn't affect how the doc is printed, but can be useful for heuristics based on doc introspection.
E.g., to decide how to print an assignment expression, we might want to know whether its right-hand side has been printed as a method call chain, not as a plain function call. If the method chain printing code uses `label` to mark its result, checking that condition can be as easy as `rightHandSideDoc.label === 'method-chain'`.
### `hardlineWithoutBreakParent` and `literallineWithoutBreakParent`
_Added in v2.3.0_