@@ -826,7 +826,7 @@ namespace ts {
826
826
getIndexAccessExpressionCache: () => indexAccessExpressionCache,
827
827
isTsPlusMacroCall,
828
828
isTsPlusMacroGetter,
829
- isClassCompanionReference ,
829
+ isCompanionReference ,
830
830
collectTsPlusFluentTags,
831
831
hasExportedPlusTags: (declaration) => {
832
832
return collectTsPlusFluentTags(declaration).length > 0 ||
@@ -1196,7 +1196,7 @@ namespace ts {
1196
1196
const copy: ESMap<string, Symbol> = new Map();
1197
1197
const copyFluent: ESMap<string, Set<TsPlusFluentExtension>> = new Map();
1198
1198
symbols.forEach((target) => {
1199
- if (typeSymbolCache.has(target) && !isClassCompanionReference (selfNode)) {
1199
+ if (typeSymbolCache.has(target) && !isCompanionReference (selfNode)) {
1200
1200
typeSymbolCache.get(target)!.forEach((typeSymbol) => {
1201
1201
const _static = staticCache.get(typeSymbol);
1202
1202
if (_static) {
@@ -1238,7 +1238,7 @@ namespace ts {
1238
1238
}
1239
1239
});
1240
1240
}
1241
- if (companionSymbolCache.has(target) && isClassCompanionReference (selfNode)) {
1241
+ if (companionSymbolCache.has(target) && isCompanionReference (selfNode)) {
1242
1242
companionSymbolCache.get(target)!.forEach((typeSymbol) => {
1243
1243
const _static = staticCache.get(typeSymbol);
1244
1244
if (_static) {
@@ -2783,6 +2783,31 @@ namespace ts {
2783
2783
result = undefined;
2784
2784
}
2785
2785
}
2786
+ // TSPLUS EXTENSION START
2787
+ else {
2788
+ if (originalLocation && originalLocation.parent && (isPropertyAccessExpression(originalLocation.parent) || isCallExpression(originalLocation.parent))) {
2789
+ const symbol = location.locals.get(name)
2790
+ if (symbol) {
2791
+ if (companionSymbolCache.has(symbol)) {
2792
+ result = symbol;
2793
+ break loop;
2794
+ }
2795
+ if (symbol.exportSymbol && companionSymbolCache.has(symbol.exportSymbol)) {
2796
+ result = symbol.exportSymbol;
2797
+ break loop;
2798
+ }
2799
+ if (symbol.declarations && symbol.declarations[0] && isImportSpecifier(symbol.declarations[0])) {
2800
+ const originalSymbol = getTargetOfImportSpecifier(symbol.declarations[0], false);
2801
+ if (originalSymbol && companionSymbolCache.has(originalSymbol)) {
2802
+ result = originalSymbol;
2803
+ symbol.isReferenced = SymbolFlags.Value;
2804
+ break loop;
2805
+ }
2806
+ }
2807
+ }
2808
+ }
2809
+ }
2810
+ // TSPLUS EXTENSION END
2786
2811
}
2787
2812
withinDeferredContext = withinDeferredContext || getIsDeferredContext(location, lastLocation);
2788
2813
switch (location.kind) {
@@ -3030,7 +3055,10 @@ namespace ts {
3030
3055
const globalImport = tsPlusGlobalImportCache.get(name as string);
3031
3056
if (globalImport) {
3032
3057
const targetSymbol = getTargetOfImportSpecifier(globalImport.importSpecifier, false);
3033
- if (targetSymbol && targetSymbol.flags & meaning) {
3058
+ if (targetSymbol &&
3059
+ ((targetSymbol.flags & meaning) ||
3060
+ companionSymbolCache.has(targetSymbol) && (isPropertyAccessExpression(originalLocation.parent) || isCallExpression(originalLocation.parent)))
3061
+ ) {
3034
3062
const withoutGlobals = resolveNameHelper(
3035
3063
originalLocation,
3036
3064
name,
@@ -5795,7 +5823,7 @@ namespace ts {
5795
5823
}
5796
5824
5797
5825
// TSPLUS EXTENSION START
5798
- function isClassCompanionReference (node: Expression | QualifiedName): boolean {
5826
+ function isCompanionReference (node: Expression | QualifiedName): boolean {
5799
5827
let type: Type | undefined
5800
5828
5801
5829
const symbol = getSymbolAtLocation(node);
@@ -5809,8 +5837,8 @@ namespace ts {
5809
5837
if (!type) {
5810
5838
return false
5811
5839
}
5812
-
5813
- return !!(getObjectFlags(type) & ObjectFlags.Anonymous && type. symbol && type. symbol.flags & SymbolFlags.Class);
5840
+ return !!(getObjectFlags(type) & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & SymbolFlags.Class)
5841
+ || (!! symbol?.declarations?.[0] && (isInterfaceDeclaration( symbol.declarations[0]) || isTypeAliasDeclaration(symbol.declarations[0])))
5814
5842
}
5815
5843
// TSPLUS EXTENSION END
5816
5844
@@ -11023,6 +11051,13 @@ namespace ts {
11023
11051
if (symbol.flags & SymbolFlags.Alias) {
11024
11052
return getTypeOfAlias(symbol);
11025
11053
}
11054
+ if ((symbol.flags & SymbolFlags.Interface) || (symbol.flags & SymbolFlags.TypeAlias)) {
11055
+ if (companionSymbolCache.has(symbol)) {
11056
+ if (symbol.declarations?.[0]) {
11057
+ return getTypeOfNode(symbol.declarations[0])
11058
+ }
11059
+ }
11060
+ }
11026
11061
return errorType;
11027
11062
}
11028
11063
@@ -30605,14 +30640,13 @@ namespace ts {
30605
30640
if (nodeLinks.tsPlusResolvedType) {
30606
30641
return nodeLinks.tsPlusResolvedType;
30607
30642
}
30608
- if (isClassCompanionReference (_left)) {
30609
- const staticExt = getStaticCompanionExtension(leftType, right.escapedText.toString());
30610
- if (staticExt ) {
30611
- nodeLinks.tsPlusStaticExtension = staticExt ;
30612
- nodeLinks.tsPlusResolvedType = staticExt .type
30613
- return staticExt .type;
30643
+ if (isCompanionReference (_left)) {
30644
+ const companionExt = getStaticCompanionExtension(leftType, right.escapedText.toString());
30645
+ if (companionExt ) {
30646
+ nodeLinks.tsPlusStaticExtension = companionExt ;
30647
+ nodeLinks.tsPlusResolvedType = companionExt .type
30648
+ return companionExt .type;
30614
30649
}
30615
- return;
30616
30650
}
30617
30651
const fluentExtType = getFluentExtension(leftType, right.escapedText.toString());
30618
30652
if (fluentExtType && isCallExpression(node.parent) && node.parent.expression === node) {
@@ -32881,37 +32915,32 @@ namespace ts {
32881
32915
32882
32916
// TSPLUS EXTENSION START
32883
32917
if (callSignatures.length === 0) {
32884
- if (isClassCompanionReference(node.expression)) {
32885
- const callExtension = getStaticCompanionExtension(apparentType, "__call");
32886
-
32887
- if (callExtension) {
32888
- callSignatures = Array.from(getSignaturesOfType(getTypeOfSymbol(callExtension.patched), SignatureKind.Call));
32889
- callCache.set(node.expression, callExtension);
32890
- getNodeLinks(node).tsPlusCallExtension = callExtension;
32891
- }
32918
+ let callExtension: TsPlusStaticFunctionExtension | undefined
32919
+ if (isCompanionReference(node.expression)) {
32920
+ callExtension = getStaticCompanionExtension(apparentType, "__call");
32921
+ }
32922
+ if (!callExtension) {
32923
+ callExtension = getStaticExtension(apparentType, "__call");
32924
+ }
32925
+ if (callExtension) {
32926
+ callSignatures = Array.from(getSignaturesOfType(getTypeOfSymbol(callExtension.patched), SignatureKind.Call));
32927
+ callCache.set(node.expression, callExtension);
32928
+ getNodeLinks(node).tsPlusCallExtension = callExtension;
32892
32929
}
32893
32930
else {
32894
- const callExtension = getStaticExtension(apparentType, "__call");
32895
-
32896
- if (callExtension) {
32897
- callSignatures = Array.from(getSignaturesOfType(getTypeOfSymbol(callExtension.patched), SignatureKind.Call));
32898
- callCache.set(node.expression, callExtension);
32899
- getNodeLinks(node).tsPlusCallExtension = callExtension;
32900
- } else {
32901
- const callFluentExtensions = getFluentExtension(apparentType, "__call");
32902
- if (callFluentExtensions) {
32903
- callSignatures = Array.from(getSignaturesOfType(callFluentExtensions, SignatureKind.Call).map((s) => {
32904
- const sig = createTsPlusSignature(
32905
- (s as TsPlusSignature).tsPlusOriginal,
32906
- (s as TsPlusSignature).tsPlusExportName,
32907
- (s as TsPlusSignature).tsPlusFile
32908
- );
32909
- sig.tsPlusDeclaration = (s as TsPlusSignature).tsPlusDeclaration;
32910
- sig.tsPlusPipeable = (s as TsPlusSignature).tsPlusPipeable;
32911
- return sig;
32912
- }));
32913
- getNodeLinks(node).isFluentCall = true;
32914
- }
32931
+ const callFluentExtensions = getFluentExtension(apparentType, "__call");
32932
+ if (callFluentExtensions) {
32933
+ callSignatures = Array.from(getSignaturesOfType(callFluentExtensions, SignatureKind.Call).map((s) => {
32934
+ const sig = createTsPlusSignature(
32935
+ (s as TsPlusSignature).tsPlusOriginal,
32936
+ (s as TsPlusSignature).tsPlusExportName,
32937
+ (s as TsPlusSignature).tsPlusFile
32938
+ );
32939
+ sig.tsPlusDeclaration = (s as TsPlusSignature).tsPlusDeclaration;
32940
+ sig.tsPlusPipeable = (s as TsPlusSignature).tsPlusPipeable;
32941
+ return sig;
32942
+ }));
32943
+ getNodeLinks(node).isFluentCall = true;
32915
32944
}
32916
32945
}
32917
32946
}
@@ -45185,6 +45214,21 @@ namespace ts {
45185
45214
symbols.set(id, symbol);
45186
45215
}
45187
45216
}
45217
+ if (companionSymbolCache.has(symbol)) {
45218
+ const id = symbol.escapedName;
45219
+ if (!symbols.has(id)) {
45220
+ symbols.set(id, symbol);
45221
+ }
45222
+ }
45223
+ if (symbol.declarations && symbol.declarations[0] && isImportSpecifier(symbol.declarations[0])) {
45224
+ const originalSymbol = getTargetOfImportSpecifier(symbol.declarations[0], false);
45225
+ if (originalSymbol && companionSymbolCache.has(originalSymbol)) {
45226
+ const id = symbol.escapedName;
45227
+ if (!symbols.has(id)) {
45228
+ symbols.set(id, symbol);
45229
+ }
45230
+ }
45231
+ }
45188
45232
}
45189
45233
45190
45234
function copySymbols(source: SymbolTable, meaning: SymbolFlags): void {
@@ -46764,7 +46808,7 @@ namespace ts {
46764
46808
return [];
46765
46809
}
46766
46810
function collectTsPlusCompanionTags(declaration: Declaration) {
46767
- if (isClassDeclaration(declaration)) {
46811
+ if (isClassDeclaration(declaration) || isInterfaceDeclaration(declaration) || isTypeAliasDeclaration(declaration) ) {
46768
46812
return declaration.tsPlusCompanionTags || [];
46769
46813
}
46770
46814
return [];
@@ -47368,15 +47412,21 @@ namespace ts {
47368
47412
function getTsPlusSourceFileCache(tag: string) {
47369
47413
return tsPlusFiles.has(tag) ? tsPlusFiles.get(tag)! : (tsPlusFiles.set(tag, new Set()), tsPlusFiles.get(tag)!);
47370
47414
}
47371
- function cacheTsPlusCompanion(declaration: ClassDeclaration): void {
47372
- const type = getTypeOfNode(declaration);
47415
+ function cacheTsPlusCompanion(declaration: ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration): void {
47373
47416
const tags = collectTsPlusCompanionTags(declaration);
47417
+ const type = getTypeOfNode(declaration)
47374
47418
if (type.symbol) {
47375
47419
for (const companionTag of tags) {
47376
47420
getTsPlusSourceFileCache(companionTag).add(getSourceFileOfNode(declaration));
47377
47421
addToCompanionSymbolCache(type.symbol, companionTag);
47378
47422
}
47379
47423
}
47424
+ if (type.aliasSymbol) {
47425
+ for (const companionTag of tags) {
47426
+ getTsPlusSourceFileCache(companionTag).add(getSourceFileOfNode(declaration));
47427
+ addToCompanionSymbolCache(type.aliasSymbol, companionTag);
47428
+ }
47429
+ }
47380
47430
}
47381
47431
function cacheTsPlusStaticVariable(file: SourceFile, declaration: VariableDeclarationWithIdentifier | ClassDeclarationWithIdentifier) {
47382
47432
const staticTags = collectTsPlusStaticTags(declaration);
0 commit comments