Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for export equals #124

Merged
merged 1 commit into from
Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@commitlint/config-angular": "^8.2.0",
"@types/jasmine": "^3.5.0",
"@types/node": "^13.1.0",
"@types/webpack-env": "^1.14.1",
"awesome-typescript-loader": "^5.2.1",
"clean-webpack-plugin": "^3.0.0",
"conventional-changelog-cli": "^2.0.31",
Expand Down
11 changes: 4 additions & 7 deletions src/transformer/descriptor/helper/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,21 @@ export namespace TypescriptHelper {
export function GetDeclarationFromNode(node: ts.Node): ts.Declaration {
const typeChecker: ts.TypeChecker = TypeChecker();
const symbol: ts.Symbol = typeChecker.getSymbolAtLocation(node);

return GetDeclarationFromSymbol(symbol);
}

export function GetDeclarationFromSymbol(symbol: ts.Symbol): ts.Declaration {
const declaration: ts.Declaration = GetFirstValidDeclaration(symbol.declarations);

if (ts.isImportSpecifier(declaration)) {
return GetDeclarationForImport(declaration) as ts.Declaration;
}

if (ts.isImportEqualsDeclaration(declaration)) {
return GetDeclarationFromNode(declaration.moduleReference);
if (ts.isImportSpecifier(declaration) || ts.isImportEqualsDeclaration(declaration)) {
return GetDeclarationForImport(declaration);
}

return declaration;
}

export function GetDeclarationForImport(node: ts.ImportClause | ts.ImportSpecifier): ts.TypeNode | ts.Declaration {
export function GetDeclarationForImport(node: ts.ImportClause | ts.ImportSpecifier | ts.ImportEqualsDeclaration): ts.Declaration {
const typeChecker: ts.TypeChecker = TypeChecker();
const symbol: ts.Symbol = typeChecker.getSymbolAtLocation(node.name);
const originalSymbol: ts.Symbol = typeChecker.getAliasedSymbol(symbol);
Expand Down
4 changes: 3 additions & 1 deletion test/frameworkContext/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ Provider.instance.provideMethodWithDeferredValue((name: string, value: () => any
return jasmine.createSpy(name).and.callFake(value);
});

const frameworkContext: __WebpackModuleApi.RequireContext = require.context('./', true, /\.test(\.valid)?\.ts$/);
// @ts-ignore
// tslint:disable-next-line:typedef
const frameworkContext = require.context('./', true, /\.test(\.valid)?\.ts$/);
frameworkContext.keys().map(frameworkContext);
4 changes: 3 additions & 1 deletion test/frameworkContext/contextDeprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ Provider.instance.provideMethod((name: string, value: any) => {
return jasmine.createSpy(name).and.returnValue(value);
});

const frameworkContext: __WebpackModuleApi.RequireContext = require.context('./', true, /\.test(\.deprecated)?\.ts$/);
// @ts-ignore
// tslint:disable-next-line:typedef
const frameworkContext = require.context('./', true, /\.test(\.deprecated)?\.ts$/);
frameworkContext.keys().map(frameworkContext);
4 changes: 3 additions & 1 deletion test/transformer/context.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
const frameworkContext: __WebpackModuleApi.RequireContext = require.context('./', true, /\.test\.ts$/);
// @ts-ignore
// tslint:disable-next-line:typedef
const frameworkContext = require.context('./', true, /\.test\.ts$/);
frameworkContext.keys().map(frameworkContext);
14 changes: 14 additions & 0 deletions test/transformer/descriptor/import/importEqual.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { createMock } from 'ts-auto-mock';
import IAmAnotherExportedWithEqual from '../utils/interfaces/anotherExportEqual';
import IAmExportedWithEqual = require('../utils/interfaces/exportEqual');
import { NameSpaceInterfaceImport } from '../utils/namespace/namespace';
import Interface = NameSpaceInterfaceImport.Interface;
import SubInterface = NameSpaceInterfaceImport.SubNamespace.SubInterface;
Expand All @@ -22,4 +24,16 @@ describe('import equal', () => {
const mock: SubInterface = createMock<SubInterface>();
expect(mock.a).toBe('');
});

it('should use the correct import for an equal exported interface used with require', () => {
const mock: IAmExportedWithEqual = createMock<IAmExportedWithEqual>();
expect(mock.a).toBe('');
expect(mock.b).toBe(0);
});

it('should use the correct import for an equal exported interface used with import', () => {
const mock: IAmAnotherExportedWithEqual = createMock<IAmAnotherExportedWithEqual>();
expect(mock.a).toBe('');
expect(mock.b).toBe(0);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface IAmAnotherExportedWithEqual {
a: string;
b: number;
}

export = IAmAnotherExportedWithEqual;
6 changes: 6 additions & 0 deletions test/transformer/descriptor/utils/interfaces/exportEqual.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface IAmExportedWithEqual {
a: string;
b: number;
}

export = IAmExportedWithEqual;