-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This must have been from an old version of babel, but nowadays there is never an id field on an export-specifier
- Loading branch information
Showing
2 changed files
with
34 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,62 @@ | ||
import { mocked } from 'ts-jest/utils'; | ||
import { statement, noopImporter } from '../../../tests/utils'; | ||
import resolveToValue from '../resolveToValue'; | ||
import resolveExportDeclaration from '../resolveExportDeclaration'; | ||
import { NodePath } from 'ast-types'; | ||
import { NodePath } from 'ast-types/lib/node-path'; | ||
|
||
jest.mock('../resolveToValue'); | ||
jest.mock('../resolveToValue', () => { | ||
return (path: NodePath) => path; | ||
}); | ||
|
||
describe('resolveExportDeclaration', () => { | ||
const returnValue = new NodePath({}); | ||
|
||
beforeEach(() => { | ||
mocked(resolveToValue).mockReturnValue(returnValue); | ||
}); | ||
|
||
it('resolves default exports', () => { | ||
const exp = statement('export default 42;'); | ||
const resolved = resolveExportDeclaration(exp, noopImporter); | ||
|
||
expect(resolved).toEqual([returnValue]); | ||
expect(resolveToValue).toBeCalledWith(exp.get('declaration'), noopImporter); | ||
expect(resolved).toEqual([exp.get('declaration')]); | ||
}); | ||
|
||
it('resolves named exports', () => { | ||
let exp = statement('export var foo = 42, bar = 21;'); | ||
let resolved = resolveExportDeclaration(exp, noopImporter); | ||
it('resolves named variable exports', () => { | ||
const exp = statement('export var foo = 42, bar = 21;'); | ||
const resolved = resolveExportDeclaration(exp, noopImporter); | ||
|
||
const declarations = exp.get('declaration', 'declarations'); | ||
expect(resolved).toEqual([returnValue, returnValue]); | ||
expect(resolveToValue).toBeCalledWith(declarations.get(0), noopImporter); | ||
expect(resolveToValue).toBeCalledWith(declarations.get(1), noopImporter); | ||
expect(resolved).toEqual([declarations.get(0), declarations.get(1)]); | ||
}); | ||
|
||
exp = statement('export function foo(){}'); | ||
resolved = resolveExportDeclaration(exp, noopImporter); | ||
it('resolves named function exports', () => { | ||
const exp = statement('export function foo(){}'); | ||
const resolved = resolveExportDeclaration(exp, noopImporter); | ||
|
||
expect(resolved).toEqual([returnValue]); | ||
expect(resolveToValue).toBeCalledWith(exp.get('declaration'), noopImporter); | ||
expect(resolved).toEqual([exp.get('declaration')]); | ||
}); | ||
|
||
exp = statement('export class Foo {}'); | ||
resolved = resolveExportDeclaration(exp, noopImporter); | ||
it('resolves named class exports', () => { | ||
const exp = statement('export class Foo {}'); | ||
const resolved = resolveExportDeclaration(exp, noopImporter); | ||
|
||
expect(resolved).toEqual([returnValue]); | ||
expect(resolveToValue).toBeCalledWith(exp.get('declaration'), noopImporter); | ||
expect(resolved).toEqual([exp.get('declaration')]); | ||
}); | ||
|
||
it('resolves named exports', () => { | ||
const exp = statement('export {foo, bar, baz}; var foo, bar, baz;'); | ||
const resolved = resolveExportDeclaration(exp, noopImporter); | ||
|
||
const specifiers = exp.get('specifiers'); | ||
expect(resolved).toEqual([returnValue, returnValue, returnValue]); | ||
expect(resolveToValue).toBeCalledWith( | ||
expect(resolved).toEqual([ | ||
specifiers.get(0, 'local'), | ||
specifiers.get(1, 'local'), | ||
specifiers.get(2, 'local'), | ||
]); | ||
}); | ||
|
||
it('resolves named exports from', () => { | ||
const exp = statement('export {foo, bar, baz} from "";'); | ||
const resolved = resolveExportDeclaration(exp, noopImporter); | ||
|
||
const specifiers = exp.get('specifiers'); | ||
expect(resolved).toEqual([ | ||
specifiers.get(0, 'local'), | ||
noopImporter, | ||
); | ||
expect(resolveToValue).toBeCalledWith( | ||
specifiers.get(1, 'local'), | ||
noopImporter, | ||
); | ||
expect(resolveToValue).toBeCalledWith( | ||
specifiers.get(2, 'local'), | ||
noopImporter, | ||
); | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters