Skip to content

Commit a476bba

Browse files
suphon-tmsp5382
authored andcommitted
fix: add missing no symbol handle
1 parent 95d43e4 commit a476bba

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/walk/3-modify-get.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export const handleGet = (
88
transformList: Map<ts.Node, ts.Node>
99
) => {
1010
// hash and move type argument to argument
11-
const symbol = globalTypeChecker.getTypeAtLocation(node.typeArguments![0]).getSymbol()
11+
const symbol = globalTypeChecker
12+
.getTypeAtLocation(node.typeArguments![0])
13+
.getSymbol();
1214
const argument = ts.factory.createStringLiteral(
13-
symbol ? hashSymbol(
14-
symbol
15-
) : hashNode(node.typeArguments![0])
15+
symbol ? hashSymbol(symbol) : hashNode(node.typeArguments![0])
1616
);
1717
const newNode = ts.factory.updateCallExpression(
1818
node,
@@ -38,9 +38,12 @@ export const getFactoryDependencies = (factory: ts.Expression) => {
3838
.getSymbol();
3939
if (symbol && symbol === getSymbol) {
4040
const classOrInterface = node.typeArguments![0];
41-
const hash = hashSymbol(
42-
globalTypeChecker.getTypeAtLocation(classOrInterface).getSymbol()!
43-
);
41+
const symbol = globalTypeChecker
42+
.getTypeAtLocation(classOrInterface)
43+
.getSymbol();
44+
const hash = symbol
45+
? hashSymbol(symbol)
46+
: hashNode(node.typeArguments![0]);
4447
dependencies.push(hash);
4548
}
4649
}

src/walk/source-templates.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ts from "typescript";
22
import { globalContext, globalTypeChecker } from ".";
3-
import { hashSymbol } from "./utils";
3+
import { hashNode, hashSymbol } from "./utils";
44

55
export const defaultFactoryTemplate = (
66
className: string,
@@ -132,9 +132,10 @@ export const factoryWrapperTemplate = (factory: ts.Expression) => {
132132
.getSymbol();
133133
if (symbol && symbol === getSymbol) {
134134
const classOrInterface = node.typeArguments![0];
135-
const hash = hashSymbol(
136-
globalTypeChecker.getTypeAtLocation(classOrInterface).getSymbol()!
137-
);
135+
const classOrInterfaceSymbol = globalTypeChecker.getTypeAtLocation(classOrInterface).getSymbol()
136+
const hash = classOrInterfaceSymbol
137+
? hashSymbol(classOrInterfaceSymbol)
138+
: hashNode(classOrInterface);
138139
const newNode = ts.factory.createCallExpression(
139140
ts.factory.createIdentifier("get"),
140141
undefined,

0 commit comments

Comments
 (0)