@@ -23,10 +23,16 @@ const isCommentOrWhiteSpace = createKindCheckFunction([
2323] ) ;
2424
2525const offsets = new Map < number , number > ( ) ;
26+ const comments : Comment [ ] = [ ] ;
27+
2628export function clearOffsets ( ) : void {
2729 offsets . clear ( ) ;
2830}
2931
32+ export function clearComments ( ) : Comment [ ] {
33+ return comments . splice ( 0 ) ;
34+ }
35+
3036function reversedIterator < T > ( children : T [ ] ) : Iterable < T > {
3137 return {
3238 [ Symbol . iterator ] ( ) : Iterator < T > {
@@ -54,21 +60,6 @@ function getOffset(children: Edge[] | Iterable<Edge>): number {
5460 return offset ;
5561}
5662
57- function collectComments (
58- comments : Comment [ ] ,
59- node : StrictAstNode | StrictAstNode [ ] | undefined
60- ) : Comment [ ] {
61- if ( node ) {
62- if ( Array . isArray ( node ) ) {
63- return node . reduce ( collectComments , comments ) ;
64- }
65- if ( node . comments . length > 0 ) {
66- comments . push ( ...node . comments . splice ( 0 ) ) ;
67- }
68- }
69- return comments ;
70- }
71-
7263export class SlangNode {
7364 comments : Comment [ ] = [ ] ;
7465
@@ -109,16 +100,16 @@ export class SlangNode {
109100 // offset, it's hard to separate these responsibilities into different
110101 // functions without doing the iteration twice.
111102 case TerminalKind . MultiLineComment :
112- this . comments . push ( new MultiLineComment ( node , offset ) ) ;
103+ comments . push ( new MultiLineComment ( node , offset ) ) ;
113104 break ;
114105 case TerminalKind . MultiLineNatSpecComment :
115- this . comments . push ( new MultiLineNatSpecComment ( node , offset ) ) ;
106+ comments . push ( new MultiLineNatSpecComment ( node , offset ) ) ;
116107 break ;
117108 case TerminalKind . SingleLineComment :
118- this . comments . push ( new SingleLineComment ( node , offset ) ) ;
109+ comments . push ( new SingleLineComment ( node , offset ) ) ;
119110 break ;
120111 case TerminalKind . SingleLineNatSpecComment :
121- this . comments . push ( new SingleLineNatSpecComment ( node , offset ) ) ;
112+ comments . push ( new SingleLineNatSpecComment ( node , offset ) ) ;
122113 break ;
123114 }
124115 }
@@ -141,10 +132,7 @@ export class SlangNode {
141132 updateMetadata (
142133 ...childNodes : ( StrictAstNode | StrictAstNode [ ] | undefined ) [ ]
143134 ) : void {
144- const { comments, loc } = this ;
145- // Collect comments
146- this . comments = childNodes . reduce ( collectComments , comments ) ;
147-
135+ const { loc } = this ;
148136 // calculate correct loc object
149137 if ( loc . leadingOffset === 0 ) {
150138 for ( const childNode of childNodes ) {
0 commit comments