Skip to content

Commit

Permalink
fix: bug in object type annotation replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Mar 18, 2024
1 parent 8ce572e commit ecb6608
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/convertReplacement/convertFlowTypeReplacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function convertFlowTypeReplacement(node: Node): Node {
return node.typeAnnotation
}
// @ts-expect-error @babel/types and ast-types aren't compatible atm
if (!t.isFlowType(node)) {
if (!t.isFlow(node)) {
const id = convertToIdentifier(node)
if (id) return t.genericTypeAnnotation(id as any, null)
}
Expand Down
29 changes: 29 additions & 0 deletions test/findReplace/flowObjectTypeAnnotationRestCapture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const input = `
type X = {| ...C, a?: number, b: string |}
`

export const find = `
type X = /**/ {| $$$a: $ |}
`

export const replace = `
type X = /**/ { $$$a: $ }
`

export const expectedReplace = `
type X = {
...C,
a?: number,
b: string
}
`
import { findReplaceTestcase } from '../findReplaceTestcase'

findReplaceTestcase({
file: __filename,
parsers: ['babel', 'recast/babel'],
input,
find,
replace,
expectedReplace,
})

0 comments on commit ecb6608

Please sign in to comment.