@@ -7,32 +7,38 @@ import type { Undone } from "./node";
77
88/**
99 * A whitespace token containing comments
10- * @typedef CommentWhitespace
11- * @type {object }
12- * @property {number } start - the start of the whitespace token.
13- * @property {number } end - the end of the whitespace token.
14- * @property {Array<Comment> } comments - the containing comments
15- * @property {Node | null } leadingNode - the immediately preceding AST node of the whitespace token
16- * @property {Node | null } trailingNode - the immediately following AST node of the whitespace token
17- * @property {Node | null } containingNode - the innermost AST node containing the whitespace
18- * with minimal size (|end - start|)
1910 */
2011export type CommentWhitespace = {
12+ /**
13+ * the start of the whitespace token.
14+ */
2115 start : number ;
16+ /**
17+ * the end of the whitespace token.
18+ */
2219 end : number ;
20+ /**
21+ * the containing comments
22+ */
2323 comments : Array < Comment > ;
24+ /**
25+ * the immediately preceding AST node of the whitespace token
26+ */
2427 leadingNode : Node | null ;
28+ /**
29+ * the immediately following AST node of the whitespace token
30+ */
2531 trailingNode : Node | null ;
32+ /**
33+ * the innermost AST node containing the whitespace with minimal size (|end - start|)
34+ */
2635 containingNode : Node | null ;
2736} ;
2837
2938/**
3039 * Merge comments with node's trailingComments or assign comments to be
3140 * trailingComments. New comments will be placed before old comments
3241 * because the commentStack is enumerated reversely.
33- *
34- * @param {Undone<Node> } node
35- * @param {Array<Comment> } comments
3642 */
3743function setTrailingComments ( node : Undone < Node > , comments : Array < Comment > ) {
3844 if ( node . trailingComments === undefined ) {
@@ -46,9 +52,6 @@ function setTrailingComments(node: Undone<Node>, comments: Array<Comment>) {
4652 * Merge comments with node's leadingComments or assign comments to be
4753 * leadingComments. New comments will be placed before old comments
4854 * because the commentStack is enumerated reversely.
49- *
50- * @param {Undone<Node> } node
51- * @param {Array<Comment> } comments
5255 */
5356function setLeadingComments ( node : Undone < Node > , comments : Array < Comment > ) {
5457 if ( node . leadingComments === undefined ) {
@@ -62,9 +65,6 @@ function setLeadingComments(node: Undone<Node>, comments: Array<Comment>) {
6265 * Merge comments with node's innerComments or assign comments to be
6366 * innerComments. New comments will be placed before old comments
6467 * because the commentStack is enumerated reversely.
65- *
66- * @param {Undone<Node> } node
67- * @param {Array<Comment> } comments
6868 */
6969export function setInnerComments (
7070 node : Undone < Node > ,
@@ -81,10 +81,6 @@ export function setInnerComments(
8181 * Given node and elements array, if elements has non-null element,
8282 * merge comments to its trailingComments, otherwise merge comments
8383 * to node's innerComments
84- *
85- * @param {Undone<Node> } node
86- * @param {Array<Node> } elements
87- * @param {Array<Comment> } comments
8884 */
8985function adjustInnerComments (
9086 node : Undone < Node > ,
@@ -103,7 +99,6 @@ function adjustInnerComments(
10399 }
104100}
105101
106- /** @class CommentsParser */
107102export default class CommentsParser extends BaseParser {
108103 addComment ( comment : Comment ) : void {
109104 if ( this . filename ) comment . loc . filename = this . filename ;
@@ -113,10 +108,6 @@ export default class CommentsParser extends BaseParser {
113108 /**
114109 * Given a newly created AST node _n_, attach _n_ to a comment whitespace _w_ if applicable
115110 * {@see {@link CommentWhitespace}}
116- *
117- * @param {Node } node
118- * @returns {void }
119- * @memberof CommentsParser
120111 */
121112 processComment ( node : Node ) : void {
122113 const { commentStack } = this . state ;
@@ -158,8 +149,6 @@ export default class CommentsParser extends BaseParser {
158149 /**
159150 * Assign the comments of comment whitespaces to related AST nodes.
160151 * Also adjust innerComments following trailing comma.
161- *
162- * @memberof CommentsParser
163152 */
164153 finalizeComment ( commentWS : CommentWhitespace ) {
165154 const { comments } = commentWS ;
@@ -219,8 +208,6 @@ export default class CommentsParser extends BaseParser {
219208 * to each comment whitespace. Used only in parseExpression
220209 * where the top level AST node is _not_ Program
221210 * {@see {@link CommentsParser#finalizeComment}}
222- *
223- * @memberof CommentsParser
224211 */
225212 finalizeRemainingComments ( ) {
226213 const { commentStack } = this . state ;
@@ -230,24 +217,25 @@ export default class CommentsParser extends BaseParser {
230217 this . state . commentStack = [ ] ;
231218 }
232219
220+ /* eslint-disable no-irregular-whitespace */
233221 /**
234222 * Reset previous node trailing comments. Used in object / class
235223 * property parsing. We parse `async`, `static`, `set` and `get`
236224 * as an identifier but may reinterpret it into an async/static/accessor
237225 * method later. In this case the identifier is not part of the AST and we
238226 * should sync the knowledge to commentStacks
239227 *
240- * For example, when parsing */
241- // async /* 1 */ function f() {}
242- /*
243- * the comment whitespace "* 1 *" has leading node Identifier(async). When
244- * we see the function token, we create a Function node and mark "* 1 *" as
245- * inner comments. So "* 1 *" should be detached from the Identifier node.
228+ * For example, when parsing
229+ * ```
230+ * async /* 1 */ function f() {}
231+ * ```
232+ * the comment whitespace `/* 1 */` has leading node Identifier(async). When
233+ * we see the function token, we create a Function node and mark `/* 1 */` as
234+ * inner comments. So `/* 1 */` should be detached from the Identifier node.
246235 *
247- * @param {N.Node } node the last finished AST node _before_ current token
248- * @returns
249- * @memberof CommentsParser
236+ * @param node the last finished AST node _before_ current token
250237 */
238+ /* eslint-enable no-irregular-whitespace */
251239 resetPreviousNodeTrailingComments ( node : Node ) {
252240 const { commentStack } = this . state ;
253241 const { length } = commentStack ;
@@ -264,10 +252,6 @@ export default class CommentsParser extends BaseParser {
264252 *
265253 * This is used to properly attach comments around parenthesized
266254 * expressions as leading/trailing comments of the inner expression.
267- *
268- * @param {Node } node
269- * @param {number } start
270- * @param {number } end
271255 */
272256 takeSurroundingComments ( node : Node , start : number , end : number ) {
273257 const { commentStack } = this . state ;
0 commit comments