@@ -151,8 +151,7 @@ const _super = (function (geti, seti) {
151151 let isEmitNotificationEnabled : ( node : Node ) => boolean ;
152152 let expressionSubstitution : ( node : Expression ) => Expression ;
153153 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 ;
156155 let nodeToGeneratedName : string [ ] ;
157156 let generatedNameSet : Map < string > ;
158157 let tempFlags : TempFlags ;
@@ -213,8 +212,7 @@ const _super = (function (geti, seti) {
213212 isEmitNotificationEnabled = undefined ;
214213 expressionSubstitution = undefined ;
215214 identifierSubstitution = undefined ;
216- onBeforeEmitNode = undefined ;
217- onAfterEmitNode = undefined ;
215+ onEmitNode = undefined ;
218216 tempFlags = TempFlags . Auto ;
219217 currentSourceFile = undefined ;
220218 currentText = undefined ;
@@ -234,8 +232,7 @@ const _super = (function (geti, seti) {
234232 isEmitNotificationEnabled = context . isEmitNotificationEnabled ;
235233 expressionSubstitution = context . expressionSubstitution ;
236234 identifierSubstitution = context . identifierSubstitution ;
237- onBeforeEmitNode = context . onBeforeEmitNode ;
238- onAfterEmitNode = context . onAfterEmitNode ;
235+ onEmitNode = context . onEmitNode ;
239236 return printSourceFile ;
240237 }
241238
@@ -249,46 +246,62 @@ const _super = (function (geti, seti) {
249246 return node ;
250247 }
251248
249+ /**
250+ * Emits a node.
251+ */
252252 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 ) ;
254262 }
255263
264+ /**
265+ * Emits an expression node.
266+ */
256267 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 ) ;
258277 }
259278
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 ) {
261283 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 ) ;
265289 }
290+ }
291+ }
266292
293+ function emitNodeWithWorker ( node : Node , emitWorker : ( node : Node ) => void ) {
294+ if ( node ) {
267295 const leadingComments = getLeadingComments ( node , getNotEmittedParent ) ;
268296 const trailingComments = getTrailingComments ( node , getNotEmittedParent ) ;
269297 emitLeadingComments ( node , leadingComments ) ;
270298 emitStart ( node ) ;
271299 emitWorker ( node ) ;
272300 emitEnd ( node ) ;
273301 emitTrailingComments ( node , trailingComments ) ;
274-
275- if ( adviseOnEmit && onAfterEmitNode ) {
276- onAfterEmitNode ( node ) ;
277- }
278302 }
279303 }
280304
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-
292305 function emitWorker ( node : Node ) : void {
293306 const kind = node . kind ;
294307 switch ( kind ) {
@@ -2361,6 +2374,17 @@ const _super = (function (geti, seti) {
23612374 && rangeEndIsOnSameLineAsRangeStart ( block , block ) ;
23622375 }
23632376
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+
23642388 function isUniqueName ( name : string ) : boolean {
23652389 return ! resolver . hasGlobalName ( name ) &&
23662390 ! hasProperty ( currentFileIdentifiers , name ) &&
0 commit comments