Skip to content

Commit ad0241b

Browse files
committed
Add improved docs
1 parent 73e8c43 commit ad0241b

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

lib/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ const own = {}.hasOwnProperty
1919
/**
2020
* Attach semistandard estree comment nodes to the tree.
2121
*
22+
* This mutates the given `tree`.
23+
* It takes `comments`, walks the tree, and adds comments as close as possible
24+
* to where they originated.
25+
*
26+
* Comment nodes are given two boolean fields: `leading` (`true` for
27+
* `/* a *\/ b`) and `trailing` (`true` for `a /* b *\/`).
28+
* Both fields are `false` for dangling comments: `[/* a *\/]`.
29+
* This is what `recast` uses too, and is somewhat similar to Babel, which is
30+
* not estree but instead uses `leadingComments`, `trailingComments`, and
31+
* `innerComments` arrays on nodes.
32+
*
33+
* The algorithm checks any node: even recent (or future) proposals or
34+
* nonstandard syntax such as JSX, because it ducktypes to find nodes instead
35+
* of having a list of visitor keys.
36+
*
37+
* The algorithm supports `loc` fields (line/column), `range` fields (offsets),
38+
* and direct `start` / `end` fields.
39+
*
2240
* @template {EstreeNode} Tree
2341
* Node type.
2442
* @param {Tree} tree

readme.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ with a tool such as recast or Babel.
4444
## Install
4545

4646
This package is [ESM only][esm].
47-
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
47+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4848

4949
```sh
5050
npm install estree-util-attach-comments
@@ -114,14 +114,14 @@ a(
114114
115115
## API
116116

117-
This package exports the identifier `attachComments`.
117+
This package exports the identifier [`attachComments`][attachcomments].
118118
There is no default export.
119119

120120
### `attachComments(tree, comments)`
121121

122122
Attach semistandard estree comment nodes to the tree.
123123

124-
This mutates the given [`tree`][estree] ([`Program`][program]).
124+
This mutates the given [`tree`][estree].
125125
It takes `comments`, walks the tree, and adds comments as close as possible
126126
to where they originated.
127127

@@ -139,9 +139,16 @@ of visitor keys.
139139
The algorithm supports `loc` fields (line/column), `range` fields (offsets),
140140
and direct `start` / `end` fields.
141141

142+
###### Parameters
143+
144+
* `tree` ([`Program`][program])
145+
— tree to attach to
146+
* `comments` (`Array<EstreeComment>`)
147+
— list of comments
148+
142149
###### Returns
143150

144-
The given `tree` (`Node`).
151+
The given `tree` ([`Program`][program]).
145152

146153
## Types
147154

@@ -152,7 +159,7 @@ It exports no additional types.
152159

153160
Projects maintained by the unified collective are compatible with all maintained
154161
versions of Node.js.
155-
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
162+
As of now, that is Node.js 14.14+ and 16.0+.
156163
Our projects sometimes work with older versions, but this is not guaranteed.
157164

158165
## Contribute
@@ -222,3 +229,5 @@ abide by its terms.
222229
[estree]: https://github.com/estree/estree
223230

224231
[program]: https://github.com/estree/estree/blob/master/es5.md#programs
232+
233+
[attachcomments]: #attachcommentstree-comments

0 commit comments

Comments
 (0)