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

Replace import equals declarations with const and type alias statements #155

Merged
merged 5 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
113 changes: 65 additions & 48 deletions src/main/render/thrift-server/typedef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import { TypeMapping } from './types'

import { DefinitionType, IRenderState, IResolvedIdentifier } from '../../types'

import { className, looseName, strictName, toolkitName } from './struct/utils'
import {
className,
looseName,
strictName,
tokens,
toolkitName,
} from './struct/utils'

import {
fieldInterfaceName,
Expand All @@ -25,6 +31,7 @@ import {
resolveIdentifierDefinition,
resolveIdentifierName,
} from '../../resolver'
import { createConst } from '../shared/utils'

function renderStrictInterfaceReexport(
id: IResolvedIdentifier,
Expand All @@ -33,14 +40,14 @@ function renderStrictInterfaceReexport(
state: IRenderState,
): ts.Statement {
if (id.pathName !== undefined) {
return ts.createImportEqualsDeclaration(
return ts.createTypeAliasDeclaration(
undefined,
[ts.createToken(ts.SyntaxKind.ExportKeyword)],
ts.createIdentifier(
strictName(node.name.value, definition.type, state),
),
ts.createIdentifier(
`${strictName(id.rawName, definition.type, state)}`,
tokens(true),
strictName(node.name.value, definition.type, state),
undefined,
ts.createTypeReferenceNode(
strictName(id.rawName, definition.type, state),
undefined,
),
)
} else {
Expand Down Expand Up @@ -69,14 +76,14 @@ function renderLooseInterfaceReexport(
state: IRenderState,
): ts.Statement {
if (id.pathName !== undefined) {
return ts.createImportEqualsDeclaration(
return ts.createTypeAliasDeclaration(
undefined,
[ts.createToken(ts.SyntaxKind.ExportKeyword)],
ts.createIdentifier(
looseName(node.name.value, definition.type, state),
),
ts.createIdentifier(
`${looseName(id.rawName, definition.type, state)}`,
tokens(true),
looseName(node.name.value, definition.type, state),
undefined,
ts.createTypeReferenceNode(
looseName(id.rawName, definition.type, state),
undefined,
),
)
} else {
Expand Down Expand Up @@ -104,11 +111,13 @@ function renderClassReexport(
state: IRenderState,
): ts.Statement {
if (id.pathName !== undefined) {
return ts.createImportEqualsDeclaration(
undefined,
[ts.createToken(ts.SyntaxKind.ExportKeyword)],
ts.createIdentifier(className(node.name.value, state)),
ts.createIdentifier(`${className(id.rawName, state)}`),
return ts.createVariableStatement(
tokens(true),
createConst(
className(node.name.value, state),
undefined,
ts.createIdentifier(className(id.rawName, state)),
),
)
} else {
return ts.createExportDeclaration(
Expand All @@ -132,11 +141,13 @@ function renderToolkitReexport(
state: IRenderState,
): ts.Statement {
if (id.pathName !== undefined) {
return ts.createImportEqualsDeclaration(
undefined,
[ts.createToken(ts.SyntaxKind.ExportKeyword)],
ts.createIdentifier(toolkitName(node.name.value, state)),
ts.createIdentifier(`${toolkitName(id.rawName, state)}`),
return ts.createVariableStatement(
tokens(true),
createConst(
toolkitName(node.name.value, state),
undefined,
ts.createIdentifier(toolkitName(id.rawName, state)),
),
)
} else {
return ts.createExportDeclaration(
Expand All @@ -159,11 +170,15 @@ function renderUnionTypeReexport(
state: IRenderState,
): ts.Statement {
if (id.pathName !== undefined) {
return ts.createImportEqualsDeclaration(
return ts.createTypeAliasDeclaration(
undefined,
tokens(true),
renderUnionTypeName(node.name.value, state),
undefined,
[ts.createToken(ts.SyntaxKind.ExportKeyword)],
ts.createIdentifier(renderUnionTypeName(node.name.value, state)),
ts.createIdentifier(`${renderUnionTypeName(id.rawName, state)}`),
ts.createTypeReferenceNode(
renderUnionTypeName(id.rawName, state),
undefined,
),
)
} else {
return ts.createExportDeclaration(
Expand Down Expand Up @@ -192,22 +207,18 @@ function renderUnionInterfaceReexports(
): Array<ts.Statement> {
if (id.pathName !== undefined) {
return union.fields.map((next: FieldDefinition) => {
return ts.createImportEqualsDeclaration(
return ts.createTypeAliasDeclaration(
undefined,
[ts.createToken(ts.SyntaxKind.ExportKeyword)],
ts.createIdentifier(
fieldInterfaceName(
node.name.value,
next.name.value,
strict,
),
),
ts.createIdentifier(
tokens(true),
fieldInterfaceName(node.name.value, next.name.value, strict),
undefined,
ts.createTypeReferenceNode(
`${id.pathName}.${fieldInterfaceName(
union.name.value,
next.name.value,
strict,
)}`,
undefined,
),
)
})
Expand Down Expand Up @@ -245,11 +256,15 @@ function renderUnionArgsReexport(
state: IRenderState,
): ts.Statement {
if (id.pathName !== undefined) {
return ts.createImportEqualsDeclaration(
return ts.createTypeAliasDeclaration(
undefined,
[ts.createToken(ts.SyntaxKind.ExportKeyword)],
ts.createIdentifier(unionTypeName(node.name.value, state, false)),
ts.createIdentifier(`${unionTypeName(id.rawName, state, false)}`),
tokens(true),
unionTypeName(node.name.value, state, false),
undefined,
ts.createTypeReferenceNode(
unionTypeName(id.rawName, state, false),
undefined,
),
)
} else {
return ts.createExportDeclaration(
Expand Down Expand Up @@ -333,11 +348,13 @@ function renderTypeDefForIdentifier(
case SyntaxType.ConstDefinition:
case SyntaxType.EnumDefinition:
return [
ts.createImportEqualsDeclaration(
undefined,
[ts.createToken(ts.SyntaxKind.ExportKeyword)],
ts.createIdentifier(node.name.value),
ts.createIdentifier(resolvedIdentifier.fullName),
ts.createVariableStatement(
tokens(true),
createConst(
node.name.value,
undefined,
ts.createIdentifier(resolvedIdentifier.fullName),
),
),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import * as com_test_operation from "./../operation";
import * as com_test_common from "./../common";
export type MyInteger = number;
export import Operation = com_test_operation.Operation;
export import ICommonStruct = com_test_common.ICommonStruct;
export import ICommonStructArgs = com_test_common.ICommonStructArgs;
export import CommonStruct = com_test_common.CommonStruct;
export import CommonStructCodec = com_test_common.CommonStructCodec;
export const Operation = com_test_operation.Operation;
export type ICommonStruct = com_test_common.ICommonStruct;
export type ICommonStructArgs = com_test_common.ICommonStructArgs;
export const CommonStruct = com_test_common.CommonStruct;
export const CommonStructCodec = com_test_common.CommonStructCodec;
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/* tslint:disable */
/*
* Autogenerated by @creditkarma/thrift-typescript v{{VERSION}}
* Autogenerated by @creditkarma/thrift-typescript v3.5.0
hayes marked this conversation as resolved.
Show resolved Hide resolved
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
import * as com_test_shared from "./../shared";
import * as __NAMESPACE__ from "./.";
export import ICommonStruct = com_test_shared.ISharedStruct;
export import ICommonStructArgs = com_test_shared.ISharedStructArgs;
export import CommonStruct = com_test_shared.SharedStruct;
export import CommonStructCodec = com_test_shared.SharedStructCodec;
export import CommonUnionType = com_test_shared.SharedUnionType;
export import CommonUnion = com_test_shared.SharedUnion;
export import ICommonUnionWithOption1 = com_test_shared.ISharedUnionWithOption1;
export import ICommonUnionWithOption2 = com_test_shared.ISharedUnionWithOption2;
export import CommonUnionArgs = com_test_shared.SharedUnionArgs;
export import ICommonUnionWithOption1Args = com_test_shared.ISharedUnionWithOption1Args;
export import ICommonUnionWithOption2Args = com_test_shared.ISharedUnionWithOption2Args;
export import CommonUnionCodec = com_test_shared.SharedUnionCodec;
export import COMMON_INT = com_test_shared.SHARED_INT;
export import INotAllowed = __NAMESPACE__.IAuthException;
export import INotAllowedArgs = __NAMESPACE__.IAuthExceptionArgs;
export import NotAllowed = __NAMESPACE__.AuthException;
export import NotAllowedCodec = __NAMESPACE__.AuthExceptionCodec;
export import MoreOptionsType = __NAMESPACE__.OtherCommonUnionType;
export import MoreOptions = __NAMESPACE__.OtherCommonUnion;
export import IMoreOptionsWithOption1 = __NAMESPACE__.IOtherCommonUnionWithOption1;
export import IMoreOptionsWithOption2 = __NAMESPACE__.IOtherCommonUnionWithOption2;
export import MoreOptionsArgs = __NAMESPACE__.OtherCommonUnionArgs;
export import IMoreOptionsWithOption1Args = __NAMESPACE__.IOtherCommonUnionWithOption1Args;
export import IMoreOptionsWithOption2Args = __NAMESPACE__.IOtherCommonUnionWithOption2Args;
export import MoreOptionsCodec = __NAMESPACE__.OtherCommonUnionCodec;
export type ICommonStruct = com_test_shared.ISharedStruct;
export type ICommonStructArgs = com_test_shared.ISharedStructArgs;
export const CommonStruct = com_test_shared.SharedStruct;
export const CommonStructCodec = com_test_shared.SharedStructCodec;
export type CommonUnionType = com_test_shared.SharedUnionType;
export const CommonUnion = com_test_shared.SharedUnion;
hayes marked this conversation as resolved.
Show resolved Hide resolved
export type ICommonUnionWithOption1 = com_test_shared.ISharedUnionWithOption1;
export type ICommonUnionWithOption2 = com_test_shared.ISharedUnionWithOption2;
export type CommonUnionArgs = com_test_shared.SharedUnionArgs;
export type ICommonUnionWithOption1Args = com_test_shared.ISharedUnionWithOption1Args;
export type ICommonUnionWithOption2Args = com_test_shared.ISharedUnionWithOption2Args;
export const CommonUnionCodec = com_test_shared.SharedUnionCodec;
export const COMMON_INT = com_test_shared.SHARED_INT;
export type INotAllowed = __NAMESPACE__.IAuthException;
export type INotAllowedArgs = __NAMESPACE__.IAuthExceptionArgs;
export const NotAllowed = __NAMESPACE__.AuthException;
export const NotAllowedCodec = __NAMESPACE__.AuthExceptionCodec;
export type MoreOptionsType = __NAMESPACE__.OtherCommonUnionType;
export const MoreOptions = __NAMESPACE__.OtherCommonUnion;
export type IMoreOptionsWithOption1 = __NAMESPACE__.IOtherCommonUnionWithOption1;
export type IMoreOptionsWithOption2 = __NAMESPACE__.IOtherCommonUnionWithOption2;
export type MoreOptionsArgs = __NAMESPACE__.OtherCommonUnionArgs;
export type IMoreOptionsWithOption1Args = __NAMESPACE__.IOtherCommonUnionWithOption1Args;
export type IMoreOptionsWithOption2Args = __NAMESPACE__.IOtherCommonUnionWithOption2Args;
export const MoreOptionsCodec = __NAMESPACE__.OtherCommonUnionCodec;
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/
import * as com_test_exceptions from "./../exceptions";
import * as __NAMESPACE__ from "./.";
export import IJankyOperation = com_test_exceptions.IInvalidOperation;
export import IJankyOperationArgs = com_test_exceptions.IInvalidOperationArgs;
export import JankyOperation = com_test_exceptions.InvalidOperation;
export import JankyOperationCodec = com_test_exceptions.InvalidOperationCodec;
export import IJankyResult = com_test_exceptions.IInvalidResult;
export import IJankyResultArgs = com_test_exceptions.IInvalidResultArgs;
export import JankyResult = com_test_exceptions.InvalidResult;
export import JankyResultCodec = com_test_exceptions.InvalidResultCodec;
export import SomethingToDo = __NAMESPACE__.Operation;
export type IJankyOperation = com_test_exceptions.IInvalidOperation;
export type IJankyOperationArgs = com_test_exceptions.IInvalidOperationArgs;
export const JankyOperation = com_test_exceptions.InvalidOperation;
export const JankyOperationCodec = com_test_exceptions.InvalidOperationCodec;
export type IJankyResult = com_test_exceptions.IInvalidResult;
export type IJankyResultArgs = com_test_exceptions.IInvalidResultArgs;
export const JankyResult = com_test_exceptions.InvalidResult;
export const JankyResultCodec = com_test_exceptions.InvalidResultCodec;
export const SomethingToDo = __NAMESPACE__.Operation;
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import * as com_test_operation from "./../operation";
import * as com_test_common from "./../common";
export type MyInteger = number;
export import Operation = com_test_operation.Operation;
export import ICommonStruct = com_test_common.ICommonStruct;
export import ICommonStructArgs = com_test_common.ICommonStructArgs;
export import CommonStruct = com_test_common.CommonStruct;
export import CommonStructCodec = com_test_common.CommonStructCodec;
export const Operation = com_test_operation.Operation;
export type ICommonStruct = com_test_common.ICommonStruct;
export type ICommonStructArgs = com_test_common.ICommonStructArgs;
export const CommonStruct = com_test_common.CommonStruct;
export const CommonStructCodec = com_test_common.CommonStructCodec;
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
*/
import * as com_test_shared from "./../shared";
import * as __NAMESPACE__ from "./.";
export import ICommonStruct = com_test_shared.ISharedStruct;
export import ICommonStructArgs = com_test_shared.ISharedStructArgs;
export import CommonStruct = com_test_shared.SharedStruct;
export import CommonStructCodec = com_test_shared.SharedStructCodec;
export import ICommonUnion = com_test_shared.ISharedUnion;
export import ICommonUnionArgs = com_test_shared.ISharedUnionArgs;
export import CommonUnion = com_test_shared.SharedUnion;
export import CommonUnionCodec = com_test_shared.SharedUnionCodec;
export import COMMON_INT = com_test_shared.SHARED_INT;
export import INotAllowed = __NAMESPACE__.IAuthException;
export import INotAllowedArgs = __NAMESPACE__.IAuthExceptionArgs;
export import NotAllowed = __NAMESPACE__.AuthException;
export import NotAllowedCodec = __NAMESPACE__.AuthExceptionCodec;
export import IMoreOptions = __NAMESPACE__.IOtherCommonUnion;
export import IMoreOptionsArgs = __NAMESPACE__.IOtherCommonUnionArgs;
export import MoreOptions = __NAMESPACE__.OtherCommonUnion;
export import MoreOptionsCodec = __NAMESPACE__.OtherCommonUnionCodec;
export type ICommonStruct = com_test_shared.ISharedStruct;
export type ICommonStructArgs = com_test_shared.ISharedStructArgs;
export const CommonStruct = com_test_shared.SharedStruct;
export const CommonStructCodec = com_test_shared.SharedStructCodec;
export type ICommonUnion = com_test_shared.ISharedUnion;
export type ICommonUnionArgs = com_test_shared.ISharedUnionArgs;
export const CommonUnion = com_test_shared.SharedUnion;
export const CommonUnionCodec = com_test_shared.SharedUnionCodec;
export const COMMON_INT = com_test_shared.SHARED_INT;
export type INotAllowed = __NAMESPACE__.IAuthException;
export type INotAllowedArgs = __NAMESPACE__.IAuthExceptionArgs;
export const NotAllowed = __NAMESPACE__.AuthException;
export const NotAllowedCodec = __NAMESPACE__.AuthExceptionCodec;
export type IMoreOptions = __NAMESPACE__.IOtherCommonUnion;
export type IMoreOptionsArgs = __NAMESPACE__.IOtherCommonUnionArgs;
export const MoreOptions = __NAMESPACE__.OtherCommonUnion;
export const MoreOptionsCodec = __NAMESPACE__.OtherCommonUnionCodec;
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/
import * as com_test_exceptions from "./../exceptions";
import * as __NAMESPACE__ from "./.";
export import IJankyOperation = com_test_exceptions.IInvalidOperation;
export import IJankyOperationArgs = com_test_exceptions.IInvalidOperationArgs;
export import JankyOperation = com_test_exceptions.InvalidOperation;
export import JankyOperationCodec = com_test_exceptions.InvalidOperationCodec;
export import IJankyResult = com_test_exceptions.IInvalidResult;
export import IJankyResultArgs = com_test_exceptions.IInvalidResultArgs;
export import JankyResult = com_test_exceptions.InvalidResult;
export import JankyResultCodec = com_test_exceptions.InvalidResultCodec;
export import SomethingToDo = __NAMESPACE__.Operation;
export type IJankyOperation = com_test_exceptions.IInvalidOperation;
export type IJankyOperationArgs = com_test_exceptions.IInvalidOperationArgs;
export const JankyOperation = com_test_exceptions.InvalidOperation;
export const JankyOperationCodec = com_test_exceptions.InvalidOperationCodec;
export type IJankyResult = com_test_exceptions.IInvalidResult;
export type IJankyResultArgs = com_test_exceptions.IInvalidResultArgs;
export const JankyResult = com_test_exceptions.InvalidResult;
export const JankyResultCodec = com_test_exceptions.InvalidResultCodec;
export const SomethingToDo = __NAMESPACE__.Operation;