Skip to content

Commit

Permalink
fix(bundle): global name conflicts are more accurately handled
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyben committed Nov 27, 2019
1 parent b3d548a commit fd2935b
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 125 deletions.
3 changes: 3 additions & 0 deletions __fixtures__/bundle/global-name-conflict/get-real-date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getRealDate(): Date {
return new Date()
}
11 changes: 11 additions & 0 deletions __fixtures__/bundle/global-name-conflict/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export { isMyPromise } from './my-promise'

export { getRealDate } from './get-real-date'

export { Date } from './my-date'

import { Date as MyDate } from './my-date'

export const myDate = new MyDate()

export const Date_1 = new Date().getTime() // tslint:disable-line: variable-name
4 changes: 4 additions & 0 deletions __fixtures__/bundle/global-name-conflict/my-date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Not the global Date.
*/
export class Date {}
8 changes: 8 additions & 0 deletions __fixtures__/bundle/global-name-conflict/my-promise.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Not the global Promise.
*/
export type Promise = { then: (value: any) => any; catch: (reason: any) => void }

export function isMyPromise(obj: any): obj is Promise {
return true
}
27 changes: 27 additions & 0 deletions __tests__/bundle-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ test('duplicate', () => {
}
})

test('global name conflict', () => {
const entryPoint = fixture('global-name-conflict', 'dist', 'main.d.ts')

build({
basePath: fixture('global-name-conflict'),
extends: '../tsconfig.json',
compilerOptions,
clean: { outDir: true },
bundleDeclaration: {
entryPoint,
},
})

const bundled = readFileSync(entryPoint, 'utf8')

for (const expected of [
/^declare type Promise_1 =/gm,
/^export declare function isMyPromise.*Promise_1/gm,
/^export declare function getRealDate.*Date;$/gm,
/^declare class Date_2/gm,
/^export { Date_2 as Date }/gm,
/^export declare const myDate: Date_2/gm,
]) {
expect(bundled).toMatch(expected)
}
})

test.skip('complex', () => {
const entryPoint = fixture('complex', 'dist', 'main.d.ts')

Expand Down
Loading

0 comments on commit fd2935b

Please sign in to comment.