Add docs on new pragma infrastructure (#4121)
parent
13103101eb
commit
4c363a7a2f
|
@ -84,6 +84,7 @@ export const parsers = {
|
||||||
parse,
|
parse,
|
||||||
// The name of the AST that
|
// The name of the AST that
|
||||||
astFormat: "dance-ast",
|
astFormat: "dance-ast",
|
||||||
|
hasPragma,
|
||||||
locStart,
|
locStart,
|
||||||
locEnd
|
locEnd
|
||||||
}
|
}
|
||||||
|
@ -102,6 +103,12 @@ The location extraction functions (`locStart` and `locEnd`) return the starting
|
||||||
function locStart(node: object): number;
|
function locStart(node: object): number;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The pragma detection function (`hasPragma`) should return if the text contains the pragma comment.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
function hasPragma(text: string): boolean;
|
||||||
|
```
|
||||||
|
|
||||||
### `printers`
|
### `printers`
|
||||||
|
|
||||||
Printers convert ASTs into a Prettier intermediate representation, also known as a Doc.
|
Printers convert ASTs into a Prettier intermediate representation, also known as a Doc.
|
||||||
|
@ -112,7 +119,8 @@ The key must match the `astFormat` that the parser produces. The value contains
|
||||||
export const printers = {
|
export const printers = {
|
||||||
"dance-ast": {
|
"dance-ast": {
|
||||||
print,
|
print,
|
||||||
embed
|
embed,
|
||||||
|
insertPragma
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -155,6 +163,12 @@ function embed(
|
||||||
|
|
||||||
If you don't want to switch to a different parser, simply return `null` or `undefined`.
|
If you don't want to switch to a different parser, simply return `null` or `undefined`.
|
||||||
|
|
||||||
|
A plugin can implement how a pragma comment is inserted in the resulting code when the `--insert-pragma` option is used, in the `insertPragma` function. Its signature is:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
function insertPragma(text: string): string;
|
||||||
|
```
|
||||||
|
|
||||||
### `options`
|
### `options`
|
||||||
|
|
||||||
`options` is an object containing the custom options your plugin supports.
|
`options` is an object containing the custom options your plugin supports.
|
||||||
|
|
Loading…
Reference in New Issue