diff --git a/src/compileMatcher/ClassProperty.ts b/src/compileMatcher/ClassProperty.ts index b3939b5..4e77448 100644 --- a/src/compileMatcher/ClassProperty.ts +++ b/src/compileMatcher/ClassProperty.ts @@ -13,6 +13,7 @@ export default function compileClassPropertyMatcher( if ( !pattern.computed && !pattern.static && + pattern.typeAnnotation == null && pattern.variance == null && pattern.value == null ) { diff --git a/src/compileReplacement/ClassProperty.ts b/src/compileReplacement/ClassProperty.ts index 911da80..579f75d 100644 --- a/src/compileReplacement/ClassProperty.ts +++ b/src/compileReplacement/ClassProperty.ts @@ -13,7 +13,18 @@ export default function compileClassPropertyReplacement( !pattern.computed && !pattern.static && pattern.variance == null && - pattern.value == null + pattern.value == null && + (pattern.typeAnnotation == null || + (n.TypeAnnotation.check(pattern.typeAnnotation) && + n.GenericTypeAnnotation.check( + pattern.typeAnnotation?.typeAnnotation + ) && + n.Identifier.check(pattern.typeAnnotation.typeAnnotation.id) && + pattern.typeAnnotation.typeAnnotation.id.name === '$') || + (n.TSTypeAnnotation.check(pattern.typeAnnotation) && + n.TSTypeReference.check(pattern.typeAnnotation?.typeAnnotation) && + n.Identifier.check(pattern.typeAnnotation.typeAnnotation.typeName) && + pattern.typeAnnotation.typeAnnotation.typeName.name === '$')) ) { const placeholderReplacement = compilePlaceholderReplacement( path, diff --git a/test/findReplace/testcases/bugs_convertToDeclare.ts b/test/findReplace/testcases/bugs_convertToDeclare.ts new file mode 100644 index 0000000..13b642b --- /dev/null +++ b/test/findReplace/testcases/bugs_convertToDeclare.ts @@ -0,0 +1,21 @@ +export const input = ` +class Foo { + a: number; + b: string; +} +` + +export const find = ` +class X { /**/ $a: $T } +` + +export const replace = ` +class X { /**/ declare $a: $T } +` + +export const expectedReplace = ` +class Foo { + declare a: number; + declare b: string; +} +` diff --git a/test/findReplace/testcases/findPromiseMethodCalls.ts b/test/findReplace/testcases/findPromiseMethodCalls.ts index a7126c9..e2eb261 100644 --- a/test/findReplace/testcases/findPromiseMethodCalls.ts +++ b/test/findReplace/testcases/findPromiseMethodCalls.ts @@ -14,20 +14,31 @@ $Or($a.then($handleValue), $a.then($handleValue, $handleError), $a.catch($handle export const expectedFind = [ { - arrayCaptures: { - $$args: ['error => blah'], + captures: { + $a: 'thing.then(() => blah)', + $handleFinally: '() => done', }, + node: 'thing.then(() => blah).finally(() => done)', + }, + { + captures: { + $a: 'thing', + $handleValue: '() => blah', + }, + node: 'thing.then(() => blah)', + }, + { captures: { $a: 'thing.then(\n value => value * 2,\n error => logged(error)\n )', + $handleError: 'error => blah', }, node: 'thing.then(\n value => value * 2,\n error => logged(error)\n ).catch(error => blah)', }, { - arrayCaptures: { - $$args: ['value => value * 2', 'error => logged(error)'], - }, captures: { $a: 'thing', + $handleError: 'error => logged(error)', + $handleValue: 'value => value * 2', }, node: 'thing.then(\n value => value * 2,\n error => logged(error)\n )', },