codemodsquad / astx

Super powerful structural search and replace for JavaScript and TypeScript to automate your refactoring
MIT License
104 stars 6 forks source link

find and replace within submatches has no effect #19

Closed jedwards1211 closed 12 months ago

jedwards1211 commented 12 months ago

This testcase demonstrates the issue

import { TransformOptions } from '../../src'
import { astxTestcase } from '../astxTestcase'

astxTestcase({
  file: __filename,
  input: `
class Connection extends Model<ConnectionAttributes, ConnectionInitAttributes> {
  declare Channels: Array<ConnectionChannel>;
  static Channels: Association.HasMany<
    Connection,
    ConnectionChannelAttributes,
    ConnectionChannelInitAttributes,
    ConnectionChannel
  > = null
}    
  `,
  astx: ({ astx }: TransformOptions): void => {
    for (const {
      $$body,
    } of astx.find`class $C extends Model<$$A> { $$body }`()) {
      $$body.find`class X { /**/ static $a: Association.HasMany<$$p> = $Maybe($i)}`()
        // this replace has no effect
        .replace`class X { /**/ declare static $a: any; }`()
    }
  },
  expected: `
class Connection extends Model<ConnectionAttributes, ConnectionInitAttributes> {
  declare Channels: Array<ConnectionChannel>;
  declare static Channels: any;
}    
  `,
})
jedwards1211 commented 11 months ago

:tada: This issue has been resolved in version 3.0.0-beta.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket: