|
8 | 8 | [![Backers][backers-badge]][collective]
|
9 | 9 | [![Chat][chat-badge]][chat]
|
10 | 10 |
|
11 |
| -Attach semistandard [estree][] comment nodes (such as from [espree][] or |
12 |
| -[acorn][] with a couple lines of code) to the nodes in that tree. |
| 11 | +Attach semistandard [estree][] comment nodes (such as from [acorn][] with a |
| 12 | +couple lines of code) to the nodes in that tree. |
13 | 13 |
|
14 | 14 | This is useful because certain estree parsers give you an array (espree and
|
15 | 15 | acorn) whereas other estree tools expect comments to be embedded on nodes in the
|
16 | 16 | tree.
|
17 | 17 |
|
| 18 | +This package uses one `comments` array where each comment has `leading` |
| 19 | +and `trailing` fields. |
| 20 | +Note that espree uses slightly different non-standard comments. |
| 21 | + |
18 | 22 | ## Install
|
19 | 23 |
|
20 | 24 | This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
|
|
72 | 76 | Note that the lines are added by `recast` in this case.
|
73 | 77 | And, some of these weird comments are off, but they’re pretty close.
|
74 | 78 |
|
75 |
| -With espree: |
76 |
| - |
77 |
| -```js |
78 |
| -import espree from 'espree' |
79 |
| -import {attachComments} from 'estree-util-attach-comments' |
80 |
| - |
81 |
| -var tree = espree.parse(code, {comment: true, ecmaVersion: 2020}) |
82 |
| - |
83 |
| -attachComments(tree, tree.comments) |
84 |
| -``` |
85 |
| - |
86 | 79 | ## API
|
87 | 80 |
|
88 | 81 | This package exports the following identifiers: `attachComments`.
|
@@ -156,6 +149,4 @@ and direct `start` / `end` fields.
|
156 | 149 |
|
157 | 150 | [estree]: https://github.com/estree/estree
|
158 | 151 |
|
159 |
| -[espree]: https://github.com/eslint/espree |
160 |
| - |
161 | 152 | [program]: https://github.com/estree/estree/blob/master/es5.md#programs
|
0 commit comments