@@ -254,6 +254,9 @@ AST.prototype.prepare = function(kind, docs, parser) {
254
254
let location = null ;
255
255
const args = Array . prototype . slice . call ( arguments ) ;
256
256
args . push ( docs ) ;
257
+ if ( typeof result . preBuild === "function" ) {
258
+ result . preBuild ( arguments ) ;
259
+ }
257
260
if ( self . withPositions || self . withSource ) {
258
261
let src = null ;
259
262
if ( self . withSource ) {
@@ -280,9 +283,13 @@ AST.prototype.prepare = function(kind, docs, parser) {
280
283
if ( typeof node !== "function" ) {
281
284
throw new Error ( 'Undefined node "' + kind + '"' ) ;
282
285
}
283
- const result = Object . create ( node . prototype ) ;
284
- node . apply ( result , args ) ;
285
- return self . resolvePrecedence ( result ) ;
286
+ const astNode = Object . create ( node . prototype ) ;
287
+ node . apply ( astNode , args ) ;
288
+ result . instance = astNode ;
289
+ if ( result . trailingComments ) {
290
+ astNode . trailingComments = result . trailingComments ;
291
+ }
292
+ return self . resolvePrecedence ( astNode ) ;
286
293
} ;
287
294
/**
288
295
* Helper to change a node kind
@@ -291,6 +298,18 @@ AST.prototype.prepare = function(kind, docs, parser) {
291
298
result . setKind = function ( newKind ) {
292
299
kind = newKind ;
293
300
} ;
301
+ /**
302
+ * Sets a list of trailing comments
303
+ * @param {* } docs
304
+ */
305
+ result . setTrailingComments = function ( docs ) {
306
+ if ( result . instance ) {
307
+ // already created
308
+ result . instance . trailingComments = docs ;
309
+ } else {
310
+ result . trailingComments = docs ;
311
+ }
312
+ } ;
294
313
/**
295
314
* Release a node without using it on the AST
296
315
*/
0 commit comments