From 7e1711dfb6759b6773abe2bcf6e956aac5399523 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 6 Jul 2018 08:52:36 -0700 Subject: [PATCH] Update LKG --- lib/protocol.d.ts | 6 + lib/tsc.js | 126 +++-- lib/tsserver.js | 988 ++++++++++++++++++++---------------- lib/tsserverlibrary.d.ts | 72 ++- lib/typescript.d.ts | 8 +- lib/typescript.js | 477 +++++++++-------- lib/typescriptServices.d.ts | 8 +- lib/typescriptServices.js | 477 +++++++++-------- lib/typingsInstaller.js | 166 +++--- 9 files changed, 1322 insertions(+), 1006 deletions(-) diff --git a/lib/protocol.d.ts b/lib/protocol.d.ts index 1500a9b5987..06275ccf8b6 100644 --- a/lib/protocol.d.ts +++ b/lib/protocol.d.ts @@ -591,6 +591,12 @@ declare namespace ts.server.protocol { interface DefinitionRequest extends FileLocationRequest { command: CommandTypes.Definition; } + interface DefinitionAndBoundSpanRequest extends FileLocationRequest { + readonly command: CommandTypes.DefinitionAndBoundSpan; + } + interface DefinitionAndBoundSpanResponse extends Response { + readonly body: DefinitionInfoAndBoundSpan; + } /** * Go to type request; value of command field is * "typeDefinition". Return response giving the file locations that diff --git a/lib/tsc.js b/lib/tsc.js index e3884ccf3bd..60678c24ccd 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -17529,6 +17529,7 @@ var ts; function isDeclarationFileName(fileName) { return ts.fileExtensionIs(fileName, ".d.ts"); } + ts.isDeclarationFileName = isDeclarationFileName; function processCommentPragmas(context, sourceText) { var triviaScanner = ts.createScanner(context.languageVersion, false, 0, sourceText); var pragmas = []; @@ -25567,17 +25568,25 @@ var ts; function getParentOfSymbol(symbol) { return getMergedSymbol(symbol.parent && getLateBoundSymbol(symbol.parent)); } - function getContainerOfSymbol(symbol) { + function getContainersOfSymbol(symbol, enclosingDeclaration) { var container = getParentOfSymbol(symbol); if (container) { - return container; + var additionalContainers = ts.mapDefined(container.declarations, fileSymbolIfFileSymbolExportEqualsContainer); + if (enclosingDeclaration && getAccessibleSymbolChain(container, enclosingDeclaration, 1920, false)) { + return ts.concatenate([container], additionalContainers); + } + return ts.append(additionalContainers, container); } - var candidate = ts.forEach(symbol.declarations, function (d) { return !ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined; }); - if (!candidate) { + var candidates = ts.mapDefined(symbol.declarations, function (d) { return !ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined; }); + if (!ts.length(candidates)) { return undefined; } - var alias = getAliasForSymbolInContainer(candidate, symbol); - return alias ? candidate : undefined; + return ts.mapDefined(candidates, function (candidate) { return getAliasForSymbolInContainer(candidate, symbol) ? candidate : undefined; }); + function fileSymbolIfFileSymbolExportEqualsContainer(d) { + var fileSymbol = getExternalModuleContainer(d); + var exported = fileSymbol && fileSymbol.exports && fileSymbol.exports.get("export="); + return resolveSymbol(exported) === resolveSymbol(container) ? fileSymbol : undefined; + } } function getAliasForSymbolInContainer(container, symbol) { if (container === getParentOfSymbol(symbol)) { @@ -25801,54 +25810,67 @@ var ts; var access = isSymbolAccessible(typeSymbol, enclosingDeclaration, 67216319, false); return access.accessibility === 0; } - function isSymbolAccessible(symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible) { - if (symbol && enclosingDeclaration) { - var initialSymbol = symbol; - var meaningToLook = meaning; - while (symbol) { - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, false); - if (accessibleSymbolChain) { - var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible); - if (!hasAccessibleDeclarations) { - return { - accessibility: 1, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), - errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, 1920) : undefined, - }; - } + function isAnySymbolAccessible(symbols, enclosingDeclaration, initialSymbol, meaning, shouldComputeAliasesToMakeVisible) { + if (!ts.length(symbols)) + return; + var hadAccessibleChain; + for (var _i = 0, _a = symbols; _i < _a.length; _i++) { + var symbol = _a[_i]; + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, false); + if (accessibleSymbolChain) { + hadAccessibleChain = symbol; + var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible); + if (hasAccessibleDeclarations) { return hasAccessibleDeclarations; } - else { - if (ts.some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { - return { - accessibility: 0 - }; - } - } - meaningToLook = getQualifiedLeftMeaning(meaning); - symbol = getContainerOfSymbol(symbol); } - var symbolExternalModule = ts.forEach(initialSymbol.declarations, getExternalModuleContainer); + else { + if (ts.some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + return { + accessibility: 0 + }; + } + } + var parentResult = isAnySymbolAccessible(getContainersOfSymbol(symbol, enclosingDeclaration), enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible); + if (parentResult) { + return parentResult; + } + } + if (hadAccessibleChain) { + return { + accessibility: 1, + errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorModuleName: hadAccessibleChain !== initialSymbol ? symbolToString(hadAccessibleChain, enclosingDeclaration, 1920) : undefined, + }; + } + } + function isSymbolAccessible(symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible) { + if (symbol && enclosingDeclaration) { + var result = isAnySymbolAccessible([symbol], enclosingDeclaration, symbol, meaning, shouldComputeAliasesToMakeVisible); + if (result) { + return result; + } + var symbolExternalModule = ts.forEach(symbol.declarations, getExternalModuleContainer); if (symbolExternalModule) { var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration); if (symbolExternalModule !== enclosingExternalModule) { return { accessibility: 2, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), errorModuleName: symbolToString(symbolExternalModule) }; } } return { accessibility: 1, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), }; } return { accessibility: 0 }; - function getExternalModuleContainer(declaration) { - var node = ts.findAncestor(declaration, hasExternalModuleSymbol); - return node && getSymbolOfNode(node); - } + } + function getExternalModuleContainer(declaration) { + var node = ts.findAncestor(declaration, hasExternalModuleSymbol); + return node && getSymbolOfNode(node); } function hasExternalModuleSymbol(declaration) { return ts.isAmbientModule(declaration) || (declaration.kind === 277 && ts.isExternalOrCommonJsModule(declaration)); @@ -26580,15 +26602,17 @@ var ts; return chain; function getSymbolChain(symbol, meaning, endOfChain) { var accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, !!(context.flags & 128)); - var parentSymbol; if (!accessibleSymbolChain || needsQualification(accessibleSymbolChain[0], context.enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { - var parent = getContainerOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol); - if (parent) { - var parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), false); - if (parentChain) { - parentSymbol = parent; - accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); + var parents = getContainersOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol, context.enclosingDeclaration); + if (ts.length(parents)) { + for (var _i = 0, _a = parents; _i < _a.length; _i++) { + var parent = _a[_i]; + var parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), false); + if (parentChain) { + accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); + break; + } } } } @@ -26596,8 +26620,10 @@ var ts; return accessibleSymbolChain; } if (endOfChain || - (yieldModuleSymbol || !(!parentSymbol && ts.forEach(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol))) && - !(symbol.flags & (2048 | 4096))) { + !(symbol.flags & (2048 | 4096))) { + if (!endOfChain && !yieldModuleSymbol && !!ts.forEach(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + return; + } return [symbol]; } } @@ -27046,7 +27072,7 @@ var ts; return !!target.resolvedReturnType; } if (propertyName === 4) { - var bc = target.resolvedBaseConstraint; + var bc = target.immediateBaseConstraint; return !!bc && bc !== circularConstraintType; } return ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); @@ -29137,15 +29163,21 @@ var ts; } return type.resolvedBaseConstraint; function getBaseConstraint(t) { + if (t.immediateBaseConstraint) { + return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint; + } if (!pushTypeResolution(t, 4)) { circular = true; + t.immediateBaseConstraint = circularConstraintType; return undefined; } var result = computeBaseConstraint(getSimplifiedType(t)); if (!popTypeResolution()) { circular = true; + t.immediateBaseConstraint = circularConstraintType; return undefined; } + t.immediateBaseConstraint = !result ? noConstraintType : result; return result; } function computeBaseConstraint(t) { diff --git a/lib/tsserver.js b/lib/tsserver.js index 7dbe902b21a..c5330b82c2d 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -21885,9 +21885,11 @@ var ts; InvalidPosition[InvalidPosition["Value"] = -1] = "Value"; })(InvalidPosition || (InvalidPosition = {})); })(IncrementalParser || (IncrementalParser = {})); + /** @internal */ function isDeclarationFileName(fileName) { return ts.fileExtensionIs(fileName, ".d.ts" /* Dts */); } + ts.isDeclarationFileName = isDeclarationFileName; /*@internal*/ function processCommentPragmas(context, sourceText) { var triviaScanner = ts.createScanner(context.languageVersion, /*skipTrivia*/ false, 0 /* Standard */, sourceText); @@ -29659,7 +29661,7 @@ var ts; TypeSystemPropertyName[TypeSystemPropertyName["ResolvedBaseConstructorType"] = 1] = "ResolvedBaseConstructorType"; TypeSystemPropertyName[TypeSystemPropertyName["DeclaredType"] = 2] = "DeclaredType"; TypeSystemPropertyName[TypeSystemPropertyName["ResolvedReturnType"] = 3] = "ResolvedReturnType"; - TypeSystemPropertyName[TypeSystemPropertyName["ResolvedBaseConstraint"] = 4] = "ResolvedBaseConstraint"; + TypeSystemPropertyName[TypeSystemPropertyName["ImmediateBaseConstraint"] = 4] = "ImmediateBaseConstraint"; })(TypeSystemPropertyName || (TypeSystemPropertyName = {})); var CheckMode; (function (CheckMode) { @@ -31366,17 +31368,25 @@ var ts; * Attempts to find the symbol corresponding to the container a symbol is in - usually this * is just its' `.parent`, but for locals, this value is `undefined` */ - function getContainerOfSymbol(symbol) { + function getContainersOfSymbol(symbol, enclosingDeclaration) { var container = getParentOfSymbol(symbol); if (container) { - return container; + var additionalContainers = ts.mapDefined(container.declarations, fileSymbolIfFileSymbolExportEqualsContainer); + if (enclosingDeclaration && getAccessibleSymbolChain(container, enclosingDeclaration, 1920 /* Namespace */, /*externalOnly*/ false)) { + return ts.concatenate([container], additionalContainers); // This order expresses a preference for the real container if it is in scope + } + return ts.append(additionalContainers, container); } - var candidate = ts.forEach(symbol.declarations, function (d) { return !ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined; }); - if (!candidate) { + var candidates = ts.mapDefined(symbol.declarations, function (d) { return !ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined; }); + if (!ts.length(candidates)) { return undefined; } - var alias = getAliasForSymbolInContainer(candidate, symbol); - return alias ? candidate : undefined; + return ts.mapDefined(candidates, function (candidate) { return getAliasForSymbolInContainer(candidate, symbol) ? candidate : undefined; }); + function fileSymbolIfFileSymbolExportEqualsContainer(d) { + var fileSymbol = getExternalModuleContainer(d); + var exported = fileSymbol && fileSymbol.exports && fileSymbol.exports.get("export=" /* ExportEquals */); + return resolveSymbol(exported) === resolveSymbol(container) ? fileSymbol : undefined; + } } function getAliasForSymbolInContainer(container, symbol) { if (container === getParentOfSymbol(symbol)) { @@ -31627,6 +31637,54 @@ var ts; var access = isSymbolAccessible(typeSymbol, enclosingDeclaration, 67216319 /* Value */, /*shouldComputeAliasesToMakeVisible*/ false); return access.accessibility === 0 /* Accessible */; } + function isAnySymbolAccessible(symbols, enclosingDeclaration, initialSymbol, meaning, shouldComputeAliasesToMakeVisible) { + if (!ts.length(symbols)) + return; + var hadAccessibleChain; + for (var _i = 0, _a = symbols; _i < _a.length; _i++) { + var symbol = _a[_i]; + // Symbol is accessible if it by itself is accessible + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, /*useOnlyExternalAliasing*/ false); + if (accessibleSymbolChain) { + hadAccessibleChain = symbol; + var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible); + if (hasAccessibleDeclarations) { + return hasAccessibleDeclarations; + } + } + else { + if (ts.some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + // Any meaning of a module symbol is always accessible via an `import` type + return { + accessibility: 0 /* Accessible */ + }; + } + } + // If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible. + // It could be a qualified symbol and hence verify the path + // e.g.: + // module m { + // export class c { + // } + // } + // const x: typeof m.c + // In the above example when we start with checking if typeof m.c symbol is accessible, + // we are going to see if c can be accessed in scope directly. + // But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible + // It is accessible if the parent m is accessible because then m.c can be accessed through qualification + var parentResult = isAnySymbolAccessible(getContainersOfSymbol(symbol, enclosingDeclaration), enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible); + if (parentResult) { + return parentResult; + } + } + if (hadAccessibleChain) { + return { + accessibility: 1 /* NotAccessible */, + errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorModuleName: hadAccessibleChain !== initialSymbol ? symbolToString(hadAccessibleChain, enclosingDeclaration, 1920 /* Namespace */) : undefined, + }; + } + } /** * Check if the given symbol in given enclosing declaration is accessible and mark all associated alias to be visible if requested * @@ -31637,55 +31695,20 @@ var ts; */ function isSymbolAccessible(symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible) { if (symbol && enclosingDeclaration) { - var initialSymbol = symbol; - var meaningToLook = meaning; - while (symbol) { - // Symbol is accessible if it by itself is accessible - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false); - if (accessibleSymbolChain) { - var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible); - if (!hasAccessibleDeclarations) { - return { - accessibility: 1 /* NotAccessible */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), - errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, 1920 /* Namespace */) : undefined, - }; - } - return hasAccessibleDeclarations; - } - else { - if (ts.some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { - // Any meaning of a module symbol is always accessible via an `import` type - return { - accessibility: 0 /* Accessible */ - }; - } - } - // If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible. - // It could be a qualified symbol and hence verify the path - // e.g.: - // module m { - // export class c { - // } - // } - // const x: typeof m.c - // In the above example when we start with checking if typeof m.c symbol is accessible, - // we are going to see if c can be accessed in scope directly. - // But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible - // It is accessible if the parent m is accessible because then m.c can be accessed through qualification - meaningToLook = getQualifiedLeftMeaning(meaning); - symbol = getContainerOfSymbol(symbol); + var result = isAnySymbolAccessible([symbol], enclosingDeclaration, symbol, meaning, shouldComputeAliasesToMakeVisible); + if (result) { + return result; } // This could be a symbol that is not exported in the external module // or it could be a symbol from different external module that is not aliased and hence cannot be named - var symbolExternalModule = ts.forEach(initialSymbol.declarations, getExternalModuleContainer); + var symbolExternalModule = ts.forEach(symbol.declarations, getExternalModuleContainer); if (symbolExternalModule) { var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration); if (symbolExternalModule !== enclosingExternalModule) { // name from different external module that is not visible return { accessibility: 2 /* CannotBeNamed */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), errorModuleName: symbolToString(symbolExternalModule) }; } @@ -31693,14 +31716,14 @@ var ts; // Just a local name that is not accessible return { accessibility: 1 /* NotAccessible */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), }; } return { accessibility: 0 /* Accessible */ }; - function getExternalModuleContainer(declaration) { - var node = ts.findAncestor(declaration, hasExternalModuleSymbol); - return node && getSymbolOfNode(node); - } + } + function getExternalModuleContainer(declaration) { + var node = ts.findAncestor(declaration, hasExternalModuleSymbol); + return node && getSymbolOfNode(node); } function hasExternalModuleSymbol(declaration) { return ts.isAmbientModule(declaration) || (declaration.kind === 277 /* SourceFile */ && ts.isExternalOrCommonJsModule(declaration)); @@ -32477,16 +32500,18 @@ var ts; /** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */ function getSymbolChain(symbol, meaning, endOfChain) { var accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, !!(context.flags & 128 /* UseOnlyExternalAliasing */)); - var parentSymbol; if (!accessibleSymbolChain || needsQualification(accessibleSymbolChain[0], context.enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { // Go up and add our parent. - var parent = getContainerOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol); - if (parent) { - var parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); - if (parentChain) { - parentSymbol = parent; - accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); + var parents = getContainersOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol, context.enclosingDeclaration); + if (ts.length(parents)) { + for (var _i = 0, _a = parents; _i < _a.length; _i++) { + var parent = _a[_i]; + var parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); + if (parentChain) { + accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); + break; + } } } } @@ -32496,10 +32521,12 @@ var ts; if ( // If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols. endOfChain || + // If a parent symbol is an anonymous type, don't write it. + !(symbol.flags & (2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */))) { // If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.) - (yieldModuleSymbol || !(!parentSymbol && ts.forEach(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol))) && - // If a parent symbol is an anonymous type, don't write it. - !(symbol.flags & (2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */))) { + if (!endOfChain && !yieldModuleSymbol && !!ts.forEach(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + return; + } return [symbol]; } } @@ -32993,8 +33020,8 @@ var ts; if (propertyName === 3 /* ResolvedReturnType */) { return !!target.resolvedReturnType; } - if (propertyName === 4 /* ResolvedBaseConstraint */) { - var bc = target.resolvedBaseConstraint; + if (propertyName === 4 /* ImmediateBaseConstraint */) { + var bc = target.immediateBaseConstraint; return !!bc && bc !== circularConstraintType; } return ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); @@ -35427,15 +35454,21 @@ var ts; } return type.resolvedBaseConstraint; function getBaseConstraint(t) { - if (!pushTypeResolution(t, 4 /* ResolvedBaseConstraint */)) { + if (t.immediateBaseConstraint) { + return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint; + } + if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { circular = true; + t.immediateBaseConstraint = circularConstraintType; return undefined; } var result = computeBaseConstraint(getSimplifiedType(t)); if (!popTypeResolution()) { circular = true; + t.immediateBaseConstraint = circularConstraintType; return undefined; } + t.immediateBaseConstraint = !result ? noConstraintType : result; return result; } function computeBaseConstraint(t) { @@ -84151,7 +84184,8 @@ var ts; } ts.parseConfigHostFromCompilerHost = parseConfigHostFromCompilerHost; /** - * Returns the target config filename of a project reference + * Returns the target config filename of a project reference. + * Note: The file might not exist. */ function resolveProjectReferencePath(host, ref) { if (!host.fileExists(ref.path)) { @@ -89093,6 +89127,14 @@ var ts; } } ts.insertImport = insertImport; + function textSpansEqual(a, b) { + return !!a && !!b && a.start === b.start && a.length === b.length; + } + ts.textSpansEqual = textSpansEqual; + function documentSpansEqual(a, b) { + return a.fileName === b.fileName && textSpansEqual(a.textSpan, b.textSpan); + } + ts.documentSpansEqual = documentSpansEqual; })(ts || (ts = {})); // Display-part writer helpers /* @internal */ @@ -95741,48 +95783,83 @@ var ts; var JsDoc; (function (JsDoc) { var jsDocTagNames = [ + "abstract", + "access", + "alias", + "argument", + "async", "augments", "author", - "argument", "borrows", "callback", "class", + "classDesc", "constant", "constructor", "constructs", + "copyright", "default", "deprecated", "description", + "emits", + "enum", "event", "example", + "exports", "extends", + "external", "field", + "file", "fileOverview", + "fires", "function", + "generator", + "global", + "hideConstructor", + "host", "ignore", + "implements", "inheritDoc", "inner", + "instance", + "interface", + "kind", "lends", - "link", + "license", + "listens", + "member", "memberOf", "method", + "mixes", + "module", "name", "namespace", + "override", + "package", "param", "private", - "prop", "property", + "protected", "public", + "readonly", "requires", "returns", "see", "since", "static", + "summary", "template", + "this", "throws", + "todo", + "tutorial", "type", "typedef", - "version" + "var", + "variation", + "version", + "virtual", + "yields" ]; var jsDocTagNameCompletionEntries; var jsDocTagCompletionEntries; @@ -96104,7 +96181,7 @@ var ts; var rawItems = []; var _loop_4 = function (sourceFile) { cancellationToken.throwIfCancellationRequested(); - if (excludeDtsFiles && ts.fileExtensionIs(sourceFile.fileName, ".d.ts" /* Dts */)) { + if (excludeDtsFiles && sourceFile.isDeclarationFile) { return "continue"; } sourceFile.getNamedDeclarations().forEach(function (declarations, name) { @@ -98662,6 +98739,106 @@ var ts; })(ts || (ts = {})); /* @internal */ var ts; +(function (ts) { + // Sometimes tools can sometimes see the following line as a source mapping url comment, so we mangle it a bit (the [M]) + var sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)\s*$/; + var whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/; + var base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/; + function getSourceMapper(getCanonicalFileName, currentDirectory, log, host, getProgram) { + var sourcemappedFileCache; + return { tryGetOriginalLocation: tryGetOriginalLocation, toLineColumnOffset: toLineColumnOffset, clearCache: clearCache }; + function scanForSourcemapURL(fileName) { + var mappedFile = sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); + if (!mappedFile) { + return; + } + var starts = ts.getLineStarts(mappedFile); + for (var index = starts.length - 1; index >= 0; index--) { + var lineText = mappedFile.text.substring(starts[index], starts[index + 1]); + var comment = sourceMapCommentRegExp.exec(lineText); + if (comment) { + return comment[1]; + } + // If we see a non-whitespace/map comment-like line, break, to avoid scanning up the entire file + else if (!lineText.match(whitespaceOrMapCommentRegExp)) { + break; + } + } + } + function convertDocumentToSourceMapper(file, contents, mapFileName) { + var maps; + try { + maps = JSON.parse(contents); + } + catch (_a) { + // swallow error + } + if (!maps || !maps.sources || !maps.file || !maps.mappings) { + // obviously invalid map + return file.sourceMapper = ts.sourcemaps.identitySourceMapper; + } + return file.sourceMapper = ts.sourcemaps.decode({ + readFile: function (s) { return host.readFile(s); }, + fileExists: function (s) { return host.fileExists(s); }, + getCanonicalFileName: getCanonicalFileName, + log: log, + }, mapFileName, maps, getProgram(), sourcemappedFileCache); + } + function getSourceMapper(fileName, file) { + if (!host.readFile || !host.fileExists) { + return file.sourceMapper = ts.sourcemaps.identitySourceMapper; + } + if (file.sourceMapper) { + return file.sourceMapper; + } + var mapFileName = scanForSourcemapURL(fileName); + if (mapFileName) { + var match = base64UrlRegExp.exec(mapFileName); + if (match) { + if (match[1]) { + var base64Object = match[1]; + return convertDocumentToSourceMapper(file, ts.base64decode(ts.sys, base64Object), fileName); + } + // Not a data URL we can parse, skip it + mapFileName = undefined; + } + } + var possibleMapLocations = []; + if (mapFileName) { + possibleMapLocations.push(mapFileName); + } + possibleMapLocations.push(fileName + ".map"); + for (var _i = 0, possibleMapLocations_1 = possibleMapLocations; _i < possibleMapLocations_1.length; _i++) { + var location = possibleMapLocations_1[_i]; + var mapPath = ts.toPath(location, ts.getDirectoryPath(fileName), getCanonicalFileName); + if (host.fileExists(mapPath)) { + return convertDocumentToSourceMapper(file, host.readFile(mapPath), mapPath); // TODO: GH#18217 + } + } + return file.sourceMapper = ts.sourcemaps.identitySourceMapper; + } + function tryGetOriginalLocation(info) { + if (!ts.isDeclarationFileName(info.fileName)) + return undefined; + var file = getProgram().getSourceFile(info.fileName) || sourcemappedFileCache.get(ts.toPath(info.fileName, currentDirectory, getCanonicalFileName)); + if (!file) + return undefined; + var newLoc = getSourceMapper(info.fileName, file).getOriginalPosition(info); + return newLoc === info ? undefined : tryGetOriginalLocation(newLoc) || newLoc; + } + function toLineColumnOffset(fileName, position) { + var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); + var file = getProgram().getSourceFile(path) || sourcemappedFileCache.get(path); // TODO: GH#18217 + return file.getLineAndCharacterOfPosition(position); + } + function clearCache() { + sourcemappedFileCache = ts.createSourceFileLikeCache(host); + } + } + ts.getSourceMapper = getSourceMapper; +})(ts || (ts = {})); +/* @internal */ +var ts; (function (ts) { function computeSuggestionDiagnostics(sourceFile, program, cancellationToken) { program.getSemanticDiagnostics(sourceFile, cancellationToken); @@ -110501,7 +110678,6 @@ var ts; if (!ts.localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) { ts.localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages(); } - var sourcemappedFileCache; function log(message) { if (host.log) { host.log(message); @@ -110509,6 +110685,7 @@ var ts; } var useCaseSensitiveFileNames = ts.hostUsesCaseSensitiveFileNames(host); var getCanonicalFileName = ts.createGetCanonicalFileName(useCaseSensitiveFileNames); + var sourceMapper = ts.getSourceMapper(getCanonicalFileName, currentDirectory, log, host, function () { return program; }); function getValidSourceFile(fileName) { var sourceFile = program.getSourceFile(fileName); if (!sourceFile) { @@ -110606,7 +110783,7 @@ var ts; // We reset this cache on structure invalidation so we don't hold on to outdated files for long; however we can't use the `compilerHost` above, // Because it only functions until `hostCache` is cleared, while we'll potentially need the functionality to lazily read sourcemap files during // the course of whatever called `synchronizeHostData` - sourcemappedFileCache = ts.createSourceFileLikeCache(host); + sourceMapper.clearCache(); // Make sure all the nodes in the program are both bound, and have their parent // pointers set property. program.getTypeChecker(); @@ -110805,165 +110982,23 @@ var ts; } return checker.getSymbolAtLocation(node); } - function toLineColumnOffset(fileName, position) { - var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); - var file = program.getSourceFile(path) || sourcemappedFileCache.get(path); // TODO: GH#18217 - return file.getLineAndCharacterOfPosition(position); - } - // Sometimes tools can sometimes see the following line as a source mapping url comment, so we mangle it a bit (the [M]) - var sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)$/; - var whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/; - var base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/; - function scanForSourcemapURL(fileName) { - var mappedFile = sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); - if (!mappedFile) { - return; - } - var starts = ts.getLineStarts(mappedFile); - for (var index = starts.length - 1; index >= 0; index--) { - var lineText = mappedFile.text.substring(starts[index], starts[index + 1]); - var comment = sourceMapCommentRegExp.exec(lineText); - if (comment) { - return comment[1]; - } - // If we see a nonwhitespace/map comment-like line, break, to avoid scanning up the entire file - else if (!lineText.match(whitespaceOrMapCommentRegExp)) { - break; - } - } - } - function convertDocumentToSourceMapper(file, contents, mapFileName) { - var maps; - try { - maps = JSON.parse(contents); - } - catch (_a) { - // swallow error - } - if (!maps || !maps.sources || !maps.file || !maps.mappings) { - // obviously invalid map - return file.sourceMapper = ts.sourcemaps.identitySourceMapper; - } - return file.sourceMapper = ts.sourcemaps.decode({ - readFile: function (s) { return host.readFile(s); }, - fileExists: function (s) { return host.fileExists(s); }, - getCanonicalFileName: getCanonicalFileName, - log: log, - }, mapFileName, maps, program, sourcemappedFileCache); - } - function getSourceMapper(fileName, file) { - if (!host.readFile || !host.fileExists) { - return file.sourceMapper = ts.sourcemaps.identitySourceMapper; - } - if (file.sourceMapper) { - return file.sourceMapper; - } - var mapFileName = scanForSourcemapURL(fileName); - if (mapFileName) { - var match = base64UrlRegExp.exec(mapFileName); - if (match) { - if (match[1]) { - var base64Object = match[1]; - return convertDocumentToSourceMapper(file, ts.base64decode(ts.sys, base64Object), fileName); - } - // Not a data URL we can parse, skip it - mapFileName = undefined; - } - } - var possibleMapLocations = []; - if (mapFileName) { - possibleMapLocations.push(mapFileName); - } - possibleMapLocations.push(fileName + ".map"); - for (var _i = 0, possibleMapLocations_1 = possibleMapLocations; _i < possibleMapLocations_1.length; _i++) { - var location = possibleMapLocations_1[_i]; - var mapPath = ts.toPath(location, ts.getDirectoryPath(fileName), getCanonicalFileName); - if (host.fileExists(mapPath)) { - return convertDocumentToSourceMapper(file, host.readFile(mapPath), mapPath); // TODO: GH#18217 - } - } - return file.sourceMapper = ts.sourcemaps.identitySourceMapper; - } - function makeGetTargetOfMappedPosition(extract, create) { - return getTargetOfMappedPosition; - function getTargetOfMappedPosition(input, original) { - if (original === void 0) { original = input; } - var info = extract(input); - if (ts.endsWith(info.fileName, ".d.ts" /* Dts */)) { - var file = program.getSourceFile(info.fileName); - if (!file) { - var path = ts.toPath(info.fileName, currentDirectory, getCanonicalFileName); - file = sourcemappedFileCache.get(path); - } - if (!file) { - return input; - } - var mapper = getSourceMapper(info.fileName, file); - var newLoc = mapper.getOriginalPosition(info); - if (newLoc === info) - return input; - return getTargetOfMappedPosition(create(newLoc, input, original), original); - } - return input; - } - } - var getTargetOfMappedDeclarationInfo = makeGetTargetOfMappedPosition(function (info) { return ({ fileName: info.fileName, position: info.textSpan.start }); }, function (newLoc, info, original) { return ({ - containerKind: info.containerKind, - containerName: info.containerName, - fileName: newLoc.fileName, - kind: info.kind, - name: info.name, - textSpan: { - start: newLoc.position, - length: info.textSpan.length - }, - originalFileName: original.fileName, - originalTextSpan: original.textSpan - }); }); - function getTargetOfMappedDeclarationFiles(infos) { - return ts.map(infos, function (d) { return getTargetOfMappedDeclarationInfo(d); }); - } /// Goto definition function getDefinitionAtPosition(fileName, position) { synchronizeHostData(); - return getTargetOfMappedDeclarationFiles(ts.GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position)); + return ts.GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position); } function getDefinitionAndBoundSpan(fileName, position) { synchronizeHostData(); - var result = ts.GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position); - if (!result) - return result; - var mappedDefs = getTargetOfMappedDeclarationFiles(result.definitions); - if (mappedDefs === result.definitions) { - return result; - } - return { - definitions: mappedDefs, - textSpan: result.textSpan - }; + return ts.GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position); } function getTypeDefinitionAtPosition(fileName, position) { synchronizeHostData(); - return getTargetOfMappedDeclarationFiles(ts.GoToDefinition.getTypeDefinitionAtPosition(program.getTypeChecker(), getValidSourceFile(fileName), position)); + return ts.GoToDefinition.getTypeDefinitionAtPosition(program.getTypeChecker(), getValidSourceFile(fileName), position); } /// Goto implementation - var getTargetOfMappedImplementationLocation = makeGetTargetOfMappedPosition(function (info) { return ({ fileName: info.fileName, position: info.textSpan.start }); }, function (newLoc, info) { return ({ - fileName: newLoc.fileName, - kind: info.kind, - displayParts: info.displayParts, - textSpan: { - start: newLoc.position, - length: info.textSpan.length - }, - originalFileName: info.fileName, - originalTextSpan: info.textSpan - }); }); - function getTargetOfMappedImplementationLocations(infos) { - return ts.map(infos, function (d) { return getTargetOfMappedImplementationLocation(d); }); - } function getImplementationAtPosition(fileName, position) { synchronizeHostData(); - return getTargetOfMappedImplementationLocations(ts.FindAllReferences.getImplementationsAtPosition(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position)); + return ts.FindAllReferences.getImplementationsAtPosition(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position); } /// References and Occurrences function getOccurrencesAtPosition(fileName, position) { @@ -111014,7 +111049,6 @@ var ts; synchronizeHostData(); return ts.FindAllReferences.findReferencedSymbols(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position); } - /// NavigateTo function getNavigateToItems(searchValue, maxResultCount, fileName, excludeDtsFiles) { if (excludeDtsFiles === void 0) { excludeDtsFiles = false; } synchronizeHostData(); @@ -111484,7 +111518,8 @@ var ts; getProgram: getProgram, getApplicableRefactors: getApplicableRefactors, getEditsForRefactor: getEditsForRefactor, - toLineColumnOffset: toLineColumnOffset + toLineColumnOffset: sourceMapper.toLineColumnOffset, + getSourceMapper: function () { return sourceMapper; }, }; } ts.createLanguageService = createLanguageService; @@ -113674,6 +113709,7 @@ var ts; CommandTypes["DefinitionAndBoundSpanFull"] = "definitionAndBoundSpan-full"; CommandTypes["Implementation"] = "implementation"; CommandTypes["ImplementationFull"] = "implementation-full"; + CommandTypes["EmitOutput"] = "emit-output"; CommandTypes["Exit"] = "exit"; CommandTypes["Format"] = "format"; CommandTypes["Formatonkey"] = "formatonkey"; @@ -114402,7 +114438,7 @@ var ts; return this.projectStateVersion.toString(); }; Project.prototype.getProjectReferences = function () { - return undefined; + return server.emptyArray; }; Project.prototype.getScriptFileNames = function () { var _this = this; @@ -114530,6 +114566,9 @@ var ts; } return this.languageService; }; + Project.prototype.getSourceMapper = function () { + return this.getLanguageService().getSourceMapper(); + }; Project.prototype.shouldEmitFile = function (scriptInfo) { return scriptInfo && !scriptInfo.isDynamicOrHasMixedContent(); }; @@ -115197,7 +115236,7 @@ var ts; return server.asNormalizedPath(this.getProjectName()); }; ConfiguredProject.prototype.getProjectReferences = function () { - return this.projectReferences; + return this.projectReferences || server.emptyArray; }; ConfiguredProject.prototype.updateReferences = function (refs) { this.projectReferences = refs; @@ -116000,7 +116039,7 @@ var ts; ProjectService.prototype.stopWatchingConfigFilesForClosedScriptInfo = function (info) { var _this = this; ts.Debug.assert(!info.isScriptOpen()); - this.forEachConfigFileLocation(info, function (configFileName, canonicalConfigFilePath) { + this.forEachConfigFileLocation(info, true, function (configFileName, canonicalConfigFilePath) { var configFileExistenceInfo = _this.configFileExistenceInfoCache.get(canonicalConfigFilePath); if (configFileExistenceInfo) { var infoIsRootOfInferredProject = configFileExistenceInfo.openFilesImpactedByConfigFile.get(info.path); @@ -116020,7 +116059,7 @@ var ts; ProjectService.prototype.startWatchingConfigFilesForInferredProjectRoot = function (info) { var _this = this; ts.Debug.assert(info.isScriptOpen()); - this.forEachConfigFileLocation(info, function (configFileName, canonicalConfigFilePath) { + this.forEachConfigFileLocation(info, true, function (configFileName, canonicalConfigFilePath) { var configFileExistenceInfo = _this.configFileExistenceInfoCache.get(canonicalConfigFilePath); if (!configFileExistenceInfo) { configFileExistenceInfo = { @@ -116039,7 +116078,7 @@ var ts; }; ProjectService.prototype.stopWatchingConfigFilesForInferredProjectRoot = function (info) { var _this = this; - this.forEachConfigFileLocation(info, function (configFileName, canonicalConfigFilePath) { + this.forEachConfigFileLocation(info, true, function (configFileName, canonicalConfigFilePath) { var configFileExistenceInfo = _this.configFileExistenceInfoCache.get(canonicalConfigFilePath); if (configFileExistenceInfo && configFileExistenceInfo.openFilesImpactedByConfigFile.has(info.path)) { ts.Debug.assert(info.isScriptOpen()); @@ -116049,12 +116088,12 @@ var ts; } }); }; - ProjectService.prototype.forEachConfigFileLocation = function (info, action) { + ProjectService.prototype.forEachConfigFileLocation = function (info, infoShouldBeOpen, action) { var _this = this; if (this.syntaxOnly) { return undefined; } - ts.Debug.assert(this.openFiles.has(info.path)); + ts.Debug.assert(!infoShouldBeOpen || this.openFiles.has(info.path)); var projectRootPath = this.openFiles.get(info.path); var searchPath = server.asNormalizedPath(ts.getDirectoryPath(info.fileName)); var isSearchPathInProjectRoot = function () { return ts.containsPath(projectRootPath, searchPath, _this.currentDirectory, !_this.host.useCaseSensitiveFileNames); }; @@ -116079,11 +116118,12 @@ var ts; } while (anySearchPathOk || isSearchPathInProjectRoot()); return undefined; }; - ProjectService.prototype.getConfigFileNameForFile = function (info) { + ProjectService.prototype.getConfigFileNameForFile = function (info, infoShouldBeOpen) { var _this = this; - ts.Debug.assert(info.isScriptOpen()); + if (infoShouldBeOpen) + ts.Debug.assert(info.isScriptOpen()); this.logger.info("Search path: " + ts.getDirectoryPath(info.fileName)); - var configFileName = this.forEachConfigFileLocation(info, function (configFileName, canonicalConfigFilePath) { + var configFileName = this.forEachConfigFileLocation(info, infoShouldBeOpen, function (configFileName, canonicalConfigFilePath) { return _this.configFileExists(configFileName, canonicalConfigFilePath, info); }); if (configFileName) { @@ -116579,7 +116619,7 @@ var ts; } var info = _this.getScriptInfoForPath(path); ts.Debug.assert(info.isScriptOpen()); - var configFileName = _this.getConfigFileNameForFile(info); + var configFileName = _this.getConfigFileNameForFile(info, true); if (configFileName) { var project = _this.findConfiguredProjectByProjectName(configFileName); if (!project) { @@ -116630,6 +116670,21 @@ var ts; ProjectService.prototype.openClientFile = function (fileName, fileContent, scriptKind, projectRootPath) { return this.openClientFileWithNormalizedPath(server.toNormalizedPath(fileName), fileContent, scriptKind, false, projectRootPath ? server.toNormalizedPath(projectRootPath) : undefined); }; + ProjectService.prototype.getProjectForFileWithoutOpening = function (fileName) { + var scriptInfo = this.filenameToScriptInfo.get(fileName) || + this.getOrCreateScriptInfoNotOpenedByClientForNormalizedPath(fileName, this.currentDirectory, undefined, undefined, undefined); + if (!scriptInfo) + return undefined; + if (scriptInfo.containingProjects.length) { + return { scriptInfo: scriptInfo, projects: scriptInfo.containingProjects }; + } + var configFileName = this.getConfigFileNameForFile(scriptInfo, false); + var project = configFileName === undefined ? undefined : this.findConfiguredProjectByProjectName(configFileName) || this.createConfiguredProject(configFileName); + return project && project.containsScriptInfo(scriptInfo) ? { scriptInfo: scriptInfo, projects: [project] } : undefined; + }; + ProjectService.prototype.fileExists = function (fileName) { + return this.filenameToScriptInfo.has(fileName) || this.host.fileExists(fileName); + }; ProjectService.prototype.findExternalProjectContainingOpenScriptInfo = function (info) { return ts.find(this.externalProjects, function (proj) { proj.updateGraph(); @@ -116644,7 +116699,7 @@ var ts; this.openFiles.set(info.path, projectRootPath); var project = this.findExternalProjectContainingOpenScriptInfo(info); if (!project && !this.syntaxOnly) { - configFileName = this.getConfigFileNameForFile(info); + configFileName = this.getConfigFileNameForFile(info, true); if (configFileName) { project = this.findConfiguredProjectByProjectName(configFileName); if (!project) { @@ -117037,25 +117092,6 @@ var ts; } return false; } - function compareNumber(a, b) { - return a - b; - } - function compareFileStart(a, b) { - if (a.file < b.file) { - return -1; - } - else if (a.file === b.file) { - var n = compareNumber(a.start.line, b.start.line); - if (n === 0) { - return compareNumber(a.start.offset, b.start.offset); - } - else - return n; - } - else { - return 1; - } - } function formatDiag(fileName, project, diag) { var scriptInfo = project.getScriptInfoForNormalizedPath(fileName); return { @@ -117220,6 +117256,131 @@ var ts; ? ts.sortAndDeduplicate(outputs, comparer, areEqual) : ts.deduplicate(outputs, areEqual); } + function combineProjectOutputWhileOpeningReferencedProjects(projects, projectService, action, getLocation, resultsEqual) { + var outputs = []; + combineProjectOutputWorker(projects, undefined, projectService, function (_a, tryAddToTodo) { + var project = _a.project; + for (var _i = 0, _b = action(project); _i < _b.length; _i++) { + var output = _b[_i]; + if (!ts.contains(outputs, output, resultsEqual) && !tryAddToTodo(project, getLocation(output))) { + outputs.push(output); + } + } + }); + return outputs; + } + function combineProjectOutputForRenameLocations(projects, initialLocation, projectService, findInStrings, findInComments) { + var outputs = []; + combineProjectOutputWorker(projects, initialLocation, projectService, function (_a, tryAddToTodo) { + var project = _a.project, location = _a.location; + for (var _i = 0, _b = project.getLanguageService().findRenameLocations(location.fileName, location.position, findInStrings, findInComments) || server.emptyArray; _i < _b.length; _i++) { + var output = _b[_i]; + if (!ts.contains(outputs, output, ts.documentSpansEqual) && !tryAddToTodo(project, documentSpanLocation(output))) { + outputs.push(output); + } + } + }); + return outputs; + } + function combineProjectOutputForReferences(projects, initialLocation, projectService) { + var outputs = []; + combineProjectOutputWorker(projects, initialLocation, projectService, function (_a, tryAddToTodo) { + var project = _a.project, location = _a.location; + var _loop_8 = function (outputReferencedSymbol) { + var symbolToAddTo = ts.find(outputs, function (o) { return ts.documentSpansEqual(o.definition, outputReferencedSymbol.definition); }); + if (!symbolToAddTo) { + symbolToAddTo = { definition: outputReferencedSymbol.definition, references: [] }; + outputs.push(symbolToAddTo); + } + for (var _i = 0, _a = outputReferencedSymbol.references; _i < _a.length; _i++) { + var ref = _a[_i]; + if (!ts.contains(symbolToAddTo.references, ref, ts.documentSpansEqual) && !tryAddToTodo(project, documentSpanLocation(ref))) { + symbolToAddTo.references.push(ref); + } + } + }; + for (var _i = 0, _b = project.getLanguageService().findReferences(location.fileName, location.position) || server.emptyArray; _i < _b.length; _i++) { + var outputReferencedSymbol = _b[_i]; + _loop_8(outputReferencedSymbol); + } + }); + return outputs.filter(function (o) { return o.references.length !== 0; }); + } + function combineProjectOutputWorker(projects, initialLocation, projectService, cb) { + var toDoAndSeenProjects; + for (var _i = 0, _a = isProjectsArray(projects) ? projects : projects.projects; _i < _a.length; _i++) { + var project = _a[_i]; + toDoAndSeenProjects = callbackProjectAndLocation(projects, { project: project, location: initialLocation }, projectService, toDoAndSeenProjects, cb); + } + if (!ts.isArray(projects) && projects.symLinkedProjects) { + projects.symLinkedProjects.forEach(function (symlinkedProjects, path) { + for (var _i = 0, symlinkedProjects_1 = symlinkedProjects; _i < symlinkedProjects_1.length; _i++) { + var project = symlinkedProjects_1[_i]; + toDoAndSeenProjects = callbackProjectAndLocation(projects, { project: project, location: { fileName: path, position: initialLocation.position } }, projectService, toDoAndSeenProjects, cb); + } + }); + } + while (toDoAndSeenProjects && toDoAndSeenProjects.toDo.length) { + toDoAndSeenProjects = callbackProjectAndLocation(projects, ts.Debug.assertDefined(toDoAndSeenProjects.toDo.pop()), projectService, toDoAndSeenProjects, cb); + } + } + function callbackProjectAndLocation(originalProjects, projectAndLocation, projectService, toDoAndSeenProjects, cb) { + if (projectAndLocation.project.getCancellationToken().isCancellationRequested()) + return undefined; + cb(projectAndLocation, function (project, location) { + var originalLocation = project.getSourceMapper().tryGetOriginalLocation(location); + if (!originalLocation) + return false; + var originalProjectAndScriptInfo = projectService.getProjectForFileWithoutOpening(server.toNormalizedPath(originalLocation.fileName)); + if (!originalProjectAndScriptInfo) + return false; + if (originalProjectAndScriptInfo) { + if (toDoAndSeenProjects === undefined) { + toDoAndSeenProjects = { toDo: [], seenProjects: ts.createMap() }; + for (var _i = 0, _a = isProjectsArray(originalProjects) ? originalProjects : originalProjects.projects; _i < _a.length; _i++) { + var project_1 = _a[_i]; + toDoAndSeenProjects.seenProjects.set(project_1.projectName, true); + } + if (!ts.isArray(originalProjects) && originalProjects.symLinkedProjects) { + originalProjects.symLinkedProjects.forEach(function (symlinkedProjects) { + for (var _i = 0, symlinkedProjects_2 = symlinkedProjects; _i < symlinkedProjects_2.length; _i++) { + var project_2 = symlinkedProjects_2[_i]; + toDoAndSeenProjects.seenProjects.set(project_2.projectName, true); + } + }); + } + } + for (var _b = 0, _c = originalProjectAndScriptInfo.projects; _b < _c.length; _b++) { + var project_3 = _c[_b]; + addToTodo({ project: project_3, location: originalLocation }, toDoAndSeenProjects); + } + var symlinkedProjectsMap = projectService.getSymlinkedProjects(originalProjectAndScriptInfo.scriptInfo); + if (symlinkedProjectsMap) { + symlinkedProjectsMap.forEach(function (symlinkedProjects) { + for (var _i = 0, symlinkedProjects_3 = symlinkedProjects; _i < symlinkedProjects_3.length; _i++) { + var symlinkedProject = symlinkedProjects_3[_i]; + addToTodo({ project: symlinkedProject, location: originalLocation }, toDoAndSeenProjects); + } + }); + } + } + return true; + }); + return toDoAndSeenProjects; + } + function addToTodo(projectAndLocation, _a) { + var seenProjects = _a.seenProjects, toDo = _a.toDo; + if (ts.addToSeen(seenProjects, projectAndLocation.project.projectName)) + toDo.push(projectAndLocation); + } + function documentSpanLocation(_a) { + var fileName = _a.fileName, textSpan = _a.textSpan; + return { fileName: fileName, position: textSpan.start }; + } + function getMappedLocation(location, projectService, project) { + var mapsTo = project.getSourceMapper().tryGetOriginalLocation(location); + return mapsTo && projectService.fileExists(server.toNormalizedPath(mapsTo.fileName)) ? mapsTo : undefined; + } var Session = (function () { function Session(opts) { var _a; @@ -117281,6 +117442,9 @@ var ts; _a[server.CommandNames.DefinitionAndBoundSpanFull] = function (request) { return _this.requiredResponse(_this.getDefinitionAndBoundSpan(request.arguments, false)); }, + _a[server.CommandNames.EmitOutput] = function (request) { + return _this.requiredResponse(_this.getEmitOutput(request.arguments)); + }, _a[server.CommandNames.TypeDefinition] = function (request) { return _this.requiredResponse(_this.getTypeDefinition(request.arguments)); }, @@ -117808,33 +117972,55 @@ var ts; Session.prototype.getDefinition = function (args, simplifiedResult) { var _a = this.getFileAndProject(args), file = _a.file, project = _a.project; var position = this.getPositionInFile(args, file); - var definitions = project.getLanguageService().getDefinitionAtPosition(file, position); - if (!definitions) { - return server.emptyArray; - } - if (simplifiedResult) { - return this.mapDefinitionInfo(definitions, project); - } - return definitions.map(Session.mapToOriginalLocation); + var definitions = this.mapDefinitionInfoLocations(project.getLanguageService().getDefinitionAtPosition(file, position) || server.emptyArray, project); + return simplifiedResult ? this.mapDefinitionInfo(definitions, project) : definitions.map(Session.mapToOriginalLocation); + }; + Session.prototype.mapDefinitionInfoLocations = function (definitions, project) { + var _this = this; + return definitions.map(function (info) { + var newLoc = getMappedLocation(documentSpanLocation(info), _this.projectService, project); + return !newLoc ? info : { + containerKind: info.containerKind, + containerName: info.containerName, + fileName: newLoc.fileName, + kind: info.kind, + name: info.name, + textSpan: { + start: newLoc.position, + length: info.textSpan.length + }, + originalFileName: info.fileName, + originalTextSpan: info.textSpan, + }; + }); }; Session.prototype.getDefinitionAndBoundSpan = function (args, simplifiedResult) { var _a = this.getFileAndProject(args), file = _a.file, project = _a.project; var position = this.getPositionInFile(args, file); - var scriptInfo = project.getScriptInfo(file); - var definitionAndBoundSpan = project.getLanguageService().getDefinitionAndBoundSpan(file, position); - if (!definitionAndBoundSpan || !definitionAndBoundSpan.definitions) { + var scriptInfo = ts.Debug.assertDefined(project.getScriptInfo(file)); + var unmappedDefinitionAndBoundSpan = project.getLanguageService().getDefinitionAndBoundSpan(file, position); + if (!unmappedDefinitionAndBoundSpan || !unmappedDefinitionAndBoundSpan.definitions) { return { definitions: server.emptyArray, textSpan: undefined }; } + var definitions = this.mapDefinitionInfoLocations(unmappedDefinitionAndBoundSpan.definitions, project); + var textSpan = unmappedDefinitionAndBoundSpan.textSpan; if (simplifiedResult) { return { - definitions: this.mapDefinitionInfo(definitionAndBoundSpan.definitions, project), - textSpan: this.toLocationTextSpan(definitionAndBoundSpan.textSpan, scriptInfo) + definitions: this.mapDefinitionInfo(definitions, project), + textSpan: this.toLocationTextSpan(textSpan, scriptInfo) }; } - return __assign({}, definitionAndBoundSpan, { definitions: definitionAndBoundSpan.definitions.map(Session.mapToOriginalLocation) }); + return { + definitions: definitions.map(Session.mapToOriginalLocation), + textSpan: textSpan, + }; + }; + Session.prototype.getEmitOutput = function (args) { + var _a = this.getFileAndProject(args), file = _a.file, project = _a.project; + return project.getLanguageService().getEmitOutput(file); }; Session.prototype.mapDefinitionInfo = function (definitions, project) { var _this = this; @@ -117860,20 +118046,31 @@ var ts; Session.prototype.getTypeDefinition = function (args) { var _a = this.getFileAndProject(args), file = _a.file, project = _a.project; var position = this.getPositionInFile(args, file); - var definitions = project.getLanguageService().getTypeDefinitionAtPosition(file, position); - if (!definitions) { - return server.emptyArray; - } + var definitions = this.mapDefinitionInfoLocations(project.getLanguageService().getTypeDefinitionAtPosition(file, position) || server.emptyArray, project); return this.mapDefinitionInfo(definitions, project); }; + Session.prototype.mapImplementationLocations = function (implementations, project) { + var _this = this; + return implementations.map(function (info) { + var newLoc = getMappedLocation(documentSpanLocation(info), _this.projectService, project); + return !newLoc ? info : { + fileName: newLoc.fileName, + kind: info.kind, + displayParts: info.displayParts, + textSpan: { + start: newLoc.position, + length: info.textSpan.length + }, + originalFileName: info.fileName, + originalTextSpan: info.textSpan, + }; + }); + }; Session.prototype.getImplementation = function (args, simplifiedResult) { var _this = this; var _a = this.getFileAndProject(args), file = _a.file, project = _a.project; var position = this.getPositionInFile(args, file); - var implementations = project.getLanguageService().getImplementationAtPosition(file, position); - if (!implementations) { - return server.emptyArray; - } + var implementations = this.mapImplementationLocations(project.getLanguageService().getImplementationAtPosition(file, position) || server.emptyArray, project); if (simplifiedResult) { return implementations.map(function (_a) { var fileName = _a.fileName, textSpan = _a.textSpan; @@ -118011,138 +118208,58 @@ var ts; return info.getDefaultProject(); }; Session.prototype.getRenameLocations = function (args, simplifiedResult) { - var _this = this; var file = server.toNormalizedPath(args.file); var position = this.getPositionInFile(args, file); var projects = this.getProjects(args); - if (simplifiedResult) { - var defaultProject = this.getDefaultProject(args); - var renameInfo = defaultProject.getLanguageService().getRenameInfo(file, position); - if (!renameInfo) { - return undefined; - } - if (!renameInfo.canRename) { - return { - info: renameInfo, - locs: server.emptyArray - }; - } - var fileSpans = combineProjectOutput(file, function (path) { return _this.projectService.getScriptInfoForPath(path).fileName; }, projects, function (project, file) { - var renameLocations = project.getLanguageService().findRenameLocations(file, position, args.findInStrings, args.findInComments); - if (!renameLocations) { - return server.emptyArray; - } - return renameLocations.map(function (location) { - var locationScriptInfo = project.getScriptInfo(location.fileName); - return { - file: location.fileName, - start: locationScriptInfo.positionToLineOffset(location.textSpan.start), - end: locationScriptInfo.positionToLineOffset(ts.textSpanEnd(location.textSpan)), - }; - }); - }, compareRenameLocation, function (a, b) { return a.file === b.file && a.start.line === b.start.line && a.start.offset === b.start.offset; }); - var locs = []; - for (var _i = 0, fileSpans_1 = fileSpans; _i < fileSpans_1.length; _i++) { - var cur = fileSpans_1[_i]; - var curFileAccum = void 0; - if (locs.length > 0) { - curFileAccum = locs[locs.length - 1]; - if (curFileAccum.file !== cur.file) { - curFileAccum = undefined; - } - } - if (!curFileAccum) { - curFileAccum = { file: cur.file, locs: [] }; - locs.push(curFileAccum); - } - curFileAccum.locs.push({ start: cur.start, end: cur.end }); - } - return { info: renameInfo, locs: locs }; - } - else { - return combineProjectOutput(file, function (path) { return _this.projectService.getScriptInfoForPath(path).fileName; }, projects, function (p, file) { return p.getLanguageService().findRenameLocations(file, position, args.findInStrings, args.findInComments); }, undefined, renameLocationIsEqualTo); - } - function renameLocationIsEqualTo(a, b) { - if (a === b) { - return true; - } - if (!a || !b) { - return false; - } - return a.fileName === b.fileName && - a.textSpan.start === b.textSpan.start && - a.textSpan.length === b.textSpan.length; - } - function compareRenameLocation(a, b) { - if (a.file < b.file) { - return -1; - } - else if (a.file > b.file) { - return 1; - } - else { - if (a.start.line < b.start.line) { - return 1; - } - else if (a.start.line > b.start.line) { - return -1; - } - else { - return b.start.offset - a.start.offset; - } - } + var locations = combineProjectOutputForRenameLocations(projects, { fileName: args.file, position: position }, this.projectService, !!args.findInStrings, !!args.findInComments); + if (!simplifiedResult) + return locations; + var defaultProject = this.getDefaultProject(args); + var renameInfo = Session.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position)); + return { info: renameInfo, locs: this.toSpanGroups(locations) }; + }; + Session.mapRenameInfo = function (_a) { + var canRename = _a.canRename, localizedErrorMessage = _a.localizedErrorMessage, displayName = _a.displayName, fullDisplayName = _a.fullDisplayName, kind = _a.kind, kindModifiers = _a.kindModifiers; + return { canRename: canRename, localizedErrorMessage: localizedErrorMessage, displayName: displayName, fullDisplayName: fullDisplayName, kind: kind, kindModifiers: kindModifiers }; + }; + Session.prototype.toSpanGroups = function (locations) { + var map = ts.createMap(); + for (var _i = 0, locations_1 = locations; _i < locations_1.length; _i++) { + var _a = locations_1[_i], fileName = _a.fileName, textSpan = _a.textSpan; + var group_1 = map.get(fileName); + if (!group_1) + map.set(fileName, group_1 = { file: fileName, locs: [] }); + group_1.locs.push(this.toLocationTextSpan(textSpan, ts.Debug.assertDefined(this.projectService.getScriptInfo(fileName)))); } + return ts.arrayFrom(map.values()); }; Session.prototype.getReferences = function (args, simplifiedResult) { var _this = this; var file = server.toNormalizedPath(args.file); var projects = this.getProjects(args); - var defaultProject = this.getDefaultProject(args); - var scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file); - var position = this.getPosition(args, scriptInfo); + var position = this.getPositionInFile(args, file); + var references = combineProjectOutputForReferences(projects, { fileName: args.file, position: position }, this.projectService); if (simplifiedResult) { + var defaultProject = this.getDefaultProject(args); + var scriptInfo = defaultProject.getScriptInfoForNormalizedPath(file); var nameInfo = defaultProject.getLanguageService().getQuickInfoAtPosition(file, position); - var displayString = nameInfo ? ts.displayPartsToString(nameInfo.displayParts) : ""; + var symbolDisplayString = nameInfo ? ts.displayPartsToString(nameInfo.displayParts) : ""; var nameSpan = nameInfo && nameInfo.textSpan; - var nameColStart = nameSpan ? scriptInfo.positionToLineOffset(nameSpan.start).offset : 0; - var nameText = nameSpan ? scriptInfo.getSnapshot().getText(nameSpan.start, ts.textSpanEnd(nameSpan)) : ""; - var refs = combineProjectOutput(file, function (path) { return _this.projectService.getScriptInfoForPath(path).fileName; }, projects, function (project, file) { - var references = project.getLanguageService().getReferencesAtPosition(file, position); - if (!references) { - return server.emptyArray; - } - return references.map(function (ref) { - var refScriptInfo = project.getScriptInfo(ref.fileName); - var start = refScriptInfo.positionToLineOffset(ref.textSpan.start); - var refLineSpan = refScriptInfo.lineToTextSpan(start.line - 1); - var lineText = refScriptInfo.getSnapshot().getText(refLineSpan.start, ts.textSpanEnd(refLineSpan)).replace(/\r|\n/g, ""); - return { - file: ref.fileName, - start: start, - lineText: lineText, - end: refScriptInfo.positionToLineOffset(ts.textSpanEnd(ref.textSpan)), - isWriteAccess: ref.isWriteAccess, - isDefinition: ref.isDefinition - }; + var symbolStartOffset = nameSpan ? scriptInfo.positionToLineOffset(nameSpan.start).offset : 0; + var symbolName_1 = nameSpan ? scriptInfo.getSnapshot().getText(nameSpan.start, ts.textSpanEnd(nameSpan)) : ""; + var refs = ts.flatMap(references, function (referencedSymbol) { + return referencedSymbol.references.map(function (_a) { + var fileName = _a.fileName, textSpan = _a.textSpan, isWriteAccess = _a.isWriteAccess, isDefinition = _a.isDefinition; + var scriptInfo = ts.Debug.assertDefined(_this.projectService.getScriptInfo(fileName)); + var lineText = scriptInfo.getSnapshot().getText(textSpan.start, ts.textSpanEnd(textSpan)); + return __assign({}, toFileSpan(fileName, textSpan, scriptInfo), { lineText: lineText, isWriteAccess: isWriteAccess, isDefinition: isDefinition }); }); - }, compareFileStart, areReferencesResponseItemsForTheSameLocation); - return { - refs: refs, - symbolName: nameText, - symbolStartOffset: nameColStart, - symbolDisplayString: displayString - }; + }); + var result = { refs: refs, symbolName: symbolName_1, symbolStartOffset: symbolStartOffset, symbolDisplayString: symbolDisplayString }; + return result; } else { - return combineProjectOutput(file, function (path) { return _this.projectService.getScriptInfoForPath(path).fileName; }, projects, function (project, file) { return project.getLanguageService().findReferences(file, position); }, undefined, ts.equateValues); - } - function areReferencesResponseItemsForTheSameLocation(a, b) { - if (a && b) { - return a.file === b.file && - a.start === b.start && - a.end === b.end; - } - return false; + return references; } }; Session.prototype.openClientFile = function (fileName, fileContent, scriptKind, projectRootPath) { @@ -118518,48 +118635,42 @@ var ts; : tree; }; Session.prototype.getNavigateToItems = function (args, simplifiedResult) { - var projects = this.getProjects(args); - var fileName = args.currentFileOnly ? args.file && ts.normalizeSlashes(args.file) : undefined; - if (simplifiedResult) { - return combineProjectOutput(fileName, function () { return undefined; }, projects, function (project, file) { - if (fileName && !file) { - return undefined; - } - var navItems = project.getLanguageService().getNavigateToItems(args.searchValue, args.maxResultCount, fileName, project.isNonTsProject()); - if (!navItems) { - return server.emptyArray; - } - return navItems.map(function (navItem) { - var scriptInfo = project.getScriptInfo(navItem.fileName); - var bakedItem = { - name: navItem.name, - kind: navItem.kind, - isCaseSensitive: navItem.isCaseSensitive, - matchKind: navItem.matchKind, - file: navItem.fileName, - start: scriptInfo.positionToLineOffset(navItem.textSpan.start), - end: scriptInfo.positionToLineOffset(ts.textSpanEnd(navItem.textSpan)) - }; - if (navItem.kindModifiers && (navItem.kindModifiers !== "")) { - bakedItem.kindModifiers = navItem.kindModifiers; - } - if (navItem.containerName && (navItem.containerName.length > 0)) { - bakedItem.containerName = navItem.containerName; - } - if (navItem.containerKind && (navItem.containerKind.length > 0)) { - bakedItem.containerKind = navItem.containerKind; - } - return bakedItem; - }); - }, undefined, areNavToItemsForTheSameLocation); + var _this = this; + var full = this.getFullNavigateToItems(args); + return !simplifiedResult ? full : full.map(function (navItem) { + var _a = _this.getFileAndProject({ file: navItem.fileName }), file = _a.file, project = _a.project; + var scriptInfo = project.getScriptInfo(file); + var bakedItem = { + name: navItem.name, + kind: navItem.kind, + isCaseSensitive: navItem.isCaseSensitive, + matchKind: navItem.matchKind, + file: navItem.fileName, + start: scriptInfo.positionToLineOffset(navItem.textSpan.start), + end: scriptInfo.positionToLineOffset(ts.textSpanEnd(navItem.textSpan)) + }; + if (navItem.kindModifiers && (navItem.kindModifiers !== "")) { + bakedItem.kindModifiers = navItem.kindModifiers; + } + if (navItem.containerName && (navItem.containerName.length > 0)) { + bakedItem.containerName = navItem.containerName; + } + if (navItem.containerKind && (navItem.containerKind.length > 0)) { + bakedItem.containerKind = navItem.containerKind; + } + return bakedItem; + }); + }; + Session.prototype.getFullNavigateToItems = function (args) { + var currentFileOnly = args.currentFileOnly, searchValue = args.searchValue, maxResultCount = args.maxResultCount; + if (currentFileOnly) { + var _a = this.getFileAndProject(args), file = _a.file, project = _a.project; + return project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, file); } else { - return combineProjectOutput(fileName, function () { return undefined; }, projects, function (project, file) { - if (fileName && !file) { - return undefined; - } - return project.getLanguageService().getNavigateToItems(args.searchValue, args.maxResultCount, fileName, project.isNonTsProject()); - }, undefined, navigateToItemIsEqualTo); + return combineProjectOutputWhileOpeningReferencedProjects(this.getProjects(args), this.projectService, function (project) { + return project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, undefined, project.isNonTsProject()); + }, documentSpanLocation, navigateToItemIsEqualTo); } function navigateToItemIsEqualTo(a, b) { if (a === b) { @@ -118579,14 +118690,6 @@ var ts; a.textSpan.start === b.textSpan.start && a.textSpan.length === b.textSpan.length; } - function areNavToItemsForTheSameLocation(a, b) { - if (a && b) { - return a.file === b.file && - a.start === b.start && - a.end === b.end; - } - return false; - } }; Session.prototype.getSupportedCodeFixes = function () { return ts.getSupportedCodeFixes(); @@ -118660,14 +118763,14 @@ var ts; this.projectService.forEachProject(function (project) { if (project.isOrphan() || !project.languageServiceEnabled) return; - var _loop_8 = function (fileTextChanges) { + var _loop_9 = function (fileTextChanges) { if (!changes.some(function (f) { return f.fileName === fileTextChanges.fileName; })) { changes.push(simplifiedResult ? _this.mapTextChangeToCodeEdit(project, fileTextChanges) : fileTextChanges); } }; for (var _i = 0, _a = project.getLanguageService().getEditsForFileRename(oldPath, newPath, formatOptions, preferences); _i < _a.length; _i++) { var fileTextChanges = _a[_i]; - _loop_8(fileTextChanges); + _loop_9(fileTextChanges); } }); return changes; @@ -118900,6 +119003,9 @@ var ts; return Session; }()); server.Session = Session; + function toFileSpan(fileName, textSpan, scriptInfo) { + return { file: fileName, start: scriptInfo.positionToLineOffset(textSpan.start), end: scriptInfo.positionToLineOffset(ts.textSpanEnd(textSpan)) }; + } function mapTextChangesToCodeEdits(textChanges, sourceFile) { ts.Debug.assert(!!textChanges.isNewFile === !sourceFile); if (sourceFile) { diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index ad8fd411384..4a4644fa1e3 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -3275,6 +3275,7 @@ declare namespace ts { aliasSymbol?: Symbol; aliasTypeArguments?: ReadonlyArray; wildcardInstantiation?: Type; + immediateBaseConstraint?: Type; } interface IntrinsicType extends Type { intrinsicName: string; @@ -7450,6 +7451,8 @@ declare namespace ts { jsDocTypeExpression: JSDocTypeExpression; diagnostics: Diagnostic[]; } | undefined; + /** @internal */ + function isDeclarationFileName(fileName: string): boolean; interface PragmaContext { languageVersion: ScriptTarget; pragmas?: PragmaMap; @@ -8822,6 +8825,16 @@ declare namespace ts { extendedDiagnostics?: boolean; } function createSourceMapWriter(host: EmitHost, writer: EmitTextWriter, compilerOptions?: SourceMapOptions): SourceMapWriter; + interface SourceMapSection { + version: 3; + file: string; + sourceRoot?: string; + sources: string[]; + names?: string[]; + mappings: string; + sourcesContent?: (string | null)[]; + sections?: undefined; + } } declare namespace ts { interface CommentWriter { @@ -8985,10 +8998,14 @@ declare namespace ts { */ function createProgram(rootNames: ReadonlyArray, options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: ReadonlyArray): Program; function parseConfigHostFromCompilerHost(host: CompilerHost): ParseConfigFileHost; + interface ResolveProjectReferencePathHost { + fileExists(fileName: string): boolean; + } /** - * Returns the target config filename of a project reference + * Returns the target config filename of a project reference. + * Note: The file might not exist. */ - function resolveProjectReferencePath(host: CompilerHost | UpToDateHost, ref: ProjectReference): ResolvedConfigFileName; + function resolveProjectReferencePath(host: ResolveProjectReferencePathHost, ref: ProjectReference): ResolvedConfigFileName; /** * Returns a DiagnosticMessage if we won't include a resolved module due to its extension. * The DiagnosticMessage's parameters are the imported module name, and the filename it resolved to. @@ -10044,6 +10061,8 @@ declare namespace ts { getJsxClosingTagAtPosition(fileName: string, position: number): JsxClosingTagInfo | undefined; getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan | undefined; toLineColumnOffset?(fileName: string, position: number): LineAndCharacter; + /** @internal */ + getSourceMapper(): SourceMapper; getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray, formatOptions: FormatCodeSettings, preferences: UserPreferences): ReadonlyArray; getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings, preferences: UserPreferences): CombinedCodeActions; applyCodeActionCommand(action: CodeActionCommand): Promise; @@ -10914,6 +10933,8 @@ declare namespace ts { function getParentNodeInSpan(node: Node | undefined, file: SourceFile, span: TextSpan): Node | undefined; function findModifier(node: Node, kind: Modifier["kind"]): Modifier | undefined; function insertImport(changes: textChanges.ChangeTracker, sourceFile: SourceFile, importDecl: Statement): void; + function textSpansEqual(a: TextSpan | undefined, b: TextSpan | undefined): boolean; + function documentSpansEqual(a: DocumentSpan, b: DocumentSpan): boolean; } declare namespace ts { function isFirstDeclarationOfSymbolParameter(symbol: Symbol): boolean; @@ -11322,6 +11343,14 @@ declare namespace ts.SignatureHelp { } function getArgumentInfoForCompletions(node: Node, position: number, sourceFile: SourceFile): ArgumentInfoForCompletions | undefined; } +declare namespace ts { + interface SourceMapper { + toLineColumnOffset(fileName: string, position: number): LineAndCharacter; + tryGetOriginalLocation(info: sourcemaps.SourceMappableLocation): sourcemaps.SourceMappableLocation | undefined; + clearCache(): void; + } + function getSourceMapper(getCanonicalFileName: GetCanonicalFileName, currentDirectory: string, log: (message: string) => void, host: LanguageServiceHost, getProgram: () => Program): SourceMapper; +} declare namespace ts { function computeSuggestionDiagnostics(sourceFile: SourceFile, program: Program, cancellationToken: CancellationToken): DiagnosticWithLocation[]; } @@ -12324,6 +12353,7 @@ declare namespace ts.server.protocol { DefinitionAndBoundSpanFull = "definitionAndBoundSpan-full", Implementation = "implementation", ImplementationFull = "implementation-full", + EmitOutput = "emit-output", Exit = "exit", Format = "format", Formatonkey = "formatonkey", @@ -12646,6 +12676,17 @@ declare namespace ts.server.protocol { interface DefinitionRequest extends FileLocationRequest { command: CommandTypes.Definition; } + interface DefinitionAndBoundSpanRequest extends FileLocationRequest { + readonly command: CommandTypes.DefinitionAndBoundSpan; + } + interface DefinitionAndBoundSpanResponse extends Response { + readonly body: DefinitionInfoAndBoundSpan; + } + interface EmitOutputRequest extends FileRequest { + } + interface EmitOutputResponse extends Response { + readonly body: EmitOutput; + } interface TypeDefinitionRequest extends FileLocationRequest { command: CommandTypes.TypeDefinition; } @@ -12744,6 +12785,13 @@ declare namespace ts.server.protocol { command: CommandTypes.Rename; arguments: RenameRequestArgs; } + interface RenameFullRequest extends FileLocationRequest { + readonly command: CommandTypes.RenameLocationsFull; + readonly arguments: RenameRequestArgs; + } + interface RenameFullResponse extends Response { + readonly body: ReadonlyArray; + } interface RenameInfo { canRename: boolean; localizedErrorMessage?: string; @@ -13634,7 +13682,7 @@ declare namespace ts.server { getCompilerOptions(): CompilerOptions; getNewLine(): string; getProjectVersion(): string; - getProjectReferences(): ReadonlyArray | undefined; + getProjectReferences(): ReadonlyArray; getScriptFileNames(): string[]; private getOrCreateScriptInfoAndAttachToProject; getScriptKind(fileName: string): ScriptKind; @@ -13666,6 +13714,7 @@ declare namespace ts.server { getGlobalProjectErrors(): ReadonlyArray; getAllProjectErrors(): ReadonlyArray; getLanguageService(ensureSynchronized?: boolean): LanguageService; + getSourceMapper(): SourceMapper; private shouldEmitFile; getCompileOnSaveAffectedFileList(scriptInfo: ScriptInfo): string[]; emitFile(scriptInfo: ScriptInfo, writeFile: (path: string, data: string, writeByteOrderMark?: boolean) => void): boolean; @@ -13748,7 +13797,7 @@ declare namespace ts.server { updateGraph(): boolean; getCachedDirectoryStructureHost(): CachedDirectoryStructureHost; getConfigFilePath(): NormalizedPath; - getProjectReferences(): ReadonlyArray | undefined; + getProjectReferences(): ReadonlyArray; updateReferences(refs: ReadonlyArray | undefined): void; enablePlugins(): void; getGlobalProjectErrors(): ReadonlyArray; @@ -14024,8 +14073,8 @@ declare namespace ts.server { getSymlinkedProjects(info: ScriptInfo): MultiMap | undefined; private watchClosedScriptInfo; private stopWatchingScriptInfo; - getOrCreateScriptInfoNotOpenedByClientForNormalizedPath(fileName: NormalizedPath, currentDirectory: string, scriptKind: ScriptKind | undefined, hasMixedContent: boolean | undefined, hostToQueryFileExistsOn: DirectoryStructureHost | undefined): ScriptInfo | undefined; - getOrCreateScriptInfoOpenedByClientForNormalizedPath(fileName: NormalizedPath, currentDirectory: string, fileContent: string | undefined, scriptKind: ScriptKind | undefined, hasMixedContent: boolean | undefined): ScriptInfo | undefined; + private getOrCreateScriptInfoNotOpenedByClientForNormalizedPath; + private getOrCreateScriptInfoOpenedByClientForNormalizedPath; getOrCreateScriptInfoForNormalizedPath(fileName: NormalizedPath, openedByClient: boolean, fileContent?: string, scriptKind?: ScriptKind, hasMixedContent?: boolean, hostToQueryFileExistsOn?: { fileExists(path: string): boolean; }): ScriptInfo | undefined; @@ -14040,6 +14089,11 @@ declare namespace ts.server { private removeRootOfInferredProjectIfNowPartOfOtherProject; private ensureProjectForOpenFiles; openClientFile(fileName: string, fileContent?: string, scriptKind?: ScriptKind, projectRootPath?: string): OpenConfiguredProjectResult; + getProjectForFileWithoutOpening(fileName: NormalizedPath): { + readonly scriptInfo: ScriptInfo; + readonly projects: ReadonlyArray; + } | undefined; + fileExists(fileName: NormalizedPath): boolean; private findExternalProjectContainingOpenScriptInfo; openClientFileWithNormalizedPath(fileName: NormalizedPath, fileContent?: string, scriptKind?: ScriptKind, hasMixedContent?: boolean, projectRootPath?: NormalizedPath): OpenConfiguredProjectResult; private telemetryOnOpenFile; @@ -14137,11 +14191,14 @@ declare namespace ts.server { private convertToDiagnosticsWithLinePosition; private getDiagnosticsWorker; private getDefinition; + private mapDefinitionInfoLocations; private getDefinitionAndBoundSpan; + private getEmitOutput; private mapDefinitionInfo; private static mapToOriginalLocation; private toFileSpan; private getTypeDefinition; + private mapImplementationLocations; private getImplementation; private getOccurrences; private getSyntacticDiagnosticsSync; @@ -14156,6 +14213,8 @@ declare namespace ts.server { private getProjects; private getDefaultProject; private getRenameLocations; + private static mapRenameInfo; + private toSpanGroups; private getReferences; private openClientFile; private getPosition; @@ -14194,6 +14253,7 @@ declare namespace ts.server { private toLocationTextSpan; private getNavigationTree; private getNavigateToItems; + private getFullNavigateToItems; private getSupportedCodeFixes; private isLocation; private extractPositionAndRange; diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 440e7824b60..4434deda35e 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -4155,10 +4155,14 @@ declare namespace ts { * @returns A 'Program' object. */ function createProgram(rootNames: ReadonlyArray, options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: ReadonlyArray): Program; + interface ResolveProjectReferencePathHost { + fileExists(fileName: string): boolean; + } /** - * Returns the target config filename of a project reference + * Returns the target config filename of a project reference. + * Note: The file might not exist. */ - function resolveProjectReferencePath(host: CompilerHost | UpToDateHost, ref: ProjectReference): ResolvedConfigFileName; + function resolveProjectReferencePath(host: ResolveProjectReferencePathHost, ref: ProjectReference): ResolvedConfigFileName; } declare namespace ts { interface EmitOutput { diff --git a/lib/typescript.js b/lib/typescript.js index 4785ced00f3..53091283e6f 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -21873,9 +21873,11 @@ var ts; InvalidPosition[InvalidPosition["Value"] = -1] = "Value"; })(InvalidPosition || (InvalidPosition = {})); })(IncrementalParser || (IncrementalParser = {})); + /** @internal */ function isDeclarationFileName(fileName) { return ts.fileExtensionIs(fileName, ".d.ts" /* Dts */); } + ts.isDeclarationFileName = isDeclarationFileName; /*@internal*/ function processCommentPragmas(context, sourceText) { var triviaScanner = ts.createScanner(context.languageVersion, /*skipTrivia*/ false, 0 /* Standard */, sourceText); @@ -29647,7 +29649,7 @@ var ts; TypeSystemPropertyName[TypeSystemPropertyName["ResolvedBaseConstructorType"] = 1] = "ResolvedBaseConstructorType"; TypeSystemPropertyName[TypeSystemPropertyName["DeclaredType"] = 2] = "DeclaredType"; TypeSystemPropertyName[TypeSystemPropertyName["ResolvedReturnType"] = 3] = "ResolvedReturnType"; - TypeSystemPropertyName[TypeSystemPropertyName["ResolvedBaseConstraint"] = 4] = "ResolvedBaseConstraint"; + TypeSystemPropertyName[TypeSystemPropertyName["ImmediateBaseConstraint"] = 4] = "ImmediateBaseConstraint"; })(TypeSystemPropertyName || (TypeSystemPropertyName = {})); var CheckMode; (function (CheckMode) { @@ -31354,17 +31356,25 @@ var ts; * Attempts to find the symbol corresponding to the container a symbol is in - usually this * is just its' `.parent`, but for locals, this value is `undefined` */ - function getContainerOfSymbol(symbol) { + function getContainersOfSymbol(symbol, enclosingDeclaration) { var container = getParentOfSymbol(symbol); if (container) { - return container; + var additionalContainers = ts.mapDefined(container.declarations, fileSymbolIfFileSymbolExportEqualsContainer); + if (enclosingDeclaration && getAccessibleSymbolChain(container, enclosingDeclaration, 1920 /* Namespace */, /*externalOnly*/ false)) { + return ts.concatenate([container], additionalContainers); // This order expresses a preference for the real container if it is in scope + } + return ts.append(additionalContainers, container); } - var candidate = ts.forEach(symbol.declarations, function (d) { return !ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined; }); - if (!candidate) { + var candidates = ts.mapDefined(symbol.declarations, function (d) { return !ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined; }); + if (!ts.length(candidates)) { return undefined; } - var alias = getAliasForSymbolInContainer(candidate, symbol); - return alias ? candidate : undefined; + return ts.mapDefined(candidates, function (candidate) { return getAliasForSymbolInContainer(candidate, symbol) ? candidate : undefined; }); + function fileSymbolIfFileSymbolExportEqualsContainer(d) { + var fileSymbol = getExternalModuleContainer(d); + var exported = fileSymbol && fileSymbol.exports && fileSymbol.exports.get("export=" /* ExportEquals */); + return resolveSymbol(exported) === resolveSymbol(container) ? fileSymbol : undefined; + } } function getAliasForSymbolInContainer(container, symbol) { if (container === getParentOfSymbol(symbol)) { @@ -31615,6 +31625,54 @@ var ts; var access = isSymbolAccessible(typeSymbol, enclosingDeclaration, 67216319 /* Value */, /*shouldComputeAliasesToMakeVisible*/ false); return access.accessibility === 0 /* Accessible */; } + function isAnySymbolAccessible(symbols, enclosingDeclaration, initialSymbol, meaning, shouldComputeAliasesToMakeVisible) { + if (!ts.length(symbols)) + return; + var hadAccessibleChain; + for (var _i = 0, _a = symbols; _i < _a.length; _i++) { + var symbol = _a[_i]; + // Symbol is accessible if it by itself is accessible + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, /*useOnlyExternalAliasing*/ false); + if (accessibleSymbolChain) { + hadAccessibleChain = symbol; + var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible); + if (hasAccessibleDeclarations) { + return hasAccessibleDeclarations; + } + } + else { + if (ts.some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + // Any meaning of a module symbol is always accessible via an `import` type + return { + accessibility: 0 /* Accessible */ + }; + } + } + // If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible. + // It could be a qualified symbol and hence verify the path + // e.g.: + // module m { + // export class c { + // } + // } + // const x: typeof m.c + // In the above example when we start with checking if typeof m.c symbol is accessible, + // we are going to see if c can be accessed in scope directly. + // But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible + // It is accessible if the parent m is accessible because then m.c can be accessed through qualification + var parentResult = isAnySymbolAccessible(getContainersOfSymbol(symbol, enclosingDeclaration), enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible); + if (parentResult) { + return parentResult; + } + } + if (hadAccessibleChain) { + return { + accessibility: 1 /* NotAccessible */, + errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorModuleName: hadAccessibleChain !== initialSymbol ? symbolToString(hadAccessibleChain, enclosingDeclaration, 1920 /* Namespace */) : undefined, + }; + } + } /** * Check if the given symbol in given enclosing declaration is accessible and mark all associated alias to be visible if requested * @@ -31625,55 +31683,20 @@ var ts; */ function isSymbolAccessible(symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible) { if (symbol && enclosingDeclaration) { - var initialSymbol = symbol; - var meaningToLook = meaning; - while (symbol) { - // Symbol is accessible if it by itself is accessible - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false); - if (accessibleSymbolChain) { - var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible); - if (!hasAccessibleDeclarations) { - return { - accessibility: 1 /* NotAccessible */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), - errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, 1920 /* Namespace */) : undefined, - }; - } - return hasAccessibleDeclarations; - } - else { - if (ts.some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { - // Any meaning of a module symbol is always accessible via an `import` type - return { - accessibility: 0 /* Accessible */ - }; - } - } - // If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible. - // It could be a qualified symbol and hence verify the path - // e.g.: - // module m { - // export class c { - // } - // } - // const x: typeof m.c - // In the above example when we start with checking if typeof m.c symbol is accessible, - // we are going to see if c can be accessed in scope directly. - // But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible - // It is accessible if the parent m is accessible because then m.c can be accessed through qualification - meaningToLook = getQualifiedLeftMeaning(meaning); - symbol = getContainerOfSymbol(symbol); + var result = isAnySymbolAccessible([symbol], enclosingDeclaration, symbol, meaning, shouldComputeAliasesToMakeVisible); + if (result) { + return result; } // This could be a symbol that is not exported in the external module // or it could be a symbol from different external module that is not aliased and hence cannot be named - var symbolExternalModule = ts.forEach(initialSymbol.declarations, getExternalModuleContainer); + var symbolExternalModule = ts.forEach(symbol.declarations, getExternalModuleContainer); if (symbolExternalModule) { var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration); if (symbolExternalModule !== enclosingExternalModule) { // name from different external module that is not visible return { accessibility: 2 /* CannotBeNamed */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), errorModuleName: symbolToString(symbolExternalModule) }; } @@ -31681,14 +31704,14 @@ var ts; // Just a local name that is not accessible return { accessibility: 1 /* NotAccessible */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), }; } return { accessibility: 0 /* Accessible */ }; - function getExternalModuleContainer(declaration) { - var node = ts.findAncestor(declaration, hasExternalModuleSymbol); - return node && getSymbolOfNode(node); - } + } + function getExternalModuleContainer(declaration) { + var node = ts.findAncestor(declaration, hasExternalModuleSymbol); + return node && getSymbolOfNode(node); } function hasExternalModuleSymbol(declaration) { return ts.isAmbientModule(declaration) || (declaration.kind === 277 /* SourceFile */ && ts.isExternalOrCommonJsModule(declaration)); @@ -32465,16 +32488,18 @@ var ts; /** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */ function getSymbolChain(symbol, meaning, endOfChain) { var accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, !!(context.flags & 128 /* UseOnlyExternalAliasing */)); - var parentSymbol; if (!accessibleSymbolChain || needsQualification(accessibleSymbolChain[0], context.enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { // Go up and add our parent. - var parent = getContainerOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol); - if (parent) { - var parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); - if (parentChain) { - parentSymbol = parent; - accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); + var parents = getContainersOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol, context.enclosingDeclaration); + if (ts.length(parents)) { + for (var _i = 0, _a = parents; _i < _a.length; _i++) { + var parent = _a[_i]; + var parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); + if (parentChain) { + accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); + break; + } } } } @@ -32484,10 +32509,12 @@ var ts; if ( // If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols. endOfChain || + // If a parent symbol is an anonymous type, don't write it. + !(symbol.flags & (2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */))) { // If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.) - (yieldModuleSymbol || !(!parentSymbol && ts.forEach(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol))) && - // If a parent symbol is an anonymous type, don't write it. - !(symbol.flags & (2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */))) { + if (!endOfChain && !yieldModuleSymbol && !!ts.forEach(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + return; + } return [symbol]; } } @@ -32981,8 +33008,8 @@ var ts; if (propertyName === 3 /* ResolvedReturnType */) { return !!target.resolvedReturnType; } - if (propertyName === 4 /* ResolvedBaseConstraint */) { - var bc = target.resolvedBaseConstraint; + if (propertyName === 4 /* ImmediateBaseConstraint */) { + var bc = target.immediateBaseConstraint; return !!bc && bc !== circularConstraintType; } return ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); @@ -35415,15 +35442,21 @@ var ts; } return type.resolvedBaseConstraint; function getBaseConstraint(t) { - if (!pushTypeResolution(t, 4 /* ResolvedBaseConstraint */)) { + if (t.immediateBaseConstraint) { + return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint; + } + if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { circular = true; + t.immediateBaseConstraint = circularConstraintType; return undefined; } var result = computeBaseConstraint(getSimplifiedType(t)); if (!popTypeResolution()) { circular = true; + t.immediateBaseConstraint = circularConstraintType; return undefined; } + t.immediateBaseConstraint = !result ? noConstraintType : result; return result; } function computeBaseConstraint(t) { @@ -84139,7 +84172,8 @@ var ts; } ts.parseConfigHostFromCompilerHost = parseConfigHostFromCompilerHost; /** - * Returns the target config filename of a project reference + * Returns the target config filename of a project reference. + * Note: The file might not exist. */ function resolveProjectReferencePath(host, ref) { if (!host.fileExists(ref.path)) { @@ -89463,6 +89497,14 @@ var ts; } } ts.insertImport = insertImport; + function textSpansEqual(a, b) { + return !!a && !!b && a.start === b.start && a.length === b.length; + } + ts.textSpansEqual = textSpansEqual; + function documentSpansEqual(a, b) { + return a.fileName === b.fileName && textSpansEqual(a.textSpan, b.textSpan); + } + ts.documentSpansEqual = documentSpansEqual; })(ts || (ts = {})); // Display-part writer helpers /* @internal */ @@ -96111,48 +96153,83 @@ var ts; var JsDoc; (function (JsDoc) { var jsDocTagNames = [ + "abstract", + "access", + "alias", + "argument", + "async", "augments", "author", - "argument", "borrows", "callback", "class", + "classDesc", "constant", "constructor", "constructs", + "copyright", "default", "deprecated", "description", + "emits", + "enum", "event", "example", + "exports", "extends", + "external", "field", + "file", "fileOverview", + "fires", "function", + "generator", + "global", + "hideConstructor", + "host", "ignore", + "implements", "inheritDoc", "inner", + "instance", + "interface", + "kind", "lends", - "link", + "license", + "listens", + "member", "memberOf", "method", + "mixes", + "module", "name", "namespace", + "override", + "package", "param", "private", - "prop", "property", + "protected", "public", + "readonly", "requires", "returns", "see", "since", "static", + "summary", "template", + "this", "throws", + "todo", + "tutorial", "type", "typedef", - "version" + "var", + "variation", + "version", + "virtual", + "yields" ]; var jsDocTagNameCompletionEntries; var jsDocTagCompletionEntries; @@ -96474,7 +96551,7 @@ var ts; var rawItems = []; var _loop_15 = function (sourceFile) { cancellationToken.throwIfCancellationRequested(); - if (excludeDtsFiles && ts.fileExtensionIs(sourceFile.fileName, ".d.ts" /* Dts */)) { + if (excludeDtsFiles && sourceFile.isDeclarationFile) { return "continue"; } sourceFile.getNamedDeclarations().forEach(function (declarations, name) { @@ -99032,6 +99109,106 @@ var ts; })(ts || (ts = {})); /* @internal */ var ts; +(function (ts) { + // Sometimes tools can sometimes see the following line as a source mapping url comment, so we mangle it a bit (the [M]) + var sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)\s*$/; + var whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/; + var base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/; + function getSourceMapper(getCanonicalFileName, currentDirectory, log, host, getProgram) { + var sourcemappedFileCache; + return { tryGetOriginalLocation: tryGetOriginalLocation, toLineColumnOffset: toLineColumnOffset, clearCache: clearCache }; + function scanForSourcemapURL(fileName) { + var mappedFile = sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); + if (!mappedFile) { + return; + } + var starts = ts.getLineStarts(mappedFile); + for (var index = starts.length - 1; index >= 0; index--) { + var lineText = mappedFile.text.substring(starts[index], starts[index + 1]); + var comment = sourceMapCommentRegExp.exec(lineText); + if (comment) { + return comment[1]; + } + // If we see a non-whitespace/map comment-like line, break, to avoid scanning up the entire file + else if (!lineText.match(whitespaceOrMapCommentRegExp)) { + break; + } + } + } + function convertDocumentToSourceMapper(file, contents, mapFileName) { + var maps; + try { + maps = JSON.parse(contents); + } + catch (_a) { + // swallow error + } + if (!maps || !maps.sources || !maps.file || !maps.mappings) { + // obviously invalid map + return file.sourceMapper = ts.sourcemaps.identitySourceMapper; + } + return file.sourceMapper = ts.sourcemaps.decode({ + readFile: function (s) { return host.readFile(s); }, + fileExists: function (s) { return host.fileExists(s); }, + getCanonicalFileName: getCanonicalFileName, + log: log, + }, mapFileName, maps, getProgram(), sourcemappedFileCache); + } + function getSourceMapper(fileName, file) { + if (!host.readFile || !host.fileExists) { + return file.sourceMapper = ts.sourcemaps.identitySourceMapper; + } + if (file.sourceMapper) { + return file.sourceMapper; + } + var mapFileName = scanForSourcemapURL(fileName); + if (mapFileName) { + var match = base64UrlRegExp.exec(mapFileName); + if (match) { + if (match[1]) { + var base64Object = match[1]; + return convertDocumentToSourceMapper(file, ts.base64decode(ts.sys, base64Object), fileName); + } + // Not a data URL we can parse, skip it + mapFileName = undefined; + } + } + var possibleMapLocations = []; + if (mapFileName) { + possibleMapLocations.push(mapFileName); + } + possibleMapLocations.push(fileName + ".map"); + for (var _i = 0, possibleMapLocations_1 = possibleMapLocations; _i < possibleMapLocations_1.length; _i++) { + var location = possibleMapLocations_1[_i]; + var mapPath = ts.toPath(location, ts.getDirectoryPath(fileName), getCanonicalFileName); + if (host.fileExists(mapPath)) { + return convertDocumentToSourceMapper(file, host.readFile(mapPath), mapPath); // TODO: GH#18217 + } + } + return file.sourceMapper = ts.sourcemaps.identitySourceMapper; + } + function tryGetOriginalLocation(info) { + if (!ts.isDeclarationFileName(info.fileName)) + return undefined; + var file = getProgram().getSourceFile(info.fileName) || sourcemappedFileCache.get(ts.toPath(info.fileName, currentDirectory, getCanonicalFileName)); + if (!file) + return undefined; + var newLoc = getSourceMapper(info.fileName, file).getOriginalPosition(info); + return newLoc === info ? undefined : tryGetOriginalLocation(newLoc) || newLoc; + } + function toLineColumnOffset(fileName, position) { + var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); + var file = getProgram().getSourceFile(path) || sourcemappedFileCache.get(path); // TODO: GH#18217 + return file.getLineAndCharacterOfPosition(position); + } + function clearCache() { + sourcemappedFileCache = ts.createSourceFileLikeCache(host); + } + } + ts.getSourceMapper = getSourceMapper; +})(ts || (ts = {})); +/* @internal */ +var ts; (function (ts) { function computeSuggestionDiagnostics(sourceFile, program, cancellationToken) { program.getSemanticDiagnostics(sourceFile, cancellationToken); @@ -110871,7 +111048,6 @@ var ts; if (!ts.localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) { ts.localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages(); } - var sourcemappedFileCache; function log(message) { if (host.log) { host.log(message); @@ -110879,6 +111055,7 @@ var ts; } var useCaseSensitiveFileNames = ts.hostUsesCaseSensitiveFileNames(host); var getCanonicalFileName = ts.createGetCanonicalFileName(useCaseSensitiveFileNames); + var sourceMapper = ts.getSourceMapper(getCanonicalFileName, currentDirectory, log, host, function () { return program; }); function getValidSourceFile(fileName) { var sourceFile = program.getSourceFile(fileName); if (!sourceFile) { @@ -110976,7 +111153,7 @@ var ts; // We reset this cache on structure invalidation so we don't hold on to outdated files for long; however we can't use the `compilerHost` above, // Because it only functions until `hostCache` is cleared, while we'll potentially need the functionality to lazily read sourcemap files during // the course of whatever called `synchronizeHostData` - sourcemappedFileCache = ts.createSourceFileLikeCache(host); + sourceMapper.clearCache(); // Make sure all the nodes in the program are both bound, and have their parent // pointers set property. program.getTypeChecker(); @@ -111175,165 +111352,23 @@ var ts; } return checker.getSymbolAtLocation(node); } - function toLineColumnOffset(fileName, position) { - var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); - var file = program.getSourceFile(path) || sourcemappedFileCache.get(path); // TODO: GH#18217 - return file.getLineAndCharacterOfPosition(position); - } - // Sometimes tools can sometimes see the following line as a source mapping url comment, so we mangle it a bit (the [M]) - var sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)$/; - var whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/; - var base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/; - function scanForSourcemapURL(fileName) { - var mappedFile = sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); - if (!mappedFile) { - return; - } - var starts = ts.getLineStarts(mappedFile); - for (var index = starts.length - 1; index >= 0; index--) { - var lineText = mappedFile.text.substring(starts[index], starts[index + 1]); - var comment = sourceMapCommentRegExp.exec(lineText); - if (comment) { - return comment[1]; - } - // If we see a nonwhitespace/map comment-like line, break, to avoid scanning up the entire file - else if (!lineText.match(whitespaceOrMapCommentRegExp)) { - break; - } - } - } - function convertDocumentToSourceMapper(file, contents, mapFileName) { - var maps; - try { - maps = JSON.parse(contents); - } - catch (_a) { - // swallow error - } - if (!maps || !maps.sources || !maps.file || !maps.mappings) { - // obviously invalid map - return file.sourceMapper = ts.sourcemaps.identitySourceMapper; - } - return file.sourceMapper = ts.sourcemaps.decode({ - readFile: function (s) { return host.readFile(s); }, - fileExists: function (s) { return host.fileExists(s); }, - getCanonicalFileName: getCanonicalFileName, - log: log, - }, mapFileName, maps, program, sourcemappedFileCache); - } - function getSourceMapper(fileName, file) { - if (!host.readFile || !host.fileExists) { - return file.sourceMapper = ts.sourcemaps.identitySourceMapper; - } - if (file.sourceMapper) { - return file.sourceMapper; - } - var mapFileName = scanForSourcemapURL(fileName); - if (mapFileName) { - var match = base64UrlRegExp.exec(mapFileName); - if (match) { - if (match[1]) { - var base64Object = match[1]; - return convertDocumentToSourceMapper(file, ts.base64decode(ts.sys, base64Object), fileName); - } - // Not a data URL we can parse, skip it - mapFileName = undefined; - } - } - var possibleMapLocations = []; - if (mapFileName) { - possibleMapLocations.push(mapFileName); - } - possibleMapLocations.push(fileName + ".map"); - for (var _i = 0, possibleMapLocations_1 = possibleMapLocations; _i < possibleMapLocations_1.length; _i++) { - var location = possibleMapLocations_1[_i]; - var mapPath = ts.toPath(location, ts.getDirectoryPath(fileName), getCanonicalFileName); - if (host.fileExists(mapPath)) { - return convertDocumentToSourceMapper(file, host.readFile(mapPath), mapPath); // TODO: GH#18217 - } - } - return file.sourceMapper = ts.sourcemaps.identitySourceMapper; - } - function makeGetTargetOfMappedPosition(extract, create) { - return getTargetOfMappedPosition; - function getTargetOfMappedPosition(input, original) { - if (original === void 0) { original = input; } - var info = extract(input); - if (ts.endsWith(info.fileName, ".d.ts" /* Dts */)) { - var file = program.getSourceFile(info.fileName); - if (!file) { - var path = ts.toPath(info.fileName, currentDirectory, getCanonicalFileName); - file = sourcemappedFileCache.get(path); - } - if (!file) { - return input; - } - var mapper = getSourceMapper(info.fileName, file); - var newLoc = mapper.getOriginalPosition(info); - if (newLoc === info) - return input; - return getTargetOfMappedPosition(create(newLoc, input, original), original); - } - return input; - } - } - var getTargetOfMappedDeclarationInfo = makeGetTargetOfMappedPosition(function (info) { return ({ fileName: info.fileName, position: info.textSpan.start }); }, function (newLoc, info, original) { return ({ - containerKind: info.containerKind, - containerName: info.containerName, - fileName: newLoc.fileName, - kind: info.kind, - name: info.name, - textSpan: { - start: newLoc.position, - length: info.textSpan.length - }, - originalFileName: original.fileName, - originalTextSpan: original.textSpan - }); }); - function getTargetOfMappedDeclarationFiles(infos) { - return ts.map(infos, function (d) { return getTargetOfMappedDeclarationInfo(d); }); - } /// Goto definition function getDefinitionAtPosition(fileName, position) { synchronizeHostData(); - return getTargetOfMappedDeclarationFiles(ts.GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position)); + return ts.GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position); } function getDefinitionAndBoundSpan(fileName, position) { synchronizeHostData(); - var result = ts.GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position); - if (!result) - return result; - var mappedDefs = getTargetOfMappedDeclarationFiles(result.definitions); - if (mappedDefs === result.definitions) { - return result; - } - return { - definitions: mappedDefs, - textSpan: result.textSpan - }; + return ts.GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position); } function getTypeDefinitionAtPosition(fileName, position) { synchronizeHostData(); - return getTargetOfMappedDeclarationFiles(ts.GoToDefinition.getTypeDefinitionAtPosition(program.getTypeChecker(), getValidSourceFile(fileName), position)); + return ts.GoToDefinition.getTypeDefinitionAtPosition(program.getTypeChecker(), getValidSourceFile(fileName), position); } /// Goto implementation - var getTargetOfMappedImplementationLocation = makeGetTargetOfMappedPosition(function (info) { return ({ fileName: info.fileName, position: info.textSpan.start }); }, function (newLoc, info) { return ({ - fileName: newLoc.fileName, - kind: info.kind, - displayParts: info.displayParts, - textSpan: { - start: newLoc.position, - length: info.textSpan.length - }, - originalFileName: info.fileName, - originalTextSpan: info.textSpan - }); }); - function getTargetOfMappedImplementationLocations(infos) { - return ts.map(infos, function (d) { return getTargetOfMappedImplementationLocation(d); }); - } function getImplementationAtPosition(fileName, position) { synchronizeHostData(); - return getTargetOfMappedImplementationLocations(ts.FindAllReferences.getImplementationsAtPosition(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position)); + return ts.FindAllReferences.getImplementationsAtPosition(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position); } /// References and Occurrences function getOccurrencesAtPosition(fileName, position) { @@ -111384,7 +111419,6 @@ var ts; synchronizeHostData(); return ts.FindAllReferences.findReferencedSymbols(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position); } - /// NavigateTo function getNavigateToItems(searchValue, maxResultCount, fileName, excludeDtsFiles) { if (excludeDtsFiles === void 0) { excludeDtsFiles = false; } synchronizeHostData(); @@ -111854,7 +111888,8 @@ var ts; getProgram: getProgram, getApplicableRefactors: getApplicableRefactors, getEditsForRefactor: getEditsForRefactor, - toLineColumnOffset: toLineColumnOffset + toLineColumnOffset: sourceMapper.toLineColumnOffset, + getSourceMapper: function () { return sourceMapper; }, }; } ts.createLanguageService = createLanguageService; diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index 133c1e1ca95..47a0725992f 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -4155,10 +4155,14 @@ declare namespace ts { * @returns A 'Program' object. */ function createProgram(rootNames: ReadonlyArray, options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: ReadonlyArray): Program; + interface ResolveProjectReferencePathHost { + fileExists(fileName: string): boolean; + } /** - * Returns the target config filename of a project reference + * Returns the target config filename of a project reference. + * Note: The file might not exist. */ - function resolveProjectReferencePath(host: CompilerHost | UpToDateHost, ref: ProjectReference): ResolvedConfigFileName; + function resolveProjectReferencePath(host: ResolveProjectReferencePathHost, ref: ProjectReference): ResolvedConfigFileName; } declare namespace ts { interface EmitOutput { diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 4785ced00f3..53091283e6f 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -21873,9 +21873,11 @@ var ts; InvalidPosition[InvalidPosition["Value"] = -1] = "Value"; })(InvalidPosition || (InvalidPosition = {})); })(IncrementalParser || (IncrementalParser = {})); + /** @internal */ function isDeclarationFileName(fileName) { return ts.fileExtensionIs(fileName, ".d.ts" /* Dts */); } + ts.isDeclarationFileName = isDeclarationFileName; /*@internal*/ function processCommentPragmas(context, sourceText) { var triviaScanner = ts.createScanner(context.languageVersion, /*skipTrivia*/ false, 0 /* Standard */, sourceText); @@ -29647,7 +29649,7 @@ var ts; TypeSystemPropertyName[TypeSystemPropertyName["ResolvedBaseConstructorType"] = 1] = "ResolvedBaseConstructorType"; TypeSystemPropertyName[TypeSystemPropertyName["DeclaredType"] = 2] = "DeclaredType"; TypeSystemPropertyName[TypeSystemPropertyName["ResolvedReturnType"] = 3] = "ResolvedReturnType"; - TypeSystemPropertyName[TypeSystemPropertyName["ResolvedBaseConstraint"] = 4] = "ResolvedBaseConstraint"; + TypeSystemPropertyName[TypeSystemPropertyName["ImmediateBaseConstraint"] = 4] = "ImmediateBaseConstraint"; })(TypeSystemPropertyName || (TypeSystemPropertyName = {})); var CheckMode; (function (CheckMode) { @@ -31354,17 +31356,25 @@ var ts; * Attempts to find the symbol corresponding to the container a symbol is in - usually this * is just its' `.parent`, but for locals, this value is `undefined` */ - function getContainerOfSymbol(symbol) { + function getContainersOfSymbol(symbol, enclosingDeclaration) { var container = getParentOfSymbol(symbol); if (container) { - return container; + var additionalContainers = ts.mapDefined(container.declarations, fileSymbolIfFileSymbolExportEqualsContainer); + if (enclosingDeclaration && getAccessibleSymbolChain(container, enclosingDeclaration, 1920 /* Namespace */, /*externalOnly*/ false)) { + return ts.concatenate([container], additionalContainers); // This order expresses a preference for the real container if it is in scope + } + return ts.append(additionalContainers, container); } - var candidate = ts.forEach(symbol.declarations, function (d) { return !ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined; }); - if (!candidate) { + var candidates = ts.mapDefined(symbol.declarations, function (d) { return !ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined; }); + if (!ts.length(candidates)) { return undefined; } - var alias = getAliasForSymbolInContainer(candidate, symbol); - return alias ? candidate : undefined; + return ts.mapDefined(candidates, function (candidate) { return getAliasForSymbolInContainer(candidate, symbol) ? candidate : undefined; }); + function fileSymbolIfFileSymbolExportEqualsContainer(d) { + var fileSymbol = getExternalModuleContainer(d); + var exported = fileSymbol && fileSymbol.exports && fileSymbol.exports.get("export=" /* ExportEquals */); + return resolveSymbol(exported) === resolveSymbol(container) ? fileSymbol : undefined; + } } function getAliasForSymbolInContainer(container, symbol) { if (container === getParentOfSymbol(symbol)) { @@ -31615,6 +31625,54 @@ var ts; var access = isSymbolAccessible(typeSymbol, enclosingDeclaration, 67216319 /* Value */, /*shouldComputeAliasesToMakeVisible*/ false); return access.accessibility === 0 /* Accessible */; } + function isAnySymbolAccessible(symbols, enclosingDeclaration, initialSymbol, meaning, shouldComputeAliasesToMakeVisible) { + if (!ts.length(symbols)) + return; + var hadAccessibleChain; + for (var _i = 0, _a = symbols; _i < _a.length; _i++) { + var symbol = _a[_i]; + // Symbol is accessible if it by itself is accessible + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, /*useOnlyExternalAliasing*/ false); + if (accessibleSymbolChain) { + hadAccessibleChain = symbol; + var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible); + if (hasAccessibleDeclarations) { + return hasAccessibleDeclarations; + } + } + else { + if (ts.some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + // Any meaning of a module symbol is always accessible via an `import` type + return { + accessibility: 0 /* Accessible */ + }; + } + } + // If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible. + // It could be a qualified symbol and hence verify the path + // e.g.: + // module m { + // export class c { + // } + // } + // const x: typeof m.c + // In the above example when we start with checking if typeof m.c symbol is accessible, + // we are going to see if c can be accessed in scope directly. + // But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible + // It is accessible if the parent m is accessible because then m.c can be accessed through qualification + var parentResult = isAnySymbolAccessible(getContainersOfSymbol(symbol, enclosingDeclaration), enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible); + if (parentResult) { + return parentResult; + } + } + if (hadAccessibleChain) { + return { + accessibility: 1 /* NotAccessible */, + errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorModuleName: hadAccessibleChain !== initialSymbol ? symbolToString(hadAccessibleChain, enclosingDeclaration, 1920 /* Namespace */) : undefined, + }; + } + } /** * Check if the given symbol in given enclosing declaration is accessible and mark all associated alias to be visible if requested * @@ -31625,55 +31683,20 @@ var ts; */ function isSymbolAccessible(symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible) { if (symbol && enclosingDeclaration) { - var initialSymbol = symbol; - var meaningToLook = meaning; - while (symbol) { - // Symbol is accessible if it by itself is accessible - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false); - if (accessibleSymbolChain) { - var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible); - if (!hasAccessibleDeclarations) { - return { - accessibility: 1 /* NotAccessible */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), - errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, 1920 /* Namespace */) : undefined, - }; - } - return hasAccessibleDeclarations; - } - else { - if (ts.some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { - // Any meaning of a module symbol is always accessible via an `import` type - return { - accessibility: 0 /* Accessible */ - }; - } - } - // If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible. - // It could be a qualified symbol and hence verify the path - // e.g.: - // module m { - // export class c { - // } - // } - // const x: typeof m.c - // In the above example when we start with checking if typeof m.c symbol is accessible, - // we are going to see if c can be accessed in scope directly. - // But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible - // It is accessible if the parent m is accessible because then m.c can be accessed through qualification - meaningToLook = getQualifiedLeftMeaning(meaning); - symbol = getContainerOfSymbol(symbol); + var result = isAnySymbolAccessible([symbol], enclosingDeclaration, symbol, meaning, shouldComputeAliasesToMakeVisible); + if (result) { + return result; } // This could be a symbol that is not exported in the external module // or it could be a symbol from different external module that is not aliased and hence cannot be named - var symbolExternalModule = ts.forEach(initialSymbol.declarations, getExternalModuleContainer); + var symbolExternalModule = ts.forEach(symbol.declarations, getExternalModuleContainer); if (symbolExternalModule) { var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration); if (symbolExternalModule !== enclosingExternalModule) { // name from different external module that is not visible return { accessibility: 2 /* CannotBeNamed */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), errorModuleName: symbolToString(symbolExternalModule) }; } @@ -31681,14 +31704,14 @@ var ts; // Just a local name that is not accessible return { accessibility: 1 /* NotAccessible */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), }; } return { accessibility: 0 /* Accessible */ }; - function getExternalModuleContainer(declaration) { - var node = ts.findAncestor(declaration, hasExternalModuleSymbol); - return node && getSymbolOfNode(node); - } + } + function getExternalModuleContainer(declaration) { + var node = ts.findAncestor(declaration, hasExternalModuleSymbol); + return node && getSymbolOfNode(node); } function hasExternalModuleSymbol(declaration) { return ts.isAmbientModule(declaration) || (declaration.kind === 277 /* SourceFile */ && ts.isExternalOrCommonJsModule(declaration)); @@ -32465,16 +32488,18 @@ var ts; /** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */ function getSymbolChain(symbol, meaning, endOfChain) { var accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, !!(context.flags & 128 /* UseOnlyExternalAliasing */)); - var parentSymbol; if (!accessibleSymbolChain || needsQualification(accessibleSymbolChain[0], context.enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { // Go up and add our parent. - var parent = getContainerOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol); - if (parent) { - var parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); - if (parentChain) { - parentSymbol = parent; - accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); + var parents = getContainersOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol, context.enclosingDeclaration); + if (ts.length(parents)) { + for (var _i = 0, _a = parents; _i < _a.length; _i++) { + var parent = _a[_i]; + var parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); + if (parentChain) { + accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); + break; + } } } } @@ -32484,10 +32509,12 @@ var ts; if ( // If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols. endOfChain || + // If a parent symbol is an anonymous type, don't write it. + !(symbol.flags & (2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */))) { // If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.) - (yieldModuleSymbol || !(!parentSymbol && ts.forEach(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol))) && - // If a parent symbol is an anonymous type, don't write it. - !(symbol.flags & (2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */))) { + if (!endOfChain && !yieldModuleSymbol && !!ts.forEach(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + return; + } return [symbol]; } } @@ -32981,8 +33008,8 @@ var ts; if (propertyName === 3 /* ResolvedReturnType */) { return !!target.resolvedReturnType; } - if (propertyName === 4 /* ResolvedBaseConstraint */) { - var bc = target.resolvedBaseConstraint; + if (propertyName === 4 /* ImmediateBaseConstraint */) { + var bc = target.immediateBaseConstraint; return !!bc && bc !== circularConstraintType; } return ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); @@ -35415,15 +35442,21 @@ var ts; } return type.resolvedBaseConstraint; function getBaseConstraint(t) { - if (!pushTypeResolution(t, 4 /* ResolvedBaseConstraint */)) { + if (t.immediateBaseConstraint) { + return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint; + } + if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { circular = true; + t.immediateBaseConstraint = circularConstraintType; return undefined; } var result = computeBaseConstraint(getSimplifiedType(t)); if (!popTypeResolution()) { circular = true; + t.immediateBaseConstraint = circularConstraintType; return undefined; } + t.immediateBaseConstraint = !result ? noConstraintType : result; return result; } function computeBaseConstraint(t) { @@ -84139,7 +84172,8 @@ var ts; } ts.parseConfigHostFromCompilerHost = parseConfigHostFromCompilerHost; /** - * Returns the target config filename of a project reference + * Returns the target config filename of a project reference. + * Note: The file might not exist. */ function resolveProjectReferencePath(host, ref) { if (!host.fileExists(ref.path)) { @@ -89463,6 +89497,14 @@ var ts; } } ts.insertImport = insertImport; + function textSpansEqual(a, b) { + return !!a && !!b && a.start === b.start && a.length === b.length; + } + ts.textSpansEqual = textSpansEqual; + function documentSpansEqual(a, b) { + return a.fileName === b.fileName && textSpansEqual(a.textSpan, b.textSpan); + } + ts.documentSpansEqual = documentSpansEqual; })(ts || (ts = {})); // Display-part writer helpers /* @internal */ @@ -96111,48 +96153,83 @@ var ts; var JsDoc; (function (JsDoc) { var jsDocTagNames = [ + "abstract", + "access", + "alias", + "argument", + "async", "augments", "author", - "argument", "borrows", "callback", "class", + "classDesc", "constant", "constructor", "constructs", + "copyright", "default", "deprecated", "description", + "emits", + "enum", "event", "example", + "exports", "extends", + "external", "field", + "file", "fileOverview", + "fires", "function", + "generator", + "global", + "hideConstructor", + "host", "ignore", + "implements", "inheritDoc", "inner", + "instance", + "interface", + "kind", "lends", - "link", + "license", + "listens", + "member", "memberOf", "method", + "mixes", + "module", "name", "namespace", + "override", + "package", "param", "private", - "prop", "property", + "protected", "public", + "readonly", "requires", "returns", "see", "since", "static", + "summary", "template", + "this", "throws", + "todo", + "tutorial", "type", "typedef", - "version" + "var", + "variation", + "version", + "virtual", + "yields" ]; var jsDocTagNameCompletionEntries; var jsDocTagCompletionEntries; @@ -96474,7 +96551,7 @@ var ts; var rawItems = []; var _loop_15 = function (sourceFile) { cancellationToken.throwIfCancellationRequested(); - if (excludeDtsFiles && ts.fileExtensionIs(sourceFile.fileName, ".d.ts" /* Dts */)) { + if (excludeDtsFiles && sourceFile.isDeclarationFile) { return "continue"; } sourceFile.getNamedDeclarations().forEach(function (declarations, name) { @@ -99032,6 +99109,106 @@ var ts; })(ts || (ts = {})); /* @internal */ var ts; +(function (ts) { + // Sometimes tools can sometimes see the following line as a source mapping url comment, so we mangle it a bit (the [M]) + var sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)\s*$/; + var whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/; + var base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/; + function getSourceMapper(getCanonicalFileName, currentDirectory, log, host, getProgram) { + var sourcemappedFileCache; + return { tryGetOriginalLocation: tryGetOriginalLocation, toLineColumnOffset: toLineColumnOffset, clearCache: clearCache }; + function scanForSourcemapURL(fileName) { + var mappedFile = sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); + if (!mappedFile) { + return; + } + var starts = ts.getLineStarts(mappedFile); + for (var index = starts.length - 1; index >= 0; index--) { + var lineText = mappedFile.text.substring(starts[index], starts[index + 1]); + var comment = sourceMapCommentRegExp.exec(lineText); + if (comment) { + return comment[1]; + } + // If we see a non-whitespace/map comment-like line, break, to avoid scanning up the entire file + else if (!lineText.match(whitespaceOrMapCommentRegExp)) { + break; + } + } + } + function convertDocumentToSourceMapper(file, contents, mapFileName) { + var maps; + try { + maps = JSON.parse(contents); + } + catch (_a) { + // swallow error + } + if (!maps || !maps.sources || !maps.file || !maps.mappings) { + // obviously invalid map + return file.sourceMapper = ts.sourcemaps.identitySourceMapper; + } + return file.sourceMapper = ts.sourcemaps.decode({ + readFile: function (s) { return host.readFile(s); }, + fileExists: function (s) { return host.fileExists(s); }, + getCanonicalFileName: getCanonicalFileName, + log: log, + }, mapFileName, maps, getProgram(), sourcemappedFileCache); + } + function getSourceMapper(fileName, file) { + if (!host.readFile || !host.fileExists) { + return file.sourceMapper = ts.sourcemaps.identitySourceMapper; + } + if (file.sourceMapper) { + return file.sourceMapper; + } + var mapFileName = scanForSourcemapURL(fileName); + if (mapFileName) { + var match = base64UrlRegExp.exec(mapFileName); + if (match) { + if (match[1]) { + var base64Object = match[1]; + return convertDocumentToSourceMapper(file, ts.base64decode(ts.sys, base64Object), fileName); + } + // Not a data URL we can parse, skip it + mapFileName = undefined; + } + } + var possibleMapLocations = []; + if (mapFileName) { + possibleMapLocations.push(mapFileName); + } + possibleMapLocations.push(fileName + ".map"); + for (var _i = 0, possibleMapLocations_1 = possibleMapLocations; _i < possibleMapLocations_1.length; _i++) { + var location = possibleMapLocations_1[_i]; + var mapPath = ts.toPath(location, ts.getDirectoryPath(fileName), getCanonicalFileName); + if (host.fileExists(mapPath)) { + return convertDocumentToSourceMapper(file, host.readFile(mapPath), mapPath); // TODO: GH#18217 + } + } + return file.sourceMapper = ts.sourcemaps.identitySourceMapper; + } + function tryGetOriginalLocation(info) { + if (!ts.isDeclarationFileName(info.fileName)) + return undefined; + var file = getProgram().getSourceFile(info.fileName) || sourcemappedFileCache.get(ts.toPath(info.fileName, currentDirectory, getCanonicalFileName)); + if (!file) + return undefined; + var newLoc = getSourceMapper(info.fileName, file).getOriginalPosition(info); + return newLoc === info ? undefined : tryGetOriginalLocation(newLoc) || newLoc; + } + function toLineColumnOffset(fileName, position) { + var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); + var file = getProgram().getSourceFile(path) || sourcemappedFileCache.get(path); // TODO: GH#18217 + return file.getLineAndCharacterOfPosition(position); + } + function clearCache() { + sourcemappedFileCache = ts.createSourceFileLikeCache(host); + } + } + ts.getSourceMapper = getSourceMapper; +})(ts || (ts = {})); +/* @internal */ +var ts; (function (ts) { function computeSuggestionDiagnostics(sourceFile, program, cancellationToken) { program.getSemanticDiagnostics(sourceFile, cancellationToken); @@ -110871,7 +111048,6 @@ var ts; if (!ts.localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) { ts.localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages(); } - var sourcemappedFileCache; function log(message) { if (host.log) { host.log(message); @@ -110879,6 +111055,7 @@ var ts; } var useCaseSensitiveFileNames = ts.hostUsesCaseSensitiveFileNames(host); var getCanonicalFileName = ts.createGetCanonicalFileName(useCaseSensitiveFileNames); + var sourceMapper = ts.getSourceMapper(getCanonicalFileName, currentDirectory, log, host, function () { return program; }); function getValidSourceFile(fileName) { var sourceFile = program.getSourceFile(fileName); if (!sourceFile) { @@ -110976,7 +111153,7 @@ var ts; // We reset this cache on structure invalidation so we don't hold on to outdated files for long; however we can't use the `compilerHost` above, // Because it only functions until `hostCache` is cleared, while we'll potentially need the functionality to lazily read sourcemap files during // the course of whatever called `synchronizeHostData` - sourcemappedFileCache = ts.createSourceFileLikeCache(host); + sourceMapper.clearCache(); // Make sure all the nodes in the program are both bound, and have their parent // pointers set property. program.getTypeChecker(); @@ -111175,165 +111352,23 @@ var ts; } return checker.getSymbolAtLocation(node); } - function toLineColumnOffset(fileName, position) { - var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); - var file = program.getSourceFile(path) || sourcemappedFileCache.get(path); // TODO: GH#18217 - return file.getLineAndCharacterOfPosition(position); - } - // Sometimes tools can sometimes see the following line as a source mapping url comment, so we mangle it a bit (the [M]) - var sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)$/; - var whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/; - var base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/; - function scanForSourcemapURL(fileName) { - var mappedFile = sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); - if (!mappedFile) { - return; - } - var starts = ts.getLineStarts(mappedFile); - for (var index = starts.length - 1; index >= 0; index--) { - var lineText = mappedFile.text.substring(starts[index], starts[index + 1]); - var comment = sourceMapCommentRegExp.exec(lineText); - if (comment) { - return comment[1]; - } - // If we see a nonwhitespace/map comment-like line, break, to avoid scanning up the entire file - else if (!lineText.match(whitespaceOrMapCommentRegExp)) { - break; - } - } - } - function convertDocumentToSourceMapper(file, contents, mapFileName) { - var maps; - try { - maps = JSON.parse(contents); - } - catch (_a) { - // swallow error - } - if (!maps || !maps.sources || !maps.file || !maps.mappings) { - // obviously invalid map - return file.sourceMapper = ts.sourcemaps.identitySourceMapper; - } - return file.sourceMapper = ts.sourcemaps.decode({ - readFile: function (s) { return host.readFile(s); }, - fileExists: function (s) { return host.fileExists(s); }, - getCanonicalFileName: getCanonicalFileName, - log: log, - }, mapFileName, maps, program, sourcemappedFileCache); - } - function getSourceMapper(fileName, file) { - if (!host.readFile || !host.fileExists) { - return file.sourceMapper = ts.sourcemaps.identitySourceMapper; - } - if (file.sourceMapper) { - return file.sourceMapper; - } - var mapFileName = scanForSourcemapURL(fileName); - if (mapFileName) { - var match = base64UrlRegExp.exec(mapFileName); - if (match) { - if (match[1]) { - var base64Object = match[1]; - return convertDocumentToSourceMapper(file, ts.base64decode(ts.sys, base64Object), fileName); - } - // Not a data URL we can parse, skip it - mapFileName = undefined; - } - } - var possibleMapLocations = []; - if (mapFileName) { - possibleMapLocations.push(mapFileName); - } - possibleMapLocations.push(fileName + ".map"); - for (var _i = 0, possibleMapLocations_1 = possibleMapLocations; _i < possibleMapLocations_1.length; _i++) { - var location = possibleMapLocations_1[_i]; - var mapPath = ts.toPath(location, ts.getDirectoryPath(fileName), getCanonicalFileName); - if (host.fileExists(mapPath)) { - return convertDocumentToSourceMapper(file, host.readFile(mapPath), mapPath); // TODO: GH#18217 - } - } - return file.sourceMapper = ts.sourcemaps.identitySourceMapper; - } - function makeGetTargetOfMappedPosition(extract, create) { - return getTargetOfMappedPosition; - function getTargetOfMappedPosition(input, original) { - if (original === void 0) { original = input; } - var info = extract(input); - if (ts.endsWith(info.fileName, ".d.ts" /* Dts */)) { - var file = program.getSourceFile(info.fileName); - if (!file) { - var path = ts.toPath(info.fileName, currentDirectory, getCanonicalFileName); - file = sourcemappedFileCache.get(path); - } - if (!file) { - return input; - } - var mapper = getSourceMapper(info.fileName, file); - var newLoc = mapper.getOriginalPosition(info); - if (newLoc === info) - return input; - return getTargetOfMappedPosition(create(newLoc, input, original), original); - } - return input; - } - } - var getTargetOfMappedDeclarationInfo = makeGetTargetOfMappedPosition(function (info) { return ({ fileName: info.fileName, position: info.textSpan.start }); }, function (newLoc, info, original) { return ({ - containerKind: info.containerKind, - containerName: info.containerName, - fileName: newLoc.fileName, - kind: info.kind, - name: info.name, - textSpan: { - start: newLoc.position, - length: info.textSpan.length - }, - originalFileName: original.fileName, - originalTextSpan: original.textSpan - }); }); - function getTargetOfMappedDeclarationFiles(infos) { - return ts.map(infos, function (d) { return getTargetOfMappedDeclarationInfo(d); }); - } /// Goto definition function getDefinitionAtPosition(fileName, position) { synchronizeHostData(); - return getTargetOfMappedDeclarationFiles(ts.GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position)); + return ts.GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position); } function getDefinitionAndBoundSpan(fileName, position) { synchronizeHostData(); - var result = ts.GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position); - if (!result) - return result; - var mappedDefs = getTargetOfMappedDeclarationFiles(result.definitions); - if (mappedDefs === result.definitions) { - return result; - } - return { - definitions: mappedDefs, - textSpan: result.textSpan - }; + return ts.GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position); } function getTypeDefinitionAtPosition(fileName, position) { synchronizeHostData(); - return getTargetOfMappedDeclarationFiles(ts.GoToDefinition.getTypeDefinitionAtPosition(program.getTypeChecker(), getValidSourceFile(fileName), position)); + return ts.GoToDefinition.getTypeDefinitionAtPosition(program.getTypeChecker(), getValidSourceFile(fileName), position); } /// Goto implementation - var getTargetOfMappedImplementationLocation = makeGetTargetOfMappedPosition(function (info) { return ({ fileName: info.fileName, position: info.textSpan.start }); }, function (newLoc, info) { return ({ - fileName: newLoc.fileName, - kind: info.kind, - displayParts: info.displayParts, - textSpan: { - start: newLoc.position, - length: info.textSpan.length - }, - originalFileName: info.fileName, - originalTextSpan: info.textSpan - }); }); - function getTargetOfMappedImplementationLocations(infos) { - return ts.map(infos, function (d) { return getTargetOfMappedImplementationLocation(d); }); - } function getImplementationAtPosition(fileName, position) { synchronizeHostData(); - return getTargetOfMappedImplementationLocations(ts.FindAllReferences.getImplementationsAtPosition(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position)); + return ts.FindAllReferences.getImplementationsAtPosition(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position); } /// References and Occurrences function getOccurrencesAtPosition(fileName, position) { @@ -111384,7 +111419,6 @@ var ts; synchronizeHostData(); return ts.FindAllReferences.findReferencedSymbols(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position); } - /// NavigateTo function getNavigateToItems(searchValue, maxResultCount, fileName, excludeDtsFiles) { if (excludeDtsFiles === void 0) { excludeDtsFiles = false; } synchronizeHostData(); @@ -111854,7 +111888,8 @@ var ts; getProgram: getProgram, getApplicableRefactors: getApplicableRefactors, getEditsForRefactor: getEditsForRefactor, - toLineColumnOffset: toLineColumnOffset + toLineColumnOffset: sourceMapper.toLineColumnOffset, + getSourceMapper: function () { return sourceMapper; }, }; } ts.createLanguageService = createLanguageService; diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 3e74564a556..cf1830681a1 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -21885,9 +21885,11 @@ var ts; InvalidPosition[InvalidPosition["Value"] = -1] = "Value"; })(InvalidPosition || (InvalidPosition = {})); })(IncrementalParser || (IncrementalParser = {})); + /** @internal */ function isDeclarationFileName(fileName) { return ts.fileExtensionIs(fileName, ".d.ts" /* Dts */); } + ts.isDeclarationFileName = isDeclarationFileName; /*@internal*/ function processCommentPragmas(context, sourceText) { var triviaScanner = ts.createScanner(context.languageVersion, /*skipTrivia*/ false, 0 /* Standard */, sourceText); @@ -29659,7 +29661,7 @@ var ts; TypeSystemPropertyName[TypeSystemPropertyName["ResolvedBaseConstructorType"] = 1] = "ResolvedBaseConstructorType"; TypeSystemPropertyName[TypeSystemPropertyName["DeclaredType"] = 2] = "DeclaredType"; TypeSystemPropertyName[TypeSystemPropertyName["ResolvedReturnType"] = 3] = "ResolvedReturnType"; - TypeSystemPropertyName[TypeSystemPropertyName["ResolvedBaseConstraint"] = 4] = "ResolvedBaseConstraint"; + TypeSystemPropertyName[TypeSystemPropertyName["ImmediateBaseConstraint"] = 4] = "ImmediateBaseConstraint"; })(TypeSystemPropertyName || (TypeSystemPropertyName = {})); var CheckMode; (function (CheckMode) { @@ -31366,17 +31368,25 @@ var ts; * Attempts to find the symbol corresponding to the container a symbol is in - usually this * is just its' `.parent`, but for locals, this value is `undefined` */ - function getContainerOfSymbol(symbol) { + function getContainersOfSymbol(symbol, enclosingDeclaration) { var container = getParentOfSymbol(symbol); if (container) { - return container; + var additionalContainers = ts.mapDefined(container.declarations, fileSymbolIfFileSymbolExportEqualsContainer); + if (enclosingDeclaration && getAccessibleSymbolChain(container, enclosingDeclaration, 1920 /* Namespace */, /*externalOnly*/ false)) { + return ts.concatenate([container], additionalContainers); // This order expresses a preference for the real container if it is in scope + } + return ts.append(additionalContainers, container); } - var candidate = ts.forEach(symbol.declarations, function (d) { return !ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined; }); - if (!candidate) { + var candidates = ts.mapDefined(symbol.declarations, function (d) { return !ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined; }); + if (!ts.length(candidates)) { return undefined; } - var alias = getAliasForSymbolInContainer(candidate, symbol); - return alias ? candidate : undefined; + return ts.mapDefined(candidates, function (candidate) { return getAliasForSymbolInContainer(candidate, symbol) ? candidate : undefined; }); + function fileSymbolIfFileSymbolExportEqualsContainer(d) { + var fileSymbol = getExternalModuleContainer(d); + var exported = fileSymbol && fileSymbol.exports && fileSymbol.exports.get("export=" /* ExportEquals */); + return resolveSymbol(exported) === resolveSymbol(container) ? fileSymbol : undefined; + } } function getAliasForSymbolInContainer(container, symbol) { if (container === getParentOfSymbol(symbol)) { @@ -31627,6 +31637,54 @@ var ts; var access = isSymbolAccessible(typeSymbol, enclosingDeclaration, 67216319 /* Value */, /*shouldComputeAliasesToMakeVisible*/ false); return access.accessibility === 0 /* Accessible */; } + function isAnySymbolAccessible(symbols, enclosingDeclaration, initialSymbol, meaning, shouldComputeAliasesToMakeVisible) { + if (!ts.length(symbols)) + return; + var hadAccessibleChain; + for (var _i = 0, _a = symbols; _i < _a.length; _i++) { + var symbol = _a[_i]; + // Symbol is accessible if it by itself is accessible + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, /*useOnlyExternalAliasing*/ false); + if (accessibleSymbolChain) { + hadAccessibleChain = symbol; + var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible); + if (hasAccessibleDeclarations) { + return hasAccessibleDeclarations; + } + } + else { + if (ts.some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + // Any meaning of a module symbol is always accessible via an `import` type + return { + accessibility: 0 /* Accessible */ + }; + } + } + // If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible. + // It could be a qualified symbol and hence verify the path + // e.g.: + // module m { + // export class c { + // } + // } + // const x: typeof m.c + // In the above example when we start with checking if typeof m.c symbol is accessible, + // we are going to see if c can be accessed in scope directly. + // But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible + // It is accessible if the parent m is accessible because then m.c can be accessed through qualification + var parentResult = isAnySymbolAccessible(getContainersOfSymbol(symbol, enclosingDeclaration), enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible); + if (parentResult) { + return parentResult; + } + } + if (hadAccessibleChain) { + return { + accessibility: 1 /* NotAccessible */, + errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorModuleName: hadAccessibleChain !== initialSymbol ? symbolToString(hadAccessibleChain, enclosingDeclaration, 1920 /* Namespace */) : undefined, + }; + } + } /** * Check if the given symbol in given enclosing declaration is accessible and mark all associated alias to be visible if requested * @@ -31637,55 +31695,20 @@ var ts; */ function isSymbolAccessible(symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible) { if (symbol && enclosingDeclaration) { - var initialSymbol = symbol; - var meaningToLook = meaning; - while (symbol) { - // Symbol is accessible if it by itself is accessible - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false); - if (accessibleSymbolChain) { - var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible); - if (!hasAccessibleDeclarations) { - return { - accessibility: 1 /* NotAccessible */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), - errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, 1920 /* Namespace */) : undefined, - }; - } - return hasAccessibleDeclarations; - } - else { - if (ts.some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { - // Any meaning of a module symbol is always accessible via an `import` type - return { - accessibility: 0 /* Accessible */ - }; - } - } - // If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible. - // It could be a qualified symbol and hence verify the path - // e.g.: - // module m { - // export class c { - // } - // } - // const x: typeof m.c - // In the above example when we start with checking if typeof m.c symbol is accessible, - // we are going to see if c can be accessed in scope directly. - // But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible - // It is accessible if the parent m is accessible because then m.c can be accessed through qualification - meaningToLook = getQualifiedLeftMeaning(meaning); - symbol = getContainerOfSymbol(symbol); + var result = isAnySymbolAccessible([symbol], enclosingDeclaration, symbol, meaning, shouldComputeAliasesToMakeVisible); + if (result) { + return result; } // This could be a symbol that is not exported in the external module // or it could be a symbol from different external module that is not aliased and hence cannot be named - var symbolExternalModule = ts.forEach(initialSymbol.declarations, getExternalModuleContainer); + var symbolExternalModule = ts.forEach(symbol.declarations, getExternalModuleContainer); if (symbolExternalModule) { var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration); if (symbolExternalModule !== enclosingExternalModule) { // name from different external module that is not visible return { accessibility: 2 /* CannotBeNamed */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), errorModuleName: symbolToString(symbolExternalModule) }; } @@ -31693,14 +31716,14 @@ var ts; // Just a local name that is not accessible return { accessibility: 1 /* NotAccessible */, - errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), }; } return { accessibility: 0 /* Accessible */ }; - function getExternalModuleContainer(declaration) { - var node = ts.findAncestor(declaration, hasExternalModuleSymbol); - return node && getSymbolOfNode(node); - } + } + function getExternalModuleContainer(declaration) { + var node = ts.findAncestor(declaration, hasExternalModuleSymbol); + return node && getSymbolOfNode(node); } function hasExternalModuleSymbol(declaration) { return ts.isAmbientModule(declaration) || (declaration.kind === 277 /* SourceFile */ && ts.isExternalOrCommonJsModule(declaration)); @@ -32477,16 +32500,18 @@ var ts; /** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */ function getSymbolChain(symbol, meaning, endOfChain) { var accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, !!(context.flags & 128 /* UseOnlyExternalAliasing */)); - var parentSymbol; if (!accessibleSymbolChain || needsQualification(accessibleSymbolChain[0], context.enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { // Go up and add our parent. - var parent = getContainerOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol); - if (parent) { - var parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); - if (parentChain) { - parentSymbol = parent; - accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); + var parents = getContainersOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol, context.enclosingDeclaration); + if (ts.length(parents)) { + for (var _i = 0, _a = parents; _i < _a.length; _i++) { + var parent = _a[_i]; + var parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); + if (parentChain) { + accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); + break; + } } } } @@ -32496,10 +32521,12 @@ var ts; if ( // If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols. endOfChain || + // If a parent symbol is an anonymous type, don't write it. + !(symbol.flags & (2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */))) { // If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.) - (yieldModuleSymbol || !(!parentSymbol && ts.forEach(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol))) && - // If a parent symbol is an anonymous type, don't write it. - !(symbol.flags & (2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */))) { + if (!endOfChain && !yieldModuleSymbol && !!ts.forEach(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + return; + } return [symbol]; } } @@ -32993,8 +33020,8 @@ var ts; if (propertyName === 3 /* ResolvedReturnType */) { return !!target.resolvedReturnType; } - if (propertyName === 4 /* ResolvedBaseConstraint */) { - var bc = target.resolvedBaseConstraint; + if (propertyName === 4 /* ImmediateBaseConstraint */) { + var bc = target.immediateBaseConstraint; return !!bc && bc !== circularConstraintType; } return ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); @@ -35427,15 +35454,21 @@ var ts; } return type.resolvedBaseConstraint; function getBaseConstraint(t) { - if (!pushTypeResolution(t, 4 /* ResolvedBaseConstraint */)) { + if (t.immediateBaseConstraint) { + return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint; + } + if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { circular = true; + t.immediateBaseConstraint = circularConstraintType; return undefined; } var result = computeBaseConstraint(getSimplifiedType(t)); if (!popTypeResolution()) { circular = true; + t.immediateBaseConstraint = circularConstraintType; return undefined; } + t.immediateBaseConstraint = !result ? noConstraintType : result; return result; } function computeBaseConstraint(t) { @@ -84151,7 +84184,8 @@ var ts; } ts.parseConfigHostFromCompilerHost = parseConfigHostFromCompilerHost; /** - * Returns the target config filename of a project reference + * Returns the target config filename of a project reference. + * Note: The file might not exist. */ function resolveProjectReferencePath(host, ref) { if (!host.fileExists(ref.path)) {