Skip to content

Commit

Permalink
Implement a temporary workaround for Issue #1095 based on a hardcoded…
Browse files Browse the repository at this point in the history
… list of common names
  • Loading branch information
octogonz committed Feb 12, 2019
1 parent 79991cb commit d120a59
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
68 changes: 68 additions & 0 deletions apps/api-extractor/src/collector/Collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export class Collector {
*/
private _makeUniqueNames(): void {
const usedNames: Set<string> = new Set<string>();
this._collectGlobalNames(usedNames);

// First collect the explicit package exports (named)
for (const entity of this._entities) {
Expand Down Expand Up @@ -375,6 +376,73 @@ export class Collector {
}
}

/**
* Adds global names to the usedNames set, to prevent API Extractor from emitting names that conflict with
* a global name.
*/
private _collectGlobalNames(usedNames: Set<string>): void {
// As a temporary workaround, this a short list of names that appear in typical projects.
// The full solution is tracked by this issue:
// https://github.com/Microsoft/web-build-tools/issues/1095
const globalNames: string[] = [
'Array',
'ArrayConstructor',
'Console',
'Date',
'DateConstructor',
'Error',
'ErrorConstructor',
'Float32Array',
'Float32ArrayConstructor',
'Float64Array',
'Float64ArrayConstructor',
'IArguments',
'Int16Array',
'Int16ArrayConstructor',
'Int32Array',
'Int32ArrayConstructor',
'Int8Array',
'Int8ArrayConstructor',
'Iterable',
'IterableIterator',
'Iterator',
'IteratorResult',
'Map',
'MapConstructor',
'Promise',
'PromiseConstructor',
'ReadonlyArray',
'ReadonlyMap',
'ReadonlySet',
'Set',
'SetConstructor',
'String',
'Symbol',
'SymbolConstructor',
'Uint16Array',
'Uint16ArrayConstructor',
'Uint32Array',
'Uint32ArrayConstructor',
'Uint8Array',
'Uint8ArrayConstructor',
'Uint8ClampedArray',
'Uint8ClampedArrayConstructor',
'WeakMap',
'WeakMapConstructor',
'WeakSet',
'WeakSetConstructor',
'clearInterval',
'clearTimeout',
'console',
'setInterval',
'setTimeout',
'undefined'
];
for (const globalName of globalNames) {
usedNames.add(globalName);
}
}

/**
* Reports an error message to the registered ApiErrorHandler.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @public (undocumented)
declare function ambientNameConflict(p1: Promise<void>, p2: Promise<void>): void;
declare function ambientNameConflict(p1: Promise<void>, p2: Promise_2<void>): void;


// (No @packageDocumentation comment for this package)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
/**
* @public
*/
export declare function ambientNameConflict(p1: Promise<void>, p2: Promise<void>): void;
export declare function ambientNameConflict(p1: Promise<void>, p2: Promise_2<void>): void;

/**
* @public
*/
declare class Promise<T> {
declare class Promise_2<T> {
notTheRealPromise(arg: T): void;
}

Expand Down

0 comments on commit d120a59

Please sign in to comment.