Skip to content

Commit 69e52e1

Browse files
committed
perf(typescript): upgrade to latest version of typescript
1 parent c5aa380 commit 69e52e1

File tree

9 files changed

+44
-21
lines changed

9 files changed

+44
-21
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"ts-node": "^10.1.0",
9393
"tsconfig-paths": "^3.10.1",
9494
"ttypescript": "1.5.12",
95-
"typescript": "^4.2.3",
95+
"typescript": "^4.3.5",
9696
"webpack": "^5.49.0",
9797
"webpack-cli": "^4.7.2",
9898
"webpack-merge": "^5.8.0",

src/transformer/descriptor/helper/helper.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@ export namespace TypescriptHelper {
3838
}
3939

4040
export function GetDeclarationFromSymbol(symbol: ts.Symbol): ts.Declaration {
41-
const declaration: ts.Declaration = GetFirstValidDeclaration(
42-
symbol.declarations
43-
);
41+
const declarations: ts.Declaration[] | undefined = symbol.declarations;
42+
43+
if (!declarations) {
44+
throw new Error(
45+
`Failed to look up declarations for \`${symbol.getName()}'.`
46+
);
47+
}
48+
49+
const declaration: ts.Declaration = GetFirstValidDeclaration(declarations);
4450

4551
if (isImportExportDeclaration(declaration)) {
4652
return GetDeclarationForImport(declaration);
@@ -52,7 +58,15 @@ export namespace TypescriptHelper {
5258
export function GetConcreteDeclarationFromSymbol(
5359
symbol: ts.Symbol
5460
): ts.Declaration {
55-
const declaration: ts.Declaration = symbol.declarations[0];
61+
const declarations: ts.Declaration[] | undefined = symbol.declarations;
62+
63+
if (!declarations) {
64+
throw new Error(
65+
`Failed to look up declarations for \`${symbol.getName()}'.`
66+
);
67+
}
68+
69+
const declaration: ts.Declaration = declarations[0];
5670

5771
if (isImportExportDeclaration(declaration)) {
5872
return GetConcreteDeclarationForImport(declaration);

src/transformer/descriptor/mock/mockProperties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function GetMockPropertiesFromSymbol(
2020
.filter((prop: ts.Symbol) => !!prop.declarations) // Dynamically generated properties (mapped types) do not have declarations
2121
.map(
2222
(prop: ts.Symbol) =>
23-
prop.declarations.filter(
23+
prop.declarations?.filter(
2424
(declaration: ts.Declaration) => !core.ts.isSetAccessor(declaration)
2525
)[0]
2626
)

src/transformer/descriptor/module/module.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
createTypeLiteralNode,
1111
createTypeQueryNode,
1212
} from '../../../typescriptFactory/typescriptFactory';
13+
import GetDeclarationFromSymbol = TypescriptHelper.GetDeclarationFromSymbol;
1314

1415
type ExternalSource = ts.SourceFile | ts.ModuleDeclaration;
1516

@@ -35,7 +36,8 @@ export function GetModuleDescriptor(
3536
}
3637

3738
const symbol: ts.Symbol = typeChecker.getAliasedSymbol(symbolAlias);
38-
const externalModuleDeclaration: ts.NamedDeclaration = symbol.declarations[0];
39+
const externalModuleDeclaration: ts.NamedDeclaration =
40+
GetDeclarationFromSymbol(symbol);
3941

4042
if (isExternalSource(externalModuleDeclaration)) {
4143
return GetPropertiesFromSourceFileOrModuleDeclarationDescriptor(
@@ -83,12 +85,12 @@ export function GetPropertiesFromSourceFileOrModuleDeclaration(
8385
const moduleExports: ts.Symbol[] = typeChecker.getExportsOfModule(symbol);
8486

8587
return moduleExports
86-
.map((prop: ts.Symbol): ModuleExportsDeclarations => {
88+
.map((prop: ts.Symbol): Partial<ModuleExportsDeclarations> => {
8789
const originalSymbol: ts.Symbol =
8890
TypescriptHelper.GetAliasedSymbolSafe(prop);
89-
const originalDeclaration: ts.NamedDeclaration =
91+
const originalDeclaration: ts.NamedDeclaration | undefined =
9092
originalSymbol?.declarations?.[0];
91-
const declaration: ts.Declaration = prop?.declarations?.[0];
93+
const declaration: ts.Declaration | undefined = prop?.declarations?.[0];
9294

9395
return {
9496
declaration,

src/transformer/descriptor/typeParameter/typeParameter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
createVariableDeclarationList,
2525
createVariableStatement,
2626
} from '../../../typescriptFactory/typescriptFactory';
27+
import GetDeclarationFromSymbol = TypescriptHelper.GetDeclarationFromSymbol;
2728

2829
export function GetTypeParameterDescriptor(
2930
node: ts.TypeParameterDeclaration,
@@ -35,7 +36,7 @@ export function GetTypeParameterDescriptor(
3536
? GetDescriptor(node.default, scope)
3637
: GetNullDescriptor();
3738

38-
const declaration: ts.Declaration = type.symbol.declarations[0];
39+
const declaration: ts.Declaration = GetDeclarationFromSymbol(type.symbol);
3940
const typeDeclaration: ts.Declaration | undefined =
4041
TypescriptHelper.GetTypeParameterOwnerMock(declaration);
4142

src/transformer/descriptor/typeQuery/typeQuery.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function GetTypeQueryDescriptor(
2626
): ts.Expression {
2727
const symbol: ts.Symbol | undefined = getTypeQuerySymbol(node);
2828

29-
if (!symbol?.declarations.length) {
29+
if (!symbol?.declarations?.length) {
3030
return GetUndefinedDescriptor();
3131
}
3232

@@ -131,7 +131,13 @@ function getTypeQuerySymbol(node: ts.TypeQueryNode): ts.Symbol | undefined {
131131
function getTypeQueryDeclarationFromSymbol(
132132
symbol: ts.Symbol
133133
): ts.NamedDeclaration {
134-
const declaration: ts.Declaration = symbol.declarations[0];
134+
const declaration: ts.Declaration | undefined = symbol.declarations?.[0];
135+
136+
if (!declaration) {
137+
throw new Error(
138+
`Failed to look up declaration for \`${symbol.getName()}'.`
139+
);
140+
}
135141

136142
if (core.ts.isImportEqualsDeclaration(declaration)) {
137143
return declaration;

src/transformer/mock/mock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
createBinaryExpression,
1515
createBlock,
1616
createCall,
17-
createEmptyStatement,
17+
createOmittedExpression,
1818
createExpressionStatement,
1919
createForStatement,
2020
createIdentifier,
@@ -71,7 +71,7 @@ export function storeRegisterMock(
7171
Logger('RegisterMock').error(
7272
'registerMock can be used only to mock type references.'
7373
);
74-
return createEmptyStatement();
74+
return createOmittedExpression();
7575
}
7676
}
7777

src/typescriptFactory/typescriptFactory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
ColonToken,
1111
ConditionalExpression,
1212
ElementAccessExpression,
13-
EmptyStatement,
13+
OmittedExpression,
1414
Expression,
1515
ExpressionStatement,
1616
ForStatement,
@@ -463,8 +463,8 @@ export function createPostfix(
463463
return core.ts.factory.createPostfixUnaryExpression(operand, operator);
464464
}
465465

466-
export function createEmptyStatement(): EmptyStatement {
467-
return core.ts.factory.createEmptyStatement();
466+
export function createOmittedExpression(): OmittedExpression {
467+
return core.ts.factory.createOmittedExpression();
468468
}
469469

470470
export function createTypeReferenceNode(

0 commit comments

Comments
 (0)