diff --git a/src/fixes/typescript.js b/src/fixes/typescript.js index 5c2072d..a1022c8 100644 --- a/src/fixes/typescript.js +++ b/src/fixes/typescript.js @@ -11,14 +11,13 @@ export function fixReferences(contents, options = {}) { const removeAll = !options.types || options.types === 'all'; const find = removeAll ? `/ + /// + import type { Task } from '../index'; + type CancelAllParams = [task: Task]; + export declare function cancelHelper(args: CancelAllParams): (...innerArgs: any[]) => any; + declare const _default: import("@ember/component/helper").FunctionBasedHelper<{ + Args: { + Positional: CancelAllParams; + Named: import("@ember/component/helper").EmptyObject; + }; + Return: (...innerArgs: any[]) => any; + }>; + export default _default; + `; + + let result = fixReferences(code); + + expect(result).toMatchInlineSnapshot(` + "import type { Task } from '../index'; + type CancelAllParams = [task: Task]; + export declare function cancelHelper(args: CancelAllParams): (...innerArgs: any[]) => any; + declare const _default: import("@ember/component/helper").FunctionBasedHelper<{ + Args: { + Positional: CancelAllParams; + Named: import("@ember/component/helper").EmptyObject; + }; + Return: (...innerArgs: any[]) => any; + }>; + export default _default;" + `); + }); + + test('declarations/-private/ember-environment.d.ts', () => { + let code = stripIndent` + export declare class EmberEnvironment extends Environment { + assert(...args: any[]): void; + reportUncaughtRejection(error: any): void; + defer(): any; + globalDebuggingEnabled(): any; + } + export declare const EMBER_ENVIRONMENT: EmberEnvironment; + import { Environment } from './external/environment'; + `; + + let result = fixReferences(code); + + expect(result).toMatchInlineSnapshot(` + "export declare class EmberEnvironment extends Environment { + assert(...args: any[]): void; + reportUncaughtRejection(error: any): void; + defer(): any; + globalDebuggingEnabled(): any; + } + export declare const EMBER_ENVIRONMENT: EmberEnvironment; + import { Environment } from './external/environment';" + `); + }); + }); }); diff --git a/src/index.test.ts b/src/index.test.ts index 334f21f..0906645 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -39,7 +39,10 @@ describe('fixBadDeclarationOutput', () => { /// /// /// + export declare const two: number; + export declare const three: string; + export declare const four: 'literal'; ` ); @@ -49,6 +52,10 @@ describe('fixBadDeclarationOutput', () => { let aContents = await read(a); - expect(aContents).toBe(`export declare const two: number;`); + expect(aContents).toMatchInlineSnapshot(` + "export declare const two: number; + export declare const three: string; + export declare const four: 'literal';" + `); }); });