7
7
8
8
import ts from 'typescript' ;
9
9
import { getLocFor , getNodeContainer } from './node-utils' ;
10
- import {
11
- ESTreeComment ,
12
- LineAndColumnData
13
- } from './temp-types-based-on-js-source' ;
10
+ import * as es from './typedefs' ;
14
11
15
12
/**
16
13
* Converts a TypeScript comment to an Esprima comment.
17
- * @param { boolean } block True if it's a block comment, false if not.
18
- * @param { string } text The text of the comment.
19
- * @param { number } start The index at which the comment starts.
20
- * @param { number } end The index at which the comment ends.
21
- * @param { LineAndColumnData } startLoc The location at which the comment starts.
22
- * @param { LineAndColumnData } endLoc The location at which the comment ends.
23
- * @returns { Object } The comment object.
24
- * @private
14
+ * @param block True if it's a block comment, false if not.
15
+ * @param text The text of the comment.
16
+ * @param start The index at which the comment starts.
17
+ * @param end The index at which the comment ends.
18
+ * @param startLoc The location at which the comment starts.
19
+ * @param endLoc The location at which the comment ends.
20
+ * @returns The comment object.
21
+ * @internal
25
22
*/
26
23
function convertTypeScriptCommentToEsprimaComment (
27
24
block : boolean ,
28
25
text : string ,
29
26
start : number ,
30
27
end : number ,
31
- startLoc : LineAndColumnData ,
32
- endLoc : LineAndColumnData
33
- ) : ESTreeComment {
34
- const comment : ESTreeComment = {
28
+ startLoc : es . LineAndColumnData ,
29
+ endLoc : es . LineAndColumnData
30
+ ) : es . Comment {
31
+ const comment : es . OptionalRangeAndLoc < es . Comment > = {
35
32
type : block ? 'Block' : 'Line' ,
36
33
value : text
37
34
} ;
@@ -47,22 +44,22 @@ function convertTypeScriptCommentToEsprimaComment(
47
44
} ;
48
45
}
49
46
50
- return comment ;
47
+ return comment as es . Comment ;
51
48
}
52
49
53
50
/**
54
51
* Convert comment from TypeScript Triva Scanner.
55
- * @param { ts.Scanner } triviaScanner TS Scanner
56
- * @param { ts.SourceFile } ast the AST object
57
- * @param { string } code TypeScript code
58
- * @returns { ESTreeComment } the converted ESTreeComment
52
+ * @param triviaScanner TS Scanner
53
+ * @param ast the AST object
54
+ * @param code TypeScript code
55
+ * @returns the converted Comment
59
56
* @private
60
57
*/
61
58
function getCommentFromTriviaScanner (
62
59
triviaScanner : ts . Scanner ,
63
60
ast : ts . SourceFile ,
64
61
code : string
65
- ) : ESTreeComment {
62
+ ) : es . Comment {
66
63
const kind = triviaScanner . getToken ( ) ;
67
64
const isBlock = kind === ts . SyntaxKind . MultiLineCommentTrivia ;
68
65
const range = {
@@ -77,30 +74,28 @@ function getCommentFromTriviaScanner(
77
74
: comment . replace ( / ^ \/ \/ / , '' ) ;
78
75
const loc = getLocFor ( range . pos , range . end , ast ) ;
79
76
80
- const esprimaComment = convertTypeScriptCommentToEsprimaComment (
77
+ return convertTypeScriptCommentToEsprimaComment (
81
78
isBlock ,
82
79
text ,
83
80
range . pos ,
84
81
range . end ,
85
82
loc . start ,
86
83
loc . end
87
84
) ;
88
-
89
- return esprimaComment ;
90
85
}
91
86
92
87
/**
93
88
* Convert all comments for the given AST.
94
- * @param { ts.SourceFile } ast the AST object
95
- * @param { string } code the TypeScript code
96
- * @returns { ESTreeComment[] } the converted ESTreeComment
89
+ * @param ast the AST object
90
+ * @param code the TypeScript code
91
+ * @returns the converted ESTreeComment
97
92
* @private
98
93
*/
99
94
export function convertComments (
100
95
ast : ts . SourceFile ,
101
96
code : string
102
- ) : ESTreeComment [ ] {
103
- const comments : ESTreeComment [ ] = [ ] ;
97
+ ) : es . Comment [ ] {
98
+ const comments : es . Comment [ ] = [ ] ;
104
99
105
100
/**
106
101
* Create a TypeScript Scanner, with skipTrivia set to false so that
0 commit comments