:
- // "A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeroes."
- var rgx = isPrerelease ? prereleaseSemverRegex : semverRegex;
- var match = rgx.exec(semver);
- return match ? new Semver(stringToInt(match[1]), stringToInt(match[2]), stringToInt(match[3]), isPrerelease) : undefined;
- };
- Object.defineProperty(Semver.prototype, "versionString", {
- get: function () {
- return this.isPrerelease ? this.major + "." + this.minor + ".0-next." + this.patch : this.major + "." + this.minor + "." + this.patch;
- },
- enumerable: true,
- configurable: true
- });
- Semver.prototype.equals = function (sem) {
- return this.major === sem.major && this.minor === sem.minor && this.patch === sem.patch && this.isPrerelease === sem.isPrerelease;
- };
- Semver.prototype.greaterThan = function (sem) {
- return this.major > sem.major || this.major === sem.major
- && (this.minor > sem.minor || this.minor === sem.minor
- && (!this.isPrerelease && sem.isPrerelease || this.isPrerelease === sem.isPrerelease
- && this.patch > sem.patch));
- };
- return Semver;
- }());
- ts.Semver = Semver;
-})(ts || (ts = {}));
var ts;
(function (ts) {
var ScriptSnapshot;
@@ -89104,6 +91057,30 @@ var ts;
IndentStyle[IndentStyle["Block"] = 1] = "Block";
IndentStyle[IndentStyle["Smart"] = 2] = "Smart";
})(IndentStyle = ts.IndentStyle || (ts.IndentStyle = {}));
+ /* @internal */
+ ts.testFormatSettings = {
+ baseIndentSize: 0,
+ indentSize: 4,
+ tabSize: 4,
+ newLineCharacter: "\n",
+ convertTabsToSpaces: true,
+ indentStyle: IndentStyle.Smart,
+ insertSpaceAfterCommaDelimiter: true,
+ insertSpaceAfterSemicolonInForStatements: true,
+ insertSpaceBeforeAndAfterBinaryOperators: true,
+ insertSpaceAfterConstructor: false,
+ insertSpaceAfterKeywordsInControlFlowStatements: true,
+ insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
+ insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
+ insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
+ insertSpaceAfterTypeAssertion: false,
+ placeOpenBraceOnNewLineForFunctions: false,
+ placeOpenBraceOnNewLineForControlBlocks: false,
+ insertSpaceBeforeTypeAnnotation: false
+ };
var SymbolDisplayPartKind;
(function (SymbolDisplayPartKind) {
SymbolDisplayPartKind[SymbolDisplayPartKind["aliasName"] = 0] = "aliasName";
@@ -89319,8 +91296,9 @@ var ts;
})(SemanticMeaning = ts.SemanticMeaning || (ts.SemanticMeaning = {}));
function getMeaningFromDeclaration(node) {
switch (node.kind) {
- case 149 /* Parameter */:
case 235 /* VariableDeclaration */:
+ return ts.isInJSFile(node) && ts.getJSDocEnumTag(node) ? 7 /* All */ : 1 /* Value */;
+ case 149 /* Parameter */:
case 184 /* BindingElement */:
case 152 /* PropertyDeclaration */:
case 151 /* PropertySignature */:
@@ -89377,7 +91355,7 @@ var ts;
if (node.kind === 277 /* SourceFile */) {
return 1 /* Value */;
}
- else if (node.parent.kind === 252 /* ExportAssignment */) {
+ else if (node.parent.kind === 252 /* ExportAssignment */ || node.parent.kind === 257 /* ExternalModuleReference */) {
return 7 /* All */;
}
else if (isInRightSideOfInternalImportEqualsDeclaration(node)) {
@@ -89499,6 +91477,13 @@ var ts;
return undefined;
}
ts.getTargetLabel = getTargetLabel;
+ function hasPropertyAccessExpressionWithName(node, funcName) {
+ if (!ts.isPropertyAccessExpression(node.expression)) {
+ return false;
+ }
+ return node.expression.name.text === funcName;
+ }
+ ts.hasPropertyAccessExpressionWithName = hasPropertyAccessExpressionWithName;
function isJumpStatementTarget(node) {
return node.kind === 71 /* Identifier */ && ts.isBreakOrContinueStatement(node.parent) && node.parent.label === node;
}
@@ -89629,7 +91614,7 @@ var ts;
case 249 /* NamespaceImport */:
return "alias" /* alias */;
case 202 /* BinaryExpression */:
- var kind = ts.getSpecialPropertyAssignmentKind(node);
+ var kind = ts.getAssignmentDeclarationKind(node);
var right = node.right;
switch (kind) {
case 0 /* None */:
@@ -89993,7 +91978,7 @@ var ts;
ts.Debug.assert(!(result && isWhiteSpaceOnlyJsxText(result)));
return result;
function find(n) {
- if (isNonWhitespaceToken(n)) {
+ if (isNonWhitespaceToken(n) && n.kind !== 1 /* EndOfFileToken */) {
return n;
}
var children = n.getChildren(sourceFile);
@@ -90011,8 +91996,8 @@ var ts;
isWhiteSpaceOnlyJsxText(child);
if (lookInPreviousChild) {
// actual start of the node is past the position - previous token should be at the end of previous child
- var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile);
- return candidate && findRightmostToken(candidate, sourceFile);
+ var candidate_2 = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile);
+ return candidate_2 && findRightmostToken(candidate_2, sourceFile);
}
else {
// candidate should be in this node
@@ -90020,15 +92005,13 @@ var ts;
}
}
}
- ts.Debug.assert(startNode !== undefined || n.kind === 277 /* SourceFile */ || ts.isJSDocCommentContainingNode(n));
+ ts.Debug.assert(startNode !== undefined || n.kind === 277 /* SourceFile */ || n.kind === 1 /* EndOfFileToken */ || ts.isJSDocCommentContainingNode(n));
// Here we know that none of child token nodes embrace the position,
// the only known case is when position is at the end of the file.
// Try to find the rightmost token in the file without filtering.
// Namely we are skipping the check: 'position < node.end'
- if (children.length) {
- var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
- return candidate && findRightmostToken(candidate, sourceFile);
- }
+ var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
+ return candidate && findRightmostToken(candidate, sourceFile);
}
}
ts.findPrecedingToken = findPrecedingToken;
@@ -90250,7 +92233,7 @@ var ts;
function nodeHasTokens(n, sourceFile) {
// If we have a token or node that has a non-zero width, it must have tokens.
// Note: getWidth() does not take trivia into account.
- return n.getWidth(sourceFile) !== 0;
+ return n.kind === 1 /* EndOfFileToken */ ? !!n.jsDoc : n.getWidth(sourceFile) !== 0;
}
function getNodeModifiers(node) {
var flags = ts.isDeclaration(node) ? ts.getCombinedModifierFlags(node) : 0 /* None */;
@@ -90364,7 +92347,7 @@ var ts;
}
ts.createTextSpanFromNode = createTextSpanFromNode;
function createTextRangeFromNode(node, sourceFile) {
- return ts.createTextRange(node.getStart(sourceFile), node.end);
+ return ts.createRange(node.getStart(sourceFile), node.end);
}
ts.createTextRangeFromNode = createTextRangeFromNode;
function createTextSpanFromRange(range) {
@@ -90372,7 +92355,7 @@ var ts;
}
ts.createTextSpanFromRange = createTextSpanFromRange;
function createTextRangeFromSpan(span) {
- return ts.createTextRange(span.start, span.start + span.length);
+ return ts.createRange(span.start, span.start + span.length);
}
ts.createTextRangeFromSpan = createTextRangeFromSpan;
function createTextChangeFromStartLength(start, length, newText) {
@@ -90514,6 +92497,13 @@ var ts;
});
}
ts.symbolEscapedNameNoDefault = symbolEscapedNameNoDefault;
+ function isObjectBindingElementWithoutPropertyName(bindingElement) {
+ return ts.isBindingElement(bindingElement) &&
+ ts.isObjectBindingPattern(bindingElement.parent) &&
+ ts.isIdentifier(bindingElement.name) &&
+ !bindingElement.propertyName;
+ }
+ ts.isObjectBindingElementWithoutPropertyName = isObjectBindingElementWithoutPropertyName;
function getPropertySymbolFromBindingElement(checker, bindingElement) {
var typeOfPattern = checker.getTypeAtLocation(bindingElement.parent);
var propSymbol = typeOfPattern && checker.getPropertyOfType(typeOfPattern, bindingElement.name.text);
@@ -90883,7 +92873,7 @@ var ts;
function getSynthesizedDeepCloneWithRenames(node, includeTrivia, renameMap, checker, callback) {
if (includeTrivia === void 0) { includeTrivia = true; }
var clone;
- if (node && ts.isIdentifier(node) && renameMap && checker) {
+ if (ts.isIdentifier(node) && renameMap && checker) {
var symbol = checker.getSymbolAtLocation(node);
var renameInfo = symbol && renameMap.get(String(ts.getSymbolId(symbol)));
if (renameInfo) {
@@ -90891,11 +92881,11 @@ var ts;
}
}
if (!clone) {
- clone = node && getSynthesizedDeepCloneWorker(node, renameMap, checker, callback);
+ clone = getSynthesizedDeepCloneWorker(node, renameMap, checker, callback);
}
if (clone && !includeTrivia)
suppressLeadingAndTrailingTrivia(clone);
- if (callback && node)
+ if (callback && clone)
callback(node, clone);
return clone;
}
@@ -90906,14 +92896,14 @@ var ts;
ts.visitEachChild(node, getSynthesizedDeepClone, ts.nullTransformationContext);
if (visited === node) {
// This only happens for leaf nodes - internal nodes always see their children change.
- var clone_7 = ts.getSynthesizedClone(node);
- if (ts.isStringLiteral(clone_7)) {
- clone_7.textSourceNode = node;
+ var clone_8 = ts.getSynthesizedClone(node);
+ if (ts.isStringLiteral(clone_8)) {
+ clone_8.textSourceNode = node;
}
- else if (ts.isNumericLiteral(clone_7)) {
- clone_7.numericLiteralFlags = node.numericLiteralFlags;
+ else if (ts.isNumericLiteral(clone_8)) {
+ clone_8.numericLiteralFlags = node.numericLiteralFlags;
}
- return ts.setTextRange(clone_7, node);
+ return ts.setTextRange(clone_8, node);
}
// PERF: As an optimization, rather than calling getSynthesizedClone, we'll update
// the new node created by visitEachChild with the extra changes getSynthesizedClone
@@ -91273,7 +93263,7 @@ var ts;
var lastEnd = 0;
for (var i = 0; i < dense.length; i += 3) {
var start = dense[i];
- var length_6 = dense[i + 1];
+ var length_5 = dense[i + 1];
var type = dense[i + 2];
// Make a whitespace entry between the last item and this one.
if (lastEnd >= 0) {
@@ -91282,8 +93272,8 @@ var ts;
entries.push({ length: whitespaceLength_1, classification: ts.TokenClass.Whitespace });
}
}
- entries.push({ length: length_6, classification: convertClassification(type) });
- lastEnd = start + length_6;
+ entries.push({ length: length_5, classification: convertClassification(type) });
+ lastEnd = start + length_5;
}
var whitespaceLength = text.length - lastEnd;
if (whitespaceLength > 0) {
@@ -92040,9 +94030,42 @@ var ts;
}
}
}
+ // check for a version redirect
+ var packageJsonPath = findPackageJson(baseDirectory, host);
+ if (packageJsonPath) {
+ var packageJson = ts.readJson(packageJsonPath, host);
+ var typesVersions = packageJson.typesVersions;
+ if (typeof typesVersions === "object") {
+ var versionResult = ts.getPackageJsonTypesVersionsPaths(typesVersions);
+ var versionPaths = versionResult && versionResult.paths;
+ var rest = absolutePath.slice(ts.ensureTrailingDirectorySeparator(baseDirectory).length);
+ if (versionPaths) {
+ addCompletionEntriesFromPaths(result, rest, baseDirectory, extensions, versionPaths, host);
+ }
+ }
+ }
}
return result;
}
+ function addCompletionEntriesFromPaths(result, fragment, baseDirectory, fileExtensions, paths, host) {
+ for (var path in paths) {
+ if (!ts.hasProperty(paths, path))
+ continue;
+ var patterns = paths[path];
+ if (patterns) {
+ var _loop_10 = function (name, kind) {
+ // Path mappings may provide a duplicate way to get to something we've already added, so don't add again.
+ if (!result.some(function (entry) { return entry.name === name; })) {
+ result.push(nameAndKind(name, kind));
+ }
+ };
+ for (var _i = 0, _a = getCompletionsForPathMapping(path, patterns, fragment, baseDirectory, fileExtensions, host); _i < _a.length; _i++) {
+ var _b = _a[_i], name = _b.name, kind = _b.kind;
+ _loop_10(name, kind);
+ }
+ }
+ }
+ }
/**
* Check all of the declared modules and those in node modules. Possible sources of modules:
* Modules that are found by the type checker
@@ -92056,27 +94079,15 @@ var ts;
var fileExtensions = getSupportedExtensionsForModuleResolution(compilerOptions);
if (baseUrl) {
var projectDir = compilerOptions.project || host.getCurrentDirectory();
- var absolute = ts.isRootedDiskPath(baseUrl) ? baseUrl : ts.combinePaths(projectDir, baseUrl);
- getCompletionEntriesForDirectoryFragment(fragment, ts.normalizePath(absolute), fileExtensions, /*includeExtensions*/ false, host, /*exclude*/ undefined, result);
- for (var path in paths) {
- var patterns = paths[path];
- if (paths.hasOwnProperty(path) && patterns) {
- var _loop_11 = function (name, kind) {
- // Path mappings may provide a duplicate way to get to something we've already added, so don't add again.
- if (!result.some(function (entry) { return entry.name === name; })) {
- result.push(nameAndKind(name, kind));
- }
- };
- for (var _i = 0, _a = getCompletionsForPathMapping(path, patterns, fragment, baseUrl, fileExtensions, host); _i < _a.length; _i++) {
- var _b = _a[_i], name = _b.name, kind = _b.kind;
- _loop_11(name, kind);
- }
- }
+ var absolute = ts.normalizePath(ts.combinePaths(projectDir, baseUrl));
+ getCompletionEntriesForDirectoryFragment(fragment, absolute, fileExtensions, /*includeExtensions*/ false, host, /*exclude*/ undefined, result);
+ if (paths) {
+ addCompletionEntriesFromPaths(result, fragment, absolute, fileExtensions, paths, host);
}
}
var fragmentDirectory = containsSlash(fragment) ? ts.hasTrailingDirectorySeparator(fragment) ? fragment : ts.getDirectoryPath(fragment) : undefined;
- for (var _c = 0, _d = getAmbientModuleCompletions(fragment, fragmentDirectory, typeChecker); _c < _d.length; _c++) {
- var ambientName = _d[_c];
+ for (var _i = 0, _a = getAmbientModuleCompletions(fragment, fragmentDirectory, typeChecker); _i < _a.length; _i++) {
+ var ambientName = _a[_i];
result.push(nameAndKind(ambientName, "external module name" /* externalModuleName */));
}
getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, result);
@@ -92085,15 +94096,15 @@ var ts;
// (But do if we didn't find anything, e.g. 'package.json' missing.)
var foundGlobal = false;
if (fragmentDirectory === undefined) {
- var _loop_12 = function (moduleName) {
+ var _loop_11 = function (moduleName) {
if (!result.some(function (entry) { return entry.name === moduleName; })) {
foundGlobal = true;
result.push(nameAndKind(moduleName, "external module name" /* externalModuleName */));
}
};
- for (var _e = 0, _f = enumerateNodeModulesVisibleToScript(host, scriptPath); _e < _f.length; _e++) {
- var moduleName = _f[_e];
- _loop_12(moduleName);
+ for (var _b = 0, _c = enumerateNodeModulesVisibleToScript(host, scriptPath); _b < _c.length; _b++) {
+ var moduleName = _c[_b];
+ _loop_11(moduleName);
}
}
if (!foundGlobal) {
@@ -92202,7 +94213,7 @@ var ts;
if (options.types) {
for (var _i = 0, _a = options.types; _i < _a.length; _i++) {
var typesName = _a[_i];
- var moduleName = ts.getUnmangledNameForScopedPackage(typesName);
+ var moduleName = ts.unmangleScopedPackageName(typesName);
pushResult(moduleName);
}
}
@@ -92235,7 +94246,7 @@ var ts;
var typeDirectory = directories_2[_i];
typeDirectory = ts.normalizePath(typeDirectory);
var directoryName = ts.getBaseFileName(typeDirectory);
- var moduleName = ts.getUnmangledNameForScopedPackage(directoryName);
+ var moduleName = ts.unmangleScopedPackageName(directoryName);
pushResult(moduleName);
}
}
@@ -92259,6 +94270,18 @@ var ts;
});
return paths;
}
+ function findPackageJson(directory, host) {
+ var packageJson;
+ ts.forEachAncestorDirectory(directory, function (ancestor) {
+ if (ancestor === "node_modules")
+ return true;
+ packageJson = ts.findConfigFile(ancestor, function (f) { return tryFileExists(host, f); }, "package.json");
+ if (packageJson) {
+ return true; // break out
+ }
+ });
+ return packageJson;
+ }
function enumerateNodeModulesVisibleToScript(host, scriptPath) {
if (!host.readFile || !host.fileExists)
return ts.emptyArray;
@@ -92366,11 +94389,12 @@ var ts;
var KeywordCompletionFilters;
(function (KeywordCompletionFilters) {
KeywordCompletionFilters[KeywordCompletionFilters["None"] = 0] = "None";
- KeywordCompletionFilters[KeywordCompletionFilters["ClassElementKeywords"] = 1] = "ClassElementKeywords";
- KeywordCompletionFilters[KeywordCompletionFilters["InterfaceElementKeywords"] = 2] = "InterfaceElementKeywords";
- KeywordCompletionFilters[KeywordCompletionFilters["ConstructorParameterKeywords"] = 3] = "ConstructorParameterKeywords";
- KeywordCompletionFilters[KeywordCompletionFilters["FunctionLikeBodyKeywords"] = 4] = "FunctionLikeBodyKeywords";
- KeywordCompletionFilters[KeywordCompletionFilters["TypeKeywords"] = 5] = "TypeKeywords";
+ KeywordCompletionFilters[KeywordCompletionFilters["All"] = 1] = "All";
+ KeywordCompletionFilters[KeywordCompletionFilters["ClassElementKeywords"] = 2] = "ClassElementKeywords";
+ KeywordCompletionFilters[KeywordCompletionFilters["InterfaceElementKeywords"] = 3] = "InterfaceElementKeywords";
+ KeywordCompletionFilters[KeywordCompletionFilters["ConstructorParameterKeywords"] = 4] = "ConstructorParameterKeywords";
+ KeywordCompletionFilters[KeywordCompletionFilters["FunctionLikeBodyKeywords"] = 5] = "FunctionLikeBodyKeywords";
+ KeywordCompletionFilters[KeywordCompletionFilters["TypeKeywords"] = 6] = "TypeKeywords";
})(KeywordCompletionFilters || (KeywordCompletionFilters = {}));
var GlobalsSearch;
(function (GlobalsSearch) {
@@ -92386,7 +94410,7 @@ var ts;
return entries && convertPathCompletions(entries);
}
var contextToken = ts.findPrecedingToken(position, sourceFile);
- if (triggerCharacter && (!contextToken || !isValidTrigger(sourceFile, triggerCharacter, contextToken, position)))
+ if (triggerCharacter && !isValidTrigger(sourceFile, triggerCharacter, contextToken, position))
return undefined;
if (ts.isInString(sourceFile, position, contextToken)) {
return !contextToken || !ts.isStringLiteralLike(contextToken)
@@ -92471,7 +94495,7 @@ var ts;
var entries = [];
if (isUncheckedFile(sourceFile, compilerOptions)) {
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries, location, sourceFile, typeChecker, compilerOptions.target, log, completionKind, preferences, propertyAccessToConvert, isJsxInitializer, recommendedCompletion, symbolToOriginInfoMap);
- getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames, compilerOptions.target, entries); // TODO: GH#18217
+ getJSCompletionEntries(sourceFile, location.pos, uniqueNames, compilerOptions.target, entries); // TODO: GH#18217
}
else {
if ((!symbols || symbols.length === 0) && keywordFilters === 0 /* None */) {
@@ -92479,22 +94503,23 @@ var ts;
}
getCompletionEntriesFromSymbols(symbols, entries, location, sourceFile, typeChecker, compilerOptions.target, log, completionKind, preferences, propertyAccessToConvert, isJsxInitializer, recommendedCompletion, symbolToOriginInfoMap);
}
- // TODO add filter for keyword based on type/value/namespace and also location
- // Add all keywords if
- // - this is not a member completion list (all the keywords)
- // - other filters are enabled in required scenario so add those keywords
- var isMemberCompletion = isMemberCompletionKind(completionKind);
- if (keywordFilters !== 0 /* None */ || !isMemberCompletion) {
- ts.addRange(entries, getKeywordCompletions(keywordFilters));
+ if (keywordFilters !== 0 /* None */) {
+ var entryNames = ts.arrayToSet(entries, function (e) { return e.name; });
+ for (var _i = 0, _a = getKeywordCompletions(keywordFilters); _i < _a.length; _i++) {
+ var keywordEntry = _a[_i];
+ if (!entryNames.has(keywordEntry.name)) {
+ entries.push(keywordEntry);
+ }
+ }
}
- for (var _i = 0, literals_1 = literals; _i < literals_1.length; _i++) {
- var literal = literals_1[_i];
+ for (var _b = 0, literals_1 = literals; _b < literals_1.length; _b++) {
+ var literal = literals_1[_b];
entries.push(createCompletionEntryForLiteral(literal));
}
- return { isGlobalCompletion: isInSnippetScope, isMemberCompletion: isMemberCompletion, isNewIdentifierLocation: isNewIdentifierLocation, entries: entries };
+ return { isGlobalCompletion: isInSnippetScope, isMemberCompletion: isMemberCompletionKind(completionKind), isNewIdentifierLocation: isNewIdentifierLocation, entries: entries };
}
function isUncheckedFile(sourceFile, compilerOptions) {
- return ts.isSourceFileJavaScript(sourceFile) && !ts.isCheckJsEnabledForFile(sourceFile, compilerOptions);
+ return ts.isSourceFileJS(sourceFile) && !ts.isCheckJsEnabledForFile(sourceFile, compilerOptions);
}
function isMemberCompletionKind(kind) {
switch (kind) {
@@ -92506,14 +94531,14 @@ var ts;
return false;
}
}
- function getJavaScriptCompletionEntries(sourceFile, position, uniqueNames, target, entries) {
+ function getJSCompletionEntries(sourceFile, position, uniqueNames, target, entries) {
ts.getNameTable(sourceFile).forEach(function (pos, name) {
// Skip identifiers produced only from the current location
if (pos === position) {
return;
}
var realName = ts.unescapeLeadingUnderscores(name);
- if (ts.addToSeen(uniqueNames, realName) && ts.isIdentifierText(realName, target) && !ts.isStringANonContextualKeyword(realName)) {
+ if (ts.addToSeen(uniqueNames, realName) && ts.isIdentifierText(realName, target)) {
entries.push({
name: realName,
kind: "warning" /* warning */,
@@ -92578,6 +94603,9 @@ var ts;
};
}
function quote(text, preferences) {
+ if (/^\d+$/.test(text)) {
+ return text;
+ }
var quoted = JSON.stringify(text);
switch (preferences.quotePreference) {
case undefined:
@@ -92663,11 +94691,12 @@ var ts;
StringLiteralCompletionKind[StringLiteralCompletionKind["Types"] = 2] = "Types";
})(StringLiteralCompletionKind || (StringLiteralCompletionKind = {}));
function getStringLiteralCompletionEntries(sourceFile, node, position, typeChecker, compilerOptions, host) {
- switch (node.parent.kind) {
+ var parent = node.parent;
+ switch (parent.kind) {
case 180 /* LiteralType */:
- switch (node.parent.parent.kind) {
+ switch (parent.parent.kind) {
case 162 /* TypeReference */:
- return { kind: 2 /* Types */, types: getStringLiteralTypes(typeChecker.getTypeArgumentConstraint(node.parent)), isNewIdentifier: false };
+ return { kind: 2 /* Types */, types: getStringLiteralTypes(typeChecker.getTypeArgumentConstraint(parent)), isNewIdentifier: false };
case 178 /* IndexedAccessType */:
// Get all apparent property names
// i.e. interface Foo {
@@ -92675,16 +94704,21 @@ var ts;
// bar: string;
// }
// let x: Foo["/*completion position*/"]
- return stringLiteralCompletionsFromProperties(typeChecker.getTypeFromTypeNode(node.parent.parent.objectType));
+ return stringLiteralCompletionsFromProperties(typeChecker.getTypeFromTypeNode(parent.parent.objectType));
case 181 /* ImportType */:
return { kind: 0 /* Paths */, paths: Completions.PathCompletions.getStringLiteralCompletionsFromModuleNames(sourceFile, node, compilerOptions, host, typeChecker) };
- case 171 /* UnionType */:
- return ts.isTypeReferenceNode(node.parent.parent.parent) ? { kind: 2 /* Types */, types: getStringLiteralTypes(typeChecker.getTypeArgumentConstraint(node.parent.parent)), isNewIdentifier: false } : undefined;
+ case 171 /* UnionType */: {
+ if (!ts.isTypeReferenceNode(parent.parent.parent))
+ return undefined;
+ var alreadyUsedTypes_1 = getAlreadyUsedTypesInStringLiteralUnion(parent.parent, parent);
+ var types = getStringLiteralTypes(typeChecker.getTypeArgumentConstraint(parent.parent)).filter(function (t) { return !ts.contains(alreadyUsedTypes_1, t.value); });
+ return { kind: 2 /* Types */, types: types, isNewIdentifier: false };
+ }
default:
return undefined;
}
case 273 /* PropertyAssignment */:
- if (ts.isObjectLiteralExpression(node.parent.parent) && node.parent.name === node) {
+ if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
// Get quoted name of properties of the object literal expression
// i.e. interface ConfigFiles {
// 'jspm:dev': string
@@ -92697,11 +94731,11 @@ var ts;
// foo({
// '/*completion position*/'
// });
- return stringLiteralCompletionsFromProperties(typeChecker.getContextualType(node.parent.parent));
+ return stringLiteralCompletionsFromProperties(typeChecker.getContextualType(parent.parent));
}
return fromContextualType();
case 188 /* ElementAccessExpression */: {
- var _a = node.parent, expression = _a.expression, argumentExpression = _a.argumentExpression;
+ var _a = parent, expression = _a.expression, argumentExpression = _a.argumentExpression;
if (node === argumentExpression) {
// Get all names of properties on the expression
// i.e. interface A {
@@ -92715,7 +94749,7 @@ var ts;
}
case 189 /* CallExpression */:
case 190 /* NewExpression */:
- if (!ts.isRequireCall(node.parent, /*checkArgumentIsStringLiteralLike*/ false) && !ts.isImportCall(node.parent)) {
+ if (!ts.isRequireCall(parent, /*checkArgumentIsStringLiteralLike*/ false) && !ts.isImportCall(parent)) {
var argumentInfo = ts.SignatureHelp.getArgumentInfoForCompletions(node, position, sourceFile);
// Get string literal completions from specialized signatures of the target
// i.e. declare function f(a: 'A');
@@ -92742,6 +94776,11 @@ var ts;
return { kind: 2 /* Types */, types: getStringLiteralTypes(getContextualTypeFromParent(node, typeChecker)), isNewIdentifier: false };
}
}
+ function getAlreadyUsedTypesInStringLiteralUnion(union, current) {
+ return ts.mapDefined(union.types, function (type) {
+ return type !== current && ts.isLiteralTypeNode(type) && ts.isStringLiteral(type.literal) ? type.literal.text : undefined;
+ });
+ }
function getStringLiteralCompletionsFromSignature(argumentInfo, checker) {
var isNewIdentifier = false;
var uniques = ts.createMap();
@@ -93150,7 +95189,10 @@ var ts;
break;
case 71 /* Identifier */:
// For `` we don't want to treat this as a jsx inializer, instead it's the attribute name.
+ if (parent !== previousToken.parent &&
+ !parent.initializer &&
+ ts.findChildOfKind(parent, 58 /* EqualsToken */, sourceFile)) {
isJsxInitializer = previousToken;
}
}
@@ -93172,6 +95214,7 @@ var ts;
tryGetGlobalSymbols();
symbols = tagSymbols.concat(symbols);
completionKind = 3 /* MemberLike */;
+ keywordFilters = 0 /* None */;
}
else if (isStartingCloseTag) {
var tagName = contextToken.parent.parent.openingElement.tagName;
@@ -93180,6 +95223,7 @@ var ts;
symbols = [tagSymbol];
}
completionKind = 3 /* MemberLike */;
+ keywordFilters = 0 /* None */;
}
else {
// For JavaScript or TypeScript, if we're not after a dot, then just try to get the
@@ -93317,7 +95361,7 @@ var ts;
// Declaring new property/method/accessor
isNewIdentifierLocation = true;
// Has keywords for constructor parameter
- keywordFilters = 3 /* ConstructorParameterKeywords */;
+ keywordFilters = 4 /* ConstructorParameterKeywords */;
return 1 /* Success */;
}
function tryGetJsxCompletionSymbols() {
@@ -93332,9 +95376,7 @@ var ts;
return 1 /* Success */;
}
function getGlobalCompletions() {
- if (tryGetFunctionLikeBodyCompletionContainer(contextToken)) {
- keywordFilters = 4 /* FunctionLikeBodyKeywords */;
- }
+ keywordFilters = tryGetFunctionLikeBodyCompletionContainer(contextToken) ? 5 /* FunctionLikeBodyKeywords */ : 1 /* All */;
// Get all entities in the current scope.
completionKind = 1 /* Global */;
isNewIdentifierLocation = isNewIdentifierDefinitionLocation(contextToken);
@@ -93371,7 +95413,7 @@ var ts;
position;
var scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile;
isInSnippetScope = isSnippetScope(scopeNode);
- var symbolMeanings = 67901928 /* Type */ | 67216319 /* Value */ | 1920 /* Namespace */ | 2097152 /* Alias */;
+ var symbolMeanings = 67897832 /* Type */ | 67220415 /* Value */ | 1920 /* Namespace */ | 2097152 /* Alias */;
symbols = ts.Debug.assertEachDefined(typeChecker.getSymbolsInScope(scopeNode, symbolMeanings), "getSymbolsInScope() should all be defined");
// Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions`
if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== 277 /* SourceFile */) {
@@ -93399,12 +95441,12 @@ var ts;
// If already using commonjs, don't introduce ES6.
if (sourceFile.commonJsModuleIndicator)
return false;
- // If some file is using ES6 modules, assume that it's OK to add more.
- if (ts.programContainsEs6Modules(program))
- return true;
// For JS, stay on the safe side.
if (isUncheckedFile)
return false;
+ // If some file is using ES6 modules, assume that it's OK to add more.
+ if (ts.programContainsEs6Modules(program))
+ return true;
// If module transpilation is enabled or we're targeting es6 or above, or not emitting, OK.
return ts.compilerOptionsIndicateEs6Modules(program.getCompilerOptions());
}
@@ -93423,7 +95465,7 @@ var ts;
var isTypeOnlyCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (ts.isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken));
var allowTypes = isTypeOnlyCompletion || !isContextTokenValueLocation(contextToken) && ts.isPossiblyTypeArgumentPosition(contextToken, sourceFile, typeChecker);
if (isTypeOnlyCompletion)
- keywordFilters = 5 /* TypeKeywords */;
+ keywordFilters = 6 /* TypeKeywords */;
ts.filterMutate(symbols, function (symbol) {
if (!ts.isSourceFile(location)) {
// export = /**/ here we want to get all meanings, so any symbol is ok
@@ -93444,7 +95486,7 @@ var ts;
}
}
// expressions are value space (which includes the value namespaces)
- return !!(ts.getCombinedLocalAndExportSymbolFlags(symbol) & 67216319 /* Value */);
+ return !!(ts.getCombinedLocalAndExportSymbolFlags(symbol) & 67220415 /* Value */);
});
}
function isContextTokenValueLocation(contextToken) {
@@ -93474,7 +95516,7 @@ var ts;
symbol = symbol.exportSymbol || symbol;
// This is an alias, follow what it aliases
symbol = ts.skipAlias(symbol, typeChecker);
- if (symbol.flags & 67901928 /* Type */) {
+ if (symbol.flags & 67897832 /* Type */) {
return true;
}
if (symbol.flags & 1536 /* Module */) {
@@ -93498,6 +95540,13 @@ var ts;
if (!ts.addToSeen(seenResolvedModules, ts.getSymbolId(resolvedModuleSymbol))) {
return;
}
+ if (resolvedModuleSymbol !== moduleSymbol &&
+ // Don't add another completion for `export =` of a symbol that's already global.
+ // So in `declare namespace foo {} declare module "foo" { export = foo; }`, there will just be the global completion for `foo`.
+ ts.some(resolvedModuleSymbol.declarations, function (d) { return !!d.getSourceFile().externalModuleIndicator; })) {
+ symbols.push(resolvedModuleSymbol);
+ symbolToOriginInfoMap[ts.getSymbolId(resolvedModuleSymbol)] = { kind: 3 /* Export */, moduleSymbol: moduleSymbol, isDefaultExport: false };
+ }
for (var _i = 0, _a = typeChecker.getExportsOfModule(moduleSymbol); _i < _a.length; _i++) {
var symbol = _a[_i];
// Don't add a completion for a re-export, only for the original.
@@ -93733,7 +95782,8 @@ var ts;
completionKind = 3 /* MemberLike */;
// Declaring new property/method/accessor
isNewIdentifierLocation = true;
- keywordFilters = ts.isClassLike(decl) ? 1 /* ClassElementKeywords */ : 2 /* InterfaceElementKeywords */;
+ keywordFilters = contextToken.kind === 39 /* AsteriskToken */ ? 0 /* None */ :
+ ts.isClassLike(decl) ? 2 /* ClassElementKeywords */ : 3 /* InterfaceElementKeywords */;
// If you're in an interface you don't want to repeat things from super-interface. So just stop here.
if (!ts.isClassLike(decl))
return 1 /* Success */;
@@ -93767,14 +95817,19 @@ var ts;
*/
function tryGetObjectLikeCompletionContainer(contextToken) {
if (contextToken) {
+ var parent = contextToken.parent;
switch (contextToken.kind) {
case 17 /* OpenBraceToken */: // const x = { |
case 26 /* CommaToken */: // const x = { a: 0, |
- var parent = contextToken.parent;
if (ts.isObjectLiteralExpression(parent) || ts.isObjectBindingPattern(parent)) {
return parent;
}
break;
+ case 39 /* AsteriskToken */:
+ return ts.isMethodDeclaration(parent) ? ts.tryCast(parent.parent, ts.isObjectLiteralExpression) : undefined;
+ case 71 /* Identifier */:
+ return contextToken.text === "async" && ts.isShorthandPropertyAssignment(contextToken.parent)
+ ? contextToken.parent.parent : undefined;
}
}
return undefined;
@@ -93928,10 +95983,7 @@ var ts;
containingNodeKind === 249 /* NamespaceImport */;
case 125 /* GetKeyword */:
case 136 /* SetKeyword */:
- if (isFromObjectTypeDeclaration(contextToken)) {
- return false;
- }
- // falls through
+ return !isFromObjectTypeDeclaration(contextToken);
case 75 /* ClassKeyword */:
case 83 /* EnumKeyword */:
case 109 /* InterfaceKeyword */:
@@ -93943,6 +95995,8 @@ var ts;
case 116 /* YieldKeyword */:
case 139 /* TypeKeyword */: // type htm|
return true;
+ case 39 /* AsteriskToken */:
+ return ts.isFunctionLike(contextToken.parent) && !ts.isMethodDeclaration(contextToken.parent);
}
// If the previous token is keyword correspoding to class member completion keyword
// there will be completion available here
@@ -93963,7 +96017,6 @@ var ts;
// Previous token may have been a keyword that was converted to an identifier.
switch (keywordForNode(contextToken)) {
case 117 /* AbstractKeyword */:
- case 120 /* AsyncKeyword */:
case 75 /* ClassKeyword */:
case 76 /* ConstKeyword */:
case 124 /* DeclareKeyword */:
@@ -93978,6 +96031,8 @@ var ts;
case 104 /* VarKeyword */:
case 116 /* YieldKeyword */:
return true;
+ case 120 /* AsyncKeyword */:
+ return ts.isPropertyDeclaration(contextToken.parent);
}
return ts.isDeclarationName(contextToken)
&& !ts.isJsxAttribute(contextToken.parent)
@@ -94151,17 +96206,19 @@ var ts;
var kind = ts.stringToToken(entry.name);
switch (keywordFilter) {
case 0 /* None */:
- // "undefined" is a global variable, so don't need a keyword completion for it.
- return kind !== 140 /* UndefinedKeyword */;
- case 1 /* ClassElementKeywords */:
+ return false;
+ case 1 /* All */:
+ return kind === 120 /* AsyncKeyword */ || !ts.isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind) || kind === 124 /* DeclareKeyword */ || kind === 129 /* ModuleKeyword */
+ || ts.isTypeKeyword(kind) && kind !== 140 /* UndefinedKeyword */;
+ case 2 /* ClassElementKeywords */:
return isClassMemberCompletionKeyword(kind);
- case 2 /* InterfaceElementKeywords */:
+ case 3 /* InterfaceElementKeywords */:
return isInterfaceOrTypeLiteralCompletionKeyword(kind);
- case 3 /* ConstructorParameterKeywords */:
+ case 4 /* ConstructorParameterKeywords */:
return ts.isParameterPropertyModifier(kind);
- case 4 /* FunctionLikeBodyKeywords */:
+ case 5 /* FunctionLikeBodyKeywords */:
return isFunctionLikeBodyKeyword(kind);
- case 5 /* TypeKeywords */:
+ case 6 /* TypeKeywords */:
return ts.isTypeKeyword(kind);
default:
return ts.Debug.assertNever(keywordFilter);
@@ -94184,7 +96241,7 @@ var ts;
}
}
function isFunctionLikeBodyKeyword(kind) {
- return kind === 120 /* AsyncKeyword */ || !isClassMemberCompletionKeyword(kind);
+ return kind === 120 /* AsyncKeyword */ || !ts.isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind);
}
function keywordForNode(node) {
return ts.isIdentifier(node) ? node.originalKeywordKind || 0 /* Unknown */ : node.kind;
@@ -94256,7 +96313,7 @@ var ts;
if (!isFromObjectTypeDeclaration(contextToken))
return undefined;
var isValidKeyword = ts.isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword;
- return (isValidKeyword(contextToken.kind) || ts.isIdentifier(contextToken) && isValidKeyword(ts.stringToToken(contextToken.text))) // TODO: GH#18217
+ return (isValidKeyword(contextToken.kind) || contextToken.kind === 39 /* AsteriskToken */ || ts.isIdentifier(contextToken) && isValidKeyword(ts.stringToToken(contextToken.text))) // TODO: GH#18217
? contextToken.parent.parent : undefined;
}
}
@@ -94276,14 +96333,14 @@ var ts;
case "'":
case "`":
// Only automatically bring up completions if this is an opening quote.
- return isStringLiteralOrTemplate(contextToken) && position === contextToken.getStart(sourceFile) + 1;
+ return !!contextToken && isStringLiteralOrTemplate(contextToken) && position === contextToken.getStart(sourceFile) + 1;
case "<":
// Opening JSX tag
- return contextToken.kind === 27 /* LessThanToken */ && (!ts.isBinaryExpression(contextToken.parent) || binaryExpressionMayBeOpenTag(contextToken.parent));
+ return !!contextToken && contextToken.kind === 27 /* LessThanToken */ && (!ts.isBinaryExpression(contextToken.parent) || binaryExpressionMayBeOpenTag(contextToken.parent));
case "/":
- return ts.isStringLiteralLike(contextToken)
+ return !!contextToken && (ts.isStringLiteralLike(contextToken)
? !!ts.tryGetImportFromModuleSpecifier(contextToken)
- : contextToken.kind === 41 /* SlashToken */ && ts.isJsxClosingElement(contextToken.parent);
+ : contextToken.kind === 41 /* SlashToken */ && ts.isJsxClosingElement(contextToken.parent));
default:
return ts.Debug.assertNever(triggerCharacter);
}
@@ -94748,9 +96805,6 @@ var ts;
// for those settings.
var buckets = ts.createMap();
var getCanonicalFileName = ts.createGetCanonicalFileName(!!useCaseSensitiveFileNames);
- function getKeyForCompilationSettings(settings) {
- return "_" + settings.target + "|" + settings.module + "|" + settings.noResolve + "|" + settings.jsx + "|" + settings.allowJs + "|" + settings.baseUrl + "|" + JSON.stringify(settings.typeRoots) + "|" + JSON.stringify(settings.rootDirs) + "|" + JSON.stringify(settings.paths);
- }
function getBucketForCompilationSettings(key, createIfMissing) {
var bucket = buckets.get(key);
if (!bucket && createIfMissing) {
@@ -94795,7 +96849,7 @@ var ts;
function acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, acquiring, scriptKind) {
var bucket = getBucketForCompilationSettings(key, /*createIfMissing*/ true);
var entry = bucket.get(path);
- var scriptTarget = scriptKind === 6 /* JSON */ ? 100 /* JSON */ : compilationSettings.target;
+ var scriptTarget = scriptKind === 6 /* JSON */ ? 100 /* JSON */ : compilationSettings.target || 1 /* ES5 */;
if (!entry && externalCache) {
var sourceFile = externalCache.getDocument(key, path);
if (sourceFile) {
@@ -94809,7 +96863,7 @@ var ts;
}
if (!entry) {
// Have never seen this file with these settings. Create a new source file for it.
- var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, /*setNodeParents*/ false, scriptKind); // TODO: GH#18217
+ var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, /*setNodeParents*/ false, scriptKind);
if (externalCache) {
externalCache.setDocument(key, path, sourceFile);
}
@@ -94876,6 +96930,9 @@ var ts;
};
}
ts.createDocumentRegistryInternal = createDocumentRegistryInternal;
+ function getKeyForCompilationSettings(settings) {
+ return ts.sourceFileAffectingCompilerOptions.map(function (option) { return ts.getCompilerOptionValue(settings, option); }).join("|");
+ }
})(ts || (ts = {}));
/* Code for finding imports of an exported symbol. Used only by FindAllReferences. */
/* @internal */
@@ -95161,8 +97218,8 @@ var ts;
function findModuleReferences(program, sourceFiles, searchModuleSymbol) {
var refs = [];
var checker = program.getTypeChecker();
- for (var _i = 0, sourceFiles_5 = sourceFiles; _i < sourceFiles_5.length; _i++) {
- var referencingFile = sourceFiles_5[_i];
+ for (var _i = 0, sourceFiles_3 = sourceFiles; _i < sourceFiles_3.length; _i++) {
+ var referencingFile = sourceFiles_3[_i];
var searchSourceFile = searchModuleSymbol.valueDeclaration;
if (searchSourceFile.kind === 277 /* SourceFile */) {
for (var _a = 0, _b = referencingFile.referencedFiles; _a < _b.length; _a++) {
@@ -95192,8 +97249,8 @@ var ts;
/** Returns a map from a module symbol Id to all import statements that directly reference the module. */
function getDirectImportsMap(sourceFiles, checker, cancellationToken) {
var map = ts.createMap();
- for (var _i = 0, sourceFiles_6 = sourceFiles; _i < sourceFiles_6.length; _i++) {
- var sourceFile = sourceFiles_6[_i];
+ for (var _i = 0, sourceFiles_4 = sourceFiles; _i < sourceFiles_4.length; _i++) {
+ var sourceFile = sourceFiles_4[_i];
if (cancellationToken)
cancellationToken.throwIfCancellationRequested();
forEachImport(sourceFile, function (importDecl, moduleSpecifier) {
@@ -95312,7 +97369,7 @@ var ts;
}
function getSpecialPropertyExport(node, useLhsSymbol) {
var kind;
- switch (ts.getSpecialPropertyAssignmentKind(node)) {
+ switch (ts.getAssignmentDeclarationKind(node)) {
case 1 /* ExportsProperty */:
kind = 0 /* Named */;
break;
@@ -95457,8 +97514,25 @@ var ts;
(function (ts) {
var FindAllReferences;
(function (FindAllReferences) {
- function nodeEntry(node, isInString) {
- return { type: "node", node: node.name || node, isInString: isInString };
+ var DefinitionKind;
+ (function (DefinitionKind) {
+ DefinitionKind[DefinitionKind["Symbol"] = 0] = "Symbol";
+ DefinitionKind[DefinitionKind["Label"] = 1] = "Label";
+ DefinitionKind[DefinitionKind["Keyword"] = 2] = "Keyword";
+ DefinitionKind[DefinitionKind["This"] = 3] = "This";
+ DefinitionKind[DefinitionKind["String"] = 4] = "String";
+ })(DefinitionKind = FindAllReferences.DefinitionKind || (FindAllReferences.DefinitionKind = {}));
+ var EntryKind;
+ (function (EntryKind) {
+ EntryKind[EntryKind["Span"] = 0] = "Span";
+ EntryKind[EntryKind["Node"] = 1] = "Node";
+ EntryKind[EntryKind["StringLiteral"] = 2] = "StringLiteral";
+ EntryKind[EntryKind["SearchedLocalFoundProperty"] = 3] = "SearchedLocalFoundProperty";
+ EntryKind[EntryKind["SearchedPropertyFoundLocal"] = 4] = "SearchedPropertyFoundLocal";
+ })(EntryKind = FindAllReferences.EntryKind || (FindAllReferences.EntryKind = {}));
+ function nodeEntry(node, kind) {
+ if (kind === void 0) { kind = 1 /* Node */; }
+ return { kind: kind, node: node.name || node };
}
FindAllReferences.nodeEntry = nodeEntry;
function findReferencedSymbols(program, cancellationToken, sourceFiles, sourceFile, position) {
@@ -95490,9 +97564,9 @@ var ts;
// If invoked directly on a shorthand property assignment, then return
// the declaration of the symbol being assigned (not the symbol being assigned to).
if (node.parent.kind === 274 /* ShorthandPropertyAssignment */) {
- var result_6 = [];
- FindAllReferences.Core.getReferenceEntriesForShorthandPropertyAssignment(node, checker, function (node) { return result_6.push(nodeEntry(node)); });
- return result_6;
+ var result_7 = [];
+ FindAllReferences.Core.getReferenceEntriesForShorthandPropertyAssignment(node, checker, function (node) { return result_7.push(nodeEntry(node)); });
+ return result_7;
}
else if (node.kind === 97 /* SuperKeyword */ || ts.isSuperProperty(node.parent)) {
// References to and accesses on the super keyword only have one possible implementation, so no
@@ -95505,10 +97579,10 @@ var ts;
return getReferenceEntriesForNode(position, node, program, sourceFiles, cancellationToken, { implementations: true });
}
}
- function findReferencedEntries(program, cancellationToken, sourceFiles, node, position, options) {
- return ts.map(flattenEntries(FindAllReferences.Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, options)), toReferenceEntry);
+ function findReferenceOrRenameEntries(program, cancellationToken, sourceFiles, node, position, options, convertEntry) {
+ return ts.map(flattenEntries(FindAllReferences.Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, options)), function (entry) { return convertEntry(entry, node); });
}
- FindAllReferences.findReferencedEntries = findReferencedEntries;
+ FindAllReferences.findReferenceOrRenameEntries = findReferenceOrRenameEntries;
function getReferenceEntriesForNode(position, node, program, sourceFiles, cancellationToken, options, sourceFilesSet) {
if (options === void 0) { options = {}; }
if (sourceFilesSet === void 0) { sourceFilesSet = ts.arrayToSet(sourceFiles, function (f) { return f.fileName; }); }
@@ -95521,28 +97595,28 @@ var ts;
function definitionToReferencedSymbolDefinitionInfo(def, checker, originalNode) {
var info = (function () {
switch (def.type) {
- case "symbol": {
+ case 0 /* Symbol */: {
var symbol = def.symbol;
var _a = getDefinitionKindAndDisplayParts(symbol, checker, originalNode), displayParts_1 = _a.displayParts, kind_1 = _a.kind;
var name_3 = displayParts_1.map(function (p) { return p.text; }).join("");
return { node: symbol.declarations ? ts.getNameOfDeclaration(ts.first(symbol.declarations)) || ts.first(symbol.declarations) : originalNode, name: name_3, kind: kind_1, displayParts: displayParts_1 };
}
- case "label": {
+ case 1 /* Label */: {
var node_3 = def.node;
return { node: node_3, name: node_3.text, kind: "label" /* label */, displayParts: [ts.displayPart(node_3.text, ts.SymbolDisplayPartKind.text)] };
}
- case "keyword": {
+ case 2 /* Keyword */: {
var node_4 = def.node;
var name_4 = ts.tokenToString(node_4.kind);
return { node: node_4, name: name_4, kind: "keyword" /* keyword */, displayParts: [{ text: name_4, kind: "keyword" /* keyword */ }] };
}
- case "this": {
+ case 3 /* This */: {
var node_5 = def.node;
var symbol = checker.getSymbolAtLocation(node_5);
var displayParts_2 = symbol && ts.SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(checker, symbol, node_5.getSourceFile(), ts.getContainerNode(node_5), node_5).displayParts || [ts.textPart("this")];
return { node: node_5, name: "this", kind: "var" /* variableElement */, displayParts: displayParts_2 };
}
- case "string": {
+ case 4 /* String */: {
var node_6 = def.node;
return { node: node_6, name: node_6.text, kind: "var" /* variableElement */, displayParts: [ts.displayPart(ts.getTextOfNode(node_6), ts.SymbolDisplayPartKind.stringLiteral)] };
}
@@ -95560,24 +97634,61 @@ var ts;
var _a = ts.SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(checker, symbol, enclosingDeclaration.getSourceFile(), enclosingDeclaration, enclosingDeclaration, meaning), displayParts = _a.displayParts, symbolKind = _a.symbolKind;
return { displayParts: displayParts, kind: symbolKind };
}
+ function toRenameLocation(entry, originalNode) {
+ return __assign({}, entryToDocumentSpan(entry), getPrefixAndSuffixText(entry, originalNode));
+ }
+ FindAllReferences.toRenameLocation = toRenameLocation;
function toReferenceEntry(entry) {
- if (entry.type === "span") {
- return { textSpan: entry.textSpan, fileName: entry.fileName, isWriteAccess: false, isDefinition: false };
+ var _a = entryToDocumentSpan(entry), textSpan = _a.textSpan, fileName = _a.fileName;
+ if (entry.kind === 0 /* Span */) {
+ return { textSpan: textSpan, fileName: fileName, isWriteAccess: false, isDefinition: false };
}
- var node = entry.node, isInString = entry.isInString;
- var sourceFile = node.getSourceFile();
+ var kind = entry.kind, node = entry.node;
return {
- fileName: sourceFile.fileName,
- textSpan: getTextSpan(node, sourceFile),
+ textSpan: textSpan,
+ fileName: fileName,
isWriteAccess: isWriteAccessForReference(node),
isDefinition: node.kind === 79 /* DefaultKeyword */
- || ts.isAnyDeclarationName(node)
+ || !!ts.getDeclarationFromName(node)
|| ts.isLiteralComputedPropertyDeclarationName(node),
- isInString: isInString,
+ isInString: kind === 2 /* StringLiteral */ ? true : undefined,
};
}
+ FindAllReferences.toReferenceEntry = toReferenceEntry;
+ function entryToDocumentSpan(entry) {
+ if (entry.kind === 0 /* Span */) {
+ return { textSpan: entry.textSpan, fileName: entry.fileName };
+ }
+ else {
+ var sourceFile = entry.node.getSourceFile();
+ return { textSpan: getTextSpan(entry.node, sourceFile), fileName: sourceFile.fileName };
+ }
+ }
+ function getPrefixAndSuffixText(entry, originalNode) {
+ if (entry.kind !== 0 /* Span */ && ts.isIdentifier(originalNode)) {
+ var node = entry.node, kind = entry.kind;
+ var name = originalNode.text;
+ var isShorthandAssignment = ts.isShorthandPropertyAssignment(node.parent);
+ if (isShorthandAssignment || ts.isObjectBindingElementWithoutPropertyName(node.parent)) {
+ if (kind === 3 /* SearchedLocalFoundProperty */) {
+ return { prefixText: name + ": " };
+ }
+ else if (kind === 4 /* SearchedPropertyFoundLocal */) {
+ return { suffixText: ": " + name };
+ }
+ else {
+ return isShorthandAssignment
+ // In `const o = { x }; o.x`, symbolAtLocation at `x` in `{ x }` is the property symbol.
+ ? { suffixText: ": " + name }
+ // For a binding element `const { x } = o;`, symbolAtLocation at `x` is the property symbol.
+ : { prefixText: name + ": " };
+ }
+ }
+ }
+ return ts.emptyOptions;
+ }
function toImplementationLocation(entry, checker) {
- if (entry.type === "node") {
+ if (entry.kind !== 0 /* Span */) {
var node = entry.node;
var sourceFile = node.getSourceFile();
return __assign({ textSpan: getTextSpan(node, sourceFile), fileName: sourceFile.fileName }, implementationKindDisplayParts(node, checker));
@@ -95609,17 +97720,17 @@ var ts;
}
}
function toHighlightSpan(entry) {
- if (entry.type === "span") {
+ if (entry.kind === 0 /* Span */) {
var fileName = entry.fileName, textSpan = entry.textSpan;
return { fileName: fileName, span: { textSpan: textSpan, kind: "reference" /* reference */ } };
}
- var node = entry.node, isInString = entry.isInString;
+ var node = entry.node, kind = entry.kind;
var sourceFile = node.getSourceFile();
var writeAccess = isWriteAccessForReference(node);
var span = {
textSpan: getTextSpan(node, sourceFile),
kind: writeAccess ? "writtenReference" /* writtenReference */ : "reference" /* reference */,
- isInString: isInString
+ isInString: kind === 2 /* StringLiteral */ ? true : undefined,
};
return { fileName: sourceFile.fileName, span: span };
}
@@ -95635,7 +97746,62 @@ var ts;
}
/** A node is considered a writeAccess iff it is a name of a declaration or a target of an assignment */
function isWriteAccessForReference(node) {
- return node.kind === 79 /* DefaultKeyword */ || ts.isAnyDeclarationName(node) || ts.isWriteAccess(node);
+ var decl = ts.getDeclarationFromName(node);
+ return !!decl && declarationIsWriteAccess(decl) || node.kind === 79 /* DefaultKeyword */ || ts.isWriteAccess(node);
+ }
+ /**
+ * True if 'decl' provides a value, as in `function f() {}`;
+ * false if 'decl' is just a location for a future write, as in 'let x;'
+ */
+ function declarationIsWriteAccess(decl) {
+ // Consider anything in an ambient declaration to be a write access since it may be coming from JS.
+ if (!!(decl.flags & 4194304 /* Ambient */))
+ return true;
+ switch (decl.kind) {
+ case 202 /* BinaryExpression */:
+ case 184 /* BindingElement */:
+ case 238 /* ClassDeclaration */:
+ case 207 /* ClassExpression */:
+ case 79 /* DefaultKeyword */:
+ case 241 /* EnumDeclaration */:
+ case 276 /* EnumMember */:
+ case 255 /* ExportSpecifier */:
+ case 248 /* ImportClause */: // default import
+ case 246 /* ImportEqualsDeclaration */:
+ case 251 /* ImportSpecifier */:
+ case 239 /* InterfaceDeclaration */:
+ case 295 /* JSDocCallbackTag */:
+ case 302 /* JSDocTypedefTag */:
+ case 265 /* JsxAttribute */:
+ case 242 /* ModuleDeclaration */:
+ case 245 /* NamespaceExportDeclaration */:
+ case 249 /* NamespaceImport */:
+ case 149 /* Parameter */:
+ case 274 /* ShorthandPropertyAssignment */:
+ case 240 /* TypeAliasDeclaration */:
+ case 148 /* TypeParameter */:
+ return true;
+ case 273 /* PropertyAssignment */:
+ // In `({ x: y } = 0);`, `x` is not a write access. (Won't call this function for `y`.)
+ return !ts.isArrayLiteralOrObjectLiteralDestructuringPattern(decl.parent);
+ case 237 /* FunctionDeclaration */:
+ case 194 /* FunctionExpression */:
+ case 155 /* Constructor */:
+ case 154 /* MethodDeclaration */:
+ case 156 /* GetAccessor */:
+ case 157 /* SetAccessor */:
+ return !!decl.body;
+ case 235 /* VariableDeclaration */:
+ case 152 /* PropertyDeclaration */:
+ return !!decl.initializer || ts.isCatchClause(decl.parent);
+ case 153 /* MethodSignature */:
+ case 151 /* PropertySignature */:
+ case 303 /* JSDocPropertyTag */:
+ case 297 /* JSDocParameterTag */:
+ return false;
+ default:
+ return ts.Debug.failBadSyntaxKind(decl);
+ }
}
})(FindAllReferences = ts.FindAllReferences || (ts.FindAllReferences = {}));
})(ts || (ts = {}));
@@ -95699,11 +97865,11 @@ var ts;
}
}
// import("foo") with no qualifier will reference the `export =` of the module, which may be referenced anyway.
- return { type: "node", node: reference.literal };
+ return FindAllReferences.nodeEntry(reference.literal);
}
else {
return {
- type: "span",
+ kind: 0 /* Span */,
fileName: reference.referencingFile.fileName,
textSpan: ts.createTextSpanFromRange(reference.ref),
};
@@ -95717,7 +97883,7 @@ var ts;
break;
case 242 /* ModuleDeclaration */:
if (sourceFilesSet.has(decl.getSourceFile().fileName)) {
- references.push({ type: "node", node: decl.name });
+ references.push(FindAllReferences.nodeEntry(decl.name));
}
break;
default:
@@ -95725,7 +97891,7 @@ var ts;
ts.Debug.fail("Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.");
}
}
- return references.length ? [{ definition: { type: "symbol", symbol: symbol }, references: references }] : ts.emptyArray;
+ return references.length ? [{ definition: { type: 0 /* Symbol */, symbol: symbol }, references: references }] : ts.emptyArray;
}
/** getReferencedSymbols for special node kinds. */
function getReferencedSymbolsSpecial(node, sourceFiles, cancellationToken) {
@@ -95763,7 +97929,7 @@ var ts;
searchForImportsOfExport(node, symbol, { exportingModuleSymbol: ts.Debug.assertDefined(symbol.parent, "Expected export symbol to have a parent"), exportKind: 1 /* Default */ }, state);
}
else {
- var search = state.createSearch(node, symbol, /*comingFrom*/ undefined, { allSearchSymbols: node ? populateSearchSymbolSet(symbol, node, checker, !!options.implementations) : [symbol] });
+ var search = state.createSearch(node, symbol, /*comingFrom*/ undefined, { allSearchSymbols: node ? populateSearchSymbolSet(symbol, node, checker, !!options.isForRename, !!options.implementations) : [symbol] });
// Try to get the smallest valid scope that we can limit our search to;
// otherwise we'll need to search globally (i.e. include each file).
var scope = getSymbolScope(symbol);
@@ -95894,15 +98060,15 @@ var ts;
var references = this.symbolIdToReferences[symbolId];
if (!references) {
references = this.symbolIdToReferences[symbolId] = [];
- this.result.push({ definition: { type: "symbol", symbol: searchSymbol }, references: references });
+ this.result.push({ definition: { type: 0 /* Symbol */, symbol: searchSymbol }, references: references });
}
- return function (node) { return references.push(FindAllReferences.nodeEntry(node)); };
+ return function (node, kind) { return references.push(FindAllReferences.nodeEntry(node, kind)); };
};
/** Add a reference with no associated definition. */
State.prototype.addStringOrCommentReference = function (fileName, textSpan) {
this.result.push({
definition: undefined,
- references: [{ type: "span", fileName: fileName, textSpan: textSpan }]
+ references: [{ kind: 0 /* Span */, fileName: fileName, textSpan: textSpan }]
});
};
/** Returns `true` the first time we search for a symbol in a file and `false` afterwards. */
@@ -96005,19 +98171,6 @@ var ts;
? checker.getPropertySymbolOfDestructuringAssignment(location)
: undefined;
}
- function getObjectBindingElementWithoutPropertyName(symbol) {
- var bindingElement = ts.getDeclarationOfKind(symbol, 184 /* BindingElement */);
- if (bindingElement &&
- bindingElement.parent.kind === 182 /* ObjectBindingPattern */ &&
- ts.isIdentifier(bindingElement.name) &&
- !bindingElement.propertyName) {
- return bindingElement;
- }
- }
- function getPropertySymbolOfObjectBindingPatternWithoutPropertyName(symbol, checker) {
- var bindingElement = getObjectBindingElementWithoutPropertyName(symbol);
- return bindingElement && ts.getPropertySymbolFromBindingElement(checker, bindingElement);
- }
/**
* Determines the smallest scope in which a symbol may have named references.
* Note that not every construct has been accounted for. This function can
@@ -96047,7 +98200,7 @@ var ts;
}
// If symbol is of object binding pattern element without property name we would want to
// look for property too and that could be anywhere
- if (getObjectBindingElementWithoutPropertyName(symbol)) {
+ if (declarations.some(ts.isObjectBindingElementWithoutPropertyName)) {
return undefined;
}
/*
@@ -96062,8 +98215,8 @@ var ts;
return undefined;
}
var scope;
- for (var _i = 0, declarations_10 = declarations; _i < declarations_10.length; _i++) {
- var declaration = declarations_10[_i];
+ for (var _i = 0, declarations_11 = declarations; _i < declarations_11.length; _i++) {
+ var declaration = declarations_11[_i];
var container = ts.getContainerNode(declaration);
if (scope && scope !== container) {
// Different declarations have different containers, bail out
@@ -96112,8 +98265,8 @@ var ts;
if (!signature.name || !ts.isIdentifier(signature.name))
return;
var symbol = ts.Debug.assertDefined(checker.getSymbolAtLocation(signature.name));
- for (var _i = 0, sourceFiles_7 = sourceFiles; _i < sourceFiles_7.length; _i++) {
- var sourceFile = sourceFiles_7[_i];
+ for (var _i = 0, sourceFiles_5 = sourceFiles; _i < sourceFiles_5.length; _i++) {
+ var sourceFile = sourceFiles_5[_i];
for (var _a = 0, _b = getPossibleSymbolReferenceNodes(sourceFile, symbol.name); _a < _b.length; _a++) {
var name = _b[_a];
if (!ts.isIdentifier(name) || name === signature.name || name.escapedText !== signature.name.escapedText)
@@ -96170,7 +98323,7 @@ var ts;
// Only pick labels that are either the target label, or have a target that is the target label
return node === targetLabel || (ts.isJumpStatementTarget(node) && ts.getTargetLabel(node, labelName) === targetLabel) ? FindAllReferences.nodeEntry(node) : undefined;
});
- return [{ definition: { type: "label", node: targetLabel }, references: references }];
+ return [{ definition: { type: 1 /* Label */, node: targetLabel }, references: references }];
}
function isValidReferencePosition(node, searchSymbolName) {
// Compare the length so we filter out strict superstrings of the symbol we are looking for
@@ -96197,7 +98350,7 @@ var ts;
return referenceLocation.kind === keywordKind ? FindAllReferences.nodeEntry(referenceLocation) : undefined;
});
});
- return references.length ? [{ definition: { type: "keyword", node: references[0].node }, references: references }] : undefined;
+ return references.length ? [{ definition: { type: 2 /* Keyword */, node: references[0].node }, references: references }] : undefined;
}
function getReferencesInSourceFile(sourceFile, search, state, addReferencesHere) {
if (addReferencesHere === void 0) { addReferencesHere = true; }
@@ -96367,12 +98520,13 @@ var ts;
}
}
function addReference(referenceLocation, relatedSymbol, state) {
- var addRef = state.referenceAdder(relatedSymbol);
+ var _a = "kind" in relatedSymbol ? relatedSymbol : { kind: undefined, symbol: relatedSymbol }, kind = _a.kind, symbol = _a.symbol;
+ var addRef = state.referenceAdder(symbol);
if (state.options.implementations) {
addImplementationReferences(referenceLocation, addRef, state);
}
else {
- addRef(referenceLocation);
+ addRef(referenceLocation, kind);
}
}
/** Adds references when a constructor is used with `new this()` in its own class and `super()` calls in subclasses. */
@@ -96602,7 +98756,7 @@ var ts;
// and has the same static qualifier as the original 'super's owner.
return container && (32 /* Static */ & ts.getModifierFlags(container)) === staticFlag && container.parent.symbol === searchSpaceNode.symbol ? FindAllReferences.nodeEntry(node) : undefined;
});
- return [{ definition: { type: "symbol", symbol: searchSpaceNode.symbol }, references: references }];
+ return [{ definition: { type: 0 /* Symbol */, symbol: searchSpaceNode.symbol }, references: references }];
}
function getReferencesForThisKeyword(thisOrSuperKeyword, sourceFiles, cancellationToken) {
var searchSpaceNode = ts.getThisContainer(thisOrSuperKeyword, /* includeArrowFunctions */ false);
@@ -96660,8 +98814,9 @@ var ts;
}
});
}).map(function (n) { return FindAllReferences.nodeEntry(n); });
+ var thisParameter = ts.firstDefined(references, function (r) { return ts.isParameter(r.node.parent) ? r.node : undefined; });
return [{
- definition: { type: "this", node: thisOrSuperKeyword },
+ definition: { type: 3 /* This */, node: thisParameter || thisOrSuperKeyword },
references: references
}];
}
@@ -96669,52 +98824,56 @@ var ts;
var references = ts.flatMap(sourceFiles, function (sourceFile) {
cancellationToken.throwIfCancellationRequested();
return ts.mapDefined(getPossibleSymbolReferenceNodes(sourceFile, node.text), function (ref) {
- return ts.isStringLiteral(ref) && ref.text === node.text ? FindAllReferences.nodeEntry(ref, /*isInString*/ true) : undefined;
+ return ts.isStringLiteral(ref) && ref.text === node.text ? FindAllReferences.nodeEntry(ref, 2 /* StringLiteral */) : undefined;
});
});
return [{
- definition: { type: "string", node: node },
+ definition: { type: 4 /* String */, node: node },
references: references
}];
}
// For certain symbol kinds, we need to include other symbols in the search set.
// This is not needed when searching for re-exports.
- function populateSearchSymbolSet(symbol, location, checker, implementations) {
+ function populateSearchSymbolSet(symbol, location, checker, isForRename, implementations) {
var result = [];
- forEachRelatedSymbol(symbol, location, checker, function (sym, root, base) { result.push(base || root || sym); },
+ forEachRelatedSymbol(symbol, location, checker, isForRename, function (sym, root, base) { result.push(base || root || sym); },
/*allowBaseTypes*/ function () { return !implementations; });
return result;
}
- function forEachRelatedSymbol(symbol, location, checker, cbSymbol, allowBaseTypes) {
+ function forEachRelatedSymbol(symbol, location, checker, isForRenamePopulateSearchSymbolSet, cbSymbol, allowBaseTypes) {
var containingObjectLiteralElement = ts.getContainingObjectLiteralElement(location);
if (containingObjectLiteralElement) {
+ /* Because in short-hand property assignment, location has two meaning : property name and as value of the property
+ * When we do findAllReference at the position of the short-hand property assignment, we would want to have references to position of
+ * property name and variable declaration of the identifier.
+ * Like in below example, when querying for all references for an identifier 'name', of the property assignment, the language service
+ * should show both 'name' in 'obj' and 'name' in variable declaration
+ * const name = "Foo";
+ * const obj = { name };
+ * In order to do that, we will populate the search set with the value symbol of the identifier as a value of the property assignment
+ * so that when matching with potential reference symbol, both symbols from property declaration and variable declaration
+ * will be included correctly.
+ */
+ var shorthandValueSymbol = checker.getShorthandAssignmentValueSymbol(location.parent); // gets the local symbol
+ if (shorthandValueSymbol && isForRenamePopulateSearchSymbolSet) {
+ // When renaming 'x' in `const o = { x }`, just rename the local variable, not the property.
+ return cbSymbol(shorthandValueSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, 3 /* SearchedLocalFoundProperty */);
+ }
// If the location is in a context sensitive location (i.e. in an object literal) try
// to get a contextual type for it, and add the property symbol from the contextual
// type to the search set
var contextualType = checker.getContextualType(containingObjectLiteralElement.parent);
- var res_1 = contextualType && ts.firstDefined(ts.getPropertySymbolsFromContextualType(containingObjectLiteralElement, checker, contextualType, /*unionSymbolOk*/ true), fromRoot);
+ var res_1 = contextualType && ts.firstDefined(ts.getPropertySymbolsFromContextualType(containingObjectLiteralElement, checker, contextualType, /*unionSymbolOk*/ true), function (sym) { return fromRoot(sym, 4 /* SearchedPropertyFoundLocal */); });
if (res_1)
return res_1;
// If the location is name of property symbol from object literal destructuring pattern
// Search the property symbol
// for ( { property: p2 } of elems) { }
var propertySymbol = getPropertySymbolOfDestructuringAssignment(location, checker);
- var res1 = propertySymbol && cbSymbol(propertySymbol);
+ var res1 = propertySymbol && cbSymbol(propertySymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, 4 /* SearchedPropertyFoundLocal */);
if (res1)
return res1;
- /* Because in short-hand property assignment, location has two meaning : property name and as value of the property
- * When we do findAllReference at the position of the short-hand property assignment, we would want to have references to position of
- * property name and variable declaration of the identifier.
- * Like in below example, when querying for all references for an identifier 'name', of the property assignment, the language service
- * should show both 'name' in 'obj' and 'name' in variable declaration
- * const name = "Foo";
- * const obj = { name };
- * In order to do that, we will populate the search set with the value symbol of the identifier as a value of the property assignment
- * so that when matching with potential reference symbol, both symbols from property declaration and variable declaration
- * will be included correctly.
- */
- var shorthandValueSymbol = checker.getShorthandAssignmentValueSymbol(location.parent);
- var res2 = shorthandValueSymbol && cbSymbol(shorthandValueSymbol);
+ var res2 = shorthandValueSymbol && cbSymbol(shorthandValueSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, 3 /* SearchedLocalFoundProperty */);
if (res2)
return res2;
}
@@ -96727,11 +98886,13 @@ var ts;
ts.Debug.assert(paramProps.length === 2 && !!(paramProps[0].flags & 1 /* FunctionScopedVariable */) && !!(paramProps[1].flags & 4 /* Property */)); // is [parameter, property]
return fromRoot(symbol.flags & 1 /* FunctionScopedVariable */ ? paramProps[1] : paramProps[0]);
}
- // If this is symbol of binding element without propertyName declaration in Object binding pattern
- // Include the property in the search
- var bindingElementPropertySymbol = getPropertySymbolOfObjectBindingPatternWithoutPropertyName(symbol, checker);
- return bindingElementPropertySymbol && fromRoot(bindingElementPropertySymbol);
- function fromRoot(sym) {
+ // symbolAtLocation for a binding element is the local symbol. See if the search symbol is the property.
+ // Don't do this when populating search set for a rename -- just rename the local.
+ if (!isForRenamePopulateSearchSymbolSet) {
+ var bindingElementPropertySymbol = ts.isObjectBindingElementWithoutPropertyName(location.parent) ? ts.getPropertySymbolFromBindingElement(checker, location.parent) : undefined;
+ return bindingElementPropertySymbol && fromRoot(bindingElementPropertySymbol, 4 /* SearchedPropertyFoundLocal */);
+ }
+ function fromRoot(sym, kind) {
// If this is a union property:
// - In populateSearchSymbolsSet we will add all the symbols from all its source symbols in all unioned types.
// - In findRelatedSymbol, we will just use the union symbol if any source symbol is included in the search.
@@ -96739,19 +98900,19 @@ var ts;
// - In populateSearchSymbolsSet, add the root the list
// - In findRelatedSymbol, return the source symbol if that is in the search. (Do not return the instantiation symbol.)
return ts.firstDefined(checker.getRootSymbols(sym), function (rootSymbol) {
- return cbSymbol(sym, rootSymbol)
+ return cbSymbol(sym, rootSymbol, /*baseSymbol*/ undefined, kind)
// Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions
|| (rootSymbol.parent && rootSymbol.parent.flags & (32 /* Class */ | 64 /* Interface */) && allowBaseTypes(rootSymbol)
- ? ts.getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.name, checker, function (base) { return cbSymbol(sym, rootSymbol, base); })
+ ? ts.getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.name, checker, function (base) { return cbSymbol(sym, rootSymbol, base, kind); })
: undefined);
});
}
}
function getRelatedSymbol(search, referenceSymbol, referenceLocation, state) {
var checker = state.checker;
- return forEachRelatedSymbol(referenceSymbol, referenceLocation, checker, function (sym, rootSymbol, baseSymbol) { return search.includes(baseSymbol || rootSymbol || sym)
+ return forEachRelatedSymbol(referenceSymbol, referenceLocation, checker, /*isForRenamePopulateSearchSymbolSet*/ false, function (sym, rootSymbol, baseSymbol, kind) { return search.includes(baseSymbol || rootSymbol || sym)
// For a base type, use the symbol for the derived type. For a synthetic (e.g. union) property, use the union symbol.
- ? rootSymbol && !(ts.getCheckFlags(sym) & 6 /* Synthetic */) ? rootSymbol : sym
+ ? { symbol: rootSymbol && !(ts.getCheckFlags(sym) & 6 /* Synthetic */) ? rootSymbol : sym, kind: kind }
: undefined; },
/*allowBaseTypes*/ function (rootSymbol) {
return !(search.parents && !search.parents.some(function (parent) { return explicitlyInheritsFrom(rootSymbol.parent, parent, state.inheritsFromCache, checker); }));
@@ -96777,8 +98938,8 @@ var ts;
// To achieve that we will keep iterating until the result stabilizes.
// Remember the last meaning
lastIterationMeaning = meaning;
- for (var _i = 0, declarations_11 = declarations; _i < declarations_11.length; _i++) {
- var declaration = declarations_11[_i];
+ for (var _i = 0, declarations_12 = declarations; _i < declarations_12.length; _i++) {
+ var declaration = declarations_12[_i];
var declarationMeaning = ts.getMeaningFromDeclaration(declaration);
if (declarationMeaning & meaning) {
meaning |= declarationMeaning;
@@ -96840,14 +99001,14 @@ var ts;
/* @internal */
var ts;
(function (ts) {
- function getEditsForFileRename(program, oldFileOrDirPath, newFileOrDirPath, host, formatContext, preferences, sourceMapper) {
+ function getEditsForFileRename(program, oldFileOrDirPath, newFileOrDirPath, host, formatContext, _preferences, sourceMapper) {
var useCaseSensitiveFileNames = ts.hostUsesCaseSensitiveFileNames(host);
var getCanonicalFileName = ts.createGetCanonicalFileName(useCaseSensitiveFileNames);
var oldToNew = getPathUpdater(oldFileOrDirPath, newFileOrDirPath, getCanonicalFileName, sourceMapper);
var newToOld = getPathUpdater(newFileOrDirPath, oldFileOrDirPath, getCanonicalFileName, sourceMapper);
return ts.textChanges.ChangeTracker.with({ host: host, formatContext: formatContext }, function (changeTracker) {
updateTsconfigFiles(program, changeTracker, oldToNew, newFileOrDirPath, host.getCurrentDirectory(), useCaseSensitiveFileNames);
- updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName, preferences);
+ updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName);
});
}
ts.getEditsForFileRename = getEditsForFileRename;
@@ -96943,9 +99104,9 @@ var ts;
return ts.getRelativePathFromDirectory(configDir, path, /*ignoreCase*/ !useCaseSensitiveFileNames);
}
}
- function updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName, preferences) {
+ function updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName) {
var allFiles = program.getSourceFiles();
- var _loop_13 = function (sourceFile) {
+ var _loop_12 = function (sourceFile) {
var newFromOld = oldToNew(sourceFile.path);
var newImportFromPath = newFromOld !== undefined ? newFromOld : sourceFile.path;
var newImportFromDirectory = ts.getDirectoryPath(newImportFromPath);
@@ -96971,13 +99132,13 @@ var ts;
: getSourceFileToImport(importedModuleSymbol, importLiteral, sourceFile, program, host, oldToNew);
// Need an update if the imported file moved, or the importing file moved and was using a relative path.
return toImport !== undefined && (toImport.updated || (importingSourceFileMoved && ts.pathIsRelative(importLiteral.text)))
- ? ts.moduleSpecifiers.getModuleSpecifier(program.getCompilerOptions(), sourceFile, newImportFromPath, toImport.newFileName, host, allFiles, preferences, program.redirectTargetsMap)
+ ? ts.moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), newImportFromPath, toImport.newFileName, host, allFiles, program.redirectTargetsMap, importLiteral.text)
: undefined;
});
};
for (var _i = 0, allFiles_1 = allFiles; _i < allFiles_1.length; _i++) {
var sourceFile = allFiles_1[_i];
- _loop_13(sourceFile);
+ _loop_12(sourceFile);
}
}
function combineNormal(pathA, pathB) {
@@ -97001,16 +99162,23 @@ var ts;
}
}
function getSourceFileToImportFromResolved(resolved, oldToNew, host) {
- return resolved && ((resolved.resolvedModule && getIfExists(resolved.resolvedModule.resolvedFileName)) || ts.firstDefined(resolved.failedLookupLocations, getIfExists));
- function getIfExists(oldLocation) {
- var newLocation = oldToNew(oldLocation);
- return host.fileExists(oldLocation) || newLocation !== undefined && host.fileExists(newLocation) // TODO: GH#18217
- ? newLocation !== undefined ? { newFileName: newLocation, updated: true } : { newFileName: oldLocation, updated: false }
- : undefined;
+ // Search through all locations looking for a moved file, and only then test already existing files.
+ // This is because if `a.ts` is compiled to `a.js` and `a.ts` is moved, we don't want to resolve anything to `a.js`, but to `a.ts`'s new location.
+ return tryEach(tryGetNewFile) || tryEach(tryGetOldFile);
+ function tryEach(cb) {
+ return resolved && ((resolved.resolvedModule && cb(resolved.resolvedModule.resolvedFileName)) || ts.firstDefined(resolved.failedLookupLocations, cb));
+ }
+ function tryGetNewFile(oldFileName) {
+ var newFileName = oldToNew(oldFileName);
+ return newFileName !== undefined && host.fileExists(newFileName) ? { newFileName: newFileName, updated: true } : undefined; // TODO: GH#18217
+ }
+ function tryGetOldFile(oldFileName) {
+ var newFileName = oldToNew(oldFileName);
+ return host.fileExists(oldFileName) ? newFileName !== undefined ? { newFileName: newFileName, updated: true } : { newFileName: oldFileName, updated: false } : undefined; // TODO: GH#18217
}
}
function updateImportsWorker(sourceFile, changeTracker, updateRef, updateImport) {
- for (var _i = 0, _a = sourceFile.referencedFiles; _i < _a.length; _i++) {
+ for (var _i = 0, _a = sourceFile.referencedFiles || ts.emptyArray; _i < _a.length; _i++) { // TODO: GH#26162
var ref = _a[_i];
var updated = updateRef(ref.fileName);
if (updated !== undefined && updated !== sourceFile.text.slice(ref.pos, ref.end))
@@ -97024,7 +99192,7 @@ var ts;
}
}
function createStringRange(node, sourceFile) {
- return ts.createTextRange(node.getStart(sourceFile) + 1, node.end - 1);
+ return ts.createRange(node.getStart(sourceFile) + 1, node.end - 1);
}
function forEachProperty(objectLiteral, cb) {
if (!ts.isObjectLiteralExpression(objectLiteral))
@@ -97066,7 +99234,7 @@ var ts;
}
var calledDeclaration = tryGetSignatureDeclaration(typeChecker, node);
// Don't go to the component constructor definition for a JSX element, just go to the component definition.
- if (calledDeclaration && !(ts.isJsxOpeningLikeElement(node.parent) && ts.isConstructorDeclaration(calledDeclaration))) {
+ if (calledDeclaration && !(ts.isJsxOpeningLikeElement(node.parent) && isConstructorLike(calledDeclaration))) {
var sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
// For a function, if this is the original function definition, return just sigInfo.
// If this is the original constructor definition, parent is the class.
@@ -97332,6 +99500,16 @@ var ts;
// Don't go to a function type, go to the value having that type.
return ts.tryCast(signature && signature.declaration, function (d) { return ts.isFunctionLike(d) && !ts.isFunctionTypeNode(d); });
}
+ function isConstructorLike(node) {
+ switch (node.kind) {
+ case 155 /* Constructor */:
+ case 164 /* ConstructorType */:
+ case 159 /* ConstructSignature */:
+ return true;
+ default:
+ return false;
+ }
+ }
})(GoToDefinition = ts.GoToDefinition || (ts.GoToDefinition = {}));
})(ts || (ts = {}));
/* @internal */
@@ -97542,7 +99720,7 @@ var ts;
kindModifiers: "",
displayParts: [ts.textPart(name)],
documentation: ts.emptyArray,
- tags: ts.emptyArray,
+ tags: undefined,
codeActions: undefined,
};
}
@@ -97575,7 +99753,7 @@ var ts;
kindModifiers: "",
displayParts: [ts.textPart(name)],
documentation: ts.emptyArray,
- tags: ts.emptyArray,
+ tags: undefined,
codeActions: undefined,
};
}
@@ -97638,7 +99816,7 @@ var ts;
// * if the caret was directly in front of the object, then we add an extra line and indentation.
var preamble = "/**" + newLine + indentationStr + " * ";
var result = preamble + newLine +
- parameterDocComments(parameters, ts.hasJavaScriptFileExtension(sourceFile.fileName), indentationStr, newLine) +
+ parameterDocComments(parameters, ts.hasJSFileExtension(sourceFile.fileName), indentationStr, newLine) +
indentationStr + " */" +
(tokenStart === position ? newLine + indentationStr : "");
return { newText: result, caretOffset: preamble.length };
@@ -97698,7 +99876,7 @@ var ts;
return commentOwner.parent.kind === 242 /* ModuleDeclaration */ ? undefined : { commentOwner: commentOwner };
case 202 /* BinaryExpression */: {
var be = commentOwner;
- if (ts.getSpecialPropertyAssignmentKind(be) === 0 /* None */) {
+ if (ts.getAssignmentDeclarationKind(be) === 0 /* None */) {
return "quit";
}
var parameters_2 = ts.isFunctionLike(be.right) ? be.right.parameters : ts.emptyArray;
@@ -97741,7 +99919,7 @@ var ts;
if (!patternMatcher)
return ts.emptyArray;
var rawItems = [];
- var _loop_14 = function (sourceFile) {
+ var _loop_13 = function (sourceFile) {
cancellationToken.throwIfCancellationRequested();
if (excludeDtsFiles && sourceFile.isDeclarationFile) {
return "continue";
@@ -97751,9 +99929,9 @@ var ts;
});
};
// Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
- for (var _i = 0, sourceFiles_8 = sourceFiles; _i < sourceFiles_8.length; _i++) {
- var sourceFile = sourceFiles_8[_i];
- _loop_14(sourceFile);
+ for (var _i = 0, sourceFiles_6 = sourceFiles; _i < sourceFiles_6.length; _i++) {
+ var sourceFile = sourceFiles_6[_i];
+ _loop_13(sourceFile);
}
rawItems.sort(compareNavigateToItems);
return (maxResultCount === undefined ? rawItems : rawItems.slice(0, maxResultCount)).map(createNavigateToItem);
@@ -97766,8 +99944,8 @@ var ts;
if (!match) {
return; // continue to next named declarations
}
- for (var _i = 0, declarations_12 = declarations; _i < declarations_12.length; _i++) {
- var declaration = declarations_12[_i];
+ for (var _i = 0, declarations_13 = declarations; _i < declarations_13.length; _i++) {
+ var declaration = declarations_13[_i];
if (!shouldKeepItem(declaration, checker))
continue;
if (patternMatcher.patternContainsDots) {
@@ -98090,7 +100268,7 @@ var ts;
addLeafNode(node);
break;
case 202 /* BinaryExpression */: {
- var special = ts.getSpecialPropertyAssignmentKind(node);
+ var special = ts.getAssignmentDeclarationKind(node);
switch (special) {
case 1 /* ExportsProperty */:
case 2 /* ModuleExports */:
@@ -98416,28 +100594,49 @@ var ts;
return ts.getNodeModifiers(node);
}
function getFunctionOrClassName(node) {
+ var parent = node.parent;
if (node.name && ts.getFullWidth(node.name) > 0) {
return ts.declarationNameToString(node.name);
}
// See if it is a var initializer. If so, use the var name.
- else if (node.parent.kind === 235 /* VariableDeclaration */) {
- return ts.declarationNameToString(node.parent.name);
+ else if (ts.isVariableDeclaration(parent)) {
+ return ts.declarationNameToString(parent.name);
}
// See if it is of the form " = function(){...}". If so, use the text from the left-hand side.
- else if (node.parent.kind === 202 /* BinaryExpression */ &&
- node.parent.operatorToken.kind === 58 /* EqualsToken */) {
- return nodeText(node.parent.left).replace(whiteSpaceRegex, "");
+ else if (ts.isBinaryExpression(parent) && parent.operatorToken.kind === 58 /* EqualsToken */) {
+ return nodeText(parent.left).replace(whiteSpaceRegex, "");
}
// See if it is a property assignment, and if so use the property name
- else if (node.parent.kind === 273 /* PropertyAssignment */ && node.parent.name) {
- return nodeText(node.parent.name);
+ else if (ts.isPropertyAssignment(parent)) {
+ return nodeText(parent.name);
}
// Default exports are named "default"
else if (ts.getModifierFlags(node) & 512 /* Default */) {
return "default";
}
+ else if (ts.isClassLike(node)) {
+ return "";
+ }
+ else if (ts.isCallExpression(parent)) {
+ var name = getCalledExpressionName(parent.expression);
+ if (name !== undefined) {
+ var args = ts.mapDefined(parent.arguments, function (a) { return ts.isStringLiteral(a) ? a.getText(curSourceFile) : undefined; }).join(", ");
+ return name + "(" + args + ") callback";
+ }
+ }
+ return "";
+ }
+ function getCalledExpressionName(expr) {
+ if (ts.isIdentifier(expr)) {
+ return expr.text;
+ }
+ else if (ts.isPropertyAccessExpression(expr)) {
+ var left = getCalledExpressionName(expr.expression);
+ var right = expr.name.text;
+ return left === undefined ? right : left + "." + right;
+ }
else {
- return ts.isClassLike(node) ? "" : "