@@ -151,8 +151,7 @@ const _super = (function (geti, seti) {
151
151
let isEmitNotificationEnabled : ( node : Node ) => boolean ;
152
152
let expressionSubstitution : ( node : Expression ) => Expression ;
153
153
let identifierSubstitution : ( node : Identifier ) => Identifier ;
154
- let onBeforeEmitNode : ( node : Node ) => void ;
155
- let onAfterEmitNode : ( node : Node ) => void ;
154
+ let onEmitNode : ( node : Node , emit : ( node : Node ) => void ) => void ;
156
155
let nodeToGeneratedName : string [ ] ;
157
156
let generatedNameSet : Map < string > ;
158
157
let tempFlags : TempFlags ;
@@ -213,8 +212,7 @@ const _super = (function (geti, seti) {
213
212
isEmitNotificationEnabled = undefined ;
214
213
expressionSubstitution = undefined ;
215
214
identifierSubstitution = undefined ;
216
- onBeforeEmitNode = undefined ;
217
- onAfterEmitNode = undefined ;
215
+ onEmitNode = undefined ;
218
216
tempFlags = TempFlags . Auto ;
219
217
currentSourceFile = undefined ;
220
218
currentText = undefined ;
@@ -234,8 +232,7 @@ const _super = (function (geti, seti) {
234
232
isEmitNotificationEnabled = context . isEmitNotificationEnabled ;
235
233
expressionSubstitution = context . expressionSubstitution ;
236
234
identifierSubstitution = context . identifierSubstitution ;
237
- onBeforeEmitNode = context . onBeforeEmitNode ;
238
- onAfterEmitNode = context . onAfterEmitNode ;
235
+ onEmitNode = context . onEmitNode ;
239
236
return printSourceFile ;
240
237
}
241
238
@@ -249,46 +246,62 @@ const _super = (function (geti, seti) {
249
246
return node ;
250
247
}
251
248
249
+ /**
250
+ * Emits a node.
251
+ */
252
252
function emit ( node : Node ) {
253
- emitWithWorker ( node , emitWorker ) ;
253
+ emitNodeWithNotificationOption ( node , emitWithoutNotificationOption ) ;
254
+ }
255
+
256
+ /**
257
+ * Emits a node without calling onEmitNode.
258
+ * NOTE: Do not call this method directly.
259
+ */
260
+ function emitWithoutNotificationOption ( node : Node ) {
261
+ emitNodeWithWorker ( node , emitWorker ) ;
254
262
}
255
263
264
+ /**
265
+ * Emits an expression node.
266
+ */
256
267
function emitExpression ( node : Expression ) {
257
- emitWithWorker ( node , emitExpressionWorker ) ;
268
+ emitNodeWithNotificationOption ( node , emitExpressionWithoutNotificationOption ) ;
269
+ }
270
+
271
+ /**
272
+ * Emits an expression without calling onEmitNode.
273
+ * NOTE: Do not call this method directly.
274
+ */
275
+ function emitExpressionWithoutNotificationOption ( node : Expression ) {
276
+ emitNodeWithWorker ( node , emitExpressionWorker ) ;
258
277
}
259
278
260
- function emitWithWorker ( node : Node , emitWorker : ( node : Node ) => void ) {
279
+ /**
280
+ * Emits a node with emit notification if available.
281
+ */
282
+ function emitNodeWithNotificationOption ( node : Node , emit : ( node : Node ) => void ) {
261
283
if ( node ) {
262
- const adviseOnEmit = isEmitNotificationEnabled ( node ) ;
263
- if ( adviseOnEmit && onBeforeEmitNode ) {
264
- onBeforeEmitNode ( node ) ;
284
+ if ( isEmitNotificationEnabled ( node ) ) {
285
+ onEmitNode ( node , emit ) ;
286
+ }
287
+ else {
288
+ emit ( node ) ;
265
289
}
290
+ }
291
+ }
266
292
293
+ function emitNodeWithWorker ( node : Node , emitWorker : ( node : Node ) => void ) {
294
+ if ( node ) {
267
295
const leadingComments = getLeadingComments ( node , getNotEmittedParent ) ;
268
296
const trailingComments = getTrailingComments ( node , getNotEmittedParent ) ;
269
297
emitLeadingComments ( node , leadingComments ) ;
270
298
emitStart ( node ) ;
271
299
emitWorker ( node ) ;
272
300
emitEnd ( node ) ;
273
301
emitTrailingComments ( node , trailingComments ) ;
274
-
275
- if ( adviseOnEmit && onAfterEmitNode ) {
276
- onAfterEmitNode ( node ) ;
277
- }
278
302
}
279
303
}
280
304
281
- function getNotEmittedParent ( node : Node ) : Node {
282
- if ( getNodeEmitFlags ( node ) & NodeEmitFlags . EmitCommentsOfNotEmittedParent ) {
283
- const parent = getOriginalNode ( node ) . parent ;
284
- if ( getNodeEmitFlags ( parent ) & NodeEmitFlags . IsNotEmittedNode ) {
285
- return parent ;
286
- }
287
- }
288
-
289
- return undefined ;
290
- }
291
-
292
305
function emitWorker ( node : Node ) : void {
293
306
const kind = node . kind ;
294
307
switch ( kind ) {
@@ -2361,6 +2374,17 @@ const _super = (function (geti, seti) {
2361
2374
&& rangeEndIsOnSameLineAsRangeStart ( block , block ) ;
2362
2375
}
2363
2376
2377
+ function getNotEmittedParent ( node : Node ) : Node {
2378
+ if ( getNodeEmitFlags ( node ) & NodeEmitFlags . EmitCommentsOfNotEmittedParent ) {
2379
+ const parent = getOriginalNode ( node ) . parent ;
2380
+ if ( getNodeEmitFlags ( parent ) & NodeEmitFlags . IsNotEmittedNode ) {
2381
+ return parent ;
2382
+ }
2383
+ }
2384
+
2385
+ return undefined ;
2386
+ }
2387
+
2364
2388
function isUniqueName ( name : string ) : boolean {
2365
2389
return ! resolver . hasGlobalName ( name ) &&
2366
2390
! hasProperty ( currentFileIdentifiers , name ) &&
0 commit comments