From 05fc1eec8db4c42de29ff0bbc1b6f565e87a46c5 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Thu, 5 Mar 2020 23:20:37 -0800 Subject: [PATCH] Fix a bug where default import statements were not renamed correctly when resolving a .d.ts rollup naming conflict --- apps/api-extractor/src/generators/DtsEmitHelpers.ts | 7 ++++++- .../dist/api-extractor-test-01-beta.d.ts | 4 ++-- .../dist/api-extractor-test-01-public.d.ts | 4 ++-- .../api-extractor-test-01/dist/api-extractor-test-01.d.ts | 4 ++-- .../api-extractor-test-01/etc/api-extractor-test-01.api.md | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/api-extractor/src/generators/DtsEmitHelpers.ts b/apps/api-extractor/src/generators/DtsEmitHelpers.ts index 6e3005ee35c..2973c9e738a 100644 --- a/apps/api-extractor/src/generators/DtsEmitHelpers.ts +++ b/apps/api-extractor/src/generators/DtsEmitHelpers.ts @@ -16,7 +16,12 @@ export class DtsEmitHelpers { public static emitImport(stringWriter: StringWriter, collectorEntity: CollectorEntity, astImport: AstImport): void { switch (astImport.importKind) { case AstImportKind.DefaultImport: - stringWriter.writeLine(`import ${astImport.exportName} from '${astImport.modulePath}';`); + if (collectorEntity.nameForEmit !== astImport.exportName) { + stringWriter.write(`import { default as ${collectorEntity.nameForEmit} }`); + } else { + stringWriter.write(`import ${astImport.exportName}`); + } + stringWriter.writeLine(` from '${astImport.modulePath}';`); break; case AstImportKind.NamedImport: if (collectorEntity.nameForEmit !== astImport.exportName) { diff --git a/build-tests/api-extractor-test-01/dist/api-extractor-test-01-beta.d.ts b/build-tests/api-extractor-test-01/dist/api-extractor-test-01-beta.d.ts index 1f17167d167..1f3d705dc2a 100644 --- a/build-tests/api-extractor-test-01/dist/api-extractor-test-01-beta.d.ts +++ b/build-tests/api-extractor-test-01/dist/api-extractor-test-01-beta.d.ts @@ -12,7 +12,7 @@ /// /// /// -import Long from 'long'; +import { default as Long_2 } from 'long'; import { MAX_UNSIGNED_VALUE } from 'long'; /** @@ -309,7 +309,7 @@ declare const unexportedCustomSymbol: unique symbol; /** @public */ export declare class UseLong { - use_long(): Long; + use_long(): Long_2; } /* Excluded from this release type: VARIABLE */ diff --git a/build-tests/api-extractor-test-01/dist/api-extractor-test-01-public.d.ts b/build-tests/api-extractor-test-01/dist/api-extractor-test-01-public.d.ts index 567cf66521b..78a0ba88367 100644 --- a/build-tests/api-extractor-test-01/dist/api-extractor-test-01-public.d.ts +++ b/build-tests/api-extractor-test-01/dist/api-extractor-test-01-public.d.ts @@ -12,7 +12,7 @@ /// /// /// -import Long from 'long'; +import { default as Long_2 } from 'long'; import { MAX_UNSIGNED_VALUE } from 'long'; /** @@ -302,7 +302,7 @@ declare const unexportedCustomSymbol: unique symbol; /** @public */ export declare class UseLong { - use_long(): Long; + use_long(): Long_2; } /* Excluded from this release type: VARIABLE */ diff --git a/build-tests/api-extractor-test-01/dist/api-extractor-test-01.d.ts b/build-tests/api-extractor-test-01/dist/api-extractor-test-01.d.ts index 2456363af22..5d7d8215328 100644 --- a/build-tests/api-extractor-test-01/dist/api-extractor-test-01.d.ts +++ b/build-tests/api-extractor-test-01/dist/api-extractor-test-01.d.ts @@ -12,7 +12,7 @@ /// /// /// -import Long from 'long'; +import { default as Long_2 } from 'long'; import { MAX_UNSIGNED_VALUE } from 'long'; /** @@ -330,7 +330,7 @@ declare const unexportedCustomSymbol: unique symbol; /** @public */ export declare class UseLong { - use_long(): Long; + use_long(): Long_2; } /** @alpha */ diff --git a/build-tests/api-extractor-test-01/etc/api-extractor-test-01.api.md b/build-tests/api-extractor-test-01/etc/api-extractor-test-01.api.md index 615874583e5..ac4de903c43 100644 --- a/build-tests/api-extractor-test-01/etc/api-extractor-test-01.api.md +++ b/build-tests/api-extractor-test-01/etc/api-extractor-test-01.api.md @@ -4,7 +4,7 @@ ```ts -import Long from 'long'; +import { default as Long_2 } from 'long'; import { MAX_UNSIGNED_VALUE } from 'long'; // @public @@ -190,7 +190,7 @@ export class TypeReferencesInAedoc { // @public (undocumented) export class UseLong { // (undocumented) - use_long(): Long; + use_long(): Long_2; } // @alpha (undocumented)