Skip to content

Commit 19a26f7

Browse files
committed
fixes
1 parent b5bd82e commit 19a26f7

File tree

4 files changed

+149
-48
lines changed

4 files changed

+149
-48
lines changed

src/compiler/checker.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,8 +2001,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20012001
getExtensionsForDeclaration: (node) => {
20022002
return collectTsPlusStaticTags(node)
20032003
.concat(collectTsPlusFluentTags(node))
2004+
.concat(collectTsPlusPipeableTags(node))
20042005
.concat(collectTsPlusGetterTags(node))
20052006
.concat(collectTsPlusOperatorTags(node))
2007+
.concat(collectTsPlusPipeableOperatorTags(node))
20062008
},
20072009
getTsPlusFiles: () => tsPlusFilesFinal,
20082010
getTsPlusGlobalImports: () => tsPlusGlobalImportCache,
@@ -4188,6 +4190,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
41884190
}
41894191
}
41904192
}
4193+
if (!result && originalLocation) {
4194+
const globalSymbol = getGlobalSymbol(name, SymbolFlags.Type, undefined);
4195+
if (globalSymbol && companionSymbolCache.has(globalSymbol)) {
4196+
result = globalSymbol;
4197+
getSymbolLinks(globalSymbol).isPossibleCompanionReference = true;
4198+
}
4199+
}
41914200
// TSPLUS EXTENSION END
41924201

41934202
// We just climbed up parents looking for the name, meaning that we started in a descendant node of `lastLocation`.
@@ -5571,7 +5580,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
55715580
if (!nodeIsSynthesized(name) && isEntityName(name) && (symbol.flags & SymbolFlags.Alias || name.parent.kind === SyntaxKind.ExportAssignment)) {
55725581
markSymbolOfAliasDeclarationIfTypeOnly(getAliasDeclarationFromName(name), symbol, /*finalTarget*/ undefined, /*overwriteEmpty*/ true);
55735582
}
5574-
return (symbol.flags & meaning) || dontResolveAlias ? symbol : resolveAlias(symbol);
5583+
return (symbol.flags & meaning) || dontResolveAlias ||
5584+
// TSPLUS EXTENSION BEGIN
5585+
getSymbolLinks(symbol).isPossibleCompanionReference
5586+
// TSPLUS EXTENSION END
5587+
? symbol
5588+
: resolveAlias(symbol);
55755589
}
55765590

55775591
/**
@@ -31931,6 +31945,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3193131945
nodeLinks.tsPlusResolvedType = companionExt.type
3193231946
return companionExt.type;
3193331947
}
31948+
return;
3193431949
}
3193531950
const fluentExtType = getFluentExtension(leftType, right.escapedText.toString());
3193631951
if (fluentExtType && isCallExpression(node.parent) && node.parent.expression === node) {
@@ -48370,11 +48385,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4837048385
returnStatement.expression.type,
4837148386
undefined
4837248387
);
48388+
4837348389
newDecl.jsDoc = pipeable.jsDoc;
4837448390
newDecl.jsDocCache = pipeable.jsDocCache;
4837548391
newDecl.symbol = createTsPlusPipeableDeclarationSymbol(name, pipeable);
48392+
setParent(newDecl, pipeable.parent);
48393+
setOriginalNode(newDecl, pipeable)
48394+
4837648395
newSig.declaration = newDecl;
4837748396
newSig.tsPlusDeclaration = pipeable;
48397+
4837848398
if (thisify) {
4837948399
const thisified = thisifyTsPlusSignature(pipeable, newSig, exportName, file, reportDiagnostic);
4838048400
if (!thisified) {
@@ -48414,11 +48434,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4841448434
rsig.declaration?.type as TypeNode,
4841548435
undefined
4841648436
);
48437+
4841748438
newDecl.jsDoc = pipeable.jsDoc;
4841848439
newDecl.jsDocCache = pipeable.jsDocCache;
4841948440
newDecl.symbol = createTsPlusPipeableDeclarationSymbol(name, pipeable);
48441+
setParent(newDecl, pipeable.parent);
48442+
setOriginalNode(newDecl, pipeable);
48443+
4842048444
newSig.declaration = newDecl;
4842148445
newSig.tsPlusDeclaration = pipeable;
48446+
4842248447
if (thisify) {
4842348448
const thisifiedSignature = thisifyTsPlusSignature(pipeable, newSig, exportName, file, reportDiagnostic);
4842448449
if (!thisifiedSignature) {
@@ -48507,11 +48532,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4850748532
factory.createBlock([])
4850848533
);
4850948534
}
48535+
4851048536
newDecl.jsDoc = pipeable.jsDoc;
4851148537
newDecl.jsDocCache = pipeable.jsDocCache;
4851248538
newDecl.symbol = createTsPlusPipeableDeclarationSymbol(name, pipeable);
48539+
setParent(newDecl, pipeable.parent);
48540+
setOriginalNode(newDecl, pipeable);
48541+
4851348542
newSig.declaration = newDecl;
4851448543
newSig.tsPlusDeclaration = pipeable;
48544+
4851548545
if (thisify) {
4851648546
const thisifiedSignature = thisifyTsPlusSignature(pipeable, newSig, exportName, file, reportDiagnostic);
4851748547
if (!thisifiedSignature) {
@@ -48553,11 +48583,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4855348583
factory.createNodeArray([...returnFn.parameters, ...(sig.declaration?.parameters as NodeArray<ParameterDeclaration> ?? [])]),
4855448584
returnFn.type
4855548585
);
48556-
newDecl.jsDoc = pipeable.jsDoc;
48557-
newDecl.jsDocCache = pipeable.jsDocCache;
48586+
48587+
newDecl.jsDoc = pipeable.parent.parent.jsDoc;
48588+
newDecl.jsDocCache = pipeable.parent.parent.jsDocCache;
4855848589
newDecl.symbol = createTsPlusPipeableDeclarationSymbol(name, pipeable);
48590+
setParent(newDecl, pipeable.parent);
48591+
setOriginalNode(newDecl, pipeable);
48592+
4855948593
newSig.declaration = newDecl;
4856048594
newSig.tsPlusDeclaration = pipeable;
48595+
4856148596
if (thisify) {
4856248597
const thisifiedSignature = thisifyTsPlusSignature(pipeable, newSig, exportName, file, reportDiagnostic);
4856348598
if (!thisifiedSignature) {

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3201,7 +3201,7 @@ function parseConfig(
32013201
basePath: string,
32023202
configFileName: string | undefined,
32033203
resolutionStack: string[],
3204-
errors: Push<Diagnostic>,
3204+
errors: Diagnostic[],
32053205
extendedConfigCache?: Map<string, ExtendedConfigCacheEntry>
32063206
): ParsedTsconfig {
32073207
const config = parseConfigOriginal(

src/compiler/parser.ts

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,9 @@ namespace Parser {
15831583
// attached to the EOF token.
15841584
let parseErrorBeforeNextFinishedNode = false;
15851585

1586+
const tsPlusExternalTypeCache = new Map<string, Record<string, TsPlusTypeDefinition[]>>()
1587+
const tsPlusResolvedPathsCache = new Map<string, string[]>()
1588+
const tsPlusResolvedModuleCache = new Map<string, any>()
15861589
let currentTsPlusTypes: TsPlusTypeDefinition[] | null = null;
15871590
let currentTsPlusFile: string | null = null;
15881591

@@ -1821,16 +1824,20 @@ namespace Parser {
18211824
}
18221825
}
18231826

1824-
function parseTsPlusExternalTypes(fileName: string, options: CompilerOptions) {
1827+
function getTsPlusExternalTypesPaths(fileName: string, options: CompilerOptions) {
18251828
if (options.configFilePath) {
1829+
if (tsPlusResolvedPathsCache.has(options.configFilePath)) {
1830+
return tsPlusResolvedPathsCache.get(options.configFilePath)!;
1831+
}
1832+
18261833
let resolvedPaths: string[] = [];
18271834
if (options.tsPlusTypes) {
18281835
for (const path of options.tsPlusTypes) {
18291836
if (pathIsRelative(path)) {
18301837
resolvedPaths.push(resolvePath(options.configFilePath.split("/").slice(0, -1).join('/'), path));
18311838
}
18321839
else {
1833-
const { resolvedModule } = resolveModuleName(path, options.configFilePath, options, sys);
1840+
const resolvedModule = resolveModuleName(path, options.configFilePath, options, sys).resolvedModule ?? resolveModuleName(path, fileName, options, sys).resolvedModule;
18341841
if (resolvedModule) {
18351842
resolvedPaths.push(resolvedModule.resolvedFileName);
18361843
break
@@ -1872,22 +1879,37 @@ namespace Parser {
18721879
}
18731880
}
18741881

1875-
if (resolvedPaths.length === 0) {
1876-
return;
1877-
}
1882+
tsPlusResolvedPathsCache.set(options.configFilePath, resolvedPaths);
1883+
return resolvedPaths;
1884+
}
1885+
return [];
1886+
}
18781887

1879-
for (const resolvedPath of resolvedPaths) {
1888+
function parseTsPlusExternalTypes(fileName: string, options: CompilerOptions) {
1889+
const resolvedPaths = getTsPlusExternalTypesPaths(fileName, options);
1890+
if (!resolvedPaths || resolvedPaths.length === 0) {
1891+
return
1892+
}
1893+
for (const resolvedPath of resolvedPaths) {
1894+
let json = tsPlusExternalTypeCache.get(resolvedPath);
1895+
if (!json) {
18801896
const text = sys.readFile(resolvedPath);
18811897
if (text) {
1882-
const json = JSON.parse(text);
1883-
for (const moduleName in json) {
1884-
const { resolvedModule } = resolveModuleName(moduleName, resolvedPath, options, sys);
1885-
if (resolvedModule && resolvedModule.resolvedFileName === fileName) {
1886-
currentTsPlusTypes = json[moduleName];
1887-
currentTsPlusFile = moduleName;
1888-
return;
1889-
}
1890-
}
1898+
json = JSON.parse(text);
1899+
}
1900+
}
1901+
if (!json) return;
1902+
for (const moduleName in json) {
1903+
const key = `${options.configFilePath ?? fileName}+${moduleName}`;
1904+
let resolvedModule = tsPlusResolvedModuleCache.get(key);
1905+
if (!resolvedModule) {
1906+
resolvedModule = resolveModuleName(moduleName, resolvedPath, options, sys).resolvedModule ?? resolveModuleName(moduleName, fileName, options, sys).resolvedModule;
1907+
tsPlusResolvedModuleCache.set(key, resolvedModule);
1908+
}
1909+
if (resolvedModule && resolvedModule.resolvedFileName === fileName) {
1910+
currentTsPlusTypes = json[moduleName];
1911+
currentTsPlusFile = moduleName;
1912+
return;
18911913
}
18921914
}
18931915
}
@@ -1896,6 +1918,15 @@ namespace Parser {
18961918
function addTsPlusTagsFromExternalTypes(declaration: VariableDeclaration | FunctionDeclaration | InterfaceDeclaration | ClassDeclaration | TypeAliasDeclaration, jsDocNode?: HasJSDoc): void {
18971919
if (currentTsPlusTypes !== null) {
18981920
if (declaration.name && declaration.name.kind === SyntaxKind.Identifier) {
1921+
if (!jsDocNode) {
1922+
jsDocNode = declaration;
1923+
}
1924+
if (jsDocNode.jsDoc &&
1925+
jsDocNode.jsDoc[0] &&
1926+
jsDocNode.jsDoc[0].tags &&
1927+
jsDocNode.jsDoc[0].tags.find((tag) => tag.tagName.escapedText === 'tsplus')) {
1928+
return;
1929+
}
18991930
const extensions = currentTsPlusTypes.filter(
19001931
(type) =>
19011932
(declaration.kind === SyntaxKind.VariableDeclaration ? (type.definitionKind === "const")
@@ -1916,15 +1947,15 @@ namespace Parser {
19161947
newTags.push(factory.createJSDocUnknownTag(factory.createIdentifier("tsplus"), comment));
19171948
}
19181949
newTags.push(factory.createJSDocUnknownTag(factory.createIdentifier("tsplus"), `location "${currentTsPlusFile}"`))
1919-
if (!jsDocNode) {
1920-
jsDocNode = declaration;
1921-
}
19221950
if (jsDocNode.jsDoc && jsDocNode.jsDoc[0]) {
1923-
const jsDocTags = factory.createNodeArray(Array.from(jsDocNode.jsDoc[0].tags ?? []).concat(newTags))
1951+
const jsDocTags = Array.from(jsDocNode.jsDoc[0].tags ?? []).concat(newTags);
19241952
// @ts-expect-error
1925-
jsDocNode.jsDoc[0].tags = jsDocTags;
1926-
} else {
1927-
jsDocNode.jsDoc = [factory.createJSDocComment(undefined, newTags)]
1953+
jsDocNode.jsDoc[0].tags = factory.createNodeArray(jsDocTags);
1954+
jsDocNode.jsDocCache = jsDocTags;
1955+
}
1956+
else {
1957+
jsDocNode.jsDoc = [factory.createJSDocComment(undefined, newTags)];
1958+
jsDocNode.jsDocCache = newTags;
19281959
}
19291960
}
19301961
}
@@ -7797,8 +7828,6 @@ namespace Parser {
77977828
const pipeableIndexTags: string[] = [];
77987829
let isImplicit = false;
77997830

7800-
addTsPlusTagsFromExternalTypes(declaration)
7801-
78027831
for (const doc of jsDoc ?? []) {
78037832
if (doc.tags) {
78047833
for (const tag of doc.tags) {
@@ -7940,6 +7969,7 @@ namespace Parser {
79407969
const node = factory.createFunctionDeclaration(modifiers, asteriskToken, name, typeParameters, parameters, type, body);
79417970
(node as Mutable<FunctionDeclaration>).illegalDecorators = decorators;
79427971
const finished = withJSDoc(finishNode(node, pos), hasJSDoc);
7972+
addTsPlusTagsFromExternalTypes(finished);
79437973
addTsPlusValueTags(finished, finished.jsDoc);
79447974
return finished;
79457975
}

0 commit comments

Comments
 (0)