@@ -19,7 +19,7 @@ export default function (context: ts.TransformationContext, ...args) {
1919 return ( sourceFile : ts . SourceFile ) => {
2020 if ( sourceFile . isDeclarationFile ) return sourceFile ;
2121 let mutated = false ;
22-
22+
2323 // Minimal mutable shape
2424 type MutableNode = ts . Node & {
2525 flags ?: ts . NodeFlags ;
@@ -182,8 +182,8 @@ export default function (context: ts.TransformationContext, ...args) {
182182 }
183183
184184 function visitNode ( node : ts . Node ) : ts . Node {
185- // Do not traverse synthesized helper trees; leave them intact
186- if ( ( ( node as MutableNode ) . flags ?? 0 ) & ts . NodeFlags . Synthesized ) {
185+ // Do not traverse synthesized helper trees; leave them intact
186+ if ( ( ( node as MutableNode ) . flags ?? 0 ) & ts . NodeFlags . Synthesized ) {
187187 return node ;
188188 }
189189 if ( ts . isSourceFile ( node ) ) {
@@ -223,7 +223,9 @@ export default function (context: ts.TransformationContext, ...args) {
223223 }
224224 const result : ts . Statement [ ] = [ ] ;
225225 for ( const statement of statements ) {
226- if ( ( ( statement as MutableNode ) . flags ?? 0 ) & ts . NodeFlags . Synthesized ) {
226+ if (
227+ ( ( statement as MutableNode ) . flags ?? 0 ) & ts . NodeFlags . Synthesized
228+ ) {
227229 result . push ( statement ) ;
228230 continue ;
229231 }
@@ -282,22 +284,6 @@ export default function (context: ts.TransformationContext, ...args) {
282284 }
283285 return [ changed ? factory . createNodeArray ( result ) : statements , changed ] ;
284286 }
285-
286-
287- // we detect ts-patch
288- if ( args . length ) {
289- const statements = ts . visitNodes ( sourceFile . statements , visitNode ) as unknown as ts . Statement [ ] ;
290- if ( ! mutated ) {
291- return sourceFile ;
292- }
293- const updatedSource = factory . updateSourceFile ( sourceFile , statements as unknown as ts . Statement [ ] ) ;
294- // Do NOT clear or rebind the entire SourceFile here. Doing so can break TS's
295- // import usage analysis and lead to import elision. The factory/update API
296- // preserves parents/bindings for original nodes (like imports). We only
297- // synthesize/bind the newly inserted class replacement statements.
298- return updatedSource ;
299- }
300-
301287 const updated = ts . visitNode ( sourceFile , visitNode ) as ts . SourceFile ;
302288 if ( ! mutated ) return sourceFile ;
303289 return updated ;
@@ -339,4 +325,4 @@ function setSynthesizedRangeRecursive(node: ts.Node): void {
339325function setOriginalRecursive ( node : ts . Node , original : ts . Node ) : void {
340326 ts . setOriginalNode ( node , original ) ;
341327 ts . forEachChild ( node , ( child ) => setOriginalRecursive ( child , original ) ) ;
342- }
328+ }
0 commit comments