- if (token.kind === 29 /* LessThanToken */ && token.parent.kind === 286 /* JsxExpression */) {
+ if (token.kind === 29 /* LessThanToken */ && token.parent.kind === 287 /* JsxExpression */) {
return true;
}
//
{
// |
// } < /div>
- if (token && token.kind === 19 /* CloseBraceToken */ && token.parent.kind === 286 /* JsxExpression */) {
+ if (token && token.kind === 19 /* CloseBraceToken */ && token.parent.kind === 287 /* JsxExpression */) {
return true;
}
//
|
- if (token.kind === 29 /* LessThanToken */ && token.parent.kind === 279 /* JsxClosingElement */) {
+ if (token.kind === 29 /* LessThanToken */ && token.parent.kind === 280 /* JsxClosingElement */) {
return true;
}
return false;
@@ -122340,7 +124641,7 @@ var ts;
function isInsideJsxElement(sourceFile, position) {
function isInsideJsxElementTraversal(node) {
while (node) {
- if (node.kind >= 277 /* JsxSelfClosingElement */ && node.kind <= 286 /* JsxExpression */
+ if (node.kind >= 278 /* JsxSelfClosingElement */ && node.kind <= 287 /* JsxExpression */
|| node.kind === 11 /* JsxText */
|| node.kind === 29 /* LessThanToken */
|| node.kind === 31 /* GreaterThanToken */
@@ -122350,7 +124651,7 @@ var ts;
|| node.kind === 43 /* SlashToken */) {
node = node.parent;
}
- else if (node.kind === 276 /* JsxElement */) {
+ else if (node.kind === 277 /* JsxElement */) {
if (position > node.getStart(sourceFile))
return true;
node = node.parent;
@@ -122498,7 +124799,7 @@ var ts;
// falls through
case 112 /* TypeOfKeyword */:
case 94 /* ExtendsKeyword */:
- case 139 /* KeyOfKeyword */:
+ case 140 /* KeyOfKeyword */:
case 24 /* DotToken */:
case 51 /* BarToken */:
case 57 /* QuestionToken */:
@@ -122558,16 +124859,16 @@ var ts;
result.push("deprecated" /* deprecatedModifier */);
if (node.flags & 8388608 /* Ambient */)
result.push("declare" /* ambientModifier */);
- if (node.kind === 269 /* ExportAssignment */)
+ if (node.kind === 270 /* ExportAssignment */)
result.push("export" /* exportedModifier */);
return result.length > 0 ? result.join(",") : "" /* none */;
}
ts.getNodeModifiers = getNodeModifiers;
function getTypeArgumentOrTypeParameterList(node) {
- if (node.kind === 176 /* TypeReference */ || node.kind === 206 /* CallExpression */) {
+ if (node.kind === 177 /* TypeReference */ || node.kind === 207 /* CallExpression */) {
return node.typeArguments;
}
- if (ts.isFunctionLike(node) || node.kind === 255 /* ClassDeclaration */ || node.kind === 256 /* InterfaceDeclaration */) {
+ if (ts.isFunctionLike(node) || node.kind === 256 /* ClassDeclaration */ || node.kind === 257 /* InterfaceDeclaration */) {
return node.typeParameters;
}
return undefined;
@@ -122612,18 +124913,18 @@ var ts;
}
ts.cloneCompilerOptions = cloneCompilerOptions;
function isArrayLiteralOrObjectLiteralDestructuringPattern(node) {
- if (node.kind === 202 /* ArrayLiteralExpression */ ||
- node.kind === 203 /* ObjectLiteralExpression */) {
+ if (node.kind === 203 /* ArrayLiteralExpression */ ||
+ node.kind === 204 /* ObjectLiteralExpression */) {
// [a,b,c] from:
// [a, b, c] = someExpression;
- if (node.parent.kind === 219 /* BinaryExpression */ &&
+ if (node.parent.kind === 220 /* BinaryExpression */ &&
node.parent.left === node &&
node.parent.operatorToken.kind === 63 /* EqualsToken */) {
return true;
}
// [a, b, c] from:
// for([a, b, c] of expression)
- if (node.parent.kind === 242 /* ForOfStatement */ &&
+ if (node.parent.kind === 243 /* ForOfStatement */ &&
node.parent.initializer === node) {
return true;
}
@@ -122631,7 +124932,7 @@ var ts;
// [x, [a, b, c] ] = someExpression
// or
// {x, a: {a, b, c} } = someExpression
- if (isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent.kind === 291 /* PropertyAssignment */ ? node.parent.parent : node.parent)) {
+ if (isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent.kind === 294 /* PropertyAssignment */ ? node.parent.parent : node.parent)) {
return true;
}
}
@@ -122693,34 +124994,38 @@ var ts;
}
ts.createTextChange = createTextChange;
ts.typeKeywords = [
- 129 /* AnyKeyword */,
+ 130 /* AnyKeyword */,
128 /* AssertsKeyword */,
- 156 /* BigIntKeyword */,
- 132 /* BooleanKeyword */,
+ 157 /* BigIntKeyword */,
+ 133 /* BooleanKeyword */,
95 /* FalseKeyword */,
- 136 /* InferKeyword */,
- 139 /* KeyOfKeyword */,
- 142 /* NeverKeyword */,
+ 137 /* InferKeyword */,
+ 140 /* KeyOfKeyword */,
+ 143 /* NeverKeyword */,
104 /* NullKeyword */,
- 145 /* NumberKeyword */,
- 146 /* ObjectKeyword */,
- 143 /* ReadonlyKeyword */,
- 148 /* StringKeyword */,
- 149 /* SymbolKeyword */,
+ 146 /* NumberKeyword */,
+ 147 /* ObjectKeyword */,
+ 144 /* ReadonlyKeyword */,
+ 149 /* StringKeyword */,
+ 150 /* SymbolKeyword */,
110 /* TrueKeyword */,
114 /* VoidKeyword */,
- 151 /* UndefinedKeyword */,
- 152 /* UniqueKeyword */,
- 153 /* UnknownKeyword */,
+ 152 /* UndefinedKeyword */,
+ 153 /* UniqueKeyword */,
+ 154 /* UnknownKeyword */,
];
function isTypeKeyword(kind) {
return ts.contains(ts.typeKeywords, kind);
}
ts.isTypeKeyword = isTypeKeyword;
function isTypeKeywordToken(node) {
- return node.kind === 150 /* TypeKeyword */;
+ return node.kind === 151 /* TypeKeyword */;
}
ts.isTypeKeywordToken = isTypeKeywordToken;
+ function isTypeKeywordTokenOrIdentifier(node) {
+ return isTypeKeywordToken(node) || ts.isIdentifier(node) && node.text === "type";
+ }
+ ts.isTypeKeywordTokenOrIdentifier = isTypeKeywordTokenOrIdentifier;
/** True if the symbol is for an external module, as opposed to a namespace. */
function isExternalModuleSymbol(moduleSymbol) {
return !!(moduleSymbol.flags & 1536 /* Module */) && moduleSymbol.name.charCodeAt(0) === 34 /* doubleQuote */;
@@ -122751,7 +125056,7 @@ var ts;
}
ts.skipConstraint = skipConstraint;
function getNameFromPropertyName(name) {
- return name.kind === 160 /* ComputedPropertyName */
+ return name.kind === 161 /* ComputedPropertyName */
// treat computed property names where expression is string/numeric literal as just string/numeric literal
? ts.isStringOrNumericLiteralLike(name.expression) ? name.expression.text : undefined
: ts.isPrivateIdentifier(name) ? ts.idText(name) : ts.getTextOfIdentifierOrLiteral(name);
@@ -122761,14 +125066,14 @@ var ts;
return program.getSourceFiles().some(function (s) { return !s.isDeclarationFile && !program.isSourceFileFromExternalLibrary(s) && !!(s.externalModuleIndicator || s.commonJsModuleIndicator); });
}
ts.programContainsModules = programContainsModules;
- function programContainsEs6Modules(program) {
+ function programContainsEsModules(program) {
return program.getSourceFiles().some(function (s) { return !s.isDeclarationFile && !program.isSourceFileFromExternalLibrary(s) && !!s.externalModuleIndicator; });
}
- ts.programContainsEs6Modules = programContainsEs6Modules;
- function compilerOptionsIndicateEs6Modules(compilerOptions) {
- return !!compilerOptions.module || compilerOptions.target >= 2 /* ES2015 */ || !!compilerOptions.noEmit;
+ ts.programContainsEsModules = programContainsEsModules;
+ function compilerOptionsIndicateEsModules(compilerOptions) {
+ return !!compilerOptions.module || ts.getEmitScriptTarget(compilerOptions) >= 2 /* ES2015 */ || !!compilerOptions.noEmit;
}
- ts.compilerOptionsIndicateEs6Modules = compilerOptionsIndicateEs6Modules;
+ ts.compilerOptionsIndicateEsModules = compilerOptionsIndicateEsModules;
function createModuleSpecifierResolutionHost(program, host) {
// Mix in `getSymlinkCache` from Program when host doesn't have it
// in order for non-Project hosts to have a symlinks cache.
@@ -122801,7 +125106,8 @@ var ts;
/*decorators*/ undefined,
/*modifiers*/ undefined, defaultImport || namedImports
? ts.factory.createImportClause(!!isTypeOnly, defaultImport, namedImports && namedImports.length ? ts.factory.createNamedImports(namedImports) : undefined)
- : undefined, typeof moduleSpecifier === "string" ? makeStringLiteral(moduleSpecifier, quotePreference) : moduleSpecifier);
+ : undefined, typeof moduleSpecifier === "string" ? makeStringLiteral(moduleSpecifier, quotePreference) : moduleSpecifier,
+ /*assertClause*/ undefined);
}
ts.makeImport = makeImport;
function makeStringLiteral(text, quotePreference) {
@@ -122892,7 +125198,7 @@ var ts;
ts.findModifier = findModifier;
function insertImports(changes, sourceFile, imports, blankLineBetween) {
var decl = ts.isArray(imports) ? imports[0] : imports;
- var importKindPredicate = decl.kind === 235 /* VariableStatement */ ? ts.isRequireVariableStatement : ts.isAnyImportSyntax;
+ var importKindPredicate = decl.kind === 236 /* VariableStatement */ ? ts.isRequireVariableStatement : ts.isAnyImportSyntax;
var existingImportStatements = ts.filter(sourceFile.statements, importKindPredicate);
var sortedNewImports = ts.isArray(imports) ? ts.stableSort(imports, ts.OrganizeImports.compareImportsOrRequireStatements) : [imports];
if (!existingImportStatements.length) {
@@ -122970,7 +125276,10 @@ var ts;
// Display-part writer helpers
// #region
function isFirstDeclarationOfSymbolParameter(symbol) {
- return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 162 /* Parameter */;
+ var declaration = symbol.declarations ? ts.firstOrUndefined(symbol.declarations) : undefined;
+ return !!ts.findAncestor(declaration, function (n) {
+ return ts.isParameter(n) ? true : ts.isBindingElement(n) || ts.isObjectBindingPattern(n) || ts.isArrayBindingPattern(n) ? false : "quit";
+ });
}
ts.isFirstDeclarationOfSymbolParameter = isFirstDeclarationOfSymbolParameter;
var displayPartWriter = getDisplayPartWriter();
@@ -123070,45 +125379,32 @@ var ts;
if (flags & 3 /* Variable */) {
return isFirstDeclarationOfSymbolParameter(symbol) ? ts.SymbolDisplayPartKind.parameterName : ts.SymbolDisplayPartKind.localName;
}
- else if (flags & 4 /* Property */) {
+ if (flags & 4 /* Property */)
return ts.SymbolDisplayPartKind.propertyName;
- }
- else if (flags & 32768 /* GetAccessor */) {
+ if (flags & 32768 /* GetAccessor */)
return ts.SymbolDisplayPartKind.propertyName;
- }
- else if (flags & 65536 /* SetAccessor */) {
+ if (flags & 65536 /* SetAccessor */)
return ts.SymbolDisplayPartKind.propertyName;
- }
- else if (flags & 8 /* EnumMember */) {
+ if (flags & 8 /* EnumMember */)
return ts.SymbolDisplayPartKind.enumMemberName;
- }
- else if (flags & 16 /* Function */) {
+ if (flags & 16 /* Function */)
return ts.SymbolDisplayPartKind.functionName;
- }
- else if (flags & 32 /* Class */) {
+ if (flags & 32 /* Class */)
return ts.SymbolDisplayPartKind.className;
- }
- else if (flags & 64 /* Interface */) {
+ if (flags & 64 /* Interface */)
return ts.SymbolDisplayPartKind.interfaceName;
- }
- else if (flags & 384 /* Enum */) {
+ if (flags & 384 /* Enum */)
return ts.SymbolDisplayPartKind.enumName;
- }
- else if (flags & 1536 /* Module */) {
+ if (flags & 1536 /* Module */)
return ts.SymbolDisplayPartKind.moduleName;
- }
- else if (flags & 8192 /* Method */) {
+ if (flags & 8192 /* Method */)
return ts.SymbolDisplayPartKind.methodName;
- }
- else if (flags & 262144 /* TypeParameter */) {
+ if (flags & 262144 /* TypeParameter */)
return ts.SymbolDisplayPartKind.typeParameterName;
- }
- else if (flags & 524288 /* TypeAlias */) {
+ if (flags & 524288 /* TypeAlias */)
return ts.SymbolDisplayPartKind.aliasName;
- }
- else if (flags & 2097152 /* Alias */) {
+ if (flags & 2097152 /* Alias */)
return ts.SymbolDisplayPartKind.aliasName;
- }
return ts.SymbolDisplayPartKind.text;
}
}
@@ -123164,9 +125460,9 @@ var ts;
return displayPart(text, ts.SymbolDisplayPartKind.linkText);
}
ts.linkTextPart = linkTextPart;
- function linkNamePart(name, target) {
+ function linkNamePart(text, target) {
return {
- text: ts.getTextOfNode(name),
+ text: text,
kind: ts.SymbolDisplayPartKind[ts.SymbolDisplayPartKind.linkName],
target: {
fileName: ts.getSourceFileOfNode(target).fileName,
@@ -123186,27 +125482,46 @@ var ts;
: "linkplain";
var parts = [linkPart("{@" + prefix + " ")];
if (!link.name) {
- if (link.text) {
+ if (link.text)
parts.push(linkTextPart(link.text));
- }
}
else {
var symbol = checker === null || checker === void 0 ? void 0 : checker.getSymbolAtLocation(link.name);
+ var suffix = findLinkNameEnd(link.text);
+ var name = ts.getTextOfNode(link.name) + link.text.slice(0, suffix);
+ var text = link.text.slice(suffix);
var decl = (symbol === null || symbol === void 0 ? void 0 : symbol.valueDeclaration) || ((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0]);
if (decl) {
- parts.push(linkNamePart(link.name, decl));
- if (link.text) {
- parts.push(linkTextPart(link.text));
- }
+ parts.push(linkNamePart(name, decl));
+ if (text)
+ parts.push(linkTextPart(text));
}
else {
- parts.push(linkTextPart(ts.getTextOfNode(link.name) + " " + link.text));
+ parts.push(linkTextPart(name + (suffix ? "" : " ") + text));
}
}
parts.push(linkPart("}"));
return parts;
}
ts.buildLinkParts = buildLinkParts;
+ function findLinkNameEnd(text) {
+ if (text.indexOf("()") === 0)
+ return 2;
+ if (text[0] !== "<")
+ return 0;
+ var brackets = 0;
+ var i = 0;
+ while (i < text.length) {
+ if (text[i] === "<")
+ brackets++;
+ if (text[i] === ">")
+ brackets--;
+ i++;
+ if (!brackets)
+ return i;
+ }
+ return 0;
+ }
var carriageReturnLineFeed = "\r\n";
/**
* The default is CRLF.
@@ -123504,15 +125819,15 @@ var ts;
function getContextualTypeFromParent(node, checker) {
var parent = node.parent;
switch (parent.kind) {
- case 207 /* NewExpression */:
+ case 208 /* NewExpression */:
return checker.getContextualType(parent);
- case 219 /* BinaryExpression */: {
+ case 220 /* BinaryExpression */: {
var _a = parent, left = _a.left, operatorToken = _a.operatorToken, right = _a.right;
return isEqualityOperatorKind(operatorToken.kind)
? checker.getTypeAtLocation(node === right ? left : right)
: checker.getContextualType(node);
}
- case 287 /* CaseClause */:
+ case 288 /* CaseClause */:
return parent.expression === node ? getSwitchedType(parent, checker) : undefined;
default:
return checker.getContextualType(node);
@@ -123542,8 +125857,8 @@ var ts;
switch (node.kind) {
case 10 /* StringLiteral */:
case 14 /* NoSubstitutionTemplateLiteral */:
- case 221 /* TemplateExpression */:
- case 208 /* TaggedTemplateExpression */:
+ case 222 /* TemplateExpression */:
+ case 209 /* TaggedTemplateExpression */:
return true;
default:
return false;
@@ -123562,7 +125877,7 @@ var ts;
function getTypeNodeIfAccessible(type, enclosingScope, program, host) {
var checker = program.getTypeChecker();
var typeIsAccessible = true;
- var notAccessible = function () { typeIsAccessible = false; };
+ var notAccessible = function () { return typeIsAccessible = false; };
var res = checker.typeToTypeNode(type, enclosingScope, 1 /* NoTruncation */, {
trackSymbol: function (symbol, declaration, meaning) {
typeIsAccessible = typeIsAccessible && checker.isSymbolAccessible(symbol, declaration, meaning, /*shouldComputeAliasToMarkVisible*/ false).accessibility === 0 /* Accessible */;
@@ -123577,41 +125892,41 @@ var ts;
}
ts.getTypeNodeIfAccessible = getTypeNodeIfAccessible;
function syntaxRequiresTrailingCommaOrSemicolonOrASI(kind) {
- return kind === 172 /* CallSignature */
- || kind === 173 /* ConstructSignature */
- || kind === 174 /* IndexSignature */
- || kind === 164 /* PropertySignature */
- || kind === 166 /* MethodSignature */;
+ return kind === 173 /* CallSignature */
+ || kind === 174 /* ConstructSignature */
+ || kind === 175 /* IndexSignature */
+ || kind === 165 /* PropertySignature */
+ || kind === 167 /* MethodSignature */;
}
ts.syntaxRequiresTrailingCommaOrSemicolonOrASI = syntaxRequiresTrailingCommaOrSemicolonOrASI;
function syntaxRequiresTrailingFunctionBlockOrSemicolonOrASI(kind) {
- return kind === 254 /* FunctionDeclaration */
- || kind === 169 /* Constructor */
- || kind === 167 /* MethodDeclaration */
- || kind === 170 /* GetAccessor */
- || kind === 171 /* SetAccessor */;
+ return kind === 255 /* FunctionDeclaration */
+ || kind === 170 /* Constructor */
+ || kind === 168 /* MethodDeclaration */
+ || kind === 171 /* GetAccessor */
+ || kind === 172 /* SetAccessor */;
}
ts.syntaxRequiresTrailingFunctionBlockOrSemicolonOrASI = syntaxRequiresTrailingFunctionBlockOrSemicolonOrASI;
function syntaxRequiresTrailingModuleBlockOrSemicolonOrASI(kind) {
- return kind === 259 /* ModuleDeclaration */;
+ return kind === 260 /* ModuleDeclaration */;
}
ts.syntaxRequiresTrailingModuleBlockOrSemicolonOrASI = syntaxRequiresTrailingModuleBlockOrSemicolonOrASI;
function syntaxRequiresTrailingSemicolonOrASI(kind) {
- return kind === 235 /* VariableStatement */
- || kind === 236 /* ExpressionStatement */
- || kind === 238 /* DoStatement */
- || kind === 243 /* ContinueStatement */
- || kind === 244 /* BreakStatement */
- || kind === 245 /* ReturnStatement */
- || kind === 249 /* ThrowStatement */
- || kind === 251 /* DebuggerStatement */
- || kind === 165 /* PropertyDeclaration */
- || kind === 257 /* TypeAliasDeclaration */
- || kind === 264 /* ImportDeclaration */
- || kind === 263 /* ImportEqualsDeclaration */
- || kind === 270 /* ExportDeclaration */
- || kind === 262 /* NamespaceExportDeclaration */
- || kind === 269 /* ExportAssignment */;
+ return kind === 236 /* VariableStatement */
+ || kind === 237 /* ExpressionStatement */
+ || kind === 239 /* DoStatement */
+ || kind === 244 /* ContinueStatement */
+ || kind === 245 /* BreakStatement */
+ || kind === 246 /* ReturnStatement */
+ || kind === 250 /* ThrowStatement */
+ || kind === 252 /* DebuggerStatement */
+ || kind === 166 /* PropertyDeclaration */
+ || kind === 258 /* TypeAliasDeclaration */
+ || kind === 265 /* ImportDeclaration */
+ || kind === 264 /* ImportEqualsDeclaration */
+ || kind === 271 /* ExportDeclaration */
+ || kind === 263 /* NamespaceExportDeclaration */
+ || kind === 270 /* ExportAssignment */;
}
ts.syntaxRequiresTrailingSemicolonOrASI = syntaxRequiresTrailingSemicolonOrASI;
ts.syntaxMayBeASICandidate = ts.or(syntaxRequiresTrailingCommaOrSemicolonOrASI, syntaxRequiresTrailingFunctionBlockOrSemicolonOrASI, syntaxRequiresTrailingModuleBlockOrSemicolonOrASI, syntaxRequiresTrailingSemicolonOrASI);
@@ -123641,7 +125956,7 @@ var ts;
return false;
}
// See comment in parser’s `parseDoStatement`
- if (node.kind === 238 /* DoStatement */) {
+ if (node.kind === 239 /* DoStatement */) {
return true;
}
var topNode = ts.findAncestor(node, function (ancestor) { return !ancestor.parent; });
@@ -123964,6 +126279,21 @@ var ts;
return ts.createTextSpanFromBounds(startPosition, endPosition === undefined ? startPosition : endPosition);
}
ts.getRefactorContextSpan = getRefactorContextSpan;
+ /* @internal */
+ function getFixableErrorSpanExpression(sourceFile, span) {
+ var token = getTokenAtPosition(sourceFile, span.start);
+ // Checker has already done work to determine that await might be possible, and has attached
+ // related info to the node, so start by finding the expression that exactly matches up
+ // with the diagnostic range.
+ var expression = ts.findAncestor(token, function (node) {
+ if (node.getStart(sourceFile) < span.start || node.getEnd() > ts.textSpanEnd(span)) {
+ return "quit";
+ }
+ return ts.isExpression(node) && textSpansEqual(span, createTextSpanFromNode(node, sourceFile));
+ });
+ return expression;
+ }
+ ts.getFixableErrorSpanExpression = getFixableErrorSpanExpression;
function mapOneOrMany(valueOrArray, f, resultSelector) {
if (resultSelector === void 0) { resultSelector = ts.identity; }
return valueOrArray ? ts.isArray(valueOrArray) ? resultSelector(ts.map(valueOrArray, f)) : f(valueOrArray, 0) : undefined;
@@ -124056,6 +126386,16 @@ var ts;
return decisionFromFile !== null && decisionFromFile !== void 0 ? decisionFromFile : program.usesUriStyleNodeCoreModules;
}
ts.shouldUseUriStyleNodeCoreModules = shouldUseUriStyleNodeCoreModules;
+ function getNewLineKind(newLineCharacter) {
+ return newLineCharacter === "\n" ? 1 /* LineFeed */ : 0 /* CarriageReturnLineFeed */;
+ }
+ ts.getNewLineKind = getNewLineKind;
+ function diagnosticToString(diag) {
+ return ts.isArray(diag)
+ ? ts.formatStringFromArgs(ts.getLocaleSpecificMessage(diag[0]), diag.slice(1))
+ : ts.getLocaleSpecificMessage(diag);
+ }
+ ts.diagnosticToString = diagnosticToString;
// #endregion
})(ts || (ts = {}));
/*@internal*/
@@ -124095,19 +126435,24 @@ var ts;
}
var isDefault = exportKind === 1 /* Default */;
var namedSymbol = isDefault && ts.getLocalSymbolForExportDefault(symbol) || symbol;
- // A re-export merged with an export from a module augmentation can result in `symbol`
- // being an external module symbol; the name it is re-exported by will be `symbolTableKey`
- // (which comes from the keys of `moduleSymbol.exports`.)
- var importedName = ts.isExternalModuleSymbol(namedSymbol)
+ // 1. A named export must be imported by its key in `moduleSymbol.exports` or `moduleSymbol.members`.
+ // 2. A re-export merged with an export from a module augmentation can result in `symbol`
+ // being an external module symbol; the name it is re-exported by will be `symbolTableKey`
+ // (which comes from the keys of `moduleSymbol.exports`.)
+ // 3. Otherwise, we have a default/namespace import that can be imported by any name, and
+ // `symbolTableKey` will be something undesirable like `export=` or `default`, so we try to
+ // get a better name.
+ var importedName = exportKind === 0 /* Named */ || ts.isExternalModuleSymbol(namedSymbol)
? ts.unescapeLeadingUnderscores(symbolTableKey)
: ts.getNameForExportedSymbol(namedSymbol, scriptTarget);
var moduleName = ts.stripQuotes(moduleSymbol.name);
var id = exportInfoId++;
+ var target = ts.skipAlias(symbol, checker);
var storedSymbol = symbol.flags & 33554432 /* Transient */ ? undefined : symbol;
var storedModuleSymbol = moduleSymbol.flags & 33554432 /* Transient */ ? undefined : moduleSymbol;
if (!storedSymbol || !storedModuleSymbol)
symbols.set(id, [symbol, moduleSymbol]);
- exportInfo.add(key(importedName, symbol, moduleName, checker), {
+ exportInfo.add(key(importedName, symbol, ts.isExternalModuleNameRelative(moduleName) ? undefined : moduleName, checker), {
id: id,
symbolTableKey: symbolTableKey,
symbolName: importedName,
@@ -124115,16 +126460,16 @@ var ts;
moduleFile: moduleFile,
moduleFileName: moduleFile === null || moduleFile === void 0 ? void 0 : moduleFile.fileName,
exportKind: exportKind,
- targetFlags: ts.skipAlias(symbol, checker).flags,
+ targetFlags: target.flags,
isFromPackageJson: isFromPackageJson,
symbol: storedSymbol,
moduleSymbol: storedModuleSymbol,
});
},
- get: function (importingFile, importedName, symbol, moduleName, checker) {
+ get: function (importingFile, key) {
if (importingFile !== usableByFileName)
return;
- var result = exportInfo.get(key(importedName, symbol, moduleName, checker));
+ var result = exportInfo.get(key);
return result === null || result === void 0 ? void 0 : result.map(rehydrateCachedInfo);
},
forEach: function (importingFile, action) {
@@ -124132,7 +126477,7 @@ var ts;
return;
exportInfo.forEach(function (info, key) {
var _a = parseKey(key), symbolName = _a.symbolName, ambientModuleName = _a.ambientModuleName;
- action(info.map(rehydrateCachedInfo), symbolName, !!ambientModuleName);
+ action(info.map(rehydrateCachedInfo), symbolName, !!ambientModuleName, key);
});
},
releaseSymbols: function () {
@@ -124197,26 +126542,16 @@ var ts;
isFromPackageJson: isFromPackageJson,
};
}
- function key(importedName, symbol, moduleName, checker) {
- var unquoted = ts.stripQuotes(moduleName);
- var moduleKey = ts.isExternalModuleNameRelative(unquoted) ? "/" : unquoted;
- var target = ts.skipAlias(symbol, checker);
- return importedName + "|" + createSymbolKey(target) + "|" + moduleKey;
+ function key(importedName, symbol, ambientModuleName, checker) {
+ var moduleKey = ambientModuleName || "";
+ return importedName + "|" + ts.getSymbolId(ts.skipAlias(symbol, checker)) + "|" + moduleKey;
}
function parseKey(key) {
var symbolName = key.substring(0, key.indexOf("|"));
var moduleKey = key.substring(key.lastIndexOf("|") + 1);
- var ambientModuleName = moduleKey === "/" ? undefined : moduleKey;
+ var ambientModuleName = moduleKey === "" ? undefined : moduleKey;
return { symbolName: symbolName, ambientModuleName: ambientModuleName };
}
- function createSymbolKey(symbol) {
- var key = symbol.name;
- while (symbol.parent) {
- key += "," + symbol.parent.name;
- symbol = symbol.parent;
- }
- return key;
- }
function fileIsGlobalOnly(file) {
return !file.commonJsModuleIndicator && !file.externalModuleIndicator && !file.moduleAugmentations && !file.ambientModuleNames;
}
@@ -124226,7 +126561,7 @@ var ts;
}
var oldFileStatementIndex = -1;
var newFileStatementIndex = -1;
- var _loop_1 = function (ambientModuleName) {
+ var _loop_2 = function (ambientModuleName) {
var isMatchingModuleDeclaration = function (node) { return ts.isNonGlobalAmbientModule(node) && node.name.text === ambientModuleName; };
oldFileStatementIndex = ts.findIndex(oldSourceFile.statements, isMatchingModuleDeclaration, oldFileStatementIndex + 1);
newFileStatementIndex = ts.findIndex(newSourceFile.statements, isMatchingModuleDeclaration, newFileStatementIndex + 1);
@@ -124236,9 +126571,9 @@ var ts;
};
for (var _i = 0, _a = newSourceFile.ambientModuleNames; _i < _a.length; _i++) {
var ambientModuleName = _a[_i];
- var state_1 = _loop_1(ambientModuleName);
- if (typeof state_1 === "object")
- return state_1.value;
+ var state_2 = _loop_2(ambientModuleName);
+ if (typeof state_2 === "object")
+ return state_2.value;
}
return true;
}
@@ -124338,7 +126673,7 @@ var ts;
cache.add(importingFile.path, defaultInfo.symbol, defaultInfo.exportKind === 1 /* Default */ ? "default" /* Default */ : "export=" /* ExportEquals */, moduleSymbol, moduleFile, defaultInfo.exportKind, isFromPackageJson, scriptTarget, checker);
}
checker.forEachExportAndPropertyOfModule(moduleSymbol, function (exported, key) {
- if (exported !== (defaultInfo === null || defaultInfo === void 0 ? void 0 : defaultInfo.symbol) && isImportableSymbol(exported, checker) && ts.addToSeen(seenExports, exported)) {
+ if (exported !== (defaultInfo === null || defaultInfo === void 0 ? void 0 : defaultInfo.symbol) && isImportableSymbol(exported, checker) && ts.addToSeen(seenExports, key)) {
cache.add(importingFile.path, exported, key, moduleSymbol, moduleFile, 0 /* Named */, isFromPackageJson, scriptTarget, checker);
}
});
@@ -124503,11 +126838,11 @@ var ts;
angleBracketStack--;
}
break;
- case 129 /* AnyKeyword */:
- case 148 /* StringKeyword */:
- case 145 /* NumberKeyword */:
- case 132 /* BooleanKeyword */:
- case 149 /* SymbolKeyword */:
+ case 130 /* AnyKeyword */:
+ case 149 /* StringKeyword */:
+ case 146 /* NumberKeyword */:
+ case 133 /* BooleanKeyword */:
+ case 150 /* SymbolKeyword */:
if (angleBracketStack > 0 && !syntacticClassifierAbsent) {
// If it looks like we're could be in something generic, don't classify this
// as a keyword. We may just get overwritten by the syntactic classifier,
@@ -124696,9 +127031,9 @@ var ts;
return true;
}
switch (keyword2) {
- case 135 /* GetKeyword */:
- case 147 /* SetKeyword */:
- case 133 /* ConstructorKeyword */:
+ case 136 /* GetKeyword */:
+ case 148 /* SetKeyword */:
+ case 134 /* ConstructorKeyword */:
case 124 /* StaticKeyword */:
return true; // Allow things like "public get", "public constructor" and "public static".
default:
@@ -124842,13 +127177,13 @@ var ts;
// That means we're calling back into the host around every 1.2k of the file we process.
// Lib.d.ts has similar numbers.
switch (kind) {
- case 259 /* ModuleDeclaration */:
- case 255 /* ClassDeclaration */:
- case 256 /* InterfaceDeclaration */:
- case 254 /* FunctionDeclaration */:
- case 224 /* ClassExpression */:
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
+ case 260 /* ModuleDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 257 /* InterfaceDeclaration */:
+ case 255 /* FunctionDeclaration */:
+ case 225 /* ClassExpression */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
cancellationToken.throwIfCancellationRequested();
}
}
@@ -125070,46 +127405,46 @@ var ts;
pos = tag.tagName.end;
var commentStart = tag.tagName.end;
switch (tag.kind) {
- case 335 /* JSDocParameterTag */:
+ case 338 /* JSDocParameterTag */:
var param = tag;
processJSDocParameterTag(param);
commentStart = param.isNameFirst && ((_a = param.typeExpression) === null || _a === void 0 ? void 0 : _a.end) || param.name.end;
break;
- case 342 /* JSDocPropertyTag */:
+ case 345 /* JSDocPropertyTag */:
var prop = tag;
commentStart = prop.isNameFirst && ((_b = prop.typeExpression) === null || _b === void 0 ? void 0 : _b.end) || prop.name.end;
break;
- case 339 /* JSDocTemplateTag */:
+ case 342 /* JSDocTemplateTag */:
processJSDocTemplateTag(tag);
pos = tag.end;
commentStart = tag.typeParameters.end;
break;
- case 340 /* JSDocTypedefTag */:
+ case 343 /* JSDocTypedefTag */:
var type = tag;
- commentStart = ((_c = type.typeExpression) === null || _c === void 0 ? void 0 : _c.kind) === 304 /* JSDocTypeExpression */ && ((_d = type.fullName) === null || _d === void 0 ? void 0 : _d.end) || ((_e = type.typeExpression) === null || _e === void 0 ? void 0 : _e.end) || commentStart;
+ commentStart = ((_c = type.typeExpression) === null || _c === void 0 ? void 0 : _c.kind) === 307 /* JSDocTypeExpression */ && ((_d = type.fullName) === null || _d === void 0 ? void 0 : _d.end) || ((_e = type.typeExpression) === null || _e === void 0 ? void 0 : _e.end) || commentStart;
break;
- case 333 /* JSDocCallbackTag */:
+ case 336 /* JSDocCallbackTag */:
commentStart = tag.typeExpression.end;
break;
- case 338 /* JSDocTypeTag */:
+ case 341 /* JSDocTypeTag */:
processElement(tag.typeExpression);
pos = tag.end;
commentStart = tag.typeExpression.end;
break;
- case 337 /* JSDocThisTag */:
- case 334 /* JSDocEnumTag */:
+ case 340 /* JSDocThisTag */:
+ case 337 /* JSDocEnumTag */:
commentStart = tag.typeExpression.end;
break;
- case 336 /* JSDocReturnTag */:
+ case 339 /* JSDocReturnTag */:
processElement(tag.typeExpression);
pos = tag.end;
commentStart = ((_f = tag.typeExpression) === null || _f === void 0 ? void 0 : _f.end) || commentStart;
break;
- case 341 /* JSDocSeeTag */:
+ case 344 /* JSDocSeeTag */:
commentStart = ((_g = tag.name) === null || _g === void 0 ? void 0 : _g.end) || commentStart;
break;
- case 323 /* JSDocAugmentsTag */:
- case 324 /* JSDocImplementsTag */:
+ case 326 /* JSDocAugmentsTag */:
+ case 327 /* JSDocImplementsTag */:
commentStart = tag.class.end;
break;
}
@@ -125266,22 +127601,22 @@ var ts;
}
function tryClassifyJsxElementName(token) {
switch (token.parent && token.parent.kind) {
- case 278 /* JsxOpeningElement */:
+ case 279 /* JsxOpeningElement */:
if (token.parent.tagName === token) {
return 19 /* jsxOpenTagName */;
}
break;
- case 279 /* JsxClosingElement */:
+ case 280 /* JsxClosingElement */:
if (token.parent.tagName === token) {
return 20 /* jsxCloseTagName */;
}
break;
- case 277 /* JsxSelfClosingElement */:
+ case 278 /* JsxSelfClosingElement */:
if (token.parent.tagName === token) {
return 21 /* jsxSelfClosingTagName */;
}
break;
- case 283 /* JsxAttribute */:
+ case 284 /* JsxAttribute */:
if (token.parent.name === token) {
return 22 /* jsxAttribute */;
}
@@ -125310,17 +127645,17 @@ var ts;
var parent = token.parent;
if (tokenKind === 63 /* EqualsToken */) {
// the '=' in a variable declaration is special cased here.
- if (parent.kind === 252 /* VariableDeclaration */ ||
- parent.kind === 165 /* PropertyDeclaration */ ||
- parent.kind === 162 /* Parameter */ ||
- parent.kind === 283 /* JsxAttribute */) {
+ if (parent.kind === 253 /* VariableDeclaration */ ||
+ parent.kind === 166 /* PropertyDeclaration */ ||
+ parent.kind === 163 /* Parameter */ ||
+ parent.kind === 284 /* JsxAttribute */) {
return 5 /* operator */;
}
}
- if (parent.kind === 219 /* BinaryExpression */ ||
- parent.kind === 217 /* PrefixUnaryExpression */ ||
- parent.kind === 218 /* PostfixUnaryExpression */ ||
- parent.kind === 220 /* ConditionalExpression */) {
+ if (parent.kind === 220 /* BinaryExpression */ ||
+ parent.kind === 218 /* PrefixUnaryExpression */ ||
+ parent.kind === 219 /* PostfixUnaryExpression */ ||
+ parent.kind === 221 /* ConditionalExpression */) {
return 5 /* operator */;
}
}
@@ -125333,7 +127668,7 @@ var ts;
return 25 /* bigintLiteral */;
}
else if (tokenKind === 10 /* StringLiteral */) {
- return token && token.parent.kind === 283 /* JsxAttribute */ ? 24 /* jsxAttributeStringLiteralValue */ : 6 /* stringLiteral */;
+ return token && token.parent.kind === 284 /* JsxAttribute */ ? 24 /* jsxAttributeStringLiteralValue */ : 6 /* stringLiteral */;
}
else if (tokenKind === 13 /* RegularExpressionLiteral */) {
// TODO: we should get another classification type for these literals.
@@ -125349,32 +127684,32 @@ var ts;
else if (tokenKind === 79 /* Identifier */) {
if (token) {
switch (token.parent.kind) {
- case 255 /* ClassDeclaration */:
+ case 256 /* ClassDeclaration */:
if (token.parent.name === token) {
return 11 /* className */;
}
return;
- case 161 /* TypeParameter */:
+ case 162 /* TypeParameter */:
if (token.parent.name === token) {
return 15 /* typeParameterName */;
}
return;
- case 256 /* InterfaceDeclaration */:
+ case 257 /* InterfaceDeclaration */:
if (token.parent.name === token) {
return 13 /* interfaceName */;
}
return;
- case 258 /* EnumDeclaration */:
+ case 259 /* EnumDeclaration */:
if (token.parent.name === token) {
return 12 /* enumName */;
}
return;
- case 259 /* ModuleDeclaration */:
+ case 260 /* ModuleDeclaration */:
if (token.parent.name === token) {
return 14 /* moduleName */;
}
return;
- case 162 /* Parameter */:
+ case 163 /* Parameter */:
if (token.parent.name === token) {
return ts.isThisIdentifier(token) ? 3 /* keyword */ : 17 /* parameterName */;
}
@@ -125476,13 +127811,13 @@ var ts;
var inJSXElement = false;
function visit(node) {
switch (node.kind) {
- case 259 /* ModuleDeclaration */:
- case 255 /* ClassDeclaration */:
- case 256 /* InterfaceDeclaration */:
- case 254 /* FunctionDeclaration */:
- case 224 /* ClassExpression */:
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
+ case 260 /* ModuleDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 257 /* InterfaceDeclaration */:
+ case 255 /* FunctionDeclaration */:
+ case 225 /* ClassExpression */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
cancellationToken.throwIfCancellationRequested();
}
if (!node || !ts.textSpanIntersectsWith(span, node.pos, node.getFullWidth()) || node.getFullWidth() === 0) {
@@ -125628,25 +127963,25 @@ var ts;
return (ts.isQualifiedName(node.parent) && node.parent.right === node) || (ts.isPropertyAccessExpression(node.parent) && node.parent.name === node);
}
var tokenFromDeclarationMapping = new ts.Map([
- [252 /* VariableDeclaration */, 7 /* variable */],
- [162 /* Parameter */, 6 /* parameter */],
- [165 /* PropertyDeclaration */, 9 /* property */],
- [259 /* ModuleDeclaration */, 3 /* namespace */],
- [258 /* EnumDeclaration */, 1 /* enum */],
- [294 /* EnumMember */, 8 /* enumMember */],
- [255 /* ClassDeclaration */, 0 /* class */],
- [167 /* MethodDeclaration */, 11 /* member */],
- [254 /* FunctionDeclaration */, 10 /* function */],
- [211 /* FunctionExpression */, 10 /* function */],
- [166 /* MethodSignature */, 11 /* member */],
- [170 /* GetAccessor */, 9 /* property */],
- [171 /* SetAccessor */, 9 /* property */],
- [164 /* PropertySignature */, 9 /* property */],
- [256 /* InterfaceDeclaration */, 2 /* interface */],
- [257 /* TypeAliasDeclaration */, 5 /* type */],
- [161 /* TypeParameter */, 4 /* typeParameter */],
- [291 /* PropertyAssignment */, 9 /* property */],
- [292 /* ShorthandPropertyAssignment */, 9 /* property */]
+ [253 /* VariableDeclaration */, 7 /* variable */],
+ [163 /* Parameter */, 6 /* parameter */],
+ [166 /* PropertyDeclaration */, 9 /* property */],
+ [260 /* ModuleDeclaration */, 3 /* namespace */],
+ [259 /* EnumDeclaration */, 1 /* enum */],
+ [297 /* EnumMember */, 8 /* enumMember */],
+ [256 /* ClassDeclaration */, 0 /* class */],
+ [168 /* MethodDeclaration */, 11 /* member */],
+ [255 /* FunctionDeclaration */, 10 /* function */],
+ [212 /* FunctionExpression */, 10 /* function */],
+ [167 /* MethodSignature */, 11 /* member */],
+ [171 /* GetAccessor */, 9 /* property */],
+ [172 /* SetAccessor */, 9 /* property */],
+ [165 /* PropertySignature */, 9 /* property */],
+ [257 /* InterfaceDeclaration */, 2 /* interface */],
+ [258 /* TypeAliasDeclaration */, 5 /* type */],
+ [162 /* TypeParameter */, 4 /* typeParameter */],
+ [294 /* PropertyAssignment */, 9 /* property */],
+ [295 /* ShorthandPropertyAssignment */, 9 /* property */]
]);
})(v2020 = classifier.v2020 || (classifier.v2020 = {}));
})(classifier = ts.classifier || (ts.classifier = {}));
@@ -125658,7 +127993,7 @@ var ts;
(function (Completions) {
var StringCompletions;
(function (StringCompletions) {
- function getStringLiteralCompletions(sourceFile, position, contextToken, checker, options, host, log, preferences) {
+ function getStringLiteralCompletions(sourceFile, position, contextToken, options, host, program, log, preferences) {
if (ts.isInReferenceComment(sourceFile, position)) {
var entries = getTripleSlashReferenceCompletion(sourceFile, position, options, host);
return entries && convertPathCompletions(entries);
@@ -125666,12 +128001,12 @@ var ts;
if (ts.isInString(sourceFile, position, contextToken)) {
if (!contextToken || !ts.isStringLiteralLike(contextToken))
return undefined;
- var entries = getStringLiteralCompletionEntries(sourceFile, contextToken, position, checker, options, host, preferences);
- return convertStringLiteralCompletions(entries, contextToken, sourceFile, checker, log, options, preferences);
+ var entries = getStringLiteralCompletionEntries(sourceFile, contextToken, position, program.getTypeChecker(), options, host, preferences);
+ return convertStringLiteralCompletions(entries, contextToken, sourceFile, host, program, log, options, preferences);
}
}
StringCompletions.getStringLiteralCompletions = getStringLiteralCompletions;
- function convertStringLiteralCompletions(completion, contextToken, sourceFile, checker, log, options, preferences) {
+ function convertStringLiteralCompletions(completion, contextToken, sourceFile, host, program, log, options, preferences) {
if (completion === undefined) {
return undefined;
}
@@ -125681,7 +128016,7 @@ var ts;
return convertPathCompletions(completion.paths);
case 1 /* Properties */: {
var entries = [];
- Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, sourceFile, sourceFile, checker, 99 /* ESNext */, log, 4 /* String */, preferences, options); // Target will not be used, so arbitrary
+ Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, contextToken, sourceFile, sourceFile, host, program, 99 /* ESNext */, log, 4 /* String */, preferences, options); // Target will not be used, so arbitrary
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: completion.hasIndexSignature, optionalReplacementSpan: optionalReplacementSpan, entries: entries };
}
case 2 /* Types */: {
@@ -125738,6 +128073,12 @@ var ts;
case ".jsx" /* Jsx */: return ".jsx" /* jsxModifier */;
case ".ts" /* Ts */: return ".ts" /* tsModifier */;
case ".tsx" /* Tsx */: return ".tsx" /* tsxModifier */;
+ case ".d.mts" /* Dmts */: return ".d.mts" /* dmtsModifier */;
+ case ".mjs" /* Mjs */: return ".mjs" /* mjsModifier */;
+ case ".mts" /* Mts */: return ".mts" /* mtsModifier */;
+ case ".d.cts" /* Dcts */: return ".d.cts" /* dctsModifier */;
+ case ".cjs" /* Cjs */: return ".cjs" /* cjsModifier */;
+ case ".cts" /* Cts */: return ".cts" /* ctsModifier */;
case ".tsbuildinfo" /* TsBuildInfo */: return ts.Debug.fail("Extension " + ".tsbuildinfo" /* TsBuildInfo */ + " is unsupported.");
case undefined: return "" /* none */;
default:
@@ -125753,10 +128094,10 @@ var ts;
function getStringLiteralCompletionEntries(sourceFile, node, position, typeChecker, compilerOptions, host, preferences) {
var parent = walkUpParentheses(node.parent);
switch (parent.kind) {
- case 194 /* LiteralType */: {
+ case 195 /* LiteralType */: {
var grandParent = walkUpParentheses(parent.parent);
switch (grandParent.kind) {
- case 176 /* TypeReference */: {
+ case 177 /* TypeReference */: {
var typeReference_1 = grandParent;
var typeArgument = ts.findAncestor(parent, function (n) { return n.parent === typeReference_1; });
if (typeArgument) {
@@ -125764,7 +128105,7 @@ var ts;
}
return undefined;
}
- case 192 /* IndexedAccessType */:
+ case 193 /* IndexedAccessType */:
// Get all apparent property names
// i.e. interface Foo {
// foo: string;
@@ -125776,9 +128117,9 @@ var ts;
return undefined;
}
return stringLiteralCompletionsFromProperties(typeChecker.getTypeFromTypeNode(objectType));
- case 198 /* ImportType */:
+ case 199 /* ImportType */:
return { kind: 0 /* Paths */, paths: getStringLiteralCompletionsFromModuleNames(sourceFile, node, compilerOptions, host, typeChecker, preferences) };
- case 185 /* UnionType */: {
+ case 186 /* UnionType */: {
if (!ts.isTypeReferenceNode(grandParent.parent)) {
return undefined;
}
@@ -125790,7 +128131,7 @@ var ts;
return undefined;
}
}
- case 291 /* PropertyAssignment */:
+ case 294 /* PropertyAssignment */:
if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
// Get quoted name of properties of the object literal expression
// i.e. interface ConfigFiles {
@@ -125807,7 +128148,7 @@ var ts;
return stringLiteralCompletionsForObjectLiteral(typeChecker, parent.parent);
}
return fromContextualType();
- case 205 /* ElementAccessExpression */: {
+ case 206 /* ElementAccessExpression */: {
var _b = parent, expression = _b.expression, argumentExpression = _b.argumentExpression;
if (node === ts.skipParentheses(argumentExpression)) {
// Get all names of properties on the expression
@@ -125820,8 +128161,8 @@ var ts;
}
return undefined;
}
- case 206 /* CallExpression */:
- case 207 /* NewExpression */:
+ case 207 /* CallExpression */:
+ case 208 /* NewExpression */:
if (!isRequireCallArgument(node) && !ts.isImportCall(parent)) {
var argumentInfo = ts.SignatureHelp.getArgumentInfoForCompletions(node, position, sourceFile);
// Get string literal completions from specialized signatures of the target
@@ -125830,9 +128171,9 @@ var ts;
return argumentInfo ? getStringLiteralCompletionsFromSignature(argumentInfo, typeChecker) : fromContextualType();
}
// falls through (is `require("")` or `require(""` or `import("")`)
- case 264 /* ImportDeclaration */:
- case 270 /* ExportDeclaration */:
- case 275 /* ExternalModuleReference */:
+ case 265 /* ImportDeclaration */:
+ case 271 /* ExportDeclaration */:
+ case 276 /* ExternalModuleReference */:
// Get all known external module names or complete a path to a module
// i.e. import * as ns from "/*completion position*/";
// var y = import("/*completion position*/");
@@ -125851,9 +128192,9 @@ var ts;
}
function walkUpParentheses(node) {
switch (node.kind) {
- case 189 /* ParenthesizedType */:
+ case 190 /* ParenthesizedType */:
return ts.walkUpParenthesizedTypes(node);
- case 210 /* ParenthesizedExpression */:
+ case 211 /* ParenthesizedExpression */:
return ts.walkUpParenthesizedExpressions(node);
default:
return node;
@@ -125927,15 +128268,18 @@ var ts;
var scriptPath = sourceFile.path;
var scriptDirectory = ts.getDirectoryPath(scriptPath);
return isPathRelativeToScript(literalValue) || !compilerOptions.baseUrl && (ts.isRootedDiskPath(literalValue) || ts.isUrl(literalValue))
- ? getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath, preferences)
+ ? getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath, getIncludeExtensionOption())
: getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, compilerOptions, host, typeChecker);
+ function getIncludeExtensionOption() {
+ var mode = ts.isStringLiteralLike(node) ? ts.getModeForUsageLocation(sourceFile, node) : undefined;
+ return preferences.importModuleSpecifierEnding === "js" || mode === ts.ModuleKind.ESNext ? 2 /* ModuleSpecifierCompletion */ : 0 /* Exclude */;
+ }
}
function getExtensionOptions(compilerOptions, includeExtensionsOption) {
if (includeExtensionsOption === void 0) { includeExtensionsOption = 0 /* Exclude */; }
- return { extensions: getSupportedExtensionsForModuleResolution(compilerOptions), includeExtensionsOption: includeExtensionsOption };
+ return { extensions: ts.flatten(getSupportedExtensionsForModuleResolution(compilerOptions)), includeExtensionsOption: includeExtensionsOption };
}
- function getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath, preferences) {
- var includeExtensions = preferences.importModuleSpecifierEnding === "js" ? 2 /* ModuleSpecifierCompletion */ : 0 /* Exclude */;
+ function getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath, includeExtensions) {
var extensionOptions = getExtensionOptions(compilerOptions, includeExtensions);
if (compilerOptions.rootDirs) {
return getCompletionEntriesForDirectoryFragmentWithRootDirs(compilerOptions.rootDirs, literalValue, scriptDirectory, extensionOptions, compilerOptions, host, scriptPath);
@@ -125946,8 +128290,8 @@ var ts;
}
function getSupportedExtensionsForModuleResolution(compilerOptions) {
var extensions = ts.getSupportedExtensions(compilerOptions);
- return compilerOptions.resolveJsonModule && ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeJs ?
- extensions.concat(".json" /* Json */) :
+ return ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeJs ?
+ ts.getSupportedExtensionsWithJsonIfResolveJsonModule(compilerOptions, extensions) :
extensions;
}
/**
@@ -126021,11 +128365,11 @@ var ts;
}
var foundFileName = void 0;
var outputExtension = ts.moduleSpecifiers.tryGetJSExtensionForFile(filePath, host.getCompilationSettings());
- if (includeExtensionsOption === 0 /* Exclude */ && !ts.fileExtensionIs(filePath, ".json" /* Json */)) {
+ if (includeExtensionsOption === 0 /* Exclude */ && !ts.fileExtensionIsOneOf(filePath, [".json" /* Json */, ".mts" /* Mts */, ".cts" /* Cts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".mjs" /* Mjs */, ".cjs" /* Cjs */])) {
foundFileName = ts.removeFileExtension(ts.getBaseFileName(filePath));
foundFiles.set(foundFileName, ts.tryGetExtensionFromPath(filePath));
}
- else if (includeExtensionsOption === 2 /* ModuleSpecifierCompletion */ && outputExtension) {
+ else if ((ts.fileExtensionIsOneOf(filePath, [".mts" /* Mts */, ".cts" /* Cts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".mjs" /* Mjs */, ".cjs" /* Cjs */]) || includeExtensionsOption === 2 /* ModuleSpecifierCompletion */) && outputExtension) {
foundFileName = ts.changeExtension(ts.getBaseFileName(filePath), outputExtension);
foundFiles.set(foundFileName, outputExtension);
}
@@ -126071,7 +128415,7 @@ var ts;
continue;
var patterns = paths[path];
if (patterns) {
- var _loop_2 = function (name, kind, extension) {
+ var _loop_3 = function (name, kind, extension) {
// 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, extension));
@@ -126079,7 +128423,7 @@ var ts;
};
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, extension = _b.extension;
- _loop_2(name, kind, extension);
+ _loop_3(name, kind, extension);
}
}
}
@@ -126114,7 +128458,7 @@ var ts;
// (But do if we didn't find anything, e.g. 'package.json' missing.)
var foundGlobal = false;
if (fragmentDirectory === undefined) {
- var _loop_3 = function (moduleName) {
+ var _loop_4 = function (moduleName) {
if (!result.some(function (entry) { return entry.name === moduleName; })) {
foundGlobal = true;
result.push(nameAndKind(moduleName, "external module name" /* externalModuleName */, /*extension*/ undefined));
@@ -126122,7 +128466,7 @@ var ts;
};
for (var _b = 0, _c = enumerateNodeModulesVisibleToScript(host, scriptPath); _b < _c.length; _b++) {
var moduleName = _c[_b];
- _loop_3(moduleName);
+ _loop_4(moduleName);
}
}
if (!foundGlobal) {
@@ -126398,6 +128742,8 @@ var ts;
(function (CompletionSource) {
/** Completions that require `this.` insertion text */
CompletionSource["ThisProperty"] = "ThisProperty/";
+ /** Auto-import that comes attached to a class member snippet */
+ CompletionSource["ClassMemberSnippet"] = "ClassMemberSnippet/";
})(CompletionSource = Completions.CompletionSource || (Completions.CompletionSource = {}));
var SymbolOriginInfoKind;
(function (SymbolOriginInfoKind) {
@@ -126444,6 +128790,7 @@ var ts;
KeywordCompletionFilters[KeywordCompletionFilters["FunctionLikeBodyKeywords"] = 5] = "FunctionLikeBodyKeywords";
KeywordCompletionFilters[KeywordCompletionFilters["TypeAssertionKeywords"] = 6] = "TypeAssertionKeywords";
KeywordCompletionFilters[KeywordCompletionFilters["TypeKeywords"] = 7] = "TypeKeywords";
+ KeywordCompletionFilters[KeywordCompletionFilters["TypeKeyword"] = 8] = "TypeKeyword";
KeywordCompletionFilters[KeywordCompletionFilters["Last"] = 7] = "Last";
})(KeywordCompletionFilters || (KeywordCompletionFilters = {}));
var GlobalsSearch;
@@ -126505,7 +128852,6 @@ var ts;
}
// If the request is a continuation of an earlier `isIncomplete` response,
// we can continue it from the cached previous response.
- var typeChecker = program.getTypeChecker();
var compilerOptions = program.getCompilerOptions();
var incompleteCompletionsCache = preferences.allowIncompleteCompletions ? (_a = host.getIncompleteCompletionsCache) === null || _a === void 0 ? void 0 : _a.call(host) : undefined;
if (incompleteCompletionsCache && completionKind === 3 /* TriggerForIncompleteCompletions */ && previousToken && ts.isIdentifier(previousToken)) {
@@ -126517,7 +128863,7 @@ var ts;
else {
incompleteCompletionsCache === null || incompleteCompletionsCache === void 0 ? void 0 : incompleteCompletionsCache.clear();
}
- var stringCompletions = Completions.StringCompletions.getStringLiteralCompletions(sourceFile, position, previousToken, typeChecker, compilerOptions, host, log, preferences);
+ var stringCompletions = Completions.StringCompletions.getStringLiteralCompletions(sourceFile, position, previousToken, compilerOptions, host, program, log, preferences);
if (stringCompletions) {
return stringCompletions;
}
@@ -126531,7 +128877,7 @@ var ts;
}
switch (completionData.kind) {
case 0 /* Data */:
- var response = completionInfoFromData(sourceFile, typeChecker, compilerOptions, log, completionData, preferences);
+ var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences);
if (response === null || response === void 0 ? void 0 : response.isIncomplete) {
incompleteCompletionsCache === null || incompleteCompletionsCache === void 0 ? void 0 : incompleteCompletionsCache.set(response);
}
@@ -126545,26 +128891,25 @@ var ts;
case 3 /* JsDocParameterName */:
return jsdocCompletionInfo(ts.JsDoc.getJSDocParameterNameCompletions(completionData.tag));
case 4 /* Keywords */:
- return specificKeywordCompletionInfo(completionData.keywords);
+ return specificKeywordCompletionInfo(completionData.keywordCompletions, completionData.isNewIdentifierLocation);
default:
return ts.Debug.assertNever(completionData);
}
}
Completions.getCompletionsAtPosition = getCompletionsAtPosition;
+ function completionEntryDataIsResolved(data) {
+ return !!(data === null || data === void 0 ? void 0 : data.moduleSpecifier);
+ }
function continuePreviousIncompleteResponse(cache, file, location, program, host, preferences, cancellationToken) {
- var _a;
var previousResponse = cache.get();
if (!previousResponse)
return undefined;
var lowerCaseTokenText = location.text.toLowerCase();
var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
- var checker = program.getTypeChecker();
- var autoImportProvider = (_a = host.getPackageJsonAutoImportProvider) === null || _a === void 0 ? void 0 : _a.call(host);
- var autoImportProviderChecker = autoImportProvider === null || autoImportProvider === void 0 ? void 0 : autoImportProvider.getTypeChecker();
var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, preferences,
/*isForImportStatementCompletion*/ false, function (context) {
var entries = ts.mapDefined(previousResponse.entries, function (entry) {
- if (!entry.hasAction || !entry.source || !entry.data || entry.data.moduleSpecifier) {
+ if (!entry.hasAction || !entry.source || !entry.data || completionEntryDataIsResolved(entry.data)) {
// Not an auto import or already resolved; keep as is
return entry;
}
@@ -126572,8 +128917,8 @@ var ts;
// No longer matches typed characters; filter out
return undefined;
}
- var _a = ts.Debug.checkDefined(getAutoImportSymbolFromCompletionEntryData(entry.name, entry.data, program, host)), symbol = _a.symbol, origin = _a.origin;
- var info = exportMap.get(file.path, entry.name, symbol, origin.moduleSymbol.name, origin.isFromPackageJson ? autoImportProviderChecker : checker);
+ var origin = ts.Debug.checkDefined(getAutoImportSymbolFromCompletionEntryData(entry.name, entry.data, program, host)).origin;
+ var info = exportMap.get(file.path, entry.data.exportMapKey);
var result = info && context.tryResolve(info, !ts.isExternalModuleNameRelative(ts.stripQuotes(origin.moduleSymbol.name)));
if (!result)
return entry;
@@ -126596,25 +128941,41 @@ var ts;
function jsdocCompletionInfo(entries) {
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: entries };
}
- function specificKeywordCompletionInfo(keywords) {
+ function keywordToCompletionEntry(keyword) {
+ return {
+ name: ts.tokenToString(keyword),
+ kind: "keyword" /* keyword */,
+ kindModifiers: "" /* none */,
+ sortText: SortText.GlobalsOrKeywords,
+ };
+ }
+ function specificKeywordCompletionInfo(entries, isNewIdentifierLocation) {
return {
isGlobalCompletion: false,
isMemberCompletion: false,
- isNewIdentifierLocation: false,
- entries: keywords.map(function (k) { return ({
- name: ts.tokenToString(k),
- kind: "keyword" /* keyword */,
- kindModifiers: "" /* none */,
- sortText: SortText.GlobalsOrKeywords,
- }); }),
+ isNewIdentifierLocation: isNewIdentifierLocation,
+ entries: entries.slice(),
+ };
+ }
+ function keywordCompletionData(keywordFilters, filterOutTsOnlyKeywords, isNewIdentifierLocation) {
+ return {
+ kind: 4 /* Keywords */,
+ keywordCompletions: getKeywordCompletions(keywordFilters, filterOutTsOnlyKeywords),
+ isNewIdentifierLocation: isNewIdentifierLocation,
};
}
+ function keywordFiltersFromSyntaxKind(keywordCompletion) {
+ switch (keywordCompletion) {
+ case 151 /* TypeKeyword */: return 8 /* TypeKeyword */;
+ default: ts.Debug.fail("Unknown mapping from SyntaxKind to KeywordCompletionFilters");
+ }
+ }
function getOptionalReplacementSpan(location) {
// StringLiteralLike locations are handled separately in stringCompletions.ts
return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
}
- function completionInfoFromData(sourceFile, typeChecker, compilerOptions, log, completionData, preferences) {
- var symbols = completionData.symbols, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
+ function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences) {
+ var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
// Verify if the file is JSX language variant
if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
@@ -126625,15 +128986,15 @@ var ts;
var entries = [];
if (isUncheckedFile(sourceFile, compilerOptions)) {
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
- /* contextToken */ undefined, location, sourceFile, typeChecker, compilerOptions.target, log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
- getJSCompletionEntries(sourceFile, location.pos, uniqueNames, compilerOptions.target, entries); // TODO: GH#18217
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
+ getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
}
else {
if (!isNewIdentifierLocation && (!symbols || symbols.length === 0) && keywordFilters === 0 /* None */) {
return undefined;
}
getCompletionEntriesFromSymbols(symbols, entries,
- /* contextToken */ undefined, location, sourceFile, typeChecker, compilerOptions.target, log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
}
if (keywordFilters !== 0 /* None */) {
var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
@@ -126674,12 +129035,12 @@ var ts;
// We wanna walk up the tree till we find a JSX closing element
var jsxClosingElement = ts.findAncestor(location, function (node) {
switch (node.kind) {
- case 279 /* JsxClosingElement */:
+ case 280 /* JsxClosingElement */:
return true;
case 43 /* SlashToken */:
case 31 /* GreaterThanToken */:
case 79 /* Identifier */:
- case 204 /* PropertyAccessExpression */:
+ case 205 /* PropertyAccessExpression */:
return false;
default:
return "quit";
@@ -126739,14 +129100,16 @@ var ts;
function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
}
- function createCompletionEntry(symbol, sortText, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences) {
- var _a;
+ function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind) {
+ var _a, _b;
var insertText;
- var replacementSpan = ts.getReplacementSpanForContextToken(contextToken);
+ var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
var data;
var isSnippet;
+ var source = getSourceFromOrigin(origin);
var sourceDisplay;
var hasAction;
+ var typeChecker = program.getTypeChecker();
var insertQuestionDot = origin && originIsNullableMember(origin);
var useBraces = origin && originIsSymbolMember(origin) || needsConvertPropertyAccess;
if (origin && originIsThisType(origin)) {
@@ -126793,10 +129156,44 @@ var ts;
if (originIsResolvedExport(origin)) {
sourceDisplay = [ts.textPart(origin.moduleSpecifier)];
if (importCompletionNode) {
- (_a = getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, origin, useSemicolons, options, preferences), insertText = _a.insertText, replacementSpan = _a.replacementSpan);
+ (_a = getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, contextToken, origin, useSemicolons, options, preferences), insertText = _a.insertText, replacementSpan = _a.replacementSpan);
isSnippet = preferences.includeCompletionsWithSnippetText ? true : undefined;
}
}
+ if (preferences.includeCompletionsWithClassMemberSnippets &&
+ preferences.includeCompletionsWithInsertText &&
+ completionKind === 3 /* MemberLike */ &&
+ isClassLikeMemberCompletion(symbol, location)) {
+ var importAdder = void 0;
+ (_b = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken), insertText = _b.insertText, isSnippet = _b.isSnippet, importAdder = _b.importAdder);
+ if (importAdder === null || importAdder === void 0 ? void 0 : importAdder.hasFixes()) {
+ hasAction = true;
+ source = CompletionSource.ClassMemberSnippet;
+ }
+ }
+ var kind = ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, location);
+ if (kind === "JSX attribute" /* jsxAttribute */ && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
+ var useBraces_1 = preferences.jsxAttributeCompletionStyle === "braces";
+ var type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
+ // If is boolean like or undefined, don't return a snippet we want just to return the completion.
+ if (preferences.jsxAttributeCompletionStyle === "auto"
+ && !(type.flags & 528 /* BooleanLike */)
+ && !(type.flags & 1048576 /* Union */ && ts.find(type.types, function (type) { return !!(type.flags & 528 /* BooleanLike */); }))) {
+ if (type.flags & 402653316 /* StringLike */ || (type.flags & 1048576 /* Union */ && ts.every(type.types, function (type) { return !!(type.flags & (402653316 /* StringLike */ | 32768 /* Undefined */)); }))) {
+ // If is string like or undefined use quotes
+ insertText = ts.escapeSnippetText(name) + "=" + ts.quote(sourceFile, preferences, "$1");
+ isSnippet = true;
+ }
+ else {
+ // Use braces for everything else
+ useBraces_1 = true;
+ }
+ }
+ if (useBraces_1) {
+ insertText = ts.escapeSnippetText(name) + "={$1}";
+ isSnippet = true;
+ }
+ }
if (insertText !== undefined && !preferences.includeCompletionsWithInsertText) {
return undefined;
}
@@ -126813,10 +129210,10 @@ var ts;
// entries (like JavaScript identifier entries).
return {
name: name,
- kind: ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, location),
+ kind: kind,
kindModifiers: ts.SymbolDisplay.getSymbolModifiers(typeChecker, symbol),
sortText: sortText,
- source: getSourceFromOrigin(origin),
+ source: source,
hasAction: hasAction ? true : undefined,
isRecommended: isRecommendedCompletionMatch(symbol, recommendedCompletion, typeChecker) || undefined,
insertText: insertText,
@@ -126828,30 +129225,243 @@ var ts;
data: data,
};
}
- function originToCompletionEntryData(origin) {
+ function isClassLikeMemberCompletion(symbol, location) {
+ // TODO: support JS files.
+ if (ts.isInJSFile(location)) {
+ return false;
+ }
+ // Completion symbol must be for a class member.
+ var memberFlags = 106500 /* ClassMember */
+ & 900095 /* EnumMemberExcludes */;
+ /* In
+ `class C {
+ |
+ }`
+ `location` is a class-like declaration.
+ In
+ `class C {
+ m|
+ }`
+ `location` is an identifier,
+ `location.parent` is a class element declaration,
+ and `location.parent.parent` is a class-like declaration.
+ In
+ `abstract class C {
+ abstract
+ abstract m|
+ }`
+ `location` is a syntax list (with modifiers as children),
+ and `location.parent` is a class-like declaration.
+ */
+ return !!(symbol.flags & memberFlags) &&
+ (ts.isClassLike(location) ||
+ (location.parent &&
+ location.parent.parent &&
+ ts.isClassElement(location.parent) &&
+ location === location.parent.name &&
+ ts.isClassLike(location.parent.parent)) ||
+ (location.parent &&
+ ts.isSyntaxList(location) &&
+ ts.isClassLike(location.parent)));
+ }
+ function getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken) {
+ var classLikeDeclaration = ts.findAncestor(location, ts.isClassLike);
+ if (!classLikeDeclaration) {
+ return { insertText: name };
+ }
+ var isSnippet;
+ var insertText = name;
+ var checker = program.getTypeChecker();
+ var sourceFile = location.getSourceFile();
+ var printer = createSnippetPrinter({
+ removeComments: true,
+ module: options.module,
+ target: options.target,
+ omitTrailingSemicolon: false,
+ newLine: ts.getNewLineKind(ts.getNewLineCharacter(options, ts.maybeBind(host, host.getNewLine))),
+ });
+ var importAdder = ts.codefix.createImportAdder(sourceFile, program, preferences, host);
+ var body;
+ if (preferences.includeCompletionsWithSnippetText) {
+ isSnippet = true;
+ // We are adding a tabstop (i.e. `$0`) in the body of the suggested member,
+ // if it has one, so that the cursor ends up in the body once the completion is inserted.
+ // Note: this assumes we won't have more than one body in the completion nodes, which should be the case.
+ var emptyStatement = ts.factory.createExpressionStatement(ts.factory.createIdentifier(""));
+ ts.setSnippetElement(emptyStatement, { kind: 0 /* TabStop */, order: 0 });
+ body = ts.factory.createBlock([emptyStatement], /* multiline */ true);
+ }
+ else {
+ body = ts.factory.createBlock([], /* multiline */ true);
+ }
+ var modifiers = 0 /* None */;
+ // Whether the suggested member should be abstract.
+ // e.g. in `abstract class C { abstract | }`, we should offer abstract method signatures at position `|`.
+ // Note: We are relying on checking if the context token is `abstract`,
+ // since other visibility modifiers (e.g. `protected`) should come *before* `abstract`.
+ // However, that is not true for the e.g. `override` modifier, so this check has its limitations.
+ var isAbstract = contextToken && isModifierLike(contextToken) === 126 /* AbstractKeyword */;
+ var completionNodes = [];
+ ts.codefix.addNewNodeForMemberSymbol(symbol, classLikeDeclaration, sourceFile, { program: program, host: host }, preferences, importAdder,
+ // `addNewNodeForMemberSymbol` calls this callback function for each new member node
+ // it adds for the given member symbol.
+ // We store these member nodes in the `completionNodes` array.
+ // Note: there might be:
+ // - No nodes if `addNewNodeForMemberSymbol` cannot figure out a node for the member;
+ // - One node;
+ // - More than one node if the member is overloaded (e.g. a method with overload signatures).
+ function (node) {
+ var requiredModifiers = 0 /* None */;
+ if (isAbstract) {
+ requiredModifiers |= 128 /* Abstract */;
+ }
+ if (ts.isClassElement(node)
+ && checker.getMemberOverrideModifierStatus(classLikeDeclaration, node) === 1 /* NeedsOverride */) {
+ requiredModifiers |= 16384 /* Override */;
+ }
+ var presentModifiers = 0 /* None */;
+ if (!completionNodes.length) {
+ // Omit already present modifiers from the first completion node/signature.
+ if (contextToken) {
+ presentModifiers = getPresentModifiers(contextToken);
+ }
+ // Keep track of added missing required modifiers and modifiers already present.
+ // This is needed when we have overloaded signatures,
+ // so this callback will be called for multiple nodes/signatures,
+ // and we need to make sure the modifiers are uniform for all nodes/signatures.
+ modifiers = node.modifierFlagsCache | requiredModifiers | presentModifiers;
+ }
+ node = ts.factory.updateModifiers(node, modifiers & (~presentModifiers));
+ completionNodes.push(node);
+ }, body, 2 /* Property */, isAbstract);
+ if (completionNodes.length) {
+ insertText = printer.printSnippetList(1 /* MultiLine */ | 131072 /* NoTrailingNewLine */, ts.factory.createNodeArray(completionNodes), sourceFile);
+ }
+ return { insertText: insertText, isSnippet: isSnippet, importAdder: importAdder };
+ }
+ function getPresentModifiers(contextToken) {
+ var modifiers = 0 /* None */;
+ var contextMod;
+ /*
+ Cases supported:
+ In
+ `class C {
+ public abstract |
+ }`
+ `contextToken` is ``abstract`` (as an identifier),
+ `contextToken.parent` is property declaration,
+ `location` is class declaration ``class C { ... }``.
+ In
+ `class C {
+ protected override m|
+ }`
+ `contextToken` is ``override`` (as a keyword),
+ `contextToken.parent` is property declaration,
+ `location` is identifier ``m``,
+ `location.parent` is property declaration ``protected override m``,
+ `location.parent.parent` is class declaration ``class C { ... }``.
+ */
+ if (contextMod = isModifierLike(contextToken)) {
+ modifiers |= ts.modifierToFlag(contextMod);
+ }
+ if (ts.isPropertyDeclaration(contextToken.parent)) {
+ modifiers |= ts.modifiersToFlags(contextToken.parent.modifiers);
+ }
+ return modifiers;
+ }
+ function isModifierLike(node) {
+ if (ts.isModifier(node)) {
+ return node.kind;
+ }
+ if (ts.isIdentifier(node) && node.originalKeywordKind && ts.isModifierKind(node.originalKeywordKind)) {
+ return node.originalKeywordKind;
+ }
+ return undefined;
+ }
+ function createSnippetPrinter(printerOptions) {
+ var printer = ts.createPrinter(printerOptions);
+ var baseWriter = ts.createTextWriter(ts.getNewLineCharacter(printerOptions));
+ var writer = __assign(__assign({}, baseWriter), { write: function (s) { return baseWriter.write(ts.escapeSnippetText(s)); }, nonEscapingWrite: baseWriter.write, writeLiteral: function (s) { return baseWriter.writeLiteral(ts.escapeSnippetText(s)); }, writeStringLiteral: function (s) { return baseWriter.writeStringLiteral(ts.escapeSnippetText(s)); }, writeSymbol: function (s, symbol) { return baseWriter.writeSymbol(ts.escapeSnippetText(s), symbol); }, writeParameter: function (s) { return baseWriter.writeParameter(ts.escapeSnippetText(s)); }, writeComment: function (s) { return baseWriter.writeComment(ts.escapeSnippetText(s)); }, writeProperty: function (s) { return baseWriter.writeProperty(ts.escapeSnippetText(s)); } });
return {
+ printSnippetList: printSnippetList,
+ };
+ /* Snippet-escaping version of `printer.printList`. */
+ function printSnippetList(format, list, sourceFile) {
+ writer.clear();
+ printer.writeList(format, list, sourceFile, writer);
+ return writer.getText();
+ }
+ }
+ function originToCompletionEntryData(origin) {
+ var ambientModuleName = origin.fileName ? undefined : ts.stripQuotes(origin.moduleSymbol.name);
+ var isPackageJsonImport = origin.isFromPackageJson ? true : undefined;
+ if (originIsResolvedExport(origin)) {
+ var resolvedData = {
+ exportName: origin.exportName,
+ moduleSpecifier: origin.moduleSpecifier,
+ ambientModuleName: ambientModuleName,
+ fileName: origin.fileName,
+ isPackageJsonImport: isPackageJsonImport,
+ };
+ return resolvedData;
+ }
+ var unresolvedData = {
exportName: origin.exportName,
+ exportMapKey: origin.exportMapKey,
fileName: origin.fileName,
ambientModuleName: origin.fileName ? undefined : ts.stripQuotes(origin.moduleSymbol.name),
isPackageJsonImport: origin.isFromPackageJson ? true : undefined,
- moduleSpecifier: originIsResolvedExport(origin) ? origin.moduleSpecifier : undefined,
};
+ return unresolvedData;
+ }
+ function completionEntryDataToSymbolOriginInfo(data, completionName, moduleSymbol) {
+ var isDefaultExport = data.exportName === "default" /* Default */;
+ var isFromPackageJson = !!data.isPackageJsonImport;
+ if (completionEntryDataIsResolved(data)) {
+ var resolvedOrigin = {
+ kind: 32 /* ResolvedExport */,
+ exportName: data.exportName,
+ moduleSpecifier: data.moduleSpecifier,
+ symbolName: completionName,
+ fileName: data.fileName,
+ moduleSymbol: moduleSymbol,
+ isDefaultExport: isDefaultExport,
+ isFromPackageJson: isFromPackageJson,
+ };
+ return resolvedOrigin;
+ }
+ var unresolvedOrigin = {
+ kind: 4 /* Export */,
+ exportName: data.exportName,
+ exportMapKey: data.exportMapKey,
+ symbolName: completionName,
+ fileName: data.fileName,
+ moduleSymbol: moduleSymbol,
+ isDefaultExport: isDefaultExport,
+ isFromPackageJson: isFromPackageJson,
+ };
+ return unresolvedOrigin;
}
- function getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, origin, useSemicolons, options, preferences) {
+ function getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, contextToken, origin, useSemicolons, options, preferences) {
+ var _a, _b, _c;
var sourceFile = importCompletionNode.getSourceFile();
- var replacementSpan = ts.createTextSpanFromNode(importCompletionNode, sourceFile);
+ var replacementSpan = ts.createTextSpanFromNode(ts.findAncestor(importCompletionNode, ts.or(ts.isImportDeclaration, ts.isImportEqualsDeclaration)) || importCompletionNode, sourceFile);
var quotedModuleSpecifier = ts.quote(sourceFile, preferences, origin.moduleSpecifier);
var exportKind = origin.isDefaultExport ? 1 /* Default */ :
origin.exportName === "export=" /* ExportEquals */ ? 2 /* ExportEquals */ :
0 /* Named */;
var tabStop = preferences.includeCompletionsWithSnippetText ? "$1" : "";
var importKind = ts.codefix.getImportKind(sourceFile, exportKind, options, /*forceImportKeyword*/ true);
+ var isTopLevelTypeOnly = ((_b = (_a = ts.tryCast(importCompletionNode, ts.isImportDeclaration)) === null || _a === void 0 ? void 0 : _a.importClause) === null || _b === void 0 ? void 0 : _b.isTypeOnly) || ((_c = ts.tryCast(importCompletionNode, ts.isImportEqualsDeclaration)) === null || _c === void 0 ? void 0 : _c.isTypeOnly);
+ var isImportSpecifierTypeOnly = couldBeTypeOnlyImportSpecifier(importCompletionNode, contextToken);
+ var topLevelTypeOnlyText = isTopLevelTypeOnly ? " " + ts.tokenToString(151 /* TypeKeyword */) + " " : " ";
+ var importSpecifierTypeOnlyText = isImportSpecifierTypeOnly ? ts.tokenToString(151 /* TypeKeyword */) + " " : "";
var suffix = useSemicolons ? ";" : "";
switch (importKind) {
- case 3 /* CommonJS */: return { replacementSpan: replacementSpan, insertText: "import " + name + tabStop + " = require(" + quotedModuleSpecifier + ")" + suffix };
- case 1 /* Default */: return { replacementSpan: replacementSpan, insertText: "import " + name + tabStop + " from " + quotedModuleSpecifier + suffix };
- case 2 /* Namespace */: return { replacementSpan: replacementSpan, insertText: "import * as " + name + " from " + quotedModuleSpecifier + suffix };
- case 0 /* Named */: return { replacementSpan: replacementSpan, insertText: "import { " + name + tabStop + " } from " + quotedModuleSpecifier + suffix };
+ case 3 /* CommonJS */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + ts.escapeSnippetText(name) + tabStop + " = require(" + quotedModuleSpecifier + ")" + suffix };
+ case 1 /* Default */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + ts.escapeSnippetText(name) + tabStop + " from " + quotedModuleSpecifier + suffix };
+ case 2 /* Namespace */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + "* as " + ts.escapeSnippetText(name) + " from " + quotedModuleSpecifier + suffix };
+ case 0 /* Named */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + "{ " + importSpecifierTypeOnlyText + ts.escapeSnippetText(name) + tabStop + " } from " + quotedModuleSpecifier + suffix };
}
}
function quotePropertyName(sourceFile, preferences, name) {
@@ -126875,11 +129485,12 @@ var ts;
return CompletionSource.ThisProperty;
}
}
- function getCompletionEntriesFromSymbols(symbols, entries, contextToken, location, sourceFile, typeChecker, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
+ function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
var _a;
var start = ts.timestamp();
var variableDeclaration = getVariableDeclaration(location);
var useSemicolons = ts.probablyUsesSemicolons(sourceFile);
+ var typeChecker = program.getTypeChecker();
// Tracks unique names.
// Value is set to false for global variables or completions from external module exports, because we can have multiple of those;
// true otherwise. Based on the order we add things we will always see locals first, then globals, then module exports.
@@ -126895,7 +129506,7 @@ var ts;
var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
- var entry = createCompletionEntry(symbol, sortText, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences);
+ var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind);
if (!entry) {
continue;
}
@@ -126988,11 +129599,13 @@ var ts;
if (entryId.data) {
var autoImport = getAutoImportSymbolFromCompletionEntryData(entryId.name, entryId.data, program, host);
if (autoImport) {
+ var _a = getRelevantTokens(position, sourceFile), contextToken_1 = _a.contextToken, previousToken_1 = _a.previousToken;
return {
type: "symbol",
symbol: autoImport.symbol,
location: ts.getTouchingPropertyName(sourceFile, position),
- previousToken: ts.findPrecedingToken(position, sourceFile, /*startNode*/ undefined),
+ previousToken: previousToken_1,
+ contextToken: contextToken_1,
isJsxInitializer: false,
isTypeOnlyLocation: false,
origin: autoImport.origin,
@@ -127007,7 +129620,7 @@ var ts;
if (completionData.kind !== 0 /* Data */) {
return { type: "request", request: completionData };
}
- var symbols = completionData.symbols, literals = completionData.literals, location = completionData.location, completionKind = completionData.completionKind, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, previousToken = completionData.previousToken, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation;
+ var symbols = completionData.symbols, literals = completionData.literals, location = completionData.location, completionKind = completionData.completionKind, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, contextToken = completionData.contextToken, previousToken = completionData.previousToken, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation;
var literal = ts.find(literals, function (l) { return completionNameForLiteral(sourceFile, preferences, l) === entryId.name; });
if (literal !== undefined)
return { type: "literal", literal: literal };
@@ -127017,16 +129630,16 @@ var ts;
// completion entry.
return ts.firstDefined(symbols, function (symbol, index) {
var origin = symbolToOriginInfoMap[index];
- var info = getCompletionEntryDisplayNameForSymbol(symbol, compilerOptions.target, origin, completionKind, completionData.isJsxIdentifierExpected);
- return info && info.name === entryId.name && getSourceFromOrigin(origin) === entryId.source
- ? { type: "symbol", symbol: symbol, location: location, origin: origin, previousToken: previousToken, isJsxInitializer: isJsxInitializer, isTypeOnlyLocation: isTypeOnlyLocation }
+ var info = getCompletionEntryDisplayNameForSymbol(symbol, ts.getEmitScriptTarget(compilerOptions), origin, completionKind, completionData.isJsxIdentifierExpected);
+ return info && info.name === entryId.name && (entryId.source === CompletionSource.ClassMemberSnippet && symbol.flags & 106500 /* ClassMember */ || getSourceFromOrigin(origin) === entryId.source)
+ ? { type: "symbol", symbol: symbol, location: location, origin: origin, contextToken: contextToken, previousToken: previousToken, isJsxInitializer: isJsxInitializer, isTypeOnlyLocation: isTypeOnlyLocation }
: undefined;
}) || { type: "none" };
}
function getCompletionEntryDetails(program, log, sourceFile, position, entryId, host, formatContext, preferences, cancellationToken) {
var typeChecker = program.getTypeChecker();
var compilerOptions = program.getCompilerOptions();
- var name = entryId.name;
+ var name = entryId.name, source = entryId.source, data = entryId.data;
var contextToken = ts.findPrecedingToken(position, sourceFile);
if (ts.isInString(sourceFile, position, contextToken)) {
return Completions.StringCompletions.getStringLiteralCompletionDetails(name, sourceFile, position, contextToken, typeChecker, compilerOptions, host, cancellationToken, preferences);
@@ -127044,14 +129657,14 @@ var ts;
case 3 /* JsDocParameterName */:
return ts.JsDoc.getJSDocParameterNameCompletionDetails(name);
case 4 /* Keywords */:
- return request.keywords.indexOf(ts.stringToToken(name)) > -1 ? createSimpleDetails(name, "keyword" /* keyword */, ts.SymbolDisplayPartKind.keyword) : undefined;
+ return ts.some(request.keywordCompletions, function (c) { return c.name === name; }) ? createSimpleDetails(name, "keyword" /* keyword */, ts.SymbolDisplayPartKind.keyword) : undefined;
default:
return ts.Debug.assertNever(request);
}
}
case "symbol": {
- var symbol = symbolCompletion.symbol, location = symbolCompletion.location, origin = symbolCompletion.origin, previousToken = symbolCompletion.previousToken;
- var _a = getCompletionEntryCodeActionsAndSourceDisplay(origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, entryId.data), codeActions = _a.codeActions, sourceDisplay = _a.sourceDisplay;
+ var symbol = symbolCompletion.symbol, location = symbolCompletion.location, contextToken_2 = symbolCompletion.contextToken, origin = symbolCompletion.origin, previousToken = symbolCompletion.previousToken;
+ var _a = getCompletionEntryCodeActionsAndSourceDisplay(name, location, contextToken_2, origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data, source), codeActions = _a.codeActions, sourceDisplay = _a.sourceDisplay;
return createCompletionDetailsForSymbol(symbol, typeChecker, sourceFile, location, cancellationToken, codeActions, sourceDisplay); // TODO: GH#18217
}
case "literal": {
@@ -127080,21 +129693,34 @@ var ts;
return { name: name, kindModifiers: kindModifiers, kind: kind, displayParts: displayParts, documentation: documentation, tags: tags, codeActions: codeActions, source: source, sourceDisplay: source };
}
Completions.createCompletionDetails = createCompletionDetails;
- function getCompletionEntryCodeActionsAndSourceDisplay(origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data) {
+ function getCompletionEntryCodeActionsAndSourceDisplay(name, location, contextToken, origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data, source) {
if (data === null || data === void 0 ? void 0 : data.moduleSpecifier) {
- var _a = getRelevantTokens(position, sourceFile), contextToken = _a.contextToken, previousToken_1 = _a.previousToken;
- if (previousToken_1 && getImportCompletionNode(contextToken || previousToken_1)) {
+ var _a = getRelevantTokens(position, sourceFile), contextToken_3 = _a.contextToken, previousToken_2 = _a.previousToken;
+ if (previousToken_2 && getImportStatementCompletionInfo(contextToken_3 || previousToken_2).replacementNode) {
// Import statement completion: 'import c|'
return { codeActions: undefined, sourceDisplay: [ts.textPart(data.moduleSpecifier)] };
}
}
+ if (source === CompletionSource.ClassMemberSnippet) {
+ var importAdder = getEntryForMemberCompletion(host, program, compilerOptions, preferences, name, symbol, location, contextToken).importAdder;
+ if (importAdder) {
+ var changes = ts.textChanges.ChangeTracker.with({ host: host, formatContext: formatContext, preferences: preferences }, importAdder.writeFixes);
+ return {
+ sourceDisplay: undefined,
+ codeActions: [{
+ changes: changes,
+ description: ts.diagnosticToString([ts.Diagnostics.Includes_imports_of_types_referenced_by_0, name]),
+ }],
+ };
+ }
+ }
if (!origin || !(originIsExport(origin) || originIsResolvedExport(origin))) {
return { codeActions: undefined, sourceDisplay: undefined };
}
var checker = origin.isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker();
var moduleSymbol = origin.moduleSymbol;
- var exportedSymbol = checker.getMergedSymbol(ts.skipAlias(symbol.exportSymbol || symbol, checker));
- var _b = ts.codefix.getImportCompletionAction(exportedSymbol, moduleSymbol, sourceFile, ts.getNameForExportedSymbol(symbol, compilerOptions.target), host, program, formatContext, previousToken && ts.isIdentifier(previousToken) ? previousToken.getStart(sourceFile) : position, preferences), moduleSpecifier = _b.moduleSpecifier, codeAction = _b.codeAction;
+ var targetSymbol = checker.getMergedSymbol(ts.skipAlias(symbol.exportSymbol || symbol, checker));
+ var _b = ts.codefix.getImportCompletionAction(targetSymbol, moduleSymbol, sourceFile, ts.getNameForExportedSymbol(symbol, ts.getEmitScriptTarget(compilerOptions)), host, program, formatContext, previousToken && ts.isIdentifier(previousToken) ? previousToken.getStart(sourceFile) : position, preferences), moduleSpecifier = _b.moduleSpecifier, codeAction = _b.codeAction;
ts.Debug.assert(!(data === null || data === void 0 ? void 0 : data.moduleSpecifier) || moduleSpecifier === data.moduleSpecifier);
return { sourceDisplay: [ts.textPart(moduleSpecifier)], codeActions: [codeAction] };
}
@@ -127137,11 +129763,11 @@ var ts;
return ts.getContextualTypeFromParent(previousToken, checker);
case 63 /* EqualsToken */:
switch (parent.kind) {
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
return checker.getContextualType(parent.initializer); // TODO: GH#18217
- case 219 /* BinaryExpression */:
+ case 220 /* BinaryExpression */:
return checker.getTypeAtLocation(parent.left);
- case 283 /* JsxAttribute */:
+ case 284 /* JsxAttribute */:
return checker.getContextualTypeForJsxAttribute(parent);
default:
return undefined;
@@ -127151,7 +129777,7 @@ var ts;
case 82 /* CaseKeyword */:
return ts.getSwitchedType(ts.cast(parent, ts.isCaseClause), checker);
case 18 /* OpenBraceToken */:
- return ts.isJsxExpression(parent) && parent.parent.kind !== 276 /* JsxElement */ ? checker.getContextualTypeForJsxAttribute(parent.parent) : undefined;
+ return ts.isJsxExpression(parent) && !ts.isJsxElement(parent.parent) && !ts.isJsxFragment(parent.parent) ? checker.getContextualTypeForJsxAttribute(parent.parent) : undefined;
default:
var argInfo = ts.SignatureHelp.getArgumentInfoForCompletions(previousToken, position, sourceFile);
return argInfo ?
@@ -127171,7 +129797,7 @@ var ts;
}
function isModuleSymbol(symbol) {
var _a;
- return !!((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d.kind === 300 /* SourceFile */; }));
+ return !!((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d.kind === 303 /* SourceFile */; }));
}
function getCompletionData(program, log, sourceFile, isUncheckedFile, position, preferences, detailsEntryId, host, cancellationToken) {
var typeChecker = program.getTypeChecker();
@@ -127222,11 +129848,11 @@ var ts;
if (tag.tagName.pos <= position && position <= tag.tagName.end) {
return { kind: 1 /* JsDocTagName */ };
}
- if (isTagWithTypeExpression(tag) && tag.typeExpression && tag.typeExpression.kind === 304 /* JSDocTypeExpression */) {
+ if (isTagWithTypeExpression(tag) && tag.typeExpression && tag.typeExpression.kind === 307 /* JSDocTypeExpression */) {
currentToken = ts.getTokenAtPosition(sourceFile, position);
if (!currentToken ||
(!ts.isDeclarationName(currentToken) &&
- (currentToken.parent.kind !== 342 /* JSDocPropertyTag */ ||
+ (currentToken.parent.kind !== 345 /* JSDocPropertyTag */ ||
currentToken.parent.name !== currentToken))) {
// Use as type location if inside tag's type expression
insideJsDocTagTypeExpression = isCurrentlyEditingNode(tag.typeExpression);
@@ -127246,6 +129872,7 @@ var ts;
start = ts.timestamp();
// The decision to provide completion depends on the contextToken, which is determined through the previousToken.
// Note: 'previousToken' (and thus 'contextToken') can be undefined if we are the beginning of the file
+ var isJsOnlyLocation = !insideJsDocTagTypeExpression && ts.isSourceFileJS(sourceFile);
var tokens = getRelevantTokens(position, sourceFile);
var previousToken = tokens.previousToken;
var contextToken = tokens.contextToken;
@@ -127263,29 +129890,41 @@ var ts;
var isJsxIdentifierExpected = false;
var importCompletionNode;
var location = ts.getTouchingPropertyName(sourceFile, position);
+ var keywordFilters = 0 /* None */;
+ var isNewIdentifierLocation = false;
if (contextToken) {
- var importCompletionCandidate = getImportCompletionNode(contextToken);
- if (importCompletionCandidate === 154 /* FromKeyword */) {
- return { kind: 4 /* Keywords */, keywords: [154 /* FromKeyword */] };
+ var importStatementCompletion = getImportStatementCompletionInfo(contextToken);
+ isNewIdentifierLocation = importStatementCompletion.isNewIdentifierLocation;
+ if (importStatementCompletion.keywordCompletion) {
+ if (importStatementCompletion.isKeywordOnlyCompletion) {
+ return {
+ kind: 4 /* Keywords */,
+ keywordCompletions: [keywordToCompletionEntry(importStatementCompletion.keywordCompletion)],
+ isNewIdentifierLocation: isNewIdentifierLocation,
+ };
+ }
+ keywordFilters = keywordFiltersFromSyntaxKind(importStatementCompletion.keywordCompletion);
}
- // Import statement completions use `insertText`, and also require the `data` property of `CompletionEntryIdentifier`
- // added in TypeScript 4.3 to be sent back from the client during `getCompletionEntryDetails`. Since this feature
- // is not backward compatible with older clients, the language service defaults to disabling it, allowing newer clients
- // to opt in with the `includeCompletionsForImportStatements` user preference.
- if (importCompletionCandidate && preferences.includeCompletionsForImportStatements && preferences.includeCompletionsWithInsertText) {
- importCompletionNode = importCompletionCandidate;
+ if (importStatementCompletion.replacementNode && preferences.includeCompletionsForImportStatements && preferences.includeCompletionsWithInsertText) {
+ // Import statement completions use `insertText`, and also require the `data` property of `CompletionEntryIdentifier`
+ // added in TypeScript 4.3 to be sent back from the client during `getCompletionEntryDetails`. Since this feature
+ // is not backward compatible with older clients, the language service defaults to disabling it, allowing newer clients
+ // to opt in with the `includeCompletionsForImportStatements` user preference.
+ importCompletionNode = importStatementCompletion.replacementNode;
}
// Bail out if this is a known invalid completion location
if (!importCompletionNode && isCompletionListBlocker(contextToken)) {
log("Returning an empty list because completion was requested in an invalid position.");
- return undefined;
+ return keywordFilters
+ ? keywordCompletionData(keywordFilters, isJsOnlyLocation, isNewIdentifierDefinitionLocation())
+ : undefined;
}
var parent = contextToken.parent;
if (contextToken.kind === 24 /* DotToken */ || contextToken.kind === 28 /* QuestionDotToken */) {
isRightOfDot = contextToken.kind === 24 /* DotToken */;
isRightOfQuestionDot = contextToken.kind === 28 /* QuestionDotToken */;
switch (parent.kind) {
- case 204 /* PropertyAccessExpression */:
+ case 205 /* PropertyAccessExpression */:
propertyAccessToConvert = parent;
node = propertyAccessToConvert.expression;
var leftmostAccessExpression = ts.getLeftmostAccessExpression(propertyAccessToConvert);
@@ -127301,16 +129940,16 @@ var ts;
return undefined;
}
break;
- case 159 /* QualifiedName */:
+ case 160 /* QualifiedName */:
node = parent.left;
break;
- case 259 /* ModuleDeclaration */:
+ case 260 /* ModuleDeclaration */:
node = parent.name;
break;
- case 198 /* ImportType */:
+ case 199 /* ImportType */:
node = parent;
break;
- case 229 /* MetaProperty */:
+ case 230 /* MetaProperty */:
node = parent.getFirstToken(sourceFile);
ts.Debug.assert(node.kind === 100 /* ImportKeyword */ || node.kind === 103 /* NewKeyword */);
break;
@@ -127324,7 +129963,7 @@ var ts;
//
// If the tagname is a property access expression, we will then walk up to the top most of property access expression.
// Then, try to get a JSX container and its associated attributes type.
- if (parent && parent.kind === 204 /* PropertyAccessExpression */) {
+ if (parent && parent.kind === 205 /* PropertyAccessExpression */) {
contextToken = parent;
parent = parent.parent;
}
@@ -127332,46 +129971,46 @@ var ts;
if (currentToken.parent === location) {
switch (currentToken.kind) {
case 31 /* GreaterThanToken */:
- if (currentToken.parent.kind === 276 /* JsxElement */ || currentToken.parent.kind === 278 /* JsxOpeningElement */) {
+ if (currentToken.parent.kind === 277 /* JsxElement */ || currentToken.parent.kind === 279 /* JsxOpeningElement */) {
location = currentToken;
}
break;
case 43 /* SlashToken */:
- if (currentToken.parent.kind === 277 /* JsxSelfClosingElement */) {
+ if (currentToken.parent.kind === 278 /* JsxSelfClosingElement */) {
location = currentToken;
}
break;
}
}
switch (parent.kind) {
- case 279 /* JsxClosingElement */:
+ case 280 /* JsxClosingElement */:
if (contextToken.kind === 43 /* SlashToken */) {
isStartingCloseTag = true;
location = contextToken;
}
break;
- case 219 /* BinaryExpression */:
+ case 220 /* BinaryExpression */:
if (!binaryExpressionMayBeOpenTag(parent)) {
break;
}
// falls through
- case 277 /* JsxSelfClosingElement */:
- case 276 /* JsxElement */:
- case 278 /* JsxOpeningElement */:
+ case 278 /* JsxSelfClosingElement */:
+ case 277 /* JsxElement */:
+ case 279 /* JsxOpeningElement */:
isJsxIdentifierExpected = true;
if (contextToken.kind === 29 /* LessThanToken */) {
isRightOfOpenTag = true;
location = contextToken;
}
break;
- case 286 /* JsxExpression */:
- case 285 /* JsxSpreadAttribute */:
+ case 287 /* JsxExpression */:
+ case 286 /* JsxSpreadAttribute */:
// For `
`, `parent` will be `{true}` and `previousToken` will be `}`
if (previousToken.kind === 19 /* CloseBraceToken */ && currentToken.kind === 31 /* GreaterThanToken */) {
isJsxIdentifierExpected = true;
}
break;
- case 283 /* JsxAttribute */:
+ case 284 /* JsxAttribute */:
// For `
`, `parent` will be JsxAttribute and `previousToken` will be its initializer
if (parent.initializer === previousToken &&
previousToken.end < position) {
@@ -127398,10 +130037,8 @@ var ts;
}
var semanticStart = ts.timestamp();
var completionKind = 5 /* None */;
- var isNewIdentifierLocation = false;
var isNonContextualObjectLiteral = false;
var hasUnresolvedAutoImports = false;
- var keywordFilters = 0 /* None */;
// This also gets mutated in nested-functions after the return
var symbols = [];
var symbolToOriginInfoMap = [];
@@ -127435,12 +130072,14 @@ var ts;
// global symbols in scope. These results should be valid for either language as
// the set of symbols that can be referenced from this location.
if (!tryGetGlobalSymbols()) {
- return undefined;
+ return keywordFilters
+ ? keywordCompletionData(keywordFilters, isJsOnlyLocation, isNewIdentifierLocation)
+ : undefined;
}
}
log("getCompletionData: Semantic work: " + (ts.timestamp() - semanticStart));
var contextualType = previousToken && getContextualType(previousToken, position, sourceFile, typeChecker);
- var literals = ts.mapDefined(contextualType && (contextualType.isUnion() ? contextualType.types : [contextualType]), function (t) { return t.isLiteral() ? t.value : undefined; });
+ var literals = ts.mapDefined(contextualType && (contextualType.isUnion() ? contextualType.types : [contextualType]), function (t) { return t.isLiteral() && !(t.flags & 1024 /* EnumLiteral */) ? t.value : undefined; });
var recommendedCompletion = previousToken && contextualType && getRecommendedCompletion(previousToken, contextualType, typeChecker);
return {
kind: 0 /* Data */,
@@ -127455,6 +130094,7 @@ var ts;
symbolToOriginInfoMap: symbolToOriginInfoMap,
recommendedCompletion: recommendedCompletion,
previousToken: previousToken,
+ contextToken: contextToken,
isJsxInitializer: isJsxInitializer,
insideJsDocTagTypeExpression: insideJsDocTagTypeExpression,
symbolToSortTextIdMap: symbolToSortTextIdMap,
@@ -127465,11 +130105,11 @@ var ts;
};
function isTagWithTypeExpression(tag) {
switch (tag.kind) {
- case 335 /* JSDocParameterTag */:
- case 342 /* JSDocPropertyTag */:
- case 336 /* JSDocReturnTag */:
- case 338 /* JSDocTypeTag */:
- case 340 /* JSDocTypedefTag */:
+ case 338 /* JSDocParameterTag */:
+ case 345 /* JSDocPropertyTag */:
+ case 339 /* JSDocReturnTag */:
+ case 341 /* JSDocTypeTag */:
+ case 343 /* JSDocTypedefTag */:
return true;
default:
return false;
@@ -127514,7 +130154,7 @@ var ts;
// If the module is merged with a value, we must get the type of the class and add its propertes (for inherited static methods).
if (!isTypeLocation &&
symbol.declarations &&
- symbol.declarations.some(function (d) { return d.kind !== 300 /* SourceFile */ && d.kind !== 259 /* ModuleDeclaration */ && d.kind !== 258 /* EnumDeclaration */; })) {
+ symbol.declarations.some(function (d) { return d.kind !== 303 /* SourceFile */ && d.kind !== 260 /* ModuleDeclaration */ && d.kind !== 259 /* EnumDeclaration */; })) {
var type = typeChecker.getTypeOfSymbolAtLocation(symbol, node).getNonOptionalType();
var insertQuestionDot = false;
if (type.isNullableType()) {
@@ -127562,7 +130202,7 @@ var ts;
if (isRightOfQuestionDot && ts.some(type.getCallSignatures())) {
isNewIdentifierLocation = true;
}
- var propertyAccess = node.kind === 198 /* ImportType */ ? node : node.parent;
+ var propertyAccess = node.kind === 199 /* ImportType */ ? node : node.parent;
if (isUncheckedFile) {
// In javascript files, for union types, we don't just get the members that
// the individual types have in common, we also include all the members that
@@ -127592,6 +130232,7 @@ var ts;
}
}
function addPropertySymbol(symbol, insertAwait, insertQuestionDot) {
+ var _a;
// For a computed property with an accessible name like `Symbol.iterator`,
// we'll add a completion for the *name* `Symbol` instead of for the property.
// If this is e.g. [Symbol.iterator], add a completion for `Symbol`.
@@ -127605,19 +130246,33 @@ var ts;
var index = symbols.length;
symbols.push(firstAccessibleSymbol);
var moduleSymbol = firstAccessibleSymbol.parent;
- if (!moduleSymbol || !ts.isExternalModuleSymbol(moduleSymbol)) {
+ if (!moduleSymbol ||
+ !ts.isExternalModuleSymbol(moduleSymbol) ||
+ typeChecker.tryGetMemberInModuleExportsAndProperties(firstAccessibleSymbol.name, moduleSymbol) !== firstAccessibleSymbol) {
symbolToOriginInfoMap[index] = { kind: getNullableSymbolOriginInfoKind(2 /* SymbolMemberNoExport */) };
}
else {
- var origin = {
- kind: getNullableSymbolOriginInfoKind(6 /* SymbolMemberExport */),
- moduleSymbol: moduleSymbol,
- isDefaultExport: false,
- symbolName: firstAccessibleSymbol.name,
- exportName: firstAccessibleSymbol.name,
- fileName: ts.isExternalModuleNameRelative(ts.stripQuotes(moduleSymbol.name)) ? ts.cast(moduleSymbol.valueDeclaration, ts.isSourceFile).fileName : undefined,
- };
- symbolToOriginInfoMap[index] = origin;
+ var fileName = ts.isExternalModuleNameRelative(ts.stripQuotes(moduleSymbol.name)) ? (_a = ts.getSourceFileOfModule(moduleSymbol)) === null || _a === void 0 ? void 0 : _a.fileName : undefined;
+ var moduleSpecifier = (ts.codefix.getModuleSpecifierForBestExportInfo([{
+ exportKind: 0 /* Named */,
+ moduleFileName: fileName,
+ isFromPackageJson: false,
+ moduleSymbol: moduleSymbol,
+ symbol: firstAccessibleSymbol,
+ targetFlags: ts.skipAlias(firstAccessibleSymbol, typeChecker).flags,
+ }], sourceFile, program, host, preferences) || {}).moduleSpecifier;
+ if (moduleSpecifier) {
+ var origin = {
+ kind: getNullableSymbolOriginInfoKind(6 /* SymbolMemberExport */),
+ moduleSymbol: moduleSymbol,
+ isDefaultExport: false,
+ symbolName: firstAccessibleSymbol.name,
+ exportName: firstAccessibleSymbol.name,
+ fileName: fileName,
+ moduleSpecifier: moduleSpecifier,
+ };
+ symbolToOriginInfoMap[index] = origin;
+ }
}
}
else if (preferences.includeCompletionsWithInsertText) {
@@ -127746,7 +130401,7 @@ var ts;
}
}
// Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions`
- if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== 300 /* SourceFile */) {
+ if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== 303 /* SourceFile */) {
var thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false);
if (thisType && !isProbablyGlobalType(thisType, sourceFile, typeChecker)) {
for (var _a = 0, _b = getPropertiesForCompletion(thisType, typeChecker); _a < _b.length; _a++) {
@@ -127774,21 +130429,21 @@ var ts;
// If not already a module, must have modules enabled.
if (!preferences.includeCompletionsForModuleExports)
return false;
- // If already using ES6 modules, OK to continue using them.
+ // If already using ES modules, OK to continue using them.
if (sourceFile.externalModuleIndicator || sourceFile.commonJsModuleIndicator)
return true;
// If module transpilation is enabled or we're targeting es6 or above, or not emitting, OK.
- if (ts.compilerOptionsIndicateEs6Modules(program.getCompilerOptions()))
+ if (ts.compilerOptionsIndicateEsModules(program.getCompilerOptions()))
return true;
// If some file is using ES6 modules, assume that it's OK to add more.
return ts.programContainsModules(program);
}
function isSnippetScope(scopeNode) {
switch (scopeNode.kind) {
- case 300 /* SourceFile */:
- case 221 /* TemplateExpression */:
- case 286 /* JsxExpression */:
- case 233 /* Block */:
+ case 303 /* SourceFile */:
+ case 222 /* TemplateExpression */:
+ case 287 /* JsxExpression */:
+ case 234 /* Block */:
return true;
default:
return ts.isStatement(scopeNode);
@@ -127796,6 +130451,7 @@ var ts;
}
function isTypeOnlyCompletion() {
return insideJsDocTagTypeExpression
+ || !!importCompletionNode && ts.isTypeOnlyImportOrExportDeclaration(location.parent)
|| !isContextTokenValueLocation(contextToken) &&
(ts.isPossiblyTypeArgumentPosition(contextToken, sourceFile, typeChecker)
|| ts.isPartOfTypeNode(location)
@@ -127804,28 +130460,28 @@ var ts;
function isContextTokenValueLocation(contextToken) {
return contextToken &&
((contextToken.kind === 112 /* TypeOfKeyword */ &&
- (contextToken.parent.kind === 179 /* TypeQuery */ || ts.isTypeOfExpression(contextToken.parent))) ||
- (contextToken.kind === 128 /* AssertsKeyword */ && contextToken.parent.kind === 175 /* TypePredicate */));
+ (contextToken.parent.kind === 180 /* TypeQuery */ || ts.isTypeOfExpression(contextToken.parent))) ||
+ (contextToken.kind === 128 /* AssertsKeyword */ && contextToken.parent.kind === 176 /* TypePredicate */));
}
function isContextTokenTypeLocation(contextToken) {
if (contextToken) {
var parentKind = contextToken.parent.kind;
switch (contextToken.kind) {
case 58 /* ColonToken */:
- return parentKind === 165 /* PropertyDeclaration */ ||
- parentKind === 164 /* PropertySignature */ ||
- parentKind === 162 /* Parameter */ ||
- parentKind === 252 /* VariableDeclaration */ ||
+ return parentKind === 166 /* PropertyDeclaration */ ||
+ parentKind === 165 /* PropertySignature */ ||
+ parentKind === 163 /* Parameter */ ||
+ parentKind === 253 /* VariableDeclaration */ ||
ts.isFunctionLikeKind(parentKind);
case 63 /* EqualsToken */:
- return parentKind === 257 /* TypeAliasDeclaration */;
+ return parentKind === 258 /* TypeAliasDeclaration */;
case 127 /* AsKeyword */:
- return parentKind === 227 /* AsExpression */;
+ return parentKind === 228 /* AsExpression */;
case 29 /* LessThanToken */:
- return parentKind === 176 /* TypeReference */ ||
- parentKind === 209 /* TypeAssertionExpression */;
+ return parentKind === 177 /* TypeReference */ ||
+ parentKind === 210 /* TypeAssertionExpression */;
case 94 /* ExtendsKeyword */:
- return parentKind === 161 /* TypeParameter */;
+ return parentKind === 162 /* TypeParameter */;
}
}
return false;
@@ -127840,13 +130496,19 @@ var ts;
// Asking for completion details for an item that is not an auto-import
return;
}
+ // import { type | -> token text should be blank
+ var isAfterTypeOnlyImportSpecifierModifier = previousToken === contextToken
+ && importCompletionNode
+ && couldBeTypeOnlyImportSpecifier(importCompletionNode, contextToken);
+ var lowerCaseTokenText = isAfterTypeOnlyImportSpecifierModifier ? "" :
+ previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() :
+ "";
var moduleSpecifierCache = (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host);
- var lowerCaseTokenText = previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() : "";
var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, preferences, !!importCompletionNode, function (context) {
- exportInfo.forEach(sourceFile.path, function (info, symbolName, isFromAmbientModule) {
+ exportInfo.forEach(sourceFile.path, function (info, symbolName, isFromAmbientModule, exportMapKey) {
if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
return;
if (!detailsEntryId && ts.isStringANonContextualKeyword(symbolName))
@@ -127871,6 +130533,7 @@ var ts;
kind: moduleSpecifier ? 32 /* ResolvedExport */ : 4 /* Export */,
moduleSpecifier: moduleSpecifier,
symbolName: symbolName,
+ exportMapKey: exportMapKey,
exportName: exportInfo_1.exportKind === 2 /* ExportEquals */ ? "export=" /* ExportEquals */ : exportInfo_1.symbol.name,
fileName: exportInfo_1.moduleFileName,
isDefaultExport: isDefaultExport,
@@ -127931,7 +130594,7 @@ var ts;
return true;
}
if (contextToken.kind === 31 /* GreaterThanToken */ && contextToken.parent) {
- if (contextToken.parent.kind === 278 /* JsxOpeningElement */) {
+ if (contextToken.parent.kind === 279 /* JsxOpeningElement */) {
// Two possibilities:
// 1.
/**/
// - contextToken: GreaterThanToken (before cursor)
@@ -127941,10 +130604,10 @@ var ts;
// - contextToken: GreaterThanToken (before cursor)
// - location: GreaterThanToken (after cursor)
// - same parent (JSXOpeningElement)
- return location.parent.kind !== 278 /* JsxOpeningElement */;
+ return location.parent.kind !== 279 /* JsxOpeningElement */;
}
- if (contextToken.parent.kind === 279 /* JsxClosingElement */ || contextToken.parent.kind === 277 /* JsxSelfClosingElement */) {
- return !!contextToken.parent.parent && contextToken.parent.parent.kind === 276 /* JsxElement */;
+ if (contextToken.parent.kind === 280 /* JsxClosingElement */ || contextToken.parent.kind === 278 /* JsxSelfClosingElement */) {
+ return !!contextToken.parent.parent && contextToken.parent.parent.kind === 277 /* JsxElement */;
}
}
return false;
@@ -127952,45 +130615,51 @@ var ts;
function isNewIdentifierDefinitionLocation() {
if (contextToken) {
var containingNodeKind = contextToken.parent.kind;
+ var tokenKind = keywordForNode(contextToken);
// Previous token may have been a keyword that was converted to an identifier.
- switch (keywordForNode(contextToken)) {
+ switch (tokenKind) {
case 27 /* CommaToken */:
- return containingNodeKind === 206 /* CallExpression */ // func( a, |
- || containingNodeKind === 169 /* Constructor */ // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */
- || containingNodeKind === 207 /* NewExpression */ // new C(a, |
- || containingNodeKind === 202 /* ArrayLiteralExpression */ // [a, |
- || containingNodeKind === 219 /* BinaryExpression */ // const x = (a, |
- || containingNodeKind === 177 /* FunctionType */ // var x: (s: string, list|
- || containingNodeKind === 203 /* ObjectLiteralExpression */; // const obj = { x, |
+ return containingNodeKind === 207 /* CallExpression */ // func( a, |
+ || containingNodeKind === 170 /* Constructor */ // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */
+ || containingNodeKind === 208 /* NewExpression */ // new C(a, |
+ || containingNodeKind === 203 /* ArrayLiteralExpression */ // [a, |
+ || containingNodeKind === 220 /* BinaryExpression */ // const x = (a, |
+ || containingNodeKind === 178 /* FunctionType */ // var x: (s: string, list|
+ || containingNodeKind === 204 /* ObjectLiteralExpression */; // const obj = { x, |
case 20 /* OpenParenToken */:
- return containingNodeKind === 206 /* CallExpression */ // func( |
- || containingNodeKind === 169 /* Constructor */ // constructor( |
- || containingNodeKind === 207 /* NewExpression */ // new C(a|
- || containingNodeKind === 210 /* ParenthesizedExpression */ // const x = (a|
- || containingNodeKind === 189 /* ParenthesizedType */; // function F(pred: (a| /* this can become an arrow function, where 'a' is the argument */
+ return containingNodeKind === 207 /* CallExpression */ // func( |
+ || containingNodeKind === 170 /* Constructor */ // constructor( |
+ || containingNodeKind === 208 /* NewExpression */ // new C(a|
+ || containingNodeKind === 211 /* ParenthesizedExpression */ // const x = (a|
+ || containingNodeKind === 190 /* ParenthesizedType */; // function F(pred: (a| /* this can become an arrow function, where 'a' is the argument */
case 22 /* OpenBracketToken */:
- return containingNodeKind === 202 /* ArrayLiteralExpression */ // [ |
- || containingNodeKind === 174 /* IndexSignature */ // [ | : string ]
- || containingNodeKind === 160 /* ComputedPropertyName */; // [ | /* this can become an index signature */
- case 140 /* ModuleKeyword */: // module |
- case 141 /* NamespaceKeyword */: // namespace |
+ return containingNodeKind === 203 /* ArrayLiteralExpression */ // [ |
+ || containingNodeKind === 175 /* IndexSignature */ // [ | : string ]
+ || containingNodeKind === 161 /* ComputedPropertyName */; // [ | /* this can become an index signature */
+ case 141 /* ModuleKeyword */: // module |
+ case 142 /* NamespaceKeyword */: // namespace |
+ case 100 /* ImportKeyword */: // import |
return true;
case 24 /* DotToken */:
- return containingNodeKind === 259 /* ModuleDeclaration */; // module A.|
+ return containingNodeKind === 260 /* ModuleDeclaration */; // module A.|
case 18 /* OpenBraceToken */:
- return containingNodeKind === 255 /* ClassDeclaration */ // class A { |
- || containingNodeKind === 203 /* ObjectLiteralExpression */; // const obj = { |
+ return containingNodeKind === 256 /* ClassDeclaration */ // class A { |
+ || containingNodeKind === 204 /* ObjectLiteralExpression */; // const obj = { |
case 63 /* EqualsToken */:
- return containingNodeKind === 252 /* VariableDeclaration */ // const x = a|
- || containingNodeKind === 219 /* BinaryExpression */; // x = a|
+ return containingNodeKind === 253 /* VariableDeclaration */ // const x = a|
+ || containingNodeKind === 220 /* BinaryExpression */; // x = a|
case 15 /* TemplateHead */:
- return containingNodeKind === 221 /* TemplateExpression */; // `aa ${|
+ return containingNodeKind === 222 /* TemplateExpression */; // `aa ${|
case 16 /* TemplateMiddle */:
- return containingNodeKind === 231 /* TemplateSpan */; // `aa ${10} dd ${|
- case 123 /* PublicKeyword */:
- case 121 /* PrivateKeyword */:
- case 122 /* ProtectedKeyword */:
- return containingNodeKind === 165 /* PropertyDeclaration */; // class A{ public |
+ return containingNodeKind === 232 /* TemplateSpan */; // `aa ${10} dd ${|
+ case 131 /* AsyncKeyword */:
+ return containingNodeKind === 168 /* MethodDeclaration */ // const obj = { async c|()
+ || containingNodeKind === 295 /* ShorthandPropertyAssignment */; // const obj = { async c|
+ case 41 /* AsteriskToken */:
+ return containingNodeKind === 168 /* MethodDeclaration */; // const obj = { * c|
+ }
+ if (isClassMemberCompletionKeyword(tokenKind)) {
+ return true;
}
}
return false;
@@ -128036,7 +130705,7 @@ var ts;
completionKind = 0 /* ObjectPropertyDeclaration */;
var typeMembers;
var existingMembers;
- if (objectLikeContainer.kind === 203 /* ObjectLiteralExpression */) {
+ if (objectLikeContainer.kind === 204 /* ObjectLiteralExpression */) {
var instantiatedType = tryGetObjectLiteralContextualType(objectLikeContainer, typeChecker);
// Check completions for Object property value shorthand
if (instantiatedType === undefined) {
@@ -128061,7 +130730,7 @@ var ts;
}
}
else {
- ts.Debug.assert(objectLikeContainer.kind === 199 /* ObjectBindingPattern */);
+ ts.Debug.assert(objectLikeContainer.kind === 200 /* ObjectBindingPattern */);
// We are *only* completing on properties from the type being destructured.
isNewIdentifierLocation = false;
var rootDeclaration = ts.getRootDeclaration(objectLikeContainer.parent);
@@ -128072,12 +130741,12 @@ var ts;
// through type declaration or inference.
// Also proceed if rootDeclaration is a parameter and if its containing function expression/arrow function is contextually typed -
// type of parameter will flow in from the contextual type of the function
- var canGetType = ts.hasInitializer(rootDeclaration) || ts.hasType(rootDeclaration) || rootDeclaration.parent.parent.kind === 242 /* ForOfStatement */;
- if (!canGetType && rootDeclaration.kind === 162 /* Parameter */) {
+ var canGetType = ts.hasInitializer(rootDeclaration) || ts.hasType(rootDeclaration) || rootDeclaration.parent.parent.kind === 243 /* ForOfStatement */;
+ if (!canGetType && rootDeclaration.kind === 163 /* Parameter */) {
if (ts.isExpression(rootDeclaration.parent)) {
canGetType = !!typeChecker.getContextualType(rootDeclaration.parent);
}
- else if (rootDeclaration.parent.kind === 167 /* MethodDeclaration */ || rootDeclaration.parent.kind === 171 /* SetAccessor */) {
+ else if (rootDeclaration.parent.kind === 168 /* MethodDeclaration */ || rootDeclaration.parent.kind === 172 /* SetAccessor */) {
canGetType = ts.isExpression(rootDeclaration.parent.parent) && !!typeChecker.getContextualType(rootDeclaration.parent.parent);
}
}
@@ -128085,14 +130754,8 @@ var ts;
var typeForObject_1 = typeChecker.getTypeAtLocation(objectLikeContainer);
if (!typeForObject_1)
return 2 /* Fail */;
- // In a binding pattern, get only known properties (unless in the same scope).
- // Everywhere else we will get all possible properties.
- var containerClass_1 = ts.getContainingClass(objectLikeContainer);
- typeMembers = typeChecker.getPropertiesOfType(typeForObject_1).filter(function (symbol) {
- // either public
- return !(ts.getDeclarationModifierFlagsFromSymbol(symbol) & 24 /* NonPublicAccessibilityModifier */)
- // or we're in it
- || containerClass_1 && ts.contains(typeForObject_1.symbol.declarations, containerClass_1);
+ typeMembers = typeChecker.getPropertiesOfType(typeForObject_1).filter(function (propertySymbol) {
+ return typeChecker.isPropertyAccessible(objectLikeContainer, /*isSuper*/ false, /*writing*/ false, typeForObject_1, propertySymbol);
});
existingMembers = objectLikeContainer.elements;
}
@@ -128118,23 +130781,38 @@ var ts;
* Relevant symbols are stored in the captured 'symbols' variable.
*/
function tryGetImportOrExportClauseCompletionSymbols() {
- // `import { |` or `import { a as 0, | }`
- var namedImportsOrExports = contextToken && (contextToken.kind === 18 /* OpenBraceToken */ || contextToken.kind === 27 /* CommaToken */)
- ? ts.tryCast(contextToken.parent, ts.isNamedImportsOrExports) : undefined;
+ if (!contextToken)
+ return 0 /* Continue */;
+ // `import { |` or `import { a as 0, | }` or `import { type | }`
+ var namedImportsOrExports = contextToken.kind === 18 /* OpenBraceToken */ || contextToken.kind === 27 /* CommaToken */ ? ts.tryCast(contextToken.parent, ts.isNamedImportsOrExports) :
+ ts.isTypeKeywordTokenOrIdentifier(contextToken) ? ts.tryCast(contextToken.parent.parent, ts.isNamedImportsOrExports) : undefined;
if (!namedImportsOrExports)
return 0 /* Continue */;
+ // We can at least offer `type` at `import { |`
+ if (!ts.isTypeKeywordTokenOrIdentifier(contextToken)) {
+ keywordFilters = 8 /* TypeKeyword */;
+ }
// try to show exported member for imported/re-exported module
- var moduleSpecifier = (namedImportsOrExports.kind === 267 /* NamedImports */ ? namedImportsOrExports.parent.parent : namedImportsOrExports.parent).moduleSpecifier;
- if (!moduleSpecifier)
- return namedImportsOrExports.kind === 267 /* NamedImports */ ? 2 /* Fail */ : 0 /* Continue */;
+ var moduleSpecifier = (namedImportsOrExports.kind === 268 /* NamedImports */ ? namedImportsOrExports.parent.parent : namedImportsOrExports.parent).moduleSpecifier;
+ if (!moduleSpecifier) {
+ isNewIdentifierLocation = true;
+ return namedImportsOrExports.kind === 268 /* NamedImports */ ? 2 /* Fail */ : 0 /* Continue */;
+ }
var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(moduleSpecifier); // TODO: GH#18217
- if (!moduleSpecifierSymbol)
+ if (!moduleSpecifierSymbol) {
+ isNewIdentifierLocation = true;
return 2 /* Fail */;
+ }
completionKind = 3 /* MemberLike */;
isNewIdentifierLocation = false;
var exports = typeChecker.getExportsAndPropertiesOfModule(moduleSpecifierSymbol);
var existing = new ts.Set(namedImportsOrExports.elements.filter(function (n) { return !isCurrentlyEditingNode(n); }).map(function (n) { return (n.propertyName || n.name).escapedText; }));
- symbols = ts.concatenate(symbols, exports.filter(function (e) { return e.escapedName !== "default" /* Default */ && !existing.has(e.escapedName); }));
+ var uniques = exports.filter(function (e) { return e.escapedName !== "default" /* Default */ && !existing.has(e.escapedName); });
+ symbols = ts.concatenate(symbols, uniques);
+ if (!uniques.length) {
+ // If there's nothing else to import, don't offer `type` either
+ keywordFilters = 0 /* None */;
+ }
return 1 /* Success */;
}
/**
@@ -128286,11 +130964,11 @@ var ts;
case 30 /* LessThanSlashToken */:
case 43 /* SlashToken */:
case 79 /* Identifier */:
- case 204 /* PropertyAccessExpression */:
- case 284 /* JsxAttributes */:
- case 283 /* JsxAttribute */:
- case 285 /* JsxSpreadAttribute */:
- if (parent && (parent.kind === 277 /* JsxSelfClosingElement */ || parent.kind === 278 /* JsxOpeningElement */)) {
+ case 205 /* PropertyAccessExpression */:
+ case 285 /* JsxAttributes */:
+ case 284 /* JsxAttribute */:
+ case 286 /* JsxSpreadAttribute */:
+ if (parent && (parent.kind === 278 /* JsxSelfClosingElement */ || parent.kind === 279 /* JsxOpeningElement */)) {
if (contextToken.kind === 31 /* GreaterThanToken */) {
var precedingToken = ts.findPrecedingToken(contextToken.pos, sourceFile, /*startNode*/ undefined);
if (!parent.typeArguments || (precedingToken && precedingToken.kind === 43 /* SlashToken */))
@@ -128298,7 +130976,7 @@ var ts;
}
return parent;
}
- else if (parent.kind === 283 /* JsxAttribute */) {
+ else if (parent.kind === 284 /* JsxAttribute */) {
// Currently we parse JsxOpeningLikeElement as:
// JsxOpeningLikeElement
// attributes: JsxAttributes
@@ -128310,7 +130988,7 @@ var ts;
// its parent is a JsxExpression, whose parent is a JsxAttribute,
// whose parent is a JsxOpeningLikeElement
case 10 /* StringLiteral */:
- if (parent && ((parent.kind === 283 /* JsxAttribute */) || (parent.kind === 285 /* JsxSpreadAttribute */))) {
+ if (parent && ((parent.kind === 284 /* JsxAttribute */) || (parent.kind === 286 /* JsxSpreadAttribute */))) {
// Currently we parse JsxOpeningLikeElement as:
// JsxOpeningLikeElement
// attributes: JsxAttributes
@@ -128320,8 +130998,8 @@ var ts;
break;
case 19 /* CloseBraceToken */:
if (parent &&
- parent.kind === 286 /* JsxExpression */ &&
- parent.parent && parent.parent.kind === 283 /* JsxAttribute */) {
+ parent.kind === 287 /* JsxExpression */ &&
+ parent.parent && parent.parent.kind === 284 /* JsxAttribute */) {
// Currently we parse JsxOpeningLikeElement as:
// JsxOpeningLikeElement
// attributes: JsxAttributes
@@ -128329,7 +131007,7 @@ var ts;
// each JsxAttribute can have initializer as JsxExpression
return parent.parent.parent.parent;
}
- if (parent && parent.kind === 285 /* JsxSpreadAttribute */) {
+ if (parent && parent.kind === 286 /* JsxSpreadAttribute */) {
// Currently we parse JsxOpeningLikeElement as:
// JsxOpeningLikeElement
// attributes: JsxAttributes
@@ -128349,52 +131027,60 @@ var ts;
var containingNodeKind = parent.kind;
switch (contextToken.kind) {
case 27 /* CommaToken */:
- return containingNodeKind === 252 /* VariableDeclaration */ ||
+ return containingNodeKind === 253 /* VariableDeclaration */ ||
isVariableDeclarationListButNotTypeArgument(contextToken) ||
- containingNodeKind === 235 /* VariableStatement */ ||
- containingNodeKind === 258 /* EnumDeclaration */ || // enum a { foo, |
+ containingNodeKind === 236 /* VariableStatement */ ||
+ containingNodeKind === 259 /* EnumDeclaration */ || // enum a { foo, |
isFunctionLikeButNotConstructor(containingNodeKind) ||
- containingNodeKind === 256 /* InterfaceDeclaration */ || // interface A= contextToken.pos);
case 24 /* DotToken */:
- return containingNodeKind === 200 /* ArrayBindingPattern */; // var [.|
+ return containingNodeKind === 201 /* ArrayBindingPattern */; // var [.|
case 58 /* ColonToken */:
- return containingNodeKind === 201 /* BindingElement */; // var {x :html|
+ return containingNodeKind === 202 /* BindingElement */; // var {x :html|
case 22 /* OpenBracketToken */:
- return containingNodeKind === 200 /* ArrayBindingPattern */; // var [x|
+ return containingNodeKind === 201 /* ArrayBindingPattern */; // var [x|
case 20 /* OpenParenToken */:
- return containingNodeKind === 290 /* CatchClause */ ||
+ return containingNodeKind === 291 /* CatchClause */ ||
isFunctionLikeButNotConstructor(containingNodeKind);
case 18 /* OpenBraceToken */:
- return containingNodeKind === 258 /* EnumDeclaration */; // enum a { |
+ return containingNodeKind === 259 /* EnumDeclaration */; // enum a { |
case 29 /* LessThanToken */:
- return containingNodeKind === 255 /* ClassDeclaration */ || // class A< |
- containingNodeKind === 224 /* ClassExpression */ || // var C = class D< |
- containingNodeKind === 256 /* InterfaceDeclaration */ || // interface A< |
- containingNodeKind === 257 /* TypeAliasDeclaration */ || // type List< |
+ return containingNodeKind === 256 /* ClassDeclaration */ || // class A< |
+ containingNodeKind === 225 /* ClassExpression */ || // var C = class D< |
+ containingNodeKind === 257 /* InterfaceDeclaration */ || // interface A< |
+ containingNodeKind === 258 /* TypeAliasDeclaration */ || // type List< |
ts.isFunctionLikeKind(containingNodeKind);
case 124 /* StaticKeyword */:
- return containingNodeKind === 165 /* PropertyDeclaration */ && !ts.isClassLike(parent.parent);
+ return containingNodeKind === 166 /* PropertyDeclaration */ && !ts.isClassLike(parent.parent);
case 25 /* DotDotDotToken */:
- return containingNodeKind === 162 /* Parameter */ ||
- (!!parent.parent && parent.parent.kind === 200 /* ArrayBindingPattern */); // var [...z|
+ return containingNodeKind === 163 /* Parameter */ ||
+ (!!parent.parent && parent.parent.kind === 201 /* ArrayBindingPattern */); // var [...z|
case 123 /* PublicKeyword */:
case 121 /* PrivateKeyword */:
case 122 /* ProtectedKeyword */:
- return containingNodeKind === 162 /* Parameter */ && !ts.isConstructorDeclaration(parent.parent);
+ return containingNodeKind === 163 /* Parameter */ && !ts.isConstructorDeclaration(parent.parent);
case 127 /* AsKeyword */:
- return containingNodeKind === 268 /* ImportSpecifier */ ||
- containingNodeKind === 273 /* ExportSpecifier */ ||
- containingNodeKind === 266 /* NamespaceImport */;
- case 135 /* GetKeyword */:
- case 147 /* SetKeyword */:
+ return containingNodeKind === 269 /* ImportSpecifier */ ||
+ containingNodeKind === 274 /* ExportSpecifier */ ||
+ containingNodeKind === 267 /* NamespaceImport */;
+ case 136 /* GetKeyword */:
+ case 148 /* SetKeyword */:
return !isFromObjectTypeDeclaration(contextToken);
+ case 79 /* Identifier */:
+ if (containingNodeKind === 269 /* ImportSpecifier */ &&
+ contextToken === parent.name &&
+ contextToken.text === "type") {
+ // import { type | }
+ return false;
+ }
+ break;
case 84 /* ClassKeyword */:
case 92 /* EnumKeyword */:
case 118 /* InterfaceKeyword */:
@@ -128403,9 +131089,11 @@ var ts;
case 100 /* ImportKeyword */:
case 119 /* LetKeyword */:
case 85 /* ConstKeyword */:
- case 136 /* InferKeyword */:
- case 150 /* TypeKeyword */: // type htm|
+ case 137 /* InferKeyword */:
return true;
+ case 151 /* TypeKeyword */:
+ // import { type foo| }
+ return containingNodeKind !== 269 /* ImportSpecifier */;
case 41 /* AsteriskToken */:
return ts.isFunctionLike(contextToken.parent) && !ts.isMethodDeclaration(contextToken.parent);
}
@@ -128430,7 +131118,7 @@ var ts;
case 126 /* AbstractKeyword */:
case 84 /* ClassKeyword */:
case 85 /* ConstKeyword */:
- case 134 /* DeclareKeyword */:
+ case 135 /* DeclareKeyword */:
case 92 /* EnumKeyword */:
case 98 /* FunctionKeyword */:
case 118 /* InterfaceKeyword */:
@@ -128441,7 +131129,7 @@ var ts;
case 124 /* StaticKeyword */:
case 113 /* VarKeyword */:
return true;
- case 130 /* AsyncKeyword */:
+ case 131 /* AsyncKeyword */:
return ts.isPropertyDeclaration(contextToken.parent);
}
// If we are inside a class declaration, and `constructor` is totally not present,
@@ -128450,7 +131138,7 @@ var ts;
if (ancestorClassLike && contextToken === previousToken && isPreviousPropertyDeclarationTerminated(contextToken, position)) {
return false; // Don't block completions.
}
- var ancestorPropertyDeclaraion = ts.getAncestor(contextToken.parent, 165 /* PropertyDeclaration */);
+ var ancestorPropertyDeclaraion = ts.getAncestor(contextToken.parent, 166 /* PropertyDeclaration */);
// If we are inside a class declaration and typing `constructor` after property declaration...
if (ancestorPropertyDeclaraion
&& contextToken !== previousToken
@@ -128482,7 +131170,7 @@ var ts;
|| !ts.positionsAreOnSameLine(contextToken.end, position, sourceFile));
}
function isFunctionLikeButNotConstructor(kind) {
- return ts.isFunctionLikeKind(kind) && kind !== 169 /* Constructor */;
+ return ts.isFunctionLikeKind(kind) && kind !== 170 /* Constructor */;
}
function isDotOfNumericLiteral(contextToken) {
if (contextToken.kind === 8 /* NumericLiteral */) {
@@ -128492,7 +131180,7 @@ var ts;
return false;
}
function isVariableDeclarationListButNotTypeArgument(node) {
- return node.parent.kind === 253 /* VariableDeclarationList */
+ return node.parent.kind === 254 /* VariableDeclarationList */
&& !ts.isPossiblyTypeArgumentPosition(node, sourceFile, typeChecker);
}
/**
@@ -128510,13 +131198,13 @@ var ts;
for (var _i = 0, existingMembers_1 = existingMembers; _i < existingMembers_1.length; _i++) {
var m = existingMembers_1[_i];
// Ignore omitted expressions for missing members
- if (m.kind !== 291 /* PropertyAssignment */ &&
- m.kind !== 292 /* ShorthandPropertyAssignment */ &&
- m.kind !== 201 /* BindingElement */ &&
- m.kind !== 167 /* MethodDeclaration */ &&
- m.kind !== 170 /* GetAccessor */ &&
- m.kind !== 171 /* SetAccessor */ &&
- m.kind !== 293 /* SpreadAssignment */) {
+ if (m.kind !== 294 /* PropertyAssignment */ &&
+ m.kind !== 295 /* ShorthandPropertyAssignment */ &&
+ m.kind !== 202 /* BindingElement */ &&
+ m.kind !== 168 /* MethodDeclaration */ &&
+ m.kind !== 171 /* GetAccessor */ &&
+ m.kind !== 172 /* SetAccessor */ &&
+ m.kind !== 296 /* SpreadAssignment */) {
continue;
}
// If this is the current item we are editing right now, do not filter it out
@@ -128591,10 +131279,10 @@ var ts;
for (var _i = 0, existingMembers_2 = existingMembers; _i < existingMembers_2.length; _i++) {
var m = existingMembers_2[_i];
// Ignore omitted expressions for missing members
- if (m.kind !== 165 /* PropertyDeclaration */ &&
- m.kind !== 167 /* MethodDeclaration */ &&
- m.kind !== 170 /* GetAccessor */ &&
- m.kind !== 171 /* SetAccessor */) {
+ if (m.kind !== 166 /* PropertyDeclaration */ &&
+ m.kind !== 168 /* MethodDeclaration */ &&
+ m.kind !== 171 /* GetAccessor */ &&
+ m.kind !== 172 /* SetAccessor */) {
continue;
}
// If this is the current item we are editing right now, do not filter it out
@@ -128636,7 +131324,7 @@ var ts;
if (isCurrentlyEditingNode(attr)) {
continue;
}
- if (attr.kind === 283 /* JsxAttribute */) {
+ if (attr.kind === 284 /* JsxAttribute */) {
seenNames.add(attr.name.escapedText);
}
else if (ts.isJsxSpreadAttribute(attr)) {
@@ -128674,18 +131362,7 @@ var ts;
return undefined;
var isDefaultExport = data.exportName === "default" /* Default */;
symbol = isDefaultExport && ts.getLocalSymbolForExportDefault(symbol) || symbol;
- return {
- symbol: symbol,
- origin: {
- kind: data.moduleSpecifier ? 32 /* ResolvedExport */ : 4 /* Export */,
- moduleSymbol: moduleSymbol,
- symbolName: name,
- isDefaultExport: isDefaultExport,
- exportName: data.exportName,
- fileName: data.fileName,
- isFromPackageJson: !!data.isPackageJsonImport,
- }
- };
+ return { symbol: symbol, origin: completionEntryDataToSymbolOriginInfo(data, name, moduleSymbol) };
}
function getCompletionEntryDisplayNameForSymbol(symbol, target, origin, kind, jsxIdentifierExpected) {
var name = originIncludesSymbolName(origin) ? origin.symbolName : symbol.name;
@@ -128722,7 +131399,7 @@ var ts;
var _keywordCompletions = [];
var allKeywordsCompletions = ts.memoize(function () {
var res = [];
- for (var i = 81 /* FirstKeyword */; i <= 158 /* LastKeyword */; i++) {
+ for (var i = 81 /* FirstKeyword */; i <= 159 /* LastKeyword */; i++) {
res.push({
name: ts.tokenToString(i),
kind: "keyword" /* keyword */,
@@ -128748,11 +131425,12 @@ var ts;
return false;
case 1 /* All */:
return isFunctionLikeBodyKeyword(kind)
- || kind === 134 /* DeclareKeyword */
- || kind === 140 /* ModuleKeyword */
- || kind === 150 /* TypeKeyword */
- || kind === 141 /* NamespaceKeyword */
- || ts.isTypeKeyword(kind) && kind !== 151 /* UndefinedKeyword */;
+ || kind === 135 /* DeclareKeyword */
+ || kind === 141 /* ModuleKeyword */
+ || kind === 151 /* TypeKeyword */
+ || kind === 142 /* NamespaceKeyword */
+ || kind === 126 /* AbstractKeyword */
+ || ts.isTypeKeyword(kind) && kind !== 152 /* UndefinedKeyword */;
case 5 /* FunctionLikeBodyKeywords */:
return isFunctionLikeBodyKeyword(kind);
case 2 /* ClassElementKeywords */:
@@ -128765,6 +131443,8 @@ var ts;
return ts.isTypeKeyword(kind) || kind === 85 /* ConstKeyword */;
case 7 /* TypeKeywords */:
return ts.isTypeKeyword(kind);
+ case 8 /* TypeKeyword */:
+ return kind === 151 /* TypeKeyword */;
default:
return ts.Debug.assertNever(keywordFilter);
}
@@ -128773,57 +131453,57 @@ var ts;
function isTypeScriptOnlyKeyword(kind) {
switch (kind) {
case 126 /* AbstractKeyword */:
- case 129 /* AnyKeyword */:
- case 156 /* BigIntKeyword */:
- case 132 /* BooleanKeyword */:
- case 134 /* DeclareKeyword */:
+ case 130 /* AnyKeyword */:
+ case 157 /* BigIntKeyword */:
+ case 133 /* BooleanKeyword */:
+ case 135 /* DeclareKeyword */:
case 92 /* EnumKeyword */:
- case 155 /* GlobalKeyword */:
+ case 156 /* GlobalKeyword */:
case 117 /* ImplementsKeyword */:
- case 136 /* InferKeyword */:
+ case 137 /* InferKeyword */:
case 118 /* InterfaceKeyword */:
- case 138 /* IsKeyword */:
- case 139 /* KeyOfKeyword */:
- case 140 /* ModuleKeyword */:
- case 141 /* NamespaceKeyword */:
- case 142 /* NeverKeyword */:
- case 145 /* NumberKeyword */:
- case 146 /* ObjectKeyword */:
- case 157 /* OverrideKeyword */:
+ case 139 /* IsKeyword */:
+ case 140 /* KeyOfKeyword */:
+ case 141 /* ModuleKeyword */:
+ case 142 /* NamespaceKeyword */:
+ case 143 /* NeverKeyword */:
+ case 146 /* NumberKeyword */:
+ case 147 /* ObjectKeyword */:
+ case 158 /* OverrideKeyword */:
case 121 /* PrivateKeyword */:
case 122 /* ProtectedKeyword */:
case 123 /* PublicKeyword */:
- case 143 /* ReadonlyKeyword */:
- case 148 /* StringKeyword */:
- case 149 /* SymbolKeyword */:
- case 150 /* TypeKeyword */:
- case 152 /* UniqueKeyword */:
- case 153 /* UnknownKeyword */:
+ case 144 /* ReadonlyKeyword */:
+ case 149 /* StringKeyword */:
+ case 150 /* SymbolKeyword */:
+ case 151 /* TypeKeyword */:
+ case 153 /* UniqueKeyword */:
+ case 154 /* UnknownKeyword */:
return true;
default:
return false;
}
}
function isInterfaceOrTypeLiteralCompletionKeyword(kind) {
- return kind === 143 /* ReadonlyKeyword */;
+ return kind === 144 /* ReadonlyKeyword */;
}
function isClassMemberCompletionKeyword(kind) {
switch (kind) {
case 126 /* AbstractKeyword */:
- case 133 /* ConstructorKeyword */:
- case 135 /* GetKeyword */:
- case 147 /* SetKeyword */:
- case 130 /* AsyncKeyword */:
- case 134 /* DeclareKeyword */:
- case 157 /* OverrideKeyword */:
+ case 134 /* ConstructorKeyword */:
+ case 136 /* GetKeyword */:
+ case 148 /* SetKeyword */:
+ case 131 /* AsyncKeyword */:
+ case 135 /* DeclareKeyword */:
+ case 158 /* OverrideKeyword */:
return true;
default:
return ts.isClassMemberModifier(kind);
}
}
function isFunctionLikeBodyKeyword(kind) {
- return kind === 130 /* AsyncKeyword */
- || kind === 131 /* AwaitKeyword */
+ return kind === 131 /* AsyncKeyword */
+ || kind === 132 /* AwaitKeyword */
|| kind === 127 /* AsKeyword */
|| !ts.isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind);
}
@@ -128840,16 +131520,9 @@ var ts;
var type = hasCompletionsType && !(completionsType.flags & 3 /* AnyOrUnknown */)
? checker.getUnionType([contextualType, completionsType])
: contextualType;
- var properties = type.isUnion()
- ? checker.getAllPossiblePropertiesOfTypes(type.types.filter(function (memberType) {
- // If we're providing completions for an object literal, skip primitive, array-like, or callable types since those shouldn't be implemented by object literals.
- return !(memberType.flags & 131068 /* Primitive */ ||
- checker.isArrayLikeType(memberType) ||
- ts.typeHasCallOrConstructSignatures(memberType, checker) ||
- checker.isTypeInvalidDueToUnionDiscriminant(memberType, obj));
- }))
- : type.getApparentProperties();
- return hasCompletionsType ? properties.filter(hasDeclarationOtherThanSelf) : properties;
+ var properties = getApparentProperties(type, obj, checker);
+ return type.isClass() && containsNonPublicProperties(properties) ? [] :
+ hasCompletionsType ? ts.filter(properties, hasDeclarationOtherThanSelf) : properties;
// Filter out members whose only declaration is the object literal itself to avoid
// self-fulfilling completions like:
//
@@ -128860,6 +131533,20 @@ var ts;
}
}
Completions.getPropertiesForObjectExpression = getPropertiesForObjectExpression;
+ function getApparentProperties(type, node, checker) {
+ if (!type.isUnion())
+ return type.getApparentProperties();
+ return checker.getAllPossiblePropertiesOfTypes(ts.filter(type.types, function (memberType) {
+ return !(memberType.flags & 131068 /* Primitive */
+ || checker.isArrayLikeType(memberType)
+ || checker.isTypeInvalidDueToUnionDiscriminant(memberType, node)
+ || ts.typeHasCallOrConstructSignatures(memberType, checker)
+ || memberType.isClass() && containsNonPublicProperties(memberType.getApparentProperties()));
+ }));
+ }
+ function containsNonPublicProperties(props) {
+ return ts.some(props, function (p) { return !!(ts.getDeclarationModifierFlagsFromSymbol(p) & 24 /* NonPublicAccessibilityModifier */); });
+ }
/**
* Gets all properties on a type, but if that type is a union of several types,
* excludes array-like types or callable/constructable types.
@@ -128876,7 +131563,7 @@ var ts;
function tryGetObjectTypeDeclarationCompletionContainer(sourceFile, contextToken, location, position) {
// class c { method() { } | method2() { } }
switch (location.kind) {
- case 343 /* SyntaxList */:
+ case 346 /* SyntaxList */:
return ts.tryCast(location.parent, ts.isObjectTypeDeclaration);
case 1 /* EndOfFileToken */:
var cls = ts.tryCast(ts.lastOrUndefined(ts.cast(location.parent, ts.isSourceFile).statements), ts.isObjectTypeDeclaration);
@@ -128898,7 +131585,7 @@ var ts;
if (!contextToken)
return undefined;
// class C { blah; constructor/**/ } and so on
- if (location.kind === 133 /* ConstructorKeyword */
+ if (location.kind === 134 /* ConstructorKeyword */
// class C { blah \n constructor/**/ }
|| (ts.isIdentifier(contextToken) && ts.isPropertyDeclaration(contextToken.parent) && ts.isClassLike(location))) {
return ts.findAncestor(contextToken, ts.isClassLike);
@@ -128941,7 +131628,7 @@ var ts;
case 26 /* SemicolonToken */:
case 27 /* CommaToken */:
case 79 /* Identifier */:
- if (parent.kind === 164 /* PropertySignature */ && ts.isTypeLiteralNode(parent.parent)) {
+ if (parent.kind === 165 /* PropertySignature */ && ts.isTypeLiteralNode(parent.parent)) {
return parent.parent;
}
break;
@@ -128958,11 +131645,11 @@ var ts;
if (!t)
return undefined;
switch (node.kind) {
- case 164 /* PropertySignature */:
+ case 165 /* PropertySignature */:
return checker.getTypeOfPropertyOfContextualType(t, node.symbol.escapedName);
- case 186 /* IntersectionType */:
- case 180 /* TypeLiteral */:
- case 185 /* UnionType */:
+ case 187 /* IntersectionType */:
+ case 181 /* TypeLiteral */:
+ case 186 /* UnionType */:
return t;
}
}
@@ -128990,7 +131677,7 @@ var ts;
? !!ts.tryGetImportFromModuleSpecifier(contextToken)
: contextToken.kind === 43 /* SlashToken */ && ts.isJsxClosingElement(contextToken.parent));
case " ":
- return !!contextToken && ts.isImportKeyword(contextToken) && contextToken.parent.kind === 300 /* SourceFile */;
+ return !!contextToken && ts.isImportKeyword(contextToken) && contextToken.parent.kind === 303 /* SourceFile */;
default:
return ts.Debug.assertNever(triggerCharacter);
}
@@ -129031,34 +131718,67 @@ var ts;
}
return undefined;
}
- function getImportCompletionNode(contextToken) {
+ function getImportStatementCompletionInfo(contextToken) {
+ var keywordCompletion;
+ var isKeywordOnlyCompletion = false;
var candidate = getCandidate();
- return candidate === 154 /* FromKeyword */ || candidate && ts.rangeIsOnSingleLine(candidate, candidate.getSourceFile()) ? candidate : undefined;
+ return {
+ isKeywordOnlyCompletion: isKeywordOnlyCompletion,
+ keywordCompletion: keywordCompletion,
+ isNewIdentifierLocation: !!(candidate || keywordCompletion === 151 /* TypeKeyword */),
+ replacementNode: candidate && ts.rangeIsOnSingleLine(candidate, candidate.getSourceFile())
+ ? candidate
+ : undefined
+ };
function getCandidate() {
var parent = contextToken.parent;
if (ts.isImportEqualsDeclaration(parent)) {
+ keywordCompletion = contextToken.kind === 151 /* TypeKeyword */ ? undefined : 151 /* TypeKeyword */;
return isModuleSpecifierMissingOrEmpty(parent.moduleReference) ? parent : undefined;
}
+ if (couldBeTypeOnlyImportSpecifier(parent, contextToken) && canCompleteFromNamedBindings(parent.parent)) {
+ return parent;
+ }
if (ts.isNamedImports(parent) || ts.isNamespaceImport(parent)) {
- if (isModuleSpecifierMissingOrEmpty(parent.parent.parent.moduleSpecifier) && (ts.isNamespaceImport(parent) || parent.elements.length < 2) && !parent.parent.name) {
+ if (!parent.parent.isTypeOnly && (contextToken.kind === 18 /* OpenBraceToken */ ||
+ contextToken.kind === 100 /* ImportKeyword */ ||
+ contextToken.kind === 27 /* CommaToken */)) {
+ keywordCompletion = 151 /* TypeKeyword */;
+ }
+ if (canCompleteFromNamedBindings(parent)) {
// At `import { ... } |` or `import * as Foo |`, the only possible completion is `from`
- return contextToken.kind === 19 /* CloseBraceToken */ || contextToken.kind === 79 /* Identifier */
- ? 154 /* FromKeyword */
- : parent.parent.parent;
+ if (contextToken.kind === 19 /* CloseBraceToken */ || contextToken.kind === 79 /* Identifier */) {
+ isKeywordOnlyCompletion = true;
+ keywordCompletion = 155 /* FromKeyword */;
+ }
+ else {
+ return parent.parent.parent;
+ }
}
return undefined;
}
if (ts.isImportKeyword(contextToken) && ts.isSourceFile(parent)) {
// A lone import keyword with nothing following it does not parse as a statement at all
+ keywordCompletion = 151 /* TypeKeyword */;
return contextToken;
}
if (ts.isImportKeyword(contextToken) && ts.isImportDeclaration(parent)) {
// `import s| from`
+ keywordCompletion = 151 /* TypeKeyword */;
return isModuleSpecifierMissingOrEmpty(parent.moduleSpecifier) ? parent : undefined;
}
return undefined;
}
}
+ function couldBeTypeOnlyImportSpecifier(importSpecifier, contextToken) {
+ return ts.isImportSpecifier(importSpecifier)
+ && (importSpecifier.isTypeOnly || contextToken === importSpecifier.name && ts.isTypeKeywordTokenOrIdentifier(contextToken));
+ }
+ function canCompleteFromNamedBindings(namedBindings) {
+ return isModuleSpecifierMissingOrEmpty(namedBindings.parent.parent.moduleSpecifier)
+ && (ts.isNamespaceImport(namedBindings) || namedBindings.elements.length < 2)
+ && !namedBindings.parent.name;
+ }
function isModuleSpecifierMissingOrEmpty(specifier) {
var _a;
if (ts.nodeIsMissing(specifier))
@@ -129221,14 +131941,14 @@ var ts;
case 115 /* WhileKeyword */:
case 90 /* DoKeyword */:
return useParent(node.parent, function (n) { return ts.isIterationStatement(n, /*lookInLabeledStatements*/ true); }, getLoopBreakContinueOccurrences);
- case 133 /* ConstructorKeyword */:
- return getFromAllDeclarations(ts.isConstructorDeclaration, [133 /* ConstructorKeyword */]);
- case 135 /* GetKeyword */:
- case 147 /* SetKeyword */:
- return getFromAllDeclarations(ts.isAccessor, [135 /* GetKeyword */, 147 /* SetKeyword */]);
- case 131 /* AwaitKeyword */:
+ case 134 /* ConstructorKeyword */:
+ return getFromAllDeclarations(ts.isConstructorDeclaration, [134 /* ConstructorKeyword */]);
+ case 136 /* GetKeyword */:
+ case 148 /* SetKeyword */:
+ return getFromAllDeclarations(ts.isAccessor, [136 /* GetKeyword */, 148 /* SetKeyword */]);
+ case 132 /* AwaitKeyword */:
return useParent(node.parent, ts.isAwaitExpression, getAsyncAndAwaitOccurrences);
- case 130 /* AsyncKeyword */:
+ case 131 /* AsyncKeyword */:
return highlightSpans(getAsyncAndAwaitOccurrences(node));
case 125 /* YieldKeyword */:
return highlightSpans(getYieldOccurrences(node));
@@ -129273,7 +131993,7 @@ var ts;
var child = throwStatement;
while (child.parent) {
var parent = child.parent;
- if (ts.isFunctionBlock(parent) || parent.kind === 300 /* SourceFile */) {
+ if (ts.isFunctionBlock(parent) || parent.kind === 303 /* SourceFile */) {
return parent;
}
// A throw-statement is only owned by a try-statement if the try-statement has
@@ -129305,16 +132025,16 @@ var ts;
function getBreakOrContinueOwner(statement) {
return ts.findAncestor(statement, function (node) {
switch (node.kind) {
- case 247 /* SwitchStatement */:
- if (statement.kind === 243 /* ContinueStatement */) {
+ case 248 /* SwitchStatement */:
+ if (statement.kind === 244 /* ContinueStatement */) {
return false;
}
// falls through
- case 240 /* ForStatement */:
- case 241 /* ForInStatement */:
- case 242 /* ForOfStatement */:
- case 239 /* WhileStatement */:
- case 238 /* DoStatement */:
+ case 241 /* ForStatement */:
+ case 242 /* ForInStatement */:
+ case 243 /* ForOfStatement */:
+ case 240 /* WhileStatement */:
+ case 239 /* DoStatement */:
return !statement.label || isLabeledBy(node, statement.label.escapedText);
default:
// Don't cross function boundaries.
@@ -129330,11 +132050,11 @@ var ts;
// Types of node whose children might have modifiers.
var container = declaration.parent;
switch (container.kind) {
- case 260 /* ModuleBlock */:
- case 300 /* SourceFile */:
- case 233 /* Block */:
- case 287 /* CaseClause */:
- case 288 /* DefaultClause */:
+ case 261 /* ModuleBlock */:
+ case 303 /* SourceFile */:
+ case 234 /* Block */:
+ case 288 /* CaseClause */:
+ case 289 /* DefaultClause */:
// Container is either a class declaration or the declaration is a classDeclaration
if (modifierFlag & 128 /* Abstract */ && ts.isClassDeclaration(declaration)) {
return __spreadArray(__spreadArray([], declaration.members, true), [declaration], false);
@@ -129342,14 +132062,14 @@ var ts;
else {
return container.statements;
}
- case 169 /* Constructor */:
- case 167 /* MethodDeclaration */:
- case 254 /* FunctionDeclaration */:
+ case 170 /* Constructor */:
+ case 168 /* MethodDeclaration */:
+ case 255 /* FunctionDeclaration */:
return __spreadArray(__spreadArray([], container.parameters, true), (ts.isClassLike(container.parent) ? container.parent.members : []), true);
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
- case 256 /* InterfaceDeclaration */:
- case 180 /* TypeLiteral */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
+ case 257 /* InterfaceDeclaration */:
+ case 181 /* TypeLiteral */:
var nodes = container.members;
// If we're an accessibility modifier, we're in an instance member and should search
// the constructor's parameter list for instance members as well.
@@ -129364,7 +132084,7 @@ var ts;
}
return nodes;
// Syntactically invalid positions that the parser might produce anyway
- case 203 /* ObjectLiteralExpression */:
+ case 204 /* ObjectLiteralExpression */:
return undefined;
default:
ts.Debug.assertNever(container, "Invalid container kind.");
@@ -129385,7 +132105,7 @@ var ts;
var keywords = [];
if (pushKeywordIf(keywords, loopNode.getFirstToken(), 97 /* ForKeyword */, 115 /* WhileKeyword */, 90 /* DoKeyword */)) {
// If we succeeded and got a do-while loop, then start looking for a 'while' keyword.
- if (loopNode.kind === 238 /* DoStatement */) {
+ if (loopNode.kind === 239 /* DoStatement */) {
var loopTokens = loopNode.getChildren();
for (var i = loopTokens.length - 1; i >= 0; i--) {
if (pushKeywordIf(keywords, loopTokens[i], 115 /* WhileKeyword */)) {
@@ -129405,13 +132125,13 @@ var ts;
var owner = getBreakOrContinueOwner(breakOrContinueStatement);
if (owner) {
switch (owner.kind) {
- case 240 /* ForStatement */:
- case 241 /* ForInStatement */:
- case 242 /* ForOfStatement */:
- case 238 /* DoStatement */:
- case 239 /* WhileStatement */:
+ case 241 /* ForStatement */:
+ case 242 /* ForInStatement */:
+ case 243 /* ForOfStatement */:
+ case 239 /* DoStatement */:
+ case 240 /* WhileStatement */:
return getLoopBreakContinueOccurrences(owner);
- case 247 /* SwitchStatement */:
+ case 248 /* SwitchStatement */:
return getSwitchCaseDefaultOccurrences(owner);
}
}
@@ -129484,13 +132204,13 @@ var ts;
var keywords = [];
if (func.modifiers) {
func.modifiers.forEach(function (modifier) {
- pushKeywordIf(keywords, modifier, 130 /* AsyncKeyword */);
+ pushKeywordIf(keywords, modifier, 131 /* AsyncKeyword */);
});
}
ts.forEachChild(func, function (child) {
traverseWithoutCrossingFunction(child, function (node) {
if (ts.isAwaitExpression(node)) {
- pushKeywordIf(keywords, node.getFirstToken(), 131 /* AwaitKeyword */);
+ pushKeywordIf(keywords, node.getFirstToken(), 132 /* AwaitKeyword */);
}
});
});
@@ -129645,7 +132365,7 @@ var ts;
}
function acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, acquiring, scriptKind) {
scriptKind = ts.ensureScriptKind(fileName, scriptKind);
- var scriptTarget = scriptKind === 6 /* JSON */ ? 100 /* JSON */ : compilationSettings.target || 1 /* ES5 */;
+ var scriptTarget = scriptKind === 6 /* JSON */ ? 100 /* JSON */ : ts.getEmitScriptTarget(compilationSettings);
var bucket = ts.getOrUpdate(buckets, key, function () { return new ts.Map(); });
var bucketEntry = bucket.get(path);
var entry = bucketEntry && getDocumentRegistryEntry(bucketEntry, scriptKind);
@@ -129820,14 +132540,14 @@ var ts;
if (cancellationToken)
cancellationToken.throwIfCancellationRequested();
switch (direct.kind) {
- case 206 /* CallExpression */:
+ case 207 /* CallExpression */:
if (ts.isImportCall(direct)) {
handleImportCall(direct);
break;
}
if (!isAvailableThroughGlobal) {
var parent = direct.parent;
- if (exportKind === 2 /* ExportEquals */ && parent.kind === 252 /* VariableDeclaration */) {
+ if (exportKind === 2 /* ExportEquals */ && parent.kind === 253 /* VariableDeclaration */) {
var name = parent.name;
if (name.kind === 79 /* Identifier */) {
directImports.push(name);
@@ -129838,25 +132558,25 @@ var ts;
break;
case 79 /* Identifier */: // for 'const x = require("y");
break; // TODO: GH#23879
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
handleNamespaceImport(direct, direct.name, ts.hasSyntacticModifier(direct, 1 /* Export */), /*alreadyAddedDirect*/ false);
break;
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
directImports.push(direct);
var namedBindings = direct.importClause && direct.importClause.namedBindings;
- if (namedBindings && namedBindings.kind === 266 /* NamespaceImport */) {
+ if (namedBindings && namedBindings.kind === 267 /* NamespaceImport */) {
handleNamespaceImport(direct, namedBindings.name, /*isReExport*/ false, /*alreadyAddedDirect*/ true);
}
else if (!isAvailableThroughGlobal && ts.isDefaultImport(direct)) {
addIndirectUser(getSourceFileLikeForImportDeclaration(direct)); // Add a check for indirect uses to handle synthetic default imports
}
break;
- case 270 /* ExportDeclaration */:
+ case 271 /* ExportDeclaration */:
if (!direct.exportClause) {
// This is `export * from "foo"`, so imports of this module may import the export too.
handleDirectImports(getContainingModuleSymbol(direct, checker));
}
- else if (direct.exportClause.kind === 272 /* NamespaceExport */) {
+ else if (direct.exportClause.kind === 273 /* NamespaceExport */) {
// `export * as foo from "foo"` add to indirect uses
addIndirectUser(getSourceFileLikeForImportDeclaration(direct), /** addTransitiveDependencies */ true);
}
@@ -129865,7 +132585,7 @@ var ts;
directImports.push(direct);
}
break;
- case 198 /* ImportType */:
+ case 199 /* ImportType */:
// Only check for typeof import('xyz')
if (direct.isTypeOf && !direct.qualifier && isExported(direct)) {
addIndirectUser(direct.getSourceFile(), /** addTransitiveDependencies */ true);
@@ -129898,7 +132618,7 @@ var ts;
}
else if (!isAvailableThroughGlobal) {
var sourceFileLike = getSourceFileLikeForImportDeclaration(importDeclaration);
- ts.Debug.assert(sourceFileLike.kind === 300 /* SourceFile */ || sourceFileLike.kind === 259 /* ModuleDeclaration */);
+ ts.Debug.assert(sourceFileLike.kind === 303 /* SourceFile */ || sourceFileLike.kind === 260 /* ModuleDeclaration */);
if (isReExport || findNamespaceReExports(sourceFileLike, name, checker)) {
addIndirectUser(sourceFileLike, /** addTransitiveDependencies */ true);
}
@@ -129954,7 +132674,7 @@ var ts;
}
return { importSearches: importSearches, singleReferences: singleReferences };
function handleImport(decl) {
- if (decl.kind === 263 /* ImportEqualsDeclaration */) {
+ if (decl.kind === 264 /* ImportEqualsDeclaration */) {
if (isExternalModuleImportEquals(decl)) {
handleNamespaceImportLike(decl.name);
}
@@ -129964,7 +132684,7 @@ var ts;
handleNamespaceImportLike(decl);
return;
}
- if (decl.kind === 198 /* ImportType */) {
+ if (decl.kind === 199 /* ImportType */) {
if (decl.qualifier) {
var firstIdentifier = ts.getFirstIdentifier(decl.qualifier);
if (firstIdentifier.escapedText === ts.symbolName(exportSymbol)) {
@@ -129980,7 +132700,7 @@ var ts;
if (decl.moduleSpecifier.kind !== 10 /* StringLiteral */) {
return;
}
- if (decl.kind === 270 /* ExportDeclaration */) {
+ if (decl.kind === 271 /* ExportDeclaration */) {
if (decl.exportClause && ts.isNamedExports(decl.exportClause)) {
searchForNamedImport(decl.exportClause);
}
@@ -129989,10 +132709,10 @@ var ts;
var _a = decl.importClause || { name: undefined, namedBindings: undefined }, name = _a.name, namedBindings = _a.namedBindings;
if (namedBindings) {
switch (namedBindings.kind) {
- case 266 /* NamespaceImport */:
+ case 267 /* NamespaceImport */:
handleNamespaceImportLike(namedBindings.name);
break;
- case 267 /* NamedImports */:
+ case 268 /* NamedImports */:
// 'default' might be accessed as a named import `{ default as foo }`.
if (exportKind === 0 /* Named */ || exportKind === 1 /* Default */) {
searchForNamedImport(namedBindings);
@@ -130042,7 +132762,7 @@ var ts;
}
}
else {
- var localSymbol = element.kind === 273 /* ExportSpecifier */ && element.propertyName
+ var localSymbol = element.kind === 274 /* ExportSpecifier */ && element.propertyName
? checker.getExportSpecifierLocalTargetSymbol(element) // For re-exporting under a different name, we want to get the re-exported symbol.
: checker.getSymbolAtLocation(name);
addSearch(name, localSymbol);
@@ -130071,7 +132791,7 @@ var ts;
for (var _i = 0, sourceFiles_1 = sourceFiles; _i < sourceFiles_1.length; _i++) {
var referencingFile = sourceFiles_1[_i];
var searchSourceFile = searchModuleSymbol.valueDeclaration;
- if ((searchSourceFile === null || searchSourceFile === void 0 ? void 0 : searchSourceFile.kind) === 300 /* SourceFile */) {
+ if ((searchSourceFile === null || searchSourceFile === void 0 ? void 0 : searchSourceFile.kind) === 303 /* SourceFile */) {
for (var _a = 0, _b = referencingFile.referencedFiles; _a < _b.length; _a++) {
var ref = _b[_a];
if (program.getSourceFileFromReference(referencingFile, ref) === searchSourceFile) {
@@ -130119,7 +132839,7 @@ var ts;
}
/** Iterates over all statements at the top level or in module declarations. Returns the first truthy result. */
function forEachPossibleImportOrExportStatement(sourceFileLike, action) {
- return ts.forEach(sourceFileLike.kind === 300 /* SourceFile */ ? sourceFileLike.statements : sourceFileLike.body.statements, function (statement) {
+ return ts.forEach(sourceFileLike.kind === 303 /* SourceFile */ ? sourceFileLike.statements : sourceFileLike.body.statements, function (statement) {
return action(statement) || (isAmbientModuleDeclaration(statement) && ts.forEach(statement.body && statement.body.statements, action));
});
}
@@ -130134,15 +132854,15 @@ var ts;
else {
forEachPossibleImportOrExportStatement(sourceFile, function (statement) {
switch (statement.kind) {
- case 270 /* ExportDeclaration */:
- case 264 /* ImportDeclaration */: {
+ case 271 /* ExportDeclaration */:
+ case 265 /* ImportDeclaration */: {
var decl = statement;
if (decl.moduleSpecifier && ts.isStringLiteral(decl.moduleSpecifier)) {
action(decl, decl.moduleSpecifier);
}
break;
}
- case 263 /* ImportEqualsDeclaration */: {
+ case 264 /* ImportEqualsDeclaration */: {
var decl = statement;
if (isExternalModuleImportEquals(decl)) {
action(decl, decl.moduleReference.expression);
@@ -130167,7 +132887,7 @@ var ts;
var parent = node.parent;
var grandparent = parent.parent;
if (symbol.exportSymbol) {
- if (parent.kind === 204 /* PropertyAccessExpression */) {
+ if (parent.kind === 205 /* PropertyAccessExpression */) {
// When accessing an export of a JS module, there's no alias. The symbol will still be flagged as an export even though we're at the use.
// So check that we are at the declaration.
return ((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d === parent; })) && ts.isBinaryExpression(grandparent)
@@ -130301,16 +133021,16 @@ var ts;
function isNodeImport(node) {
var parent = node.parent;
switch (parent.kind) {
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return parent.name === node && isExternalModuleImportEquals(parent);
- case 268 /* ImportSpecifier */:
+ case 269 /* ImportSpecifier */:
// For a rename import `{ foo as bar }`, don't search for the imported symbol. Just find local uses of `bar`.
return !parent.propertyName;
- case 265 /* ImportClause */:
- case 266 /* NamespaceImport */:
+ case 266 /* ImportClause */:
+ case 267 /* NamespaceImport */:
ts.Debug.assert(parent.name === node);
return true;
- case 201 /* BindingElement */:
+ case 202 /* BindingElement */:
return ts.isInJSFile(node) && ts.isRequireVariableDeclaration(parent);
default:
return false;
@@ -130351,21 +133071,21 @@ var ts;
return checker.getMergedSymbol(getSourceFileLikeForImportDeclaration(importer).symbol);
}
function getSourceFileLikeForImportDeclaration(node) {
- if (node.kind === 206 /* CallExpression */) {
+ if (node.kind === 207 /* CallExpression */) {
return node.getSourceFile();
}
var parent = node.parent;
- if (parent.kind === 300 /* SourceFile */) {
+ if (parent.kind === 303 /* SourceFile */) {
return parent;
}
- ts.Debug.assert(parent.kind === 260 /* ModuleBlock */);
+ ts.Debug.assert(parent.kind === 261 /* ModuleBlock */);
return ts.cast(parent.parent, isAmbientModuleDeclaration);
}
function isAmbientModuleDeclaration(node) {
- return node.kind === 259 /* ModuleDeclaration */ && node.name.kind === 10 /* StringLiteral */;
+ return node.kind === 260 /* ModuleDeclaration */ && node.name.kind === 10 /* StringLiteral */;
}
function isExternalModuleImportEquals(eq) {
- return eq.moduleReference.kind === 275 /* ExternalModuleReference */ && eq.moduleReference.expression.kind === 10 /* StringLiteral */;
+ return eq.moduleReference.kind === 276 /* ExternalModuleReference */ && eq.moduleReference.expression.kind === 10 /* StringLiteral */;
}
})(FindAllReferences = ts.FindAllReferences || (ts.FindAllReferences = {}));
})(ts || (ts = {}));
@@ -130468,7 +133188,7 @@ var ts;
if (!node)
return undefined;
switch (node.kind) {
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
return !ts.isVariableDeclarationList(node.parent) || node.parent.declarations.length !== 1 ?
node :
ts.isVariableStatement(node.parent.parent) ?
@@ -130476,28 +133196,28 @@ var ts;
ts.isForInOrOfStatement(node.parent.parent) ?
getContextNode(node.parent.parent) :
node.parent;
- case 201 /* BindingElement */:
+ case 202 /* BindingElement */:
return getContextNode(node.parent.parent);
- case 268 /* ImportSpecifier */:
+ case 269 /* ImportSpecifier */:
return node.parent.parent.parent;
- case 273 /* ExportSpecifier */:
- case 266 /* NamespaceImport */:
+ case 274 /* ExportSpecifier */:
+ case 267 /* NamespaceImport */:
return node.parent.parent;
- case 265 /* ImportClause */:
- case 272 /* NamespaceExport */:
+ case 266 /* ImportClause */:
+ case 273 /* NamespaceExport */:
return node.parent;
- case 219 /* BinaryExpression */:
+ case 220 /* BinaryExpression */:
return ts.isExpressionStatement(node.parent) ?
node.parent :
node;
- case 242 /* ForOfStatement */:
- case 241 /* ForInStatement */:
+ case 243 /* ForOfStatement */:
+ case 242 /* ForInStatement */:
return {
start: node.initializer,
end: node.expression
};
- case 291 /* PropertyAssignment */:
- case 292 /* ShorthandPropertyAssignment */:
+ case 294 /* PropertyAssignment */:
+ case 295 /* ShorthandPropertyAssignment */:
return ts.isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent) ?
getContextNode(ts.findAncestor(node.parent, function (node) {
return ts.isBinaryExpression(node) || ts.isForInOrOfStatement(node);
@@ -130540,12 +133260,13 @@ var ts;
var node = ts.getTouchingPropertyName(sourceFile, position);
var referencedSymbols = Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, { use: 1 /* References */ });
var checker = program.getTypeChecker();
+ var symbol = checker.getSymbolAtLocation(node);
return !referencedSymbols || !referencedSymbols.length ? undefined : ts.mapDefined(referencedSymbols, function (_a) {
var definition = _a.definition, references = _a.references;
// Only include referenced symbols that have a valid definition.
return definition && {
definition: checker.runWithCancellationToken(cancellationToken, function (checker) { return definitionToReferencedSymbolDefinitionInfo(definition, checker, node); }),
- references: references.map(toReferenceEntry)
+ references: references.map(function (r) { return toReferenceEntry(r, symbol); })
};
});
}
@@ -130554,9 +133275,9 @@ var ts;
var node = ts.getTouchingPropertyName(sourceFile, position);
var referenceEntries;
var entries = getImplementationReferenceEntries(program, cancellationToken, sourceFiles, node, position);
- if (node.parent.kind === 204 /* PropertyAccessExpression */
- || node.parent.kind === 201 /* BindingElement */
- || node.parent.kind === 205 /* ElementAccessExpression */
+ if (node.parent.kind === 205 /* PropertyAccessExpression */
+ || node.parent.kind === 202 /* BindingElement */
+ || node.parent.kind === 206 /* ElementAccessExpression */
|| node.kind === 106 /* SuperKeyword */) {
referenceEntries = entries && __spreadArray([], entries, true);
}
@@ -130580,13 +133301,13 @@ var ts;
}
FindAllReferences.getImplementationsAtPosition = getImplementationsAtPosition;
function getImplementationReferenceEntries(program, cancellationToken, sourceFiles, node, position) {
- if (node.kind === 300 /* SourceFile */) {
+ if (node.kind === 303 /* SourceFile */) {
return undefined;
}
var checker = program.getTypeChecker();
// 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 === 292 /* ShorthandPropertyAssignment */) {
+ if (node.parent.kind === 295 /* ShorthandPropertyAssignment */) {
var result_2 = [];
Core.getReferenceEntriesForShorthandPropertyAssignment(node, checker, function (node) { return result_2.push(nodeEntry(node)); });
return result_2;
@@ -130678,13 +133399,13 @@ var ts;
return __assign(__assign({}, entryToDocumentSpan(entry)), (providePrefixAndSuffixText && getPrefixAndSuffixText(entry, originalNode, checker)));
}
FindAllReferences.toRenameLocation = toRenameLocation;
- function toReferenceEntry(entry) {
+ function toReferenceEntry(entry, symbol) {
var documentSpan = entryToDocumentSpan(entry);
if (entry.kind === 0 /* Span */) {
return __assign(__assign({}, documentSpan), { isWriteAccess: false, isDefinition: false });
}
var kind = entry.kind, node = entry.node;
- return __assign(__assign({}, documentSpan), { isWriteAccess: isWriteAccessForReference(node), isDefinition: isDefinitionForReference(node), isInString: kind === 2 /* StringLiteral */ ? true : undefined });
+ return __assign(__assign({}, documentSpan), { isWriteAccess: isWriteAccessForReference(node), isDefinition: isDeclarationOfSymbol(node, symbol), isInString: kind === 2 /* StringLiteral */ ? true : undefined });
}
FindAllReferences.toReferenceEntry = toReferenceEntry;
function entryToDocumentSpan(entry) {
@@ -130756,13 +133477,13 @@ var ts;
if (symbol) {
return getDefinitionKindAndDisplayParts(symbol, checker, node);
}
- else if (node.kind === 203 /* ObjectLiteralExpression */) {
+ else if (node.kind === 204 /* ObjectLiteralExpression */) {
return {
kind: "interface" /* interfaceElement */,
displayParts: [ts.punctuationPart(20 /* OpenParenToken */), ts.textPart("object literal"), ts.punctuationPart(21 /* CloseParenToken */)]
};
}
- else if (node.kind === 224 /* ClassExpression */) {
+ else if (node.kind === 225 /* ClassExpression */) {
return {
kind: "local class" /* localClassElement */,
displayParts: [ts.punctuationPart(20 /* OpenParenToken */), ts.textPart("anonymous local class"), ts.punctuationPart(21 /* CloseParenToken */)]
@@ -130808,11 +133529,18 @@ var ts;
var decl = ts.getDeclarationFromName(node);
return !!decl && declarationIsWriteAccess(decl) || node.kind === 88 /* DefaultKeyword */ || ts.isWriteAccess(node);
}
- function isDefinitionForReference(node) {
- return node.kind === 88 /* DefaultKeyword */
- || !!ts.getDeclarationFromName(node)
- || ts.isLiteralComputedPropertyDeclarationName(node)
- || (node.kind === 133 /* ConstructorKeyword */ && ts.isConstructorDeclaration(node.parent));
+ /** Whether a reference, `node`, is a definition of the `target` symbol */
+ function isDeclarationOfSymbol(node, target) {
+ var _a;
+ if (!target)
+ return false;
+ var source = ts.getDeclarationFromName(node) ||
+ (node.kind === 88 /* DefaultKeyword */ ? node.parent
+ : ts.isLiteralComputedPropertyDeclarationName(node) ? node.parent.parent
+ : node.kind === 134 /* ConstructorKeyword */ && ts.isConstructorDeclaration(node.parent) ? node.parent.parent
+ : undefined);
+ var commonjsSource = source && ts.isBinaryExpression(source) ? source.left : undefined;
+ return !!(source && ((_a = target.declarations) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d === source || d === commonjsSource; })));
}
/**
* True if 'decl' provides a value, as in `function f() {}`;
@@ -130823,47 +133551,47 @@ var ts;
if (!!(decl.flags & 8388608 /* Ambient */))
return true;
switch (decl.kind) {
- case 219 /* BinaryExpression */:
- case 201 /* BindingElement */:
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
+ case 220 /* BinaryExpression */:
+ case 202 /* BindingElement */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
case 88 /* DefaultKeyword */:
- case 258 /* EnumDeclaration */:
- case 294 /* EnumMember */:
- case 273 /* ExportSpecifier */:
- case 265 /* ImportClause */: // default import
- case 263 /* ImportEqualsDeclaration */:
- case 268 /* ImportSpecifier */:
- case 256 /* InterfaceDeclaration */:
- case 333 /* JSDocCallbackTag */:
- case 340 /* JSDocTypedefTag */:
- case 283 /* JsxAttribute */:
- case 259 /* ModuleDeclaration */:
- case 262 /* NamespaceExportDeclaration */:
- case 266 /* NamespaceImport */:
- case 272 /* NamespaceExport */:
- case 162 /* Parameter */:
- case 292 /* ShorthandPropertyAssignment */:
- case 257 /* TypeAliasDeclaration */:
- case 161 /* TypeParameter */:
+ case 259 /* EnumDeclaration */:
+ case 297 /* EnumMember */:
+ case 274 /* ExportSpecifier */:
+ case 266 /* ImportClause */: // default import
+ case 264 /* ImportEqualsDeclaration */:
+ case 269 /* ImportSpecifier */:
+ case 257 /* InterfaceDeclaration */:
+ case 336 /* JSDocCallbackTag */:
+ case 343 /* JSDocTypedefTag */:
+ case 284 /* JsxAttribute */:
+ case 260 /* ModuleDeclaration */:
+ case 263 /* NamespaceExportDeclaration */:
+ case 267 /* NamespaceImport */:
+ case 273 /* NamespaceExport */:
+ case 163 /* Parameter */:
+ case 295 /* ShorthandPropertyAssignment */:
+ case 258 /* TypeAliasDeclaration */:
+ case 162 /* TypeParameter */:
return true;
- case 291 /* PropertyAssignment */:
+ case 294 /* PropertyAssignment */:
// In `({ x: y } = 0);`, `x` is not a write access. (Won't call this function for `y`.)
return !ts.isArrayLiteralOrObjectLiteralDestructuringPattern(decl.parent);
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
- case 169 /* Constructor */:
- case 167 /* MethodDeclaration */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 170 /* Constructor */:
+ case 168 /* MethodDeclaration */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
return !!decl.body;
- case 252 /* VariableDeclaration */:
- case 165 /* PropertyDeclaration */:
+ case 253 /* VariableDeclaration */:
+ case 166 /* PropertyDeclaration */:
return !!decl.initializer || ts.isCatchClause(decl.parent);
- case 166 /* MethodSignature */:
- case 164 /* PropertySignature */:
- case 342 /* JSDocPropertyTag */:
- case 335 /* JSDocParameterTag */:
+ case 167 /* MethodSignature */:
+ case 165 /* PropertySignature */:
+ case 345 /* JSDocPropertyTag */:
+ case 338 /* JSDocParameterTag */:
return false;
default:
return ts.Debug.failBadSyntaxKind(decl);
@@ -130916,7 +133644,7 @@ var ts;
if (!options.implementations && ts.isStringLiteralLike(node)) {
if (ts.isModuleSpecifierLike(node)) {
var fileIncludeReasons = program.getFileIncludeReasons();
- var referencedFileName = (_b = (_a = node.getSourceFile().resolvedModules) === null || _a === void 0 ? void 0 : _a.get(node.text)) === null || _b === void 0 ? void 0 : _b.resolvedFileName;
+ var referencedFileName = (_b = (_a = node.getSourceFile().resolvedModules) === null || _a === void 0 ? void 0 : _a.get(node.text, ts.getModeForUsageLocation(node.getSourceFile(), node))) === null || _b === void 0 ? void 0 : _b.resolvedFileName;
var referencedFile = referencedFileName ? program.getSourceFile(referencedFileName) : undefined;
if (referencedFile) {
return [{ definition: { type: 4 /* String */, node: node }, references: getReferencesForNonModule(referencedFile, fileIncludeReasons, program) || ts.emptyArray }];
@@ -131015,7 +133743,7 @@ var ts;
result = references;
continue;
}
- var _loop_4 = function (entry) {
+ var _loop_5 = function (entry) {
if (!entry.definition || entry.definition.type !== 0 /* Symbol */) {
result.push(entry);
return "continue";
@@ -131047,7 +133775,7 @@ var ts;
};
for (var _b = 0, references_2 = references; _b < references_2.length; _b++) {
var entry = references_2[_b];
- _loop_4(entry);
+ _loop_5(entry);
}
}
return result;
@@ -131084,10 +133812,10 @@ var ts;
for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
var decl = _a[_i];
switch (decl.kind) {
- case 300 /* SourceFile */:
+ case 303 /* SourceFile */:
// Don't include the source file itself. (This may not be ideal behavior, but awkward to include an entire file as a reference.)
break;
- case 259 /* ModuleDeclaration */:
+ case 260 /* ModuleDeclaration */:
if (sourceFilesSet.has(decl.getSourceFile().fileName)) {
references.push(nodeEntry(decl.name));
}
@@ -131116,9 +133844,9 @@ var ts;
}
/** As in a `readonly prop: any` or `constructor(readonly prop: any)`, not a `readonly any[]`. */
function isReadonlyTypeOperator(node) {
- return node.kind === 143 /* ReadonlyKeyword */
+ return node.kind === 144 /* ReadonlyKeyword */
&& ts.isTypeOperatorNode(node.parent)
- && node.parent.operator === 143 /* ReadonlyKeyword */;
+ && node.parent.operator === 144 /* ReadonlyKeyword */;
}
/** getReferencedSymbols for special node kinds. */
function getReferencedSymbolsSpecial(node, sourceFiles, cancellationToken) {
@@ -131129,12 +133857,12 @@ var ts;
}
// A modifier readonly (like on a property declaration) is not special;
// a readonly type keyword (like `readonly string[]`) is.
- if (node.kind === 143 /* ReadonlyKeyword */ && !isReadonlyTypeOperator(node)) {
+ if (node.kind === 144 /* ReadonlyKeyword */ && !isReadonlyTypeOperator(node)) {
return undefined;
}
// Likewise, when we *are* looking for a special keyword, make sure we
// *don’t* include readonly member modifiers.
- return getAllReferencesForKeyword(sourceFiles, node.kind, cancellationToken, node.kind === 143 /* ReadonlyKeyword */ ? isReadonlyTypeOperator : undefined);
+ return getAllReferencesForKeyword(sourceFiles, node.kind, cancellationToken, node.kind === 144 /* ReadonlyKeyword */ ? isReadonlyTypeOperator : undefined);
}
if (ts.isStaticModifier(node) && ts.isClassStaticBlockDeclaration(node.parent)) {
return [{ definition: { type: 2 /* Keyword */, node: node }, references: [nodeEntry(node)] }];
@@ -131198,8 +133926,8 @@ var ts;
}
function getSpecialSearchKind(node) {
switch (node.kind) {
- case 169 /* Constructor */:
- case 133 /* ConstructorKeyword */:
+ case 170 /* Constructor */:
+ case 134 /* ConstructorKeyword */:
return 1 /* Constructor */;
case 79 /* Identifier */:
if (ts.isClassLike(node.parent)) {
@@ -131418,7 +134146,7 @@ var ts;
getReferencesInSourceFile(exportingFile, state.createSearch(declaration, symbol, 0 /* Import */), state, state.includesSourceFile(exportingFile));
}
}
- /** Search for all occurences of an identifier in a source file (and filter out the ones that match). */
+ /** Search for all occurrences of an identifier in a source file (and filter out the ones that match). */
function searchForName(sourceFile, search, state) {
if (ts.getNameTable(sourceFile).get(search.escapedText) !== undefined) {
getReferencesInSourceFile(sourceFile, search, state);
@@ -131441,7 +134169,7 @@ var ts;
// If this is the symbol of a named function expression or named class expression,
// then named references are limited to its own scope.
var declarations = symbol.declarations, flags = symbol.flags, parent = symbol.parent, valueDeclaration = symbol.valueDeclaration;
- if (valueDeclaration && (valueDeclaration.kind === 211 /* FunctionExpression */ || valueDeclaration.kind === 224 /* ClassExpression */)) {
+ if (valueDeclaration && (valueDeclaration.kind === 212 /* FunctionExpression */ || valueDeclaration.kind === 225 /* ClassExpression */)) {
return valueDeclaration;
}
if (!declarations) {
@@ -131451,7 +134179,7 @@ var ts;
if (flags & (4 /* Property */ | 8192 /* Method */)) {
var privateDeclaration = ts.find(declarations, function (d) { return ts.hasEffectiveModifier(d, 8 /* Private */) || ts.isPrivateIdentifierClassElementDeclaration(d); });
if (privateDeclaration) {
- return ts.getAncestor(privateDeclaration, 255 /* ClassDeclaration */);
+ return ts.getAncestor(privateDeclaration, 256 /* ClassDeclaration */);
}
// Else this is a public property and could be accessed from anywhere.
return undefined;
@@ -131480,7 +134208,7 @@ var ts;
// Different declarations have different containers, bail out
return undefined;
}
- if (!container || container.kind === 300 /* SourceFile */ && !ts.isExternalOrCommonJsModule(container)) {
+ if (!container || container.kind === 303 /* SourceFile */ && !ts.isExternalOrCommonJsModule(container)) {
// This is a global variable and not an external module, any declaration defined
// within this scope is visible outside the file
return undefined;
@@ -131701,9 +134429,15 @@ var ts;
ts.Debug.assertNever(state.specialSearchKind);
}
// Use the parent symbol if the location is commonjs require syntax on javascript files only.
- referenceSymbol = ts.isInJSFile(referenceLocation) && referenceLocation.parent.kind === 201 /* BindingElement */ && ts.isRequireVariableDeclaration(referenceLocation.parent)
- ? referenceLocation.parent.symbol
- : referenceSymbol;
+ if (ts.isInJSFile(referenceLocation)
+ && referenceLocation.parent.kind === 202 /* BindingElement */
+ && ts.isRequireVariableDeclaration(referenceLocation.parent)) {
+ referenceSymbol = referenceLocation.parent.symbol;
+ // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In
+ // this case, just skip it, since the bound identifiers are not an alias of the import.
+ if (!referenceSymbol)
+ return;
+ }
getImportOrExportReferences(referenceLocation, referenceSymbol, search, state);
}
function getReferencesAtExportSpecifier(referenceLocation, referenceSymbol, exportSpecifier, search, state, addReferencesHere, alwaysGetReferences) {
@@ -131865,15 +134599,15 @@ var ts;
if (constructorSymbol && constructorSymbol.declarations) {
for (var _i = 0, _a = constructorSymbol.declarations; _i < _a.length; _i++) {
var decl = _a[_i];
- var ctrKeyword = ts.findChildOfKind(decl, 133 /* ConstructorKeyword */, sourceFile);
- ts.Debug.assert(decl.kind === 169 /* Constructor */ && !!ctrKeyword);
+ var ctrKeyword = ts.findChildOfKind(decl, 134 /* ConstructorKeyword */, sourceFile);
+ ts.Debug.assert(decl.kind === 170 /* Constructor */ && !!ctrKeyword);
addNode(ctrKeyword);
}
}
if (classSymbol.exports) {
classSymbol.exports.forEach(function (member) {
var decl = member.valueDeclaration;
- if (decl && decl.kind === 167 /* MethodDeclaration */) {
+ if (decl && decl.kind === 168 /* MethodDeclaration */) {
var body = decl.body;
if (body) {
forEachDescendantOfKind(body, 108 /* ThisKeyword */, function (thisKeyword) {
@@ -131897,7 +134631,7 @@ var ts;
}
for (var _i = 0, _a = constructor.declarations; _i < _a.length; _i++) {
var decl = _a[_i];
- ts.Debug.assert(decl.kind === 169 /* Constructor */);
+ ts.Debug.assert(decl.kind === 170 /* Constructor */);
var body = decl.body;
if (body) {
forEachDescendantOfKind(body, 106 /* SuperKeyword */, function (node) {
@@ -131927,7 +134661,7 @@ var ts;
if (refNode.kind !== 79 /* Identifier */) {
return;
}
- if (refNode.parent.kind === 292 /* ShorthandPropertyAssignment */) {
+ if (refNode.parent.kind === 295 /* ShorthandPropertyAssignment */) {
// Go ahead and dereference the shorthand assignment by going to its definition
getReferenceEntriesForShorthandPropertyAssignment(refNode, state.checker, addReference);
}
@@ -131947,7 +134681,7 @@ var ts;
}
else if (ts.isFunctionLike(typeHavingNode) && typeHavingNode.body) {
var body = typeHavingNode.body;
- if (body.kind === 233 /* Block */) {
+ if (body.kind === 234 /* Block */) {
ts.forEachReturnStatement(body, function (returnStatement) {
if (returnStatement.expression)
addIfImplementation(returnStatement.expression);
@@ -131975,13 +134709,13 @@ var ts;
*/
function isImplementationExpression(node) {
switch (node.kind) {
- case 210 /* ParenthesizedExpression */:
+ case 211 /* ParenthesizedExpression */:
return isImplementationExpression(node.expression);
- case 212 /* ArrowFunction */:
- case 211 /* FunctionExpression */:
- case 203 /* ObjectLiteralExpression */:
- case 224 /* ClassExpression */:
- case 202 /* ArrayLiteralExpression */:
+ case 213 /* ArrowFunction */:
+ case 212 /* FunctionExpression */:
+ case 204 /* ObjectLiteralExpression */:
+ case 225 /* ClassExpression */:
+ case 203 /* ArrayLiteralExpression */:
return true;
default:
return false;
@@ -132034,13 +134768,13 @@ var ts;
// Whether 'super' occurs in a static context within a class.
var staticFlag = 32 /* Static */;
switch (searchSpaceNode.kind) {
- case 165 /* PropertyDeclaration */:
- case 164 /* PropertySignature */:
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
- case 169 /* Constructor */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
+ case 166 /* PropertyDeclaration */:
+ case 165 /* PropertySignature */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
+ case 170 /* Constructor */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
staticFlag &= ts.getSyntacticModifierFlags(searchSpaceNode);
searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning class
break;
@@ -132061,43 +134795,43 @@ var ts;
return [{ definition: { type: 0 /* Symbol */, symbol: searchSpaceNode.symbol }, references: references }];
}
function isParameterName(node) {
- return node.kind === 79 /* Identifier */ && node.parent.kind === 162 /* Parameter */ && node.parent.name === node;
+ return node.kind === 79 /* Identifier */ && node.parent.kind === 163 /* Parameter */ && node.parent.name === node;
}
function getReferencesForThisKeyword(thisOrSuperKeyword, sourceFiles, cancellationToken) {
var searchSpaceNode = ts.getThisContainer(thisOrSuperKeyword, /* includeArrowFunctions */ false);
// Whether 'this' occurs in a static context within a class.
var staticFlag = 32 /* Static */;
switch (searchSpaceNode.kind) {
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
if (ts.isObjectLiteralMethod(searchSpaceNode)) {
staticFlag &= ts.getSyntacticModifierFlags(searchSpaceNode);
searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning object literals
break;
}
// falls through
- case 165 /* PropertyDeclaration */:
- case 164 /* PropertySignature */:
- case 169 /* Constructor */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
+ case 166 /* PropertyDeclaration */:
+ case 165 /* PropertySignature */:
+ case 170 /* Constructor */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
staticFlag &= ts.getSyntacticModifierFlags(searchSpaceNode);
searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning class
break;
- case 300 /* SourceFile */:
+ case 303 /* SourceFile */:
if (ts.isExternalModule(searchSpaceNode) || isParameterName(thisOrSuperKeyword)) {
return undefined;
}
// falls through
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
break;
// Computed properties in classes are not handled here because references to this are illegal,
// so there is no point finding references to them.
default:
return undefined;
}
- var references = ts.flatMap(searchSpaceNode.kind === 300 /* SourceFile */ ? sourceFiles : [searchSpaceNode.getSourceFile()], function (sourceFile) {
+ var references = ts.flatMap(searchSpaceNode.kind === 303 /* SourceFile */ ? sourceFiles : [searchSpaceNode.getSourceFile()], function (sourceFile) {
cancellationToken.throwIfCancellationRequested();
return getPossibleSymbolReferenceNodes(sourceFile, "this", ts.isSourceFile(searchSpaceNode) ? sourceFile : searchSpaceNode).filter(function (node) {
if (!ts.isThis(node)) {
@@ -132105,20 +134839,20 @@ var ts;
}
var container = ts.getThisContainer(node, /* includeArrowFunctions */ false);
switch (searchSpaceNode.kind) {
- case 211 /* FunctionExpression */:
- case 254 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 255 /* FunctionDeclaration */:
return searchSpaceNode.symbol === container.symbol;
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
return ts.isObjectLiteralMethod(searchSpaceNode) && searchSpaceNode.symbol === container.symbol;
- case 224 /* ClassExpression */:
- case 255 /* ClassDeclaration */:
- case 203 /* ObjectLiteralExpression */:
+ case 225 /* ClassExpression */:
+ case 256 /* ClassDeclaration */:
+ case 204 /* ObjectLiteralExpression */:
// Make sure the container belongs to the same class/object literals
// and has the appropriate static modifier from the original container.
return container.parent && searchSpaceNode.symbol === container.parent.symbol && ts.isStatic(container) === !!staticFlag;
- case 300 /* SourceFile */:
- return container.kind === 300 /* SourceFile */ && !ts.isExternalModule(container) && !isParameterName(node);
+ case 303 /* SourceFile */:
+ return container.kind === 303 /* SourceFile */ && !ts.isExternalModule(container) && !isParameterName(node);
}
});
}).map(function (n) { return nodeEntry(n); });
@@ -132129,13 +134863,13 @@ var ts;
}];
}
function getReferencesForStringLiteral(node, sourceFiles, checker, cancellationToken) {
- var type = ts.getContextualTypeOrAncestorTypeNodeType(node, checker);
+ var type = ts.getContextualTypeFromParentOrAncestorTypeNode(node, checker);
var references = ts.flatMap(sourceFiles, function (sourceFile) {
cancellationToken.throwIfCancellationRequested();
return ts.mapDefined(getPossibleSymbolReferenceNodes(sourceFile, node.text), function (ref) {
if (ts.isStringLiteralLike(ref) && ref.text === node.text) {
if (type) {
- var refType = ts.getContextualTypeOrAncestorTypeNodeType(ref, checker);
+ var refType = ts.getContextualTypeFromParentOrAncestorTypeNode(ref, checker);
if (type !== checker.getStringType() && type === refType) {
return nodeEntry(ref, 2 /* StringLiteral */);
}
@@ -132228,7 +134962,7 @@ 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]);
}
- var exportSpecifier = ts.getDeclarationOfKind(symbol, 273 /* ExportSpecifier */);
+ var exportSpecifier = ts.getDeclarationOfKind(symbol, 274 /* ExportSpecifier */);
if (!isForRenamePopulateSearchSymbolSet || exportSpecifier && !exportSpecifier.propertyName) {
var localSymbol = exportSpecifier && checker.getExportSpecifierLocalTargetSymbol(exportSpecifier);
if (localSymbol) {
@@ -132273,7 +135007,7 @@ var ts;
});
}
function getPropertySymbolOfObjectBindingPatternWithoutPropertyName(symbol, checker) {
- var bindingElement = ts.getDeclarationOfKind(symbol, 201 /* BindingElement */);
+ var bindingElement = ts.getDeclarationOfKind(symbol, 202 /* BindingElement */);
if (bindingElement && ts.isObjectBindingElementWithoutPropertyName(bindingElement)) {
return ts.getPropertySymbolFromBindingElement(checker, bindingElement);
}
@@ -132306,9 +135040,8 @@ var ts;
}
}
function isStaticSymbol(symbol) {
- if (!symbol.valueDeclaration) {
+ if (!symbol.valueDeclaration)
return false;
- }
var modifierFlags = ts.getEffectiveModifierFlags(symbol.valueDeclaration);
return !!(modifierFlags & 32 /* Static */);
}
@@ -132537,16 +135270,16 @@ var ts;
return;
}
switch (node.kind) {
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
- case 167 /* MethodDeclaration */:
- if (node.parent.kind === 203 /* ObjectLiteralExpression */) {
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
+ case 168 /* MethodDeclaration */:
+ if (node.parent.kind === 204 /* ObjectLiteralExpression */) {
return (_a = ts.getAssignedName(node.parent)) === null || _a === void 0 ? void 0 : _a.getText();
}
return (_b = ts.getNameOfDeclaration(node.parent)) === null || _b === void 0 ? void 0 : _b.getText();
- case 254 /* FunctionDeclaration */:
- case 255 /* ClassDeclaration */:
- case 259 /* ModuleDeclaration */:
+ case 255 /* FunctionDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 260 /* ModuleDeclaration */:
if (ts.isModuleBlock(node.parent) && ts.isIdentifier(node.parent.parent.name)) {
return node.parent.parent.name.getText();
}
@@ -132761,58 +135494,58 @@ var ts;
}
switch (node.kind) {
case 79 /* Identifier */:
- case 263 /* ImportEqualsDeclaration */:
- case 264 /* ImportDeclaration */:
- case 270 /* ExportDeclaration */:
- case 256 /* InterfaceDeclaration */:
- case 257 /* TypeAliasDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
+ case 265 /* ImportDeclaration */:
+ case 271 /* ExportDeclaration */:
+ case 257 /* InterfaceDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
// do not descend into nodes that cannot contain callable nodes
return;
- case 168 /* ClassStaticBlockDeclaration */:
+ case 169 /* ClassStaticBlockDeclaration */:
recordCallSite(node);
return;
- case 209 /* TypeAssertionExpression */:
- case 227 /* AsExpression */:
+ case 210 /* TypeAssertionExpression */:
+ case 228 /* AsExpression */:
// do not descend into the type side of an assertion
collect(node.expression);
return;
- case 252 /* VariableDeclaration */:
- case 162 /* Parameter */:
+ case 253 /* VariableDeclaration */:
+ case 163 /* Parameter */:
// do not descend into the type of a variable or parameter declaration
collect(node.name);
collect(node.initializer);
return;
- case 206 /* CallExpression */:
+ case 207 /* CallExpression */:
// do not descend into the type arguments of a call expression
recordCallSite(node);
collect(node.expression);
ts.forEach(node.arguments, collect);
return;
- case 207 /* NewExpression */:
+ case 208 /* NewExpression */:
// do not descend into the type arguments of a new expression
recordCallSite(node);
collect(node.expression);
ts.forEach(node.arguments, collect);
return;
- case 208 /* TaggedTemplateExpression */:
+ case 209 /* TaggedTemplateExpression */:
// do not descend into the type arguments of a tagged template expression
recordCallSite(node);
collect(node.tag);
collect(node.template);
return;
- case 278 /* JsxOpeningElement */:
- case 277 /* JsxSelfClosingElement */:
+ case 279 /* JsxOpeningElement */:
+ case 278 /* JsxSelfClosingElement */:
// do not descend into the type arguments of a JsxOpeningLikeElement
recordCallSite(node);
collect(node.tagName);
collect(node.attributes);
return;
- case 163 /* Decorator */:
+ case 164 /* Decorator */:
recordCallSite(node);
collect(node.expression);
return;
- case 204 /* PropertyAccessExpression */:
- case 205 /* ElementAccessExpression */:
+ case 205 /* PropertyAccessExpression */:
+ case 206 /* ElementAccessExpression */:
recordCallSite(node);
ts.forEachChild(node, collect);
break;
@@ -132868,25 +135601,25 @@ var ts;
var callSites = [];
var collect = createCallSiteCollector(program, callSites);
switch (node.kind) {
- case 300 /* SourceFile */:
+ case 303 /* SourceFile */:
collectCallSitesOfSourceFile(node, collect);
break;
- case 259 /* ModuleDeclaration */:
+ case 260 /* ModuleDeclaration */:
collectCallSitesOfModuleDeclaration(node, collect);
break;
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
- case 167 /* MethodDeclaration */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
+ case 168 /* MethodDeclaration */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
collectCallSitesOfFunctionLikeDeclaration(program.getTypeChecker(), node, collect);
break;
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
collectCallSitesOfClassLikeDeclaration(node, collect);
break;
- case 168 /* ClassStaticBlockDeclaration */:
+ case 169 /* ClassStaticBlockDeclaration */:
collectCallSitesOfClassStaticBlockDeclaration(node, collect);
break;
default:
@@ -133020,7 +135753,7 @@ var ts;
}
function updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName) {
var allFiles = program.getSourceFiles();
- var _loop_5 = function (sourceFile) {
+ var _loop_6 = function (sourceFile) {
var newFromOld = oldToNew(sourceFile.fileName);
var newImportFromPath = newFromOld !== null && newFromOld !== void 0 ? newFromOld : sourceFile.fileName;
var newImportFromDirectory = ts.getDirectoryPath(newImportFromPath);
@@ -133052,7 +135785,7 @@ var ts;
};
for (var _i = 0, allFiles_1 = allFiles; _i < allFiles_1.length; _i++) {
var sourceFile = allFiles_1[_i];
- _loop_5(sourceFile);
+ _loop_6(sourceFile);
}
}
function combineNormal(pathA, pathB) {
@@ -133069,9 +135802,10 @@ var ts;
return newFileName === undefined ? { newFileName: oldFileName, updated: false } : { newFileName: newFileName, updated: true };
}
else {
+ var mode = ts.getModeForUsageLocation(importingSourceFile, importLiteral);
var resolved = host.resolveModuleNames
- ? host.getResolvedModuleWithFailedLookupLocationsFromCache && host.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName)
- : program.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName);
+ ? host.getResolvedModuleWithFailedLookupLocationsFromCache && host.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName, mode)
+ : program.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName, mode);
return getSourceFileToImportFromResolved(importLiteral, resolved, oldToNew, program.getSourceFiles());
}
}
@@ -133154,7 +135888,7 @@ var ts;
}
var parent = node.parent;
var typeChecker = program.getTypeChecker();
- if (node.kind === 157 /* OverrideKeyword */ || (ts.isJSDocOverrideTag(node) && ts.rangeContainsPosition(node.tagName, position))) {
+ if (node.kind === 158 /* OverrideKeyword */ || (ts.isJSDocOverrideTag(node) && ts.rangeContainsPosition(node.tagName, position))) {
return getDefinitionFromOverriddenMember(typeChecker, node) || ts.emptyArray;
}
// Labels
@@ -133200,7 +135934,7 @@ var ts;
// go to the declaration of the property name (in this case stay at the same position). However, if go-to-definition
// is performed at the location of property access, we would like to go to definition of the property in the short-hand
// assignment. This case and others are handled by the following code.
- if (node.parent.kind === 292 /* ShorthandPropertyAssignment */) {
+ if (node.parent.kind === 295 /* ShorthandPropertyAssignment */) {
var shorthandSymbol_1 = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration);
var definitions = (shorthandSymbol_1 === null || shorthandSymbol_1 === void 0 ? void 0 : shorthandSymbol_1.declarations) ? shorthandSymbol_1.declarations.map(function (decl) { return createDefinitionInfo(decl, typeChecker, shorthandSymbol_1, node); }) : ts.emptyArray;
return ts.concatenate(definitions, getDefinitionFromObjectLiteralElement(typeChecker, node) || ts.emptyArray);
@@ -133296,10 +136030,10 @@ var ts;
var file = program.getLibFileFromReference(libReferenceDirective);
return file && { reference: libReferenceDirective, fileName: file.fileName, file: file, unverified: false };
}
- if ((_a = sourceFile.resolvedModules) === null || _a === void 0 ? void 0 : _a.size) {
+ if ((_a = sourceFile.resolvedModules) === null || _a === void 0 ? void 0 : _a.size()) {
var node = ts.getTokenAtPosition(sourceFile, position);
- if (ts.isModuleSpecifierLike(node) && ts.isExternalModuleNameRelative(node.text) && sourceFile.resolvedModules.has(node.text)) {
- var verifiedFileName = (_b = sourceFile.resolvedModules.get(node.text)) === null || _b === void 0 ? void 0 : _b.resolvedFileName;
+ if (ts.isModuleSpecifierLike(node) && ts.isExternalModuleNameRelative(node.text) && sourceFile.resolvedModules.has(node.text, ts.getModeForUsageLocation(sourceFile, node))) {
+ var verifiedFileName = (_b = sourceFile.resolvedModules.get(node.text, ts.getModeForUsageLocation(sourceFile, node))) === null || _b === void 0 ? void 0 : _b.resolvedFileName;
var fileName = verifiedFileName || ts.resolvePath(ts.getDirectoryPath(sourceFile.fileName), node.text);
return {
file: program.getSourceFile(fileName),
@@ -133397,13 +136131,13 @@ var ts;
return true;
}
switch (declaration.kind) {
- case 265 /* ImportClause */:
- case 263 /* ImportEqualsDeclaration */:
+ case 266 /* ImportClause */:
+ case 264 /* ImportEqualsDeclaration */:
return true;
- case 268 /* ImportSpecifier */:
- return declaration.parent.kind === 267 /* NamedImports */;
- case 201 /* BindingElement */:
- case 252 /* VariableDeclaration */:
+ case 269 /* ImportSpecifier */:
+ return declaration.parent.kind === 268 /* NamedImports */;
+ case 202 /* BindingElement */:
+ case 253 /* VariableDeclaration */:
return ts.isInJSFile(declaration) && ts.isRequireVariableDeclaration(declaration);
default:
return false;
@@ -133419,7 +136153,7 @@ var ts;
function getConstructSignatureDefinition() {
// Applicable only if we are in a new expression, or we are on a constructor declaration
// and in either case the symbol has a construct signature definition, i.e. class
- if (symbol.flags & 32 /* Class */ && !(symbol.flags & (16 /* Function */ | 3 /* Variable */)) && (ts.isNewExpressionTarget(node) || node.kind === 133 /* ConstructorKeyword */)) {
+ if (symbol.flags & 32 /* Class */ && !(symbol.flags & (16 /* Function */ | 3 /* Variable */)) && (ts.isNewExpressionTarget(node) || node.kind === 134 /* ConstructorKeyword */)) {
var cls = ts.find(filteredDeclarations, ts.isClassLike) || ts.Debug.fail("Expected declaration to have at least one class-like declaration");
return getSignatureDefinition(cls.members, /*selectConstructors*/ true);
}
@@ -133470,22 +136204,22 @@ var ts;
return isDefinitionVisible(checker, declaration.parent);
// Handle some exceptions here like arrow function, members of class and object literal expression which are technically not visible but we want the definition to be determined by its parent
switch (declaration.kind) {
- case 165 /* PropertyDeclaration */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
- case 167 /* MethodDeclaration */:
+ case 166 /* PropertyDeclaration */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
+ case 168 /* MethodDeclaration */:
// Private/protected properties/methods are not visible
if (ts.hasEffectiveModifier(declaration, 8 /* Private */))
return false;
// Public properties/methods are visible if its parents are visible, so:
// falls through
- case 169 /* Constructor */:
- case 291 /* PropertyAssignment */:
- case 292 /* ShorthandPropertyAssignment */:
- case 203 /* ObjectLiteralExpression */:
- case 224 /* ClassExpression */:
- case 212 /* ArrowFunction */:
- case 211 /* FunctionExpression */:
+ case 170 /* Constructor */:
+ case 294 /* PropertyAssignment */:
+ case 295 /* ShorthandPropertyAssignment */:
+ case 204 /* ObjectLiteralExpression */:
+ case 225 /* ClassExpression */:
+ case 213 /* ArrowFunction */:
+ case 212 /* FunctionExpression */:
return isDefinitionVisible(checker, declaration.parent);
default:
return false;
@@ -133523,9 +136257,9 @@ var ts;
}
function isConstructorLike(node) {
switch (node.kind) {
- case 169 /* Constructor */:
- case 178 /* ConstructorType */:
- case 173 /* ConstructSignature */:
+ case 170 /* Constructor */:
+ case 179 /* ConstructorType */:
+ case 174 /* ConstructSignature */:
return true;
default:
return false;
@@ -133637,10 +136371,10 @@ var ts;
// - @param or @return indicate that the author thinks of it as a 'local' @typedef that's part of the function documentation
if (jsdoc.comment === undefined
|| ts.isJSDoc(jsdoc)
- && declaration.kind !== 340 /* JSDocTypedefTag */ && declaration.kind !== 333 /* JSDocCallbackTag */
+ && declaration.kind !== 343 /* JSDocTypedefTag */ && declaration.kind !== 336 /* JSDocCallbackTag */
&& jsdoc.tags
- && jsdoc.tags.some(function (t) { return t.kind === 340 /* JSDocTypedefTag */ || t.kind === 333 /* JSDocCallbackTag */; })
- && !jsdoc.tags.some(function (t) { return t.kind === 335 /* JSDocParameterTag */ || t.kind === 336 /* JSDocReturnTag */; })) {
+ && jsdoc.tags.some(function (t) { return t.kind === 343 /* JSDocTypedefTag */ || t.kind === 336 /* JSDocCallbackTag */; })
+ && !jsdoc.tags.some(function (t) { return t.kind === 338 /* JSDocParameterTag */ || t.kind === 339 /* JSDocReturnTag */; })) {
continue;
}
var newparts = getDisplayPartsFromComment(jsdoc.comment, checker);
@@ -133657,11 +136391,11 @@ var ts;
}
function getCommentHavingNodes(declaration) {
switch (declaration.kind) {
- case 335 /* JSDocParameterTag */:
- case 342 /* JSDocPropertyTag */:
+ case 338 /* JSDocParameterTag */:
+ case 345 /* JSDocPropertyTag */:
return [declaration];
- case 333 /* JSDocCallbackTag */:
- case 340 /* JSDocTypedefTag */:
+ case 336 /* JSDocCallbackTag */:
+ case 343 /* JSDocTypedefTag */:
return [declaration, declaration.parent];
default:
return ts.getJSDocCommentsAndTags(declaration);
@@ -133675,8 +136409,8 @@ var ts;
// skip comments containing @typedefs since they're not associated with particular declarations
// Exceptions:
// - @param or @return indicate that the author thinks of it as a 'local' @typedef that's part of the function documentation
- if (tags.some(function (t) { return t.kind === 340 /* JSDocTypedefTag */ || t.kind === 333 /* JSDocCallbackTag */; })
- && !tags.some(function (t) { return t.kind === 335 /* JSDocParameterTag */ || t.kind === 336 /* JSDocReturnTag */; })) {
+ if (tags.some(function (t) { return t.kind === 343 /* JSDocTypedefTag */ || t.kind === 336 /* JSDocCallbackTag */; })
+ && !tags.some(function (t) { return t.kind === 338 /* JSDocParameterTag */ || t.kind === 339 /* JSDocReturnTag */; })) {
return;
}
for (var _i = 0, tags_1 = tags; _i < tags_1.length; _i++) {
@@ -133691,25 +136425,25 @@ var ts;
if (typeof comment === "string") {
return [ts.textPart(comment)];
}
- return ts.flatMap(comment, function (node) { return node.kind === 316 /* JSDocText */ ? [ts.textPart(node.text)] : ts.buildLinkParts(node, checker); });
+ return ts.flatMap(comment, function (node) { return node.kind === 319 /* JSDocText */ ? [ts.textPart(node.text)] : ts.buildLinkParts(node, checker); });
}
function getCommentDisplayParts(tag, checker) {
var comment = tag.comment, kind = tag.kind;
var namePart = getTagNameDisplayPart(kind);
switch (kind) {
- case 324 /* JSDocImplementsTag */:
+ case 327 /* JSDocImplementsTag */:
return withNode(tag.class);
- case 323 /* JSDocAugmentsTag */:
+ case 326 /* JSDocAugmentsTag */:
return withNode(tag.class);
- case 339 /* JSDocTemplateTag */:
+ case 342 /* JSDocTemplateTag */:
return addComment(tag.typeParameters.map(function (tp) { return tp.getText(); }).join(", "));
- case 338 /* JSDocTypeTag */:
+ case 341 /* JSDocTypeTag */:
return withNode(tag.typeExpression);
- case 340 /* JSDocTypedefTag */:
- case 333 /* JSDocCallbackTag */:
- case 342 /* JSDocPropertyTag */:
- case 335 /* JSDocParameterTag */:
- case 341 /* JSDocSeeTag */:
+ case 343 /* JSDocTypedefTag */:
+ case 336 /* JSDocCallbackTag */:
+ case 345 /* JSDocPropertyTag */:
+ case 338 /* JSDocParameterTag */:
+ case 344 /* JSDocSeeTag */:
var name = tag.name;
return name ? withNode(name)
: comment === undefined ? undefined
@@ -133736,14 +136470,14 @@ var ts;
}
function getTagNameDisplayPart(kind) {
switch (kind) {
- case 335 /* JSDocParameterTag */:
+ case 338 /* JSDocParameterTag */:
return ts.parameterNamePart;
- case 342 /* JSDocPropertyTag */:
+ case 345 /* JSDocPropertyTag */:
return ts.propertyNamePart;
- case 339 /* JSDocTemplateTag */:
+ case 342 /* JSDocTemplateTag */:
return ts.typeParameterNamePart;
- case 340 /* JSDocTypedefTag */:
- case 333 /* JSDocCallbackTag */:
+ case 343 /* JSDocTypedefTag */:
+ case 336 /* JSDocCallbackTag */:
return ts.typeAliasNamePart;
default:
return ts.textPart;
@@ -133907,24 +136641,24 @@ var ts;
}
function getCommentOwnerInfoWorker(commentOwner, options) {
switch (commentOwner.kind) {
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
- case 167 /* MethodDeclaration */:
- case 169 /* Constructor */:
- case 166 /* MethodSignature */:
- case 212 /* ArrowFunction */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 168 /* MethodDeclaration */:
+ case 170 /* Constructor */:
+ case 167 /* MethodSignature */:
+ case 213 /* ArrowFunction */:
var host = commentOwner;
return { commentOwner: commentOwner, parameters: host.parameters, hasReturn: hasReturn(host, options) };
- case 291 /* PropertyAssignment */:
+ case 294 /* PropertyAssignment */:
return getCommentOwnerInfoWorker(commentOwner.initializer, options);
- case 255 /* ClassDeclaration */:
- case 256 /* InterfaceDeclaration */:
- case 164 /* PropertySignature */:
- case 258 /* EnumDeclaration */:
- case 294 /* EnumMember */:
- case 257 /* TypeAliasDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 257 /* InterfaceDeclaration */:
+ case 165 /* PropertySignature */:
+ case 259 /* EnumDeclaration */:
+ case 297 /* EnumMember */:
+ case 258 /* TypeAliasDeclaration */:
return { commentOwner: commentOwner };
- case 235 /* VariableStatement */: {
+ case 236 /* VariableStatement */: {
var varStatement = commentOwner;
var varDeclarations = varStatement.declarationList.declarations;
var host_1 = varDeclarations.length === 1 && varDeclarations[0].initializer
@@ -133934,16 +136668,16 @@ var ts;
? { commentOwner: commentOwner, parameters: host_1.parameters, hasReturn: hasReturn(host_1, options) }
: { commentOwner: commentOwner };
}
- case 300 /* SourceFile */:
+ case 303 /* SourceFile */:
return "quit";
- case 259 /* ModuleDeclaration */:
+ case 260 /* ModuleDeclaration */:
// If in walking up the tree, we hit a a nested namespace declaration,
// then we must be somewhere within a dotted namespace name; however we don't
// want to give back a JSDoc template for the 'b' or 'c' in 'namespace a.b.c { }'.
- return commentOwner.parent.kind === 259 /* ModuleDeclaration */ ? undefined : { commentOwner: commentOwner };
- case 236 /* ExpressionStatement */:
+ return commentOwner.parent.kind === 260 /* ModuleDeclaration */ ? undefined : { commentOwner: commentOwner };
+ case 237 /* ExpressionStatement */:
return getCommentOwnerInfoWorker(commentOwner.expression, options);
- case 219 /* BinaryExpression */: {
+ case 220 /* BinaryExpression */: {
var be = commentOwner;
if (ts.getAssignmentDeclarationKind(be) === 0 /* None */) {
return "quit";
@@ -133952,7 +136686,7 @@ var ts;
? { commentOwner: commentOwner, parameters: be.right.parameters, hasReturn: hasReturn(be.right, options) }
: { commentOwner: commentOwner };
}
- case 165 /* PropertyDeclaration */:
+ case 166 /* PropertyDeclaration */:
var init = commentOwner.initializer;
if (init && (ts.isFunctionExpression(init) || ts.isArrowFunction(init))) {
return { commentOwner: commentOwner, parameters: init.parameters, hasReturn: hasReturn(init, options) };
@@ -133965,14 +136699,14 @@ var ts;
|| ts.isFunctionLikeDeclaration(node) && node.body && ts.isBlock(node.body) && !!ts.forEachReturnStatement(node.body, function (n) { return n; }));
}
function getRightHandSideOfAssignment(rightHandSide) {
- while (rightHandSide.kind === 210 /* ParenthesizedExpression */) {
+ while (rightHandSide.kind === 211 /* ParenthesizedExpression */) {
rightHandSide = rightHandSide.expression;
}
switch (rightHandSide.kind) {
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
return rightHandSide;
- case 224 /* ClassExpression */:
+ case 225 /* ClassExpression */:
return ts.find(rightHandSide.members, ts.isConstructorDeclaration);
}
}
@@ -133988,7 +136722,7 @@ var ts;
if (!patternMatcher)
return ts.emptyArray;
var rawItems = [];
- var _loop_6 = function (sourceFile) {
+ var _loop_7 = function (sourceFile) {
cancellationToken.throwIfCancellationRequested();
if (excludeDtsFiles && sourceFile.isDeclarationFile) {
return "continue";
@@ -134000,7 +136734,7 @@ var ts;
// Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
for (var _i = 0, sourceFiles_4 = sourceFiles; _i < sourceFiles_4.length; _i++) {
var sourceFile = sourceFiles_4[_i];
- _loop_6(sourceFile);
+ _loop_7(sourceFile);
}
rawItems.sort(compareNavigateToItems);
return (maxResultCount === undefined ? rawItems : rawItems.slice(0, maxResultCount)).map(createNavigateToItem);
@@ -134031,9 +136765,9 @@ var ts;
}
function shouldKeepItem(declaration, checker) {
switch (declaration.kind) {
- case 265 /* ImportClause */:
- case 268 /* ImportSpecifier */:
- case 263 /* ImportEqualsDeclaration */:
+ case 266 /* ImportClause */:
+ case 269 /* ImportSpecifier */:
+ case 264 /* ImportEqualsDeclaration */:
var importer = checker.getSymbolAtLocation(declaration.name); // TODO: GH#18217
var imported = checker.getAliasedSymbol(importer);
return importer.escapedName !== imported.escapedName;
@@ -134043,7 +136777,7 @@ var ts;
}
function tryAddSingleDeclarationName(declaration, containers) {
var name = ts.getNameOfDeclaration(declaration);
- return !!name && (pushLiteral(name, containers) || name.kind === 160 /* ComputedPropertyName */ && tryAddComputedPropertyName(name.expression, containers));
+ return !!name && (pushLiteral(name, containers) || name.kind === 161 /* ComputedPropertyName */ && tryAddComputedPropertyName(name.expression, containers));
}
// Only added the names of computed properties if they're simple dotted expressions, like:
//
@@ -134060,7 +136794,7 @@ var ts;
// First, if we started with a computed property name, then add all but the last
// portion into the container array.
var name = ts.getNameOfDeclaration(declaration);
- if (name && name.kind === 160 /* ComputedPropertyName */ && !tryAddComputedPropertyName(name.expression, containers)) {
+ if (name && name.kind === 161 /* ComputedPropertyName */ && !tryAddComputedPropertyName(name.expression, containers)) {
return ts.emptyArray;
}
// Don't include the last portion.
@@ -134277,7 +137011,7 @@ var ts;
*/
function hasNavigationBarName(node) {
return !ts.hasDynamicName(node) ||
- (node.kind !== 219 /* BinaryExpression */ &&
+ (node.kind !== 220 /* BinaryExpression */ &&
ts.isPropertyAccessExpression(node.name.expression) &&
ts.isIdentifier(node.name.expression.expression) &&
ts.idText(node.name.expression.expression) === "Symbol");
@@ -134290,7 +137024,7 @@ var ts;
return;
}
switch (node.kind) {
- case 169 /* Constructor */:
+ case 170 /* Constructor */:
// Get parameter properties, and treat them as being on the *same* level as the constructor, not under it.
var ctr = node;
addNodeWithRecursiveChild(ctr, ctr.body);
@@ -134302,25 +137036,25 @@ var ts;
}
}
break;
- case 167 /* MethodDeclaration */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
- case 166 /* MethodSignature */:
+ case 168 /* MethodDeclaration */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
+ case 167 /* MethodSignature */:
if (hasNavigationBarName(node)) {
addNodeWithRecursiveChild(node, node.body);
}
break;
- case 165 /* PropertyDeclaration */:
+ case 166 /* PropertyDeclaration */:
if (hasNavigationBarName(node)) {
addNodeWithRecursiveInitializer(node);
}
break;
- case 164 /* PropertySignature */:
+ case 165 /* PropertySignature */:
if (hasNavigationBarName(node)) {
addLeafNode(node);
}
break;
- case 265 /* ImportClause */:
+ case 266 /* ImportClause */:
var importClause = node;
// Handle default import case e.g.:
// import d from "mod";
@@ -134332,7 +137066,7 @@ var ts;
// import {a, b as B} from "mod";
var namedBindings = importClause.namedBindings;
if (namedBindings) {
- if (namedBindings.kind === 266 /* NamespaceImport */) {
+ if (namedBindings.kind === 267 /* NamespaceImport */) {
addLeafNode(namedBindings);
}
else {
@@ -134343,17 +137077,17 @@ var ts;
}
}
break;
- case 292 /* ShorthandPropertyAssignment */:
+ case 295 /* ShorthandPropertyAssignment */:
addNodeWithRecursiveChild(node, node.name);
break;
- case 293 /* SpreadAssignment */:
+ case 296 /* SpreadAssignment */:
var expression = node.expression;
// Use the expression as the name of the SpreadAssignment, otherwise show as .
ts.isIdentifier(expression) ? addLeafNode(node, expression) : addLeafNode(node);
break;
- case 201 /* BindingElement */:
- case 291 /* PropertyAssignment */:
- case 252 /* VariableDeclaration */: {
+ case 202 /* BindingElement */:
+ case 294 /* PropertyAssignment */:
+ case 253 /* VariableDeclaration */: {
var child = node;
if (ts.isBindingPattern(child.name)) {
addChildrenRecursively(child.name);
@@ -134363,7 +137097,7 @@ var ts;
}
break;
}
- case 254 /* FunctionDeclaration */:
+ case 255 /* FunctionDeclaration */:
var nameNode = node.name;
// If we see a function declaration track as a possible ES5 class
if (nameNode && ts.isIdentifier(nameNode)) {
@@ -134371,11 +137105,11 @@ var ts;
}
addNodeWithRecursiveChild(node, node.body);
break;
- case 212 /* ArrowFunction */:
- case 211 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
+ case 212 /* FunctionExpression */:
addNodeWithRecursiveChild(node, node.body);
break;
- case 258 /* EnumDeclaration */:
+ case 259 /* EnumDeclaration */:
startNode(node);
for (var _e = 0, _f = node.members; _e < _f.length; _e++) {
var member = _f[_e];
@@ -134385,9 +137119,9 @@ var ts;
}
endNode();
break;
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
- case 256 /* InterfaceDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
+ case 257 /* InterfaceDeclaration */:
startNode(node);
for (var _g = 0, _h = node.members; _g < _h.length; _g++) {
var member = _h[_g];
@@ -134395,10 +137129,10 @@ var ts;
}
endNode();
break;
- case 259 /* ModuleDeclaration */:
+ case 260 /* ModuleDeclaration */:
addNodeWithRecursiveChild(node, getInteriorModule(node).body);
break;
- case 269 /* ExportAssignment */: {
+ case 270 /* ExportAssignment */: {
var expression_1 = node.expression;
var child = ts.isObjectLiteralExpression(expression_1) || ts.isCallExpression(expression_1) ? expression_1 :
ts.isArrowFunction(expression_1) || ts.isFunctionExpression(expression_1) ? expression_1.body : undefined;
@@ -134412,16 +137146,16 @@ var ts;
}
break;
}
- case 273 /* ExportSpecifier */:
- case 263 /* ImportEqualsDeclaration */:
- case 174 /* IndexSignature */:
- case 172 /* CallSignature */:
- case 173 /* ConstructSignature */:
- case 257 /* TypeAliasDeclaration */:
+ case 274 /* ExportSpecifier */:
+ case 264 /* ImportEqualsDeclaration */:
+ case 175 /* IndexSignature */:
+ case 173 /* CallSignature */:
+ case 174 /* ConstructSignature */:
+ case 258 /* TypeAliasDeclaration */:
addLeafNode(node);
break;
- case 206 /* CallExpression */:
- case 219 /* BinaryExpression */: {
+ case 207 /* CallExpression */:
+ case 220 /* BinaryExpression */: {
var special = ts.getAssignmentDeclarationKind(node);
switch (special) {
case 1 /* ExportsProperty */:
@@ -134663,12 +137397,12 @@ var ts;
return false;
}
switch (a.kind) {
- case 165 /* PropertyDeclaration */:
- case 167 /* MethodDeclaration */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
+ case 166 /* PropertyDeclaration */:
+ case 168 /* MethodDeclaration */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
return ts.isStatic(a) === ts.isStatic(b);
- case 259 /* ModuleDeclaration */:
+ case 260 /* ModuleDeclaration */:
return areSameModule(a, b)
&& getFullyQualifiedModuleName(a) === getFullyQualifiedModuleName(b);
default:
@@ -134687,7 +137421,7 @@ var ts;
// We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
// Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
function areSameModule(a, b) {
- return a.body.kind === b.body.kind && (a.body.kind !== 259 /* ModuleDeclaration */ || areSameModule(a.body, b.body));
+ return a.body.kind === b.body.kind && (a.body.kind !== 260 /* ModuleDeclaration */ || areSameModule(a.body, b.body));
}
/** Merge source into target. Source should be thrown away after this is called. */
function merge(target, source) {
@@ -134717,7 +137451,7 @@ var ts;
* So `new()` can still come before an `aardvark` method.
*/
function tryGetName(node) {
- if (node.kind === 259 /* ModuleDeclaration */) {
+ if (node.kind === 260 /* ModuleDeclaration */) {
return getModuleName(node);
}
var declName = ts.getNameOfDeclaration(node);
@@ -134726,16 +137460,16 @@ var ts;
return propertyName && ts.unescapeLeadingUnderscores(propertyName);
}
switch (node.kind) {
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
- case 224 /* ClassExpression */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
+ case 225 /* ClassExpression */:
return getFunctionOrClassName(node);
default:
return undefined;
}
}
function getItemName(node, name) {
- if (node.kind === 259 /* ModuleDeclaration */) {
+ if (node.kind === 260 /* ModuleDeclaration */) {
return cleanText(getModuleName(node));
}
if (name) {
@@ -134747,18 +137481,18 @@ var ts;
}
}
switch (node.kind) {
- case 300 /* SourceFile */:
+ case 303 /* SourceFile */:
var sourceFile = node;
return ts.isExternalModule(sourceFile)
? "\"" + ts.escapeString(ts.getBaseFileName(ts.removeFileExtension(ts.normalizePath(sourceFile.fileName)))) + "\""
: "";
- case 269 /* ExportAssignment */:
+ case 270 /* ExportAssignment */:
return ts.isExportAssignment(node) && node.isExportEquals ? "export=" /* ExportEquals */ : "default" /* Default */;
- case 212 /* ArrowFunction */:
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
+ case 213 /* ArrowFunction */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
if (ts.getSyntacticModifierFlags(node) & 512 /* Default */) {
return "default";
}
@@ -134766,13 +137500,13 @@ var ts;
// (eg: "app\n.onactivated"), so we should remove the whitespace for readability in the
// navigation bar.
return getFunctionOrClassName(node);
- case 169 /* Constructor */:
+ case 170 /* Constructor */:
return "constructor";
- case 173 /* ConstructSignature */:
+ case 174 /* ConstructSignature */:
return "new()";
- case 172 /* CallSignature */:
+ case 173 /* CallSignature */:
return "()";
- case 174 /* IndexSignature */:
+ case 175 /* IndexSignature */:
return "[]";
default:
return "";
@@ -134805,19 +137539,19 @@ var ts;
}
// Some nodes are otherwise important enough to always include in the primary navigation menu.
switch (navigationBarNodeKind(item)) {
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
- case 258 /* EnumDeclaration */:
- case 256 /* InterfaceDeclaration */:
- case 259 /* ModuleDeclaration */:
- case 300 /* SourceFile */:
- case 257 /* TypeAliasDeclaration */:
- case 340 /* JSDocTypedefTag */:
- case 333 /* JSDocCallbackTag */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
+ case 259 /* EnumDeclaration */:
+ case 257 /* InterfaceDeclaration */:
+ case 260 /* ModuleDeclaration */:
+ case 303 /* SourceFile */:
+ case 258 /* TypeAliasDeclaration */:
+ case 343 /* JSDocTypedefTag */:
+ case 336 /* JSDocCallbackTag */:
return true;
- case 212 /* ArrowFunction */:
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
return isTopLevelFunctionDeclaration(item);
default:
return false;
@@ -134827,10 +137561,10 @@ var ts;
return false;
}
switch (navigationBarNodeKind(item.parent)) {
- case 260 /* ModuleBlock */:
- case 300 /* SourceFile */:
- case 167 /* MethodDeclaration */:
- case 169 /* Constructor */:
+ case 261 /* ModuleBlock */:
+ case 303 /* SourceFile */:
+ case 168 /* MethodDeclaration */:
+ case 170 /* Constructor */:
return true;
default:
return false;
@@ -134892,7 +137626,7 @@ var ts;
function getFullyQualifiedModuleName(moduleDeclaration) {
// Otherwise, we need to aggregate each identifier to build up the qualified name.
var result = [ts.getTextOfIdentifierOrLiteral(moduleDeclaration.name)];
- while (moduleDeclaration.body && moduleDeclaration.body.kind === 259 /* ModuleDeclaration */) {
+ while (moduleDeclaration.body && moduleDeclaration.body.kind === 260 /* ModuleDeclaration */) {
moduleDeclaration = moduleDeclaration.body;
result.push(ts.getTextOfIdentifierOrLiteral(moduleDeclaration.name));
}
@@ -134906,13 +137640,13 @@ var ts;
return decl.body && ts.isModuleDeclaration(decl.body) ? getInteriorModule(decl.body) : decl;
}
function isComputedProperty(member) {
- return !member.name || member.name.kind === 160 /* ComputedPropertyName */;
+ return !member.name || member.name.kind === 161 /* ComputedPropertyName */;
}
function getNodeSpan(node) {
- return node.kind === 300 /* SourceFile */ ? ts.createTextSpanFromRange(node) : ts.createTextSpanFromNode(node, curSourceFile);
+ return node.kind === 303 /* SourceFile */ ? ts.createTextSpanFromRange(node) : ts.createTextSpanFromNode(node, curSourceFile);
}
function getModifiers(node) {
- if (node.parent && node.parent.kind === 252 /* VariableDeclaration */) {
+ if (node.parent && node.parent.kind === 253 /* VariableDeclaration */) {
node = node.parent;
}
return ts.getNodeModifiers(node);
@@ -134970,9 +137704,9 @@ var ts;
}
function isFunctionOrClassExpression(node) {
switch (node.kind) {
- case 212 /* ArrowFunction */:
- case 211 /* FunctionExpression */:
- case 224 /* ClassExpression */:
+ case 213 /* ArrowFunction */:
+ case 212 /* FunctionExpression */:
+ case 225 /* ClassExpression */:
return true;
default:
return false;
@@ -135012,9 +137746,8 @@ var ts;
organizeImportsWorker(topLevelExportDecls, coalesceExports);
for (var _i = 0, _a = sourceFile.statements.filter(ts.isAmbientModule); _i < _a.length; _i++) {
var ambientModule = _a[_i];
- if (!ambientModule.body) {
+ if (!ambientModule.body)
continue;
- }
var ambientModuleImportDecls = ambientModule.body.statements.filter(ts.isImportDeclaration);
organizeImportsWorker(ambientModuleImportDecls, coalesceAndOrganizeImports);
var ambientModuleExportDecls = ambientModule.body.statements.filter(ts.isExportDeclaration);
@@ -135110,7 +137843,8 @@ var ts;
// If we’re in a declaration file, it’s safe to remove the import clause from it
if (sourceFile.isDeclarationFile) {
usedImports.push(ts.factory.createImportDeclaration(importDecl.decorators, importDecl.modifiers,
- /*importClause*/ undefined, moduleSpecifier));
+ /*importClause*/ undefined, moduleSpecifier,
+ /*assertClause*/ undefined));
}
// If we’re not in a declaration file, we can’t remove the import clause even though
// the imported symbols are unused, because removing them makes it look like the import
@@ -135184,7 +137918,7 @@ var ts;
else {
for (var _e = 0, defaultImports_1 = defaultImports; _e < defaultImports_1.length; _e++) {
var defaultImport = defaultImports_1[_e];
- newImportSpecifiers.push(ts.factory.createImportSpecifier(ts.factory.createIdentifier("default"), defaultImport.importClause.name)); // TODO: GH#18217
+ newImportSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, ts.factory.createIdentifier("default"), defaultImport.importClause.name)); // TODO: GH#18217
}
}
newImportSpecifiers.push.apply(newImportSpecifiers, ts.flatMap(namedImports, function (i) { return i.importClause.namedBindings.elements; })); // TODO: GH#18217
@@ -135276,7 +138010,7 @@ var ts;
var exportDecl = exportGroup_1[0];
coalescedExports.push(ts.factory.updateExportDeclaration(exportDecl, exportDecl.decorators, exportDecl.modifiers, exportDecl.isTypeOnly, exportDecl.exportClause && (ts.isNamedExports(exportDecl.exportClause) ?
ts.factory.updateNamedExports(exportDecl.exportClause, sortedExportSpecifiers) :
- ts.factory.updateNamespaceExport(exportDecl.exportClause, exportDecl.exportClause.name)), exportDecl.moduleSpecifier));
+ ts.factory.updateNamespaceExport(exportDecl.exportClause, exportDecl.exportClause.name)), exportDecl.moduleSpecifier, exportDecl.assertClause));
}
return coalescedExports;
/*
@@ -135312,13 +138046,14 @@ var ts;
OrganizeImports.coalesceExports = coalesceExports;
function updateImportDeclarationAndClause(importDeclaration, name, namedBindings) {
return ts.factory.updateImportDeclaration(importDeclaration, importDeclaration.decorators, importDeclaration.modifiers, ts.factory.updateImportClause(importDeclaration.importClause, importDeclaration.importClause.isTypeOnly, name, namedBindings), // TODO: GH#18217
- importDeclaration.moduleSpecifier);
+ importDeclaration.moduleSpecifier, importDeclaration.assertClause);
}
function sortSpecifiers(specifiers) {
return ts.stableSort(specifiers, compareImportOrExportSpecifiers);
}
function compareImportOrExportSpecifiers(s1, s2) {
- return compareIdentifiers(s1.propertyName || s1.name, s2.propertyName || s2.name)
+ return ts.compareBooleans(s1.isTypeOnly, s2.isTypeOnly)
+ || compareIdentifiers(s1.propertyName || s1.name, s2.propertyName || s2.name)
|| compareIdentifiers(s1.name, s2.name);
}
OrganizeImports.compareImportOrExportSpecifiers = compareImportOrExportSpecifiers;
@@ -135337,11 +138072,11 @@ var ts;
function getModuleSpecifierExpression(declaration) {
var _a;
switch (declaration.kind) {
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return (_a = ts.tryCast(declaration.moduleReference, ts.isExternalModuleReference)) === null || _a === void 0 ? void 0 : _a.expression;
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
return declaration.moduleSpecifier;
- case 235 /* VariableStatement */:
+ case 236 /* VariableStatement */:
return declaration.declarationList.declarations[0].initializer.arguments[0];
}
}
@@ -135380,19 +138115,19 @@ var ts;
function getImportKindOrder(s1) {
var _a;
switch (s1.kind) {
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
if (!s1.importClause)
return 0;
if (s1.importClause.isTypeOnly)
return 1;
- if (((_a = s1.importClause.namedBindings) === null || _a === void 0 ? void 0 : _a.kind) === 266 /* NamespaceImport */)
+ if (((_a = s1.importClause.namedBindings) === null || _a === void 0 ? void 0 : _a.kind) === 267 /* NamespaceImport */)
return 2;
if (s1.importClause.name)
return 3;
return 4;
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return 5;
- case 235 /* VariableStatement */:
+ case 236 /* VariableStatement */:
return 6;
}
}
@@ -135566,7 +138301,7 @@ var ts;
}
function getOutliningSpanForNode(n, sourceFile) {
switch (n.kind) {
- case 233 /* Block */:
+ case 234 /* Block */:
if (ts.isFunctionLike(n.parent)) {
return functionSpan(n.parent, n, sourceFile);
}
@@ -135574,16 +138309,16 @@ var ts;
// If the latter, we want to collapse the block, but consider its hint span
// to be the entire span of the parent.
switch (n.parent.kind) {
- case 238 /* DoStatement */:
- case 241 /* ForInStatement */:
- case 242 /* ForOfStatement */:
- case 240 /* ForStatement */:
- case 237 /* IfStatement */:
- case 239 /* WhileStatement */:
- case 246 /* WithStatement */:
- case 290 /* CatchClause */:
+ case 239 /* DoStatement */:
+ case 242 /* ForInStatement */:
+ case 243 /* ForOfStatement */:
+ case 241 /* ForStatement */:
+ case 238 /* IfStatement */:
+ case 240 /* WhileStatement */:
+ case 247 /* WithStatement */:
+ case 291 /* CatchClause */:
return spanForNode(n.parent);
- case 250 /* TryStatement */:
+ case 251 /* TryStatement */:
// Could be the try-block, or the finally-block.
var tryStatement = n.parent;
if (tryStatement.tryBlock === n) {
@@ -135600,40 +138335,40 @@ var ts;
// the span of the block, independent of any parent span.
return createOutliningSpan(ts.createTextSpanFromNode(n, sourceFile), "code" /* Code */);
}
- case 260 /* ModuleBlock */:
+ case 261 /* ModuleBlock */:
return spanForNode(n.parent);
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
- case 256 /* InterfaceDeclaration */:
- case 258 /* EnumDeclaration */:
- case 261 /* CaseBlock */:
- case 180 /* TypeLiteral */:
- case 199 /* ObjectBindingPattern */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
+ case 257 /* InterfaceDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 262 /* CaseBlock */:
+ case 181 /* TypeLiteral */:
+ case 200 /* ObjectBindingPattern */:
return spanForNode(n);
- case 182 /* TupleType */:
+ case 183 /* TupleType */:
return spanForNode(n, /*autoCollapse*/ false, /*useFullStart*/ !ts.isTupleTypeNode(n.parent), 22 /* OpenBracketToken */);
- case 287 /* CaseClause */:
- case 288 /* DefaultClause */:
+ case 288 /* CaseClause */:
+ case 289 /* DefaultClause */:
return spanForNodeArray(n.statements);
- case 203 /* ObjectLiteralExpression */:
+ case 204 /* ObjectLiteralExpression */:
return spanForObjectOrArrayLiteral(n);
- case 202 /* ArrayLiteralExpression */:
+ case 203 /* ArrayLiteralExpression */:
return spanForObjectOrArrayLiteral(n, 22 /* OpenBracketToken */);
- case 276 /* JsxElement */:
+ case 277 /* JsxElement */:
return spanForJSXElement(n);
- case 280 /* JsxFragment */:
+ case 281 /* JsxFragment */:
return spanForJSXFragment(n);
- case 277 /* JsxSelfClosingElement */:
- case 278 /* JsxOpeningElement */:
+ case 278 /* JsxSelfClosingElement */:
+ case 279 /* JsxOpeningElement */:
return spanForJSXAttributes(n.attributes);
- case 221 /* TemplateExpression */:
+ case 222 /* TemplateExpression */:
case 14 /* NoSubstitutionTemplateLiteral */:
return spanForTemplateLiteral(n);
- case 200 /* ArrayBindingPattern */:
+ case 201 /* ArrayBindingPattern */:
return spanForNode(n, /*autoCollapse*/ false, /*useFullStart*/ !ts.isBindingElement(n.parent), 22 /* OpenBracketToken */);
- case 212 /* ArrowFunction */:
+ case 213 /* ArrowFunction */:
return spanForArrowFunction(n);
- case 206 /* CallExpression */:
+ case 207 /* CallExpression */:
return spanForCallExpression(n);
}
function spanForCallExpression(node) {
@@ -135700,7 +138435,7 @@ var ts;
function functionSpan(node, body, sourceFile) {
var openToken = tryGetFunctionOpenToken(node, body, sourceFile);
var closeToken = ts.findChildOfKind(body, 19 /* CloseBraceToken */, sourceFile);
- return openToken && closeToken && spanBetweenTokens(openToken, closeToken, node, sourceFile, /*autoCollapse*/ node.kind !== 212 /* ArrowFunction */);
+ return openToken && closeToken && spanBetweenTokens(openToken, closeToken, node, sourceFile, /*autoCollapse*/ node.kind !== 213 /* ArrowFunction */);
}
function spanBetweenTokens(openToken, closeToken, hintSpanNode, sourceFile, autoCollapse, useFullStart) {
if (autoCollapse === void 0) { autoCollapse = false; }
@@ -136003,15 +138738,15 @@ var ts;
// Assumes 'value' is already lowercase.
function indexOfIgnoringCase(str, value) {
var n = str.length - value.length;
- var _loop_7 = function (start) {
+ var _loop_8 = function (start) {
if (every(value, function (valueChar, i) { return toLowerCase(str.charCodeAt(i + start)) === valueChar; })) {
return { value: start };
}
};
for (var start = 0; start <= n; start++) {
- var state_2 = _loop_7(start);
- if (typeof state_2 === "object")
- return state_2.value;
+ var state_3 = _loop_8(start);
+ if (typeof state_3 === "object")
+ return state_3.value;
}
return -1;
}
@@ -136244,10 +138979,10 @@ var ts;
*/
function tryConsumeDeclare() {
var token = ts.scanner.getToken();
- if (token === 134 /* DeclareKeyword */) {
+ if (token === 135 /* DeclareKeyword */) {
// declare module "mod"
token = nextToken();
- if (token === 140 /* ModuleKeyword */) {
+ if (token === 141 /* ModuleKeyword */) {
token = nextToken();
if (token === 10 /* StringLiteral */) {
recordAmbientExternalModule();
@@ -136281,10 +139016,10 @@ var ts;
return true;
}
else {
- if (token === 150 /* TypeKeyword */) {
+ if (token === 151 /* TypeKeyword */) {
var skipTypeKeyword = ts.scanner.lookAhead(function () {
var token = ts.scanner.scan();
- return token !== 154 /* FromKeyword */ && (token === 41 /* AsteriskToken */ ||
+ return token !== 155 /* FromKeyword */ && (token === 41 /* AsteriskToken */ ||
token === 18 /* OpenBraceToken */ ||
token === 79 /* Identifier */ ||
ts.isKeyword(token));
@@ -136295,7 +139030,7 @@ var ts;
}
if (token === 79 /* Identifier */ || ts.isKeyword(token)) {
token = nextToken();
- if (token === 154 /* FromKeyword */) {
+ if (token === 155 /* FromKeyword */) {
token = nextToken();
if (token === 10 /* StringLiteral */) {
// import d from "mod";
@@ -136326,7 +139061,7 @@ var ts;
}
if (token === 19 /* CloseBraceToken */) {
token = nextToken();
- if (token === 154 /* FromKeyword */) {
+ if (token === 155 /* FromKeyword */) {
token = nextToken();
if (token === 10 /* StringLiteral */) {
// import {a as A} from "mod";
@@ -136342,7 +139077,7 @@ var ts;
token = nextToken();
if (token === 79 /* Identifier */ || ts.isKeyword(token)) {
token = nextToken();
- if (token === 154 /* FromKeyword */) {
+ if (token === 155 /* FromKeyword */) {
token = nextToken();
if (token === 10 /* StringLiteral */) {
// import * as NS from "mod"
@@ -136363,7 +139098,7 @@ var ts;
if (token === 93 /* ExportKeyword */) {
markAsExternalModuleIfTopLevel();
token = nextToken();
- if (token === 150 /* TypeKeyword */) {
+ if (token === 151 /* TypeKeyword */) {
var skipTypeKeyword = ts.scanner.lookAhead(function () {
var token = ts.scanner.scan();
return token === 41 /* AsteriskToken */ ||
@@ -136382,7 +139117,7 @@ var ts;
}
if (token === 19 /* CloseBraceToken */) {
token = nextToken();
- if (token === 154 /* FromKeyword */) {
+ if (token === 155 /* FromKeyword */) {
token = nextToken();
if (token === 10 /* StringLiteral */) {
// export {a as A} from "mod";
@@ -136394,7 +139129,7 @@ var ts;
}
else if (token === 41 /* AsteriskToken */) {
token = nextToken();
- if (token === 154 /* FromKeyword */) {
+ if (token === 155 /* FromKeyword */) {
token = nextToken();
if (token === 10 /* StringLiteral */) {
// export * from "mod"
@@ -136404,7 +139139,7 @@ var ts;
}
else if (token === 100 /* ImportKeyword */) {
token = nextToken();
- if (token === 150 /* TypeKeyword */) {
+ if (token === 151 /* TypeKeyword */) {
var skipTypeKeyword = ts.scanner.lookAhead(function () {
var token = ts.scanner.scan();
return token === 79 /* Identifier */ ||
@@ -136430,7 +139165,7 @@ var ts;
function tryConsumeRequireCall(skipCurrentToken, allowTemplateLiterals) {
if (allowTemplateLiterals === void 0) { allowTemplateLiterals = false; }
var token = skipCurrentToken ? nextToken() : ts.scanner.getToken();
- if (token === 144 /* RequireKeyword */) {
+ if (token === 145 /* RequireKeyword */) {
token = nextToken();
if (token === 20 /* OpenParenToken */) {
token = nextToken();
@@ -136575,7 +139310,7 @@ var ts;
var symbol = typeChecker.getSymbolAtLocation(node);
if (!symbol) {
if (ts.isStringLiteralLike(node)) {
- var type = ts.getContextualTypeOrAncestorTypeNodeType(node, typeChecker);
+ var type = ts.getContextualTypeFromParentOrAncestorTypeNode(node, typeChecker);
if (type && ((type.flags & 128 /* StringLiteral */) || ((type.flags & 1048576 /* Union */) && ts.every(type.types, function (type) { return !!(type.flags & 128 /* StringLiteral */); })))) {
return getRenameInfoSuccess(node.text, node.text, "string" /* string */, "", node, sourceFile);
}
@@ -136602,7 +139337,7 @@ var ts;
return options && options.allowRenameOfImportPath ? getRenameInfoForModule(node, sourceFile, symbol) : undefined;
}
var kind = ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, node);
- var specifierName = (ts.isImportOrExportSpecifierName(node) || ts.isStringOrNumericLiteralLike(node) && node.parent.kind === 160 /* ComputedPropertyName */)
+ var specifierName = (ts.isImportOrExportSpecifierName(node) || ts.isStringOrNumericLiteralLike(node) && node.parent.kind === 161 /* ComputedPropertyName */)
? ts.stripQuotes(ts.getTextOfIdentifierOrLiteral(node))
: undefined;
var displayName = specifierName || typeChecker.symbolToString(symbol);
@@ -136674,6 +139409,7 @@ var ts;
return false;
}
}
+ Rename.nodeIsEligibleForRename = nodeIsEligibleForRename;
})(Rename = ts.Rename || (ts.Rename = {}));
})(ts || (ts = {}));
/* @internal */
@@ -136828,14 +139564,14 @@ var ts;
ts.Debug.assertEqual(closeBraceToken.kind, 19 /* CloseBraceToken */);
// Group `-/+readonly` and `-/+?`
var groupedWithPlusMinusTokens = groupChildren(children, function (child) {
- return child === node.readonlyToken || child.kind === 143 /* ReadonlyKeyword */ ||
+ return child === node.readonlyToken || child.kind === 144 /* ReadonlyKeyword */ ||
child === node.questionToken || child.kind === 57 /* QuestionToken */;
});
// Group type parameter with surrounding brackets
var groupedWithBrackets = groupChildren(groupedWithPlusMinusTokens, function (_a) {
var kind = _a.kind;
return kind === 22 /* OpenBracketToken */ ||
- kind === 161 /* TypeParameter */ ||
+ kind === 162 /* TypeParameter */ ||
kind === 23 /* CloseBracketToken */;
});
return [
@@ -136949,22 +139685,22 @@ var ts;
return kind === 18 /* OpenBraceToken */
|| kind === 22 /* OpenBracketToken */
|| kind === 20 /* OpenParenToken */
- || kind === 278 /* JsxOpeningElement */;
+ || kind === 279 /* JsxOpeningElement */;
}
function isListCloser(token) {
var kind = token && token.kind;
return kind === 19 /* CloseBraceToken */
|| kind === 23 /* CloseBracketToken */
|| kind === 21 /* CloseParenToken */
- || kind === 279 /* JsxClosingElement */;
+ || kind === 280 /* JsxClosingElement */;
}
function getEndPos(sourceFile, node) {
switch (node.kind) {
- case 335 /* JSDocParameterTag */:
- case 333 /* JSDocCallbackTag */:
- case 342 /* JSDocPropertyTag */:
- case 340 /* JSDocTypedefTag */:
- case 337 /* JSDocThisTag */:
+ case 338 /* JSDocParameterTag */:
+ case 336 /* JSDocCallbackTag */:
+ case 345 /* JSDocPropertyTag */:
+ case 343 /* JSDocTypedefTag */:
+ case 340 /* JSDocThisTag */:
return sourceFile.getLineEndOfPosition(node.getStart());
default:
return node.getEnd();
@@ -137174,10 +139910,10 @@ var ts;
}
return undefined;
}
- else if (ts.isTemplateHead(node) && parent.parent.kind === 208 /* TaggedTemplateExpression */) {
+ else if (ts.isTemplateHead(node) && parent.parent.kind === 209 /* TaggedTemplateExpression */) {
var templateExpression = parent;
var tagExpression = templateExpression.parent;
- ts.Debug.assert(templateExpression.kind === 221 /* TemplateExpression */);
+ ts.Debug.assert(templateExpression.kind === 222 /* TemplateExpression */);
var argumentIndex = ts.isInsideTemplateLiteral(node, position, sourceFile) ? 0 : 1;
return getArgumentListInfoForTemplate(tagExpression, argumentIndex, sourceFile);
}
@@ -137246,17 +139982,17 @@ var ts;
return undefined;
var parent = startingToken.parent;
switch (parent.kind) {
- case 210 /* ParenthesizedExpression */:
- case 167 /* MethodDeclaration */:
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
+ case 211 /* ParenthesizedExpression */:
+ case 168 /* MethodDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
var info = getArgumentOrParameterListInfo(startingToken, sourceFile);
if (!info)
return undefined;
var argumentIndex = info.argumentIndex, argumentCount = info.argumentCount, argumentsSpan = info.argumentsSpan;
var contextualType = ts.isMethodDeclaration(parent) ? checker.getContextualTypeForObjectLiteralElement(parent) : checker.getContextualType(parent);
return contextualType && { contextualType: contextualType, argumentIndex: argumentIndex, argumentCount: argumentCount, argumentsSpan: argumentsSpan };
- case 219 /* BinaryExpression */: {
+ case 220 /* BinaryExpression */: {
var highestBinary = getHighestBinary(parent);
var contextualType_1 = checker.getContextualType(highestBinary);
var argumentIndex_1 = startingToken.kind === 20 /* OpenParenToken */ ? 0 : countBinaryExpressionParameters(parent) - 1;
@@ -137380,7 +140116,7 @@ var ts;
// | |
// This is because a Missing node has no width. However, what we actually want is to include trivia
// leading up to the next token in case the user is about to type in a TemplateMiddle or TemplateTail.
- if (template.kind === 221 /* TemplateExpression */) {
+ if (template.kind === 222 /* TemplateExpression */) {
var lastSpan = ts.last(template.templateSpans);
if (lastSpan.literal.getFullWidth() === 0) {
applicableSpanEnd = ts.skipTrivia(sourceFile.text, applicableSpanEnd, /*stopAfterLineBreak*/ false);
@@ -137389,7 +140125,7 @@ var ts;
return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
}
function getContainingArgumentInfo(node, position, sourceFile, checker, isManuallyInvoked) {
- var _loop_8 = function (n) {
+ var _loop_9 = function (n) {
// If the node is not a subspan of its parent, this is a big problem.
// There have been crashes that might be caused by this violation.
ts.Debug.assert(ts.rangeContainsRange(n.parent, n), "Not a subspan", function () { return "Child: " + ts.Debug.formatSyntaxKind(n.kind) + ", parent: " + ts.Debug.formatSyntaxKind(n.parent.kind); });
@@ -137399,9 +140135,9 @@ var ts;
}
};
for (var n = node; !ts.isSourceFile(n) && (isManuallyInvoked || !ts.isBlock(n)); n = n.parent) {
- var state_3 = _loop_8(n);
- if (typeof state_3 === "object")
- return state_3.value;
+ var state_4 = _loop_9(n);
+ if (typeof state_4 === "object")
+ return state_4.value;
}
return undefined;
}
@@ -137585,14 +140321,14 @@ var ts;
return;
}
switch (node.kind) {
- case 259 /* ModuleDeclaration */:
- case 255 /* ClassDeclaration */:
- case 256 /* InterfaceDeclaration */:
- case 254 /* FunctionDeclaration */:
- case 224 /* ClassExpression */:
- case 211 /* FunctionExpression */:
- case 167 /* MethodDeclaration */:
- case 212 /* ArrowFunction */:
+ case 260 /* ModuleDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 257 /* InterfaceDeclaration */:
+ case 255 /* FunctionDeclaration */:
+ case 225 /* ClassExpression */:
+ case 212 /* FunctionExpression */:
+ case 168 /* MethodDeclaration */:
+ case 213 /* ArrowFunction */:
cancellationToken.throwIfCancellationRequested();
}
if (!ts.textSpanIntersectsWith(span, node.pos, node.getFullWidth())) {
@@ -137732,13 +140468,15 @@ var ts;
}
function isHintableLiteral(node) {
switch (node.kind) {
- case 217 /* PrefixUnaryExpression */: {
+ case 218 /* PrefixUnaryExpression */: {
var operand = node.operand;
return ts.isLiteralExpression(operand) || ts.isIdentifier(operand) && ts.isInfinityOrNaNString(operand.escapedText);
}
case 110 /* TrueKeyword */:
case 95 /* FalseKeyword */:
case 104 /* NullKeyword */:
+ case 14 /* NoSubstitutionTemplateLiteral */:
+ case 222 /* TemplateExpression */:
return true;
case 79 /* Identifier */: {
var name = node.escapedText;
@@ -137793,7 +140531,7 @@ var ts;
if (!typeDisplayString) {
continue;
}
- addTypeHints(typeDisplayString, param.end);
+ addTypeHints(typeDisplayString, param.name.end);
}
}
function getParameterDeclarationTypeDisplayString(symbol) {
@@ -137991,10 +140729,12 @@ var ts;
program.getSemanticDiagnostics(sourceFile, cancellationToken);
var diags = [];
var checker = program.getTypeChecker();
- if (sourceFile.commonJsModuleIndicator &&
- (ts.programContainsEs6Modules(program) || ts.compilerOptionsIndicateEs6Modules(program.getCompilerOptions())) &&
+ var isCommonJSFile = sourceFile.impliedNodeFormat === ts.ModuleKind.CommonJS || ts.fileExtensionIsOneOf(sourceFile.fileName, [".cts" /* Cts */, ".cjs" /* Cjs */]);
+ if (!isCommonJSFile &&
+ sourceFile.commonJsModuleIndicator &&
+ (ts.programContainsEsModules(program) || ts.compilerOptionsIndicateEsModules(program.getCompilerOptions())) &&
containsTopLevelCommonjs(sourceFile)) {
- diags.push(ts.createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), ts.Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
+ diags.push(ts.createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), ts.Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES_module));
}
var isJsFile = ts.isSourceFileJS(sourceFile);
visitedNestedConvertibleFunctions.clear();
@@ -138006,7 +140746,7 @@ var ts;
var name = importNameForConvertToDefaultImport(importNode);
if (!name)
continue;
- var module_1 = ts.getResolvedModule(sourceFile, moduleSpecifier.text);
+ var module_1 = ts.getResolvedModule(sourceFile, moduleSpecifier.text, ts.getModeForUsageLocation(sourceFile, moduleSpecifier));
var resolvedFile = module_1 && program.getSourceFile(module_1.resolvedFileName);
if (resolvedFile && resolvedFile.externalModuleIndicator && ts.isExportAssignment(resolvedFile.externalModuleIndicator) && resolvedFile.externalModuleIndicator.isExportEquals) {
diags.push(ts.createDiagnosticForNode(name, ts.Diagnostics.Import_may_be_converted_to_a_default_import));
@@ -138043,15 +140783,15 @@ var ts;
}
}
ts.computeSuggestionDiagnostics = computeSuggestionDiagnostics;
- // convertToEs6Module only works on top-level, so don't trigger it if commonjs code only appears in nested scopes.
+ // convertToEsModule only works on top-level, so don't trigger it if commonjs code only appears in nested scopes.
function containsTopLevelCommonjs(sourceFile) {
return sourceFile.statements.some(function (statement) {
switch (statement.kind) {
- case 235 /* VariableStatement */:
+ case 236 /* VariableStatement */:
return statement.declarationList.declarations.some(function (decl) {
return !!decl.initializer && ts.isRequireCall(propertyAccessLeftHandSide(decl.initializer), /*checkArgumentIsStringLiteralLike*/ true);
});
- case 236 /* ExpressionStatement */: {
+ case 237 /* ExpressionStatement */: {
var expression = statement.expression;
if (!ts.isBinaryExpression(expression))
return ts.isRequireCall(expression, /*checkArgumentIsStringLiteralLike*/ true);
@@ -138068,12 +140808,12 @@ var ts;
}
function importNameForConvertToDefaultImport(node) {
switch (node.kind) {
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
var importClause = node.importClause, moduleSpecifier = node.moduleSpecifier;
- return importClause && !importClause.name && importClause.namedBindings && importClause.namedBindings.kind === 266 /* NamespaceImport */ && ts.isStringLiteral(moduleSpecifier)
+ return importClause && !importClause.name && importClause.namedBindings && importClause.namedBindings.kind === 267 /* NamespaceImport */ && ts.isStringLiteral(moduleSpecifier)
? importClause.namedBindings.name
: undefined;
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return node.name;
default:
return undefined;
@@ -138111,51 +140851,58 @@ var ts;
// Should be kept up to date with transformExpression in convertToAsyncFunction.ts
function isFixablePromiseHandler(node, checker) {
// ensure outermost call exists and is a promise handler
- if (!isPromiseHandler(node) || !node.arguments.every(function (arg) { return isFixablePromiseArgument(arg, checker); })) {
+ if (!isPromiseHandler(node) || !hasSupportedNumberOfArguments(node) || !node.arguments.every(function (arg) { return isFixablePromiseArgument(arg, checker); })) {
return false;
}
// ensure all chained calls are valid
- var currentNode = node.expression;
+ var currentNode = node.expression.expression;
while (isPromiseHandler(currentNode) || ts.isPropertyAccessExpression(currentNode)) {
- if (ts.isCallExpression(currentNode) && !currentNode.arguments.every(function (arg) { return isFixablePromiseArgument(arg, checker); })) {
- return false;
+ if (ts.isCallExpression(currentNode)) {
+ if (!hasSupportedNumberOfArguments(currentNode) || !currentNode.arguments.every(function (arg) { return isFixablePromiseArgument(arg, checker); })) {
+ return false;
+ }
+ currentNode = currentNode.expression.expression;
+ }
+ else {
+ currentNode = currentNode.expression;
}
- currentNode = currentNode.expression;
}
return true;
}
ts.isFixablePromiseHandler = isFixablePromiseHandler;
function isPromiseHandler(node) {
- return ts.isCallExpression(node) && (ts.hasPropertyAccessExpressionWithName(node, "then") && hasSupportedNumberOfArguments(node) ||
- ts.hasPropertyAccessExpressionWithName(node, "catch"));
+ return ts.isCallExpression(node) && (ts.hasPropertyAccessExpressionWithName(node, "then") ||
+ ts.hasPropertyAccessExpressionWithName(node, "catch") ||
+ ts.hasPropertyAccessExpressionWithName(node, "finally"));
}
function hasSupportedNumberOfArguments(node) {
- if (node.arguments.length > 2)
+ var name = node.expression.name.text;
+ var maxArguments = name === "then" ? 2 : name === "catch" ? 1 : name === "finally" ? 1 : 0;
+ if (node.arguments.length > maxArguments)
return false;
- if (node.arguments.length < 2)
+ if (node.arguments.length < maxArguments)
return true;
- return ts.some(node.arguments, function (arg) {
- return arg.kind === 104 /* NullKeyword */ ||
- ts.isIdentifier(arg) && arg.text === "undefined";
+ return maxArguments === 1 || ts.some(node.arguments, function (arg) {
+ return arg.kind === 104 /* NullKeyword */ || ts.isIdentifier(arg) && arg.text === "undefined";
});
}
// should be kept up to date with getTransformationBody in convertToAsyncFunction.ts
function isFixablePromiseArgument(arg, checker) {
switch (arg.kind) {
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
var functionFlags = ts.getFunctionFlags(arg);
if (functionFlags & 1 /* Generator */) {
return false;
}
// falls through
- case 212 /* ArrowFunction */:
+ case 213 /* ArrowFunction */:
visitedNestedConvertibleFunctions.set(getKeyFromNode(arg), true);
// falls through
case 104 /* NullKeyword */:
return true;
case 79 /* Identifier */:
- case 204 /* PropertyAccessExpression */: {
+ case 205 /* PropertyAccessExpression */: {
var symbol = checker.getSymbolAtLocation(arg);
if (!symbol) {
return false;
@@ -138172,24 +140919,24 @@ var ts;
}
function canBeConvertedToClass(node, checker) {
var _a, _b, _c, _d;
- if (node.kind === 211 /* FunctionExpression */) {
+ if (node.kind === 212 /* FunctionExpression */) {
if (ts.isVariableDeclaration(node.parent) && ((_a = node.symbol.members) === null || _a === void 0 ? void 0 : _a.size)) {
return true;
}
var symbol = checker.getSymbolOfExpando(node, /*allowDeclaration*/ false);
return !!(symbol && (((_b = symbol.exports) === null || _b === void 0 ? void 0 : _b.size) || ((_c = symbol.members) === null || _c === void 0 ? void 0 : _c.size)));
}
- if (node.kind === 254 /* FunctionDeclaration */) {
+ if (node.kind === 255 /* FunctionDeclaration */) {
return !!((_d = node.symbol.members) === null || _d === void 0 ? void 0 : _d.size);
}
return false;
}
function canBeConvertedToAsync(node) {
switch (node.kind) {
- case 254 /* FunctionDeclaration */:
- case 167 /* MethodDeclaration */:
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
+ case 255 /* FunctionDeclaration */:
+ case 168 /* MethodDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
return true;
default:
return false;
@@ -138211,7 +140958,7 @@ var ts;
}
var flags = ts.getCombinedLocalAndExportSymbolFlags(symbol);
if (flags & 32 /* Class */) {
- return ts.getDeclarationOfKind(symbol, 224 /* ClassExpression */) ?
+ return ts.getDeclarationOfKind(symbol, 225 /* ClassExpression */) ?
"local class" /* localClassElement */ : "class" /* classElement */;
}
if (flags & 384 /* Enum */)
@@ -138295,11 +141042,11 @@ var ts;
// If we requested completions after `x.` at the top-level, we may be at a source file location.
switch (location.parent && location.parent.kind) {
// If we've typed a character of the attribute name, will be 'JsxAttribute', else will be 'JsxOpeningElement'.
- case 278 /* JsxOpeningElement */:
- case 276 /* JsxElement */:
- case 277 /* JsxSelfClosingElement */:
+ case 279 /* JsxOpeningElement */:
+ case 277 /* JsxElement */:
+ case 278 /* JsxSelfClosingElement */:
return location.kind === 79 /* Identifier */ ? "property" /* memberVariableElement */ : "JSX attribute" /* jsxAttribute */;
- case 283 /* JsxAttribute */:
+ case 284 /* JsxAttribute */:
return "JSX attribute" /* jsxAttribute */;
default:
return "property" /* memberVariableElement */;
@@ -138367,7 +141114,7 @@ var ts;
}
var signature = void 0;
type = isThisExpression ? typeChecker.getTypeAtLocation(location) : typeChecker.getTypeOfSymbolAtLocation(symbol, location);
- if (location.parent && location.parent.kind === 204 /* PropertyAccessExpression */) {
+ if (location.parent && location.parent.kind === 205 /* PropertyAccessExpression */) {
var right = location.parent.name;
// Either the location is on the right of a property access, or on the left and the right is missing
if (right === location || (right && right.getFullWidth() === 0)) {
@@ -138387,7 +141134,7 @@ var ts;
}
if (callExpressionLike) {
signature = typeChecker.getResolvedSignature(callExpressionLike); // TODO: GH#18217
- var useConstructSignatures = callExpressionLike.kind === 207 /* NewExpression */ || (ts.isCallExpression(callExpressionLike) && callExpressionLike.expression.kind === 106 /* SuperKeyword */);
+ var useConstructSignatures = callExpressionLike.kind === 208 /* NewExpression */ || (ts.isCallExpression(callExpressionLike) && callExpressionLike.expression.kind === 106 /* SuperKeyword */);
var allSignatures = useConstructSignatures ? type.getConstructSignatures() : type.getCallSignatures();
if (signature && !ts.contains(allSignatures, signature.target) && !ts.contains(allSignatures, signature)) {
// Get the first signature if there is one -- allSignatures may contain
@@ -138451,29 +141198,29 @@ var ts;
}
}
else if ((ts.isNameOfFunctionDeclaration(location) && !(symbolFlags & 98304 /* Accessor */)) || // name of function declaration
- (location.kind === 133 /* ConstructorKeyword */ && location.parent.kind === 169 /* Constructor */)) { // At constructor keyword of constructor declaration
+ (location.kind === 134 /* ConstructorKeyword */ && location.parent.kind === 170 /* Constructor */)) { // At constructor keyword of constructor declaration
// get the signature from the declaration and write it
var functionDeclaration_1 = location.parent;
// Use function declaration to write the signatures only if the symbol corresponding to this declaration
var locationIsSymbolDeclaration = symbol.declarations && ts.find(symbol.declarations, function (declaration) {
- return declaration === (location.kind === 133 /* ConstructorKeyword */ ? functionDeclaration_1.parent : functionDeclaration_1);
+ return declaration === (location.kind === 134 /* ConstructorKeyword */ ? functionDeclaration_1.parent : functionDeclaration_1);
});
if (locationIsSymbolDeclaration) {
- var allSignatures = functionDeclaration_1.kind === 169 /* Constructor */ ? type.getNonNullableType().getConstructSignatures() : type.getNonNullableType().getCallSignatures();
+ var allSignatures = functionDeclaration_1.kind === 170 /* Constructor */ ? type.getNonNullableType().getConstructSignatures() : type.getNonNullableType().getCallSignatures();
if (!typeChecker.isImplementationOfOverload(functionDeclaration_1)) {
signature = typeChecker.getSignatureFromDeclaration(functionDeclaration_1); // TODO: GH#18217
}
else {
signature = allSignatures[0];
}
- if (functionDeclaration_1.kind === 169 /* Constructor */) {
+ if (functionDeclaration_1.kind === 170 /* Constructor */) {
// show (constructor) Type(...) signature
symbolKind = "constructor" /* constructorImplementationElement */;
addPrefixForAnyFunctionOrVar(type.symbol, symbolKind);
}
else {
// (function/method) symbol(..signature)
- addPrefixForAnyFunctionOrVar(functionDeclaration_1.kind === 172 /* CallSignature */ &&
+ addPrefixForAnyFunctionOrVar(functionDeclaration_1.kind === 173 /* CallSignature */ &&
!(type.symbol.flags & 2048 /* TypeLiteral */ || type.symbol.flags & 4096 /* ObjectLiteral */) ? type.symbol : symbol, symbolKind);
}
if (signature) {
@@ -138486,7 +141233,7 @@ var ts;
}
if (symbolFlags & 32 /* Class */ && !hasAddedSymbolInfo && !isThisExpression) {
addAliasPrefixIfNecessary();
- if (ts.getDeclarationOfKind(symbol, 224 /* ClassExpression */)) {
+ if (ts.getDeclarationOfKind(symbol, 225 /* ClassExpression */)) {
// Special case for class expressions because we would like to indicate that
// the class name is local to the class body (similar to function expression)
// (local class) class
@@ -138509,7 +141256,7 @@ var ts;
}
if ((symbolFlags & 524288 /* TypeAlias */) && (semanticMeaning & 2 /* Type */)) {
prefixNextMeaning();
- displayParts.push(ts.keywordPart(150 /* TypeKeyword */));
+ displayParts.push(ts.keywordPart(151 /* TypeKeyword */));
displayParts.push(ts.spacePart());
addFullSymbolName(symbol);
writeTypeParametersOfSymbol(symbol, sourceFile);
@@ -138530,9 +141277,9 @@ var ts;
}
if (symbolFlags & 1536 /* Module */ && !isThisExpression) {
prefixNextMeaning();
- var declaration = ts.getDeclarationOfKind(symbol, 259 /* ModuleDeclaration */);
+ var declaration = ts.getDeclarationOfKind(symbol, 260 /* ModuleDeclaration */);
var isNamespace = declaration && declaration.name && declaration.name.kind === 79 /* Identifier */;
- displayParts.push(ts.keywordPart(isNamespace ? 141 /* NamespaceKeyword */ : 140 /* ModuleKeyword */));
+ displayParts.push(ts.keywordPart(isNamespace ? 142 /* NamespaceKeyword */ : 141 /* ModuleKeyword */));
displayParts.push(ts.spacePart());
addFullSymbolName(symbol);
}
@@ -138551,7 +141298,7 @@ var ts;
}
else {
// Method/function type parameter
- var decl = ts.getDeclarationOfKind(symbol, 161 /* TypeParameter */);
+ var decl = ts.getDeclarationOfKind(symbol, 162 /* TypeParameter */);
if (decl === undefined)
return ts.Debug.fail();
var declaration = decl.parent;
@@ -138559,21 +141306,21 @@ var ts;
if (ts.isFunctionLikeKind(declaration.kind)) {
addInPrefix();
var signature = typeChecker.getSignatureFromDeclaration(declaration); // TODO: GH#18217
- if (declaration.kind === 173 /* ConstructSignature */) {
+ if (declaration.kind === 174 /* ConstructSignature */) {
displayParts.push(ts.keywordPart(103 /* NewKeyword */));
displayParts.push(ts.spacePart());
}
- else if (declaration.kind !== 172 /* CallSignature */ && declaration.name) {
+ else if (declaration.kind !== 173 /* CallSignature */ && declaration.name) {
addFullSymbolName(declaration.symbol);
}
ts.addRange(displayParts, ts.signatureToDisplayParts(typeChecker, signature, sourceFile, 32 /* WriteTypeArgumentsOfSignature */));
}
- else if (declaration.kind === 257 /* TypeAliasDeclaration */) {
+ else if (declaration.kind === 258 /* TypeAliasDeclaration */) {
// Type alias type parameter
// For example
// type list = T[]; // Both T will go through same code path
addInPrefix();
- displayParts.push(ts.keywordPart(150 /* TypeKeyword */));
+ displayParts.push(ts.keywordPart(151 /* TypeKeyword */));
displayParts.push(ts.spacePart());
addFullSymbolName(declaration.symbol);
writeTypeParametersOfSymbol(declaration.symbol, sourceFile);
@@ -138585,7 +141332,7 @@ var ts;
symbolKind = "enum member" /* enumMemberElement */;
addPrefixForAnyFunctionOrVar(symbol, "enum member");
var declaration = (_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a[0];
- if ((declaration === null || declaration === void 0 ? void 0 : declaration.kind) === 294 /* EnumMember */) {
+ if ((declaration === null || declaration === void 0 ? void 0 : declaration.kind) === 297 /* EnumMember */) {
var constantValue = typeChecker.getConstantValue(declaration);
if (constantValue !== undefined) {
displayParts.push(ts.spacePart());
@@ -138621,17 +141368,17 @@ var ts;
}
if (symbol.declarations) {
switch (symbol.declarations[0].kind) {
- case 262 /* NamespaceExportDeclaration */:
+ case 263 /* NamespaceExportDeclaration */:
displayParts.push(ts.keywordPart(93 /* ExportKeyword */));
displayParts.push(ts.spacePart());
- displayParts.push(ts.keywordPart(141 /* NamespaceKeyword */));
+ displayParts.push(ts.keywordPart(142 /* NamespaceKeyword */));
break;
- case 269 /* ExportAssignment */:
+ case 270 /* ExportAssignment */:
displayParts.push(ts.keywordPart(93 /* ExportKeyword */));
displayParts.push(ts.spacePart());
displayParts.push(ts.keywordPart(symbol.declarations[0].isExportEquals ? 63 /* EqualsToken */ : 88 /* DefaultKeyword */));
break;
- case 273 /* ExportSpecifier */:
+ case 274 /* ExportSpecifier */:
displayParts.push(ts.keywordPart(93 /* ExportKeyword */));
break;
default:
@@ -138641,13 +141388,13 @@ var ts;
displayParts.push(ts.spacePart());
addFullSymbolName(symbol);
ts.forEach(symbol.declarations, function (declaration) {
- if (declaration.kind === 263 /* ImportEqualsDeclaration */) {
+ if (declaration.kind === 264 /* ImportEqualsDeclaration */) {
var importEqualsDeclaration = declaration;
if (ts.isExternalModuleImportEqualsDeclaration(importEqualsDeclaration)) {
displayParts.push(ts.spacePart());
displayParts.push(ts.operatorPart(63 /* EqualsToken */));
displayParts.push(ts.spacePart());
- displayParts.push(ts.keywordPart(144 /* RequireKeyword */));
+ displayParts.push(ts.keywordPart(145 /* RequireKeyword */));
displayParts.push(ts.punctuationPart(20 /* OpenParenToken */));
displayParts.push(ts.displayPart(ts.getTextOfNode(ts.getExternalModuleImportEqualsDeclarationExpression(importEqualsDeclaration)), ts.SymbolDisplayPartKind.stringLiteral));
displayParts.push(ts.punctuationPart(21 /* CloseParenToken */));
@@ -138728,10 +141475,10 @@ var ts;
// For some special property access expressions like `exports.foo = foo` or `module.exports.foo = foo`
// there documentation comments might be attached to the right hand side symbol of their declarations.
// The pattern of such special property access is that the parent symbol is the symbol of the file.
- if (symbol.parent && symbol.declarations && ts.forEach(symbol.parent.declarations, function (declaration) { return declaration.kind === 300 /* SourceFile */; })) {
+ if (symbol.parent && symbol.declarations && ts.forEach(symbol.parent.declarations, function (declaration) { return declaration.kind === 303 /* SourceFile */; })) {
for (var _i = 0, _b = symbol.declarations; _i < _b.length; _i++) {
var declaration = _b[_i];
- if (!declaration.parent || declaration.parent.kind !== 219 /* BinaryExpression */) {
+ if (!declaration.parent || declaration.parent.kind !== 220 /* BinaryExpression */) {
continue;
}
var rhsSymbol = typeChecker.getSymbolAtLocation(declaration.parent.right);
@@ -138849,16 +141596,16 @@ var ts;
}
return ts.forEach(symbol.declarations, function (declaration) {
// Function expressions are local
- if (declaration.kind === 211 /* FunctionExpression */) {
+ if (declaration.kind === 212 /* FunctionExpression */) {
return true;
}
- if (declaration.kind !== 252 /* VariableDeclaration */ && declaration.kind !== 254 /* FunctionDeclaration */) {
+ if (declaration.kind !== 253 /* VariableDeclaration */ && declaration.kind !== 255 /* FunctionDeclaration */) {
return false;
}
// If the parent is not sourceFile or module block it is local variable
for (var parent = declaration.parent; !ts.isFunctionBlock(parent); parent = parent.parent) {
// Reached source file or module block
- if (parent.kind === 300 /* SourceFile */ || parent.kind === 260 /* ModuleBlock */) {
+ if (parent.kind === 303 /* SourceFile */ || parent.kind === 261 /* ModuleBlock */) {
return false;
}
}
@@ -138899,7 +141646,7 @@ var ts;
options.allowNonTsExtensions = true;
// if jsx is specified then treat file as .tsx
var inputFileName = transpileOptions.fileName || (transpileOptions.compilerOptions && transpileOptions.compilerOptions.jsx ? "module.tsx" : "module.ts");
- var sourceFile = ts.createSourceFile(inputFileName, input, options.target); // TODO: GH#18217
+ var sourceFile = ts.createSourceFile(inputFileName, input, ts.getEmitScriptTarget(options));
if (transpileOptions.moduleName) {
sourceFile.moduleName = transpileOptions.moduleName;
}
@@ -138963,7 +141710,7 @@ var ts;
commandLineOptionsStringToEnum = commandLineOptionsStringToEnum ||
ts.filter(ts.optionDeclarations, function (o) { return typeof o.type === "object" && !ts.forEachEntry(o.type, function (v) { return typeof v !== "number"; }); });
options = ts.cloneCompilerOptions(options);
- var _loop_9 = function (opt) {
+ var _loop_10 = function (opt) {
if (!ts.hasProperty(options, opt.name)) {
return "continue";
}
@@ -138982,7 +141729,7 @@ var ts;
};
for (var _i = 0, commandLineOptionsStringToEnum_1 = commandLineOptionsStringToEnum; _i < commandLineOptionsStringToEnum_1.length; _i++) {
var opt = commandLineOptionsStringToEnum_1[_i];
- _loop_9(opt);
+ _loop_10(opt);
}
return options;
}
@@ -139158,10 +141905,10 @@ var ts;
function shouldRescanJsxIdentifier(node) {
if (node.parent) {
switch (node.parent.kind) {
- case 283 /* JsxAttribute */:
- case 278 /* JsxOpeningElement */:
- case 279 /* JsxClosingElement */:
- case 277 /* JsxSelfClosingElement */:
+ case 284 /* JsxAttribute */:
+ case 279 /* JsxOpeningElement */:
+ case 280 /* JsxClosingElement */:
+ case 278 /* JsxSelfClosingElement */:
// May parse an identifier like `module-layout`; that will be scanned as a keyword at first, but we should parse the whole thing to get an identifier.
return ts.isKeyword(node.kind) || node.kind === 79 /* Identifier */;
}
@@ -139355,7 +142102,7 @@ var ts;
(function (formatting) {
function getAllRules() {
var allTokens = [];
- for (var token = 0 /* FirstToken */; token <= 158 /* LastToken */; token++) {
+ for (var token = 0 /* FirstToken */; token <= 159 /* LastToken */; token++) {
if (token !== 1 /* EndOfFileToken */) {
allTokens.push(token);
}
@@ -139370,9 +142117,9 @@ var ts;
var anyToken = { tokens: allTokens, isSpecific: false };
var anyTokenIncludingMultilineComments = tokenRangeFrom(__spreadArray(__spreadArray([], allTokens, true), [3 /* MultiLineCommentTrivia */], false));
var anyTokenIncludingEOF = tokenRangeFrom(__spreadArray(__spreadArray([], allTokens, true), [1 /* EndOfFileToken */], false));
- var keywords = tokenRangeFromRange(81 /* FirstKeyword */, 158 /* LastKeyword */);
+ var keywords = tokenRangeFromRange(81 /* FirstKeyword */, 159 /* LastKeyword */);
var binaryOperators = tokenRangeFromRange(29 /* FirstBinaryOperator */, 78 /* LastBinaryOperator */);
- var binaryKeywordOperators = [101 /* InKeyword */, 102 /* InstanceOfKeyword */, 158 /* OfKeyword */, 127 /* AsKeyword */, 138 /* IsKeyword */];
+ var binaryKeywordOperators = [101 /* InKeyword */, 102 /* InstanceOfKeyword */, 159 /* OfKeyword */, 127 /* AsKeyword */, 139 /* IsKeyword */];
var unaryPrefixOperators = [45 /* PlusPlusToken */, 46 /* MinusMinusToken */, 54 /* TildeToken */, 53 /* ExclamationToken */];
var unaryPrefixExpressions = [
8 /* NumericLiteral */, 9 /* BigIntLiteral */, 79 /* Identifier */, 20 /* OpenParenToken */,
@@ -139446,11 +142193,11 @@ var ts;
// Though, we do extra check on the context to make sure we are dealing with get/set node. Example:
// get x() {}
// set x(val) {}
- rule("SpaceAfterGetSetInMember", [135 /* GetKeyword */, 147 /* SetKeyword */], 79 /* Identifier */, [isFunctionDeclContext], 4 /* InsertSpace */),
+ rule("SpaceAfterGetSetInMember", [136 /* GetKeyword */, 148 /* SetKeyword */], 79 /* Identifier */, [isFunctionDeclContext], 4 /* InsertSpace */),
rule("NoSpaceBetweenYieldKeywordAndStar", 125 /* YieldKeyword */, 41 /* AsteriskToken */, [isNonJsxSameLineTokenContext, isYieldOrYieldStarWithOperand], 16 /* DeleteSpace */),
rule("SpaceBetweenYieldOrYieldStarAndOperand", [125 /* YieldKeyword */, 41 /* AsteriskToken */], anyToken, [isNonJsxSameLineTokenContext, isYieldOrYieldStarWithOperand], 4 /* InsertSpace */),
rule("NoSpaceBetweenReturnAndSemicolon", 105 /* ReturnKeyword */, 26 /* SemicolonToken */, [isNonJsxSameLineTokenContext], 16 /* DeleteSpace */),
- rule("SpaceAfterCertainKeywords", [113 /* VarKeyword */, 109 /* ThrowKeyword */, 103 /* NewKeyword */, 89 /* DeleteKeyword */, 105 /* ReturnKeyword */, 112 /* TypeOfKeyword */, 131 /* AwaitKeyword */], anyToken, [isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
+ rule("SpaceAfterCertainKeywords", [113 /* VarKeyword */, 109 /* ThrowKeyword */, 103 /* NewKeyword */, 89 /* DeleteKeyword */, 105 /* ReturnKeyword */, 112 /* TypeOfKeyword */, 132 /* AwaitKeyword */], anyToken, [isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
rule("SpaceAfterLetConstInVariableDeclaration", [119 /* LetKeyword */, 85 /* ConstKeyword */], anyToken, [isNonJsxSameLineTokenContext, isStartOfVariableDeclarationList], 4 /* InsertSpace */),
rule("NoSpaceBeforeOpenParenInFuncCall", anyToken, 20 /* OpenParenToken */, [isNonJsxSameLineTokenContext, isFunctionCallOrNewContext, isPreviousTokenNotComma], 16 /* DeleteSpace */),
// Special case for binary operators (that are keywords). For these we have to add a space and shouldn't follow any user options.
@@ -139458,8 +142205,8 @@ var ts;
rule("SpaceAfterBinaryKeywordOperator", binaryKeywordOperators, anyToken, [isNonJsxSameLineTokenContext, isBinaryOpContext], 4 /* InsertSpace */),
rule("SpaceAfterVoidOperator", 114 /* VoidKeyword */, anyToken, [isNonJsxSameLineTokenContext, isVoidOpContext], 4 /* InsertSpace */),
// Async-await
- rule("SpaceBetweenAsyncAndOpenParen", 130 /* AsyncKeyword */, 20 /* OpenParenToken */, [isArrowFunctionContext, isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
- rule("SpaceBetweenAsyncAndFunctionKeyword", 130 /* AsyncKeyword */, [98 /* FunctionKeyword */, 79 /* Identifier */], [isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
+ rule("SpaceBetweenAsyncAndOpenParen", 131 /* AsyncKeyword */, 20 /* OpenParenToken */, [isArrowFunctionContext, isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
+ rule("SpaceBetweenAsyncAndFunctionKeyword", 131 /* AsyncKeyword */, [98 /* FunctionKeyword */, 79 /* Identifier */], [isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
// Template string
rule("NoSpaceBetweenTagAndTemplateString", [79 /* Identifier */, 21 /* CloseParenToken */], [14 /* NoSubstitutionTemplateLiteral */, 15 /* TemplateHead */], [isNonJsxSameLineTokenContext], 16 /* DeleteSpace */),
// JSX opening elements
@@ -139470,34 +142217,34 @@ var ts;
rule("NoSpaceAfterEqualInJsxAttribute", 63 /* EqualsToken */, anyToken, [isJsxAttributeContext, isNonJsxSameLineTokenContext], 16 /* DeleteSpace */),
// TypeScript-specific rules
// Use of module as a function call. e.g.: import m2 = module("m2");
- rule("NoSpaceAfterModuleImport", [140 /* ModuleKeyword */, 144 /* RequireKeyword */], 20 /* OpenParenToken */, [isNonJsxSameLineTokenContext], 16 /* DeleteSpace */),
+ rule("NoSpaceAfterModuleImport", [141 /* ModuleKeyword */, 145 /* RequireKeyword */], 20 /* OpenParenToken */, [isNonJsxSameLineTokenContext], 16 /* DeleteSpace */),
// Add a space around certain TypeScript keywords
rule("SpaceAfterCertainTypeScriptKeywords", [
126 /* AbstractKeyword */,
84 /* ClassKeyword */,
- 134 /* DeclareKeyword */,
+ 135 /* DeclareKeyword */,
88 /* DefaultKeyword */,
92 /* EnumKeyword */,
93 /* ExportKeyword */,
94 /* ExtendsKeyword */,
- 135 /* GetKeyword */,
+ 136 /* GetKeyword */,
117 /* ImplementsKeyword */,
100 /* ImportKeyword */,
118 /* InterfaceKeyword */,
- 140 /* ModuleKeyword */,
- 141 /* NamespaceKeyword */,
+ 141 /* ModuleKeyword */,
+ 142 /* NamespaceKeyword */,
121 /* PrivateKeyword */,
123 /* PublicKeyword */,
122 /* ProtectedKeyword */,
- 143 /* ReadonlyKeyword */,
- 147 /* SetKeyword */,
+ 144 /* ReadonlyKeyword */,
+ 148 /* SetKeyword */,
124 /* StaticKeyword */,
- 150 /* TypeKeyword */,
- 154 /* FromKeyword */,
- 139 /* KeyOfKeyword */,
- 136 /* InferKeyword */,
+ 151 /* TypeKeyword */,
+ 155 /* FromKeyword */,
+ 140 /* KeyOfKeyword */,
+ 137 /* InferKeyword */,
], anyToken, [isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
- rule("SpaceBeforeCertainTypeScriptKeywords", anyToken, [94 /* ExtendsKeyword */, 117 /* ImplementsKeyword */, 154 /* FromKeyword */], [isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
+ rule("SpaceBeforeCertainTypeScriptKeywords", anyToken, [94 /* ExtendsKeyword */, 117 /* ImplementsKeyword */, 155 /* FromKeyword */], [isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
// Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" {
rule("SpaceAfterModuleName", 10 /* StringLiteral */, 18 /* OpenBraceToken */, [isModuleDeclContext], 4 /* InsertSpace */),
// Lambda expressions
@@ -139528,8 +142275,8 @@ var ts;
123 /* PublicKeyword */,
121 /* PrivateKeyword */,
122 /* ProtectedKeyword */,
- 135 /* GetKeyword */,
- 147 /* SetKeyword */,
+ 136 /* GetKeyword */,
+ 148 /* SetKeyword */,
22 /* OpenBracketToken */,
41 /* AsteriskToken */,
], [isEndOfDecoratorContextOnSameLine], 4 /* InsertSpace */),
@@ -139540,8 +142287,8 @@ var ts;
// These rules are applied after high priority
var userConfigurableRules = [
// Treat constructor as an identifier in a function declaration, and remove spaces between constructor and following left parentheses
- rule("SpaceAfterConstructor", 133 /* ConstructorKeyword */, 20 /* OpenParenToken */, [isOptionEnabled("insertSpaceAfterConstructor"), isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
- rule("NoSpaceAfterConstructor", 133 /* ConstructorKeyword */, 20 /* OpenParenToken */, [isOptionDisabledOrUndefined("insertSpaceAfterConstructor"), isNonJsxSameLineTokenContext], 16 /* DeleteSpace */),
+ rule("SpaceAfterConstructor", 134 /* ConstructorKeyword */, 20 /* OpenParenToken */, [isOptionEnabled("insertSpaceAfterConstructor"), isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
+ rule("NoSpaceAfterConstructor", 134 /* ConstructorKeyword */, 20 /* OpenParenToken */, [isOptionDisabledOrUndefined("insertSpaceAfterConstructor"), isNonJsxSameLineTokenContext], 16 /* DeleteSpace */),
rule("SpaceAfterComma", 27 /* CommaToken */, anyToken, [isOptionEnabled("insertSpaceAfterCommaDelimiter"), isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext, isNextTokenNotCloseBracket, isNextTokenNotCloseParen], 4 /* InsertSpace */),
rule("NoSpaceAfterComma", 27 /* CommaToken */, anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterCommaDelimiter"), isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext], 16 /* DeleteSpace */),
// Insert space after function keyword for anonymous functions
@@ -139615,11 +142362,11 @@ var ts;
rule("SpaceBeforeOpenBraceInTypeScriptDeclWithBlock", typeScriptOpenBraceLeftTokenRange, 18 /* OpenBraceToken */, [isOptionDisabledOrUndefinedOrTokensOnSameLine("placeOpenBraceOnNewLineForFunctions"), isTypeScriptDeclWithBlockContext, isNotFormatOnEnter, isSameLineTokenOrBeforeBlockContext], 4 /* InsertSpace */, 1 /* CanDeleteNewLines */),
rule("NoSpaceBeforeComma", anyToken, 27 /* CommaToken */, [isNonJsxSameLineTokenContext], 16 /* DeleteSpace */),
// No space before and after indexer `x[]`
- rule("NoSpaceBeforeOpenBracket", anyTokenExcept(130 /* AsyncKeyword */, 82 /* CaseKeyword */), 22 /* OpenBracketToken */, [isNonJsxSameLineTokenContext], 16 /* DeleteSpace */),
+ rule("NoSpaceBeforeOpenBracket", anyTokenExcept(131 /* AsyncKeyword */, 82 /* CaseKeyword */), 22 /* OpenBracketToken */, [isNonJsxSameLineTokenContext], 16 /* DeleteSpace */),
rule("NoSpaceAfterCloseBracket", 23 /* CloseBracketToken */, anyToken, [isNonJsxSameLineTokenContext, isNotBeforeBlockInFunctionDeclarationContext], 16 /* DeleteSpace */),
rule("SpaceAfterSemicolon", 26 /* SemicolonToken */, anyToken, [isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
// Remove extra space between for and await
- rule("SpaceBetweenForAndAwaitKeyword", 97 /* ForKeyword */, 131 /* AwaitKeyword */, [isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
+ rule("SpaceBetweenForAndAwaitKeyword", 97 /* ForKeyword */, 132 /* AwaitKeyword */, [isNonJsxSameLineTokenContext], 4 /* InsertSpace */),
// Add a space between statements. All keywords except (do,else,case) has open/close parens after them.
// So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any]
rule("SpaceBetweenStatements", [21 /* CloseParenToken */, 90 /* DoKeyword */, 91 /* ElseKeyword */, 82 /* CaseKeyword */], anyToken, [isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext, isNotForContext], 4 /* InsertSpace */),
@@ -139683,54 +142430,54 @@ var ts;
return function (context) { return !context.options || !context.options.hasOwnProperty(optionName) || !!context.options[optionName]; };
}
function isForContext(context) {
- return context.contextNode.kind === 240 /* ForStatement */;
+ return context.contextNode.kind === 241 /* ForStatement */;
}
function isNotForContext(context) {
return !isForContext(context);
}
function isBinaryOpContext(context) {
switch (context.contextNode.kind) {
- case 219 /* BinaryExpression */:
+ case 220 /* BinaryExpression */:
return context.contextNode.operatorToken.kind !== 27 /* CommaToken */;
- case 220 /* ConditionalExpression */:
- case 187 /* ConditionalType */:
- case 227 /* AsExpression */:
- case 273 /* ExportSpecifier */:
- case 268 /* ImportSpecifier */:
- case 175 /* TypePredicate */:
- case 185 /* UnionType */:
- case 186 /* IntersectionType */:
+ case 221 /* ConditionalExpression */:
+ case 188 /* ConditionalType */:
+ case 228 /* AsExpression */:
+ case 274 /* ExportSpecifier */:
+ case 269 /* ImportSpecifier */:
+ case 176 /* TypePredicate */:
+ case 186 /* UnionType */:
+ case 187 /* IntersectionType */:
return true;
// equals in binding elements: function foo([[x, y] = [1, 2]])
- case 201 /* BindingElement */:
+ case 202 /* BindingElement */:
// equals in type X = ...
// falls through
- case 257 /* TypeAliasDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
// equal in import a = module('a');
// falls through
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
// equal in export = 1
// falls through
- case 269 /* ExportAssignment */:
+ case 270 /* ExportAssignment */:
// equal in let a = 0
// falls through
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
// equal in p = 0
// falls through
- case 162 /* Parameter */:
- case 294 /* EnumMember */:
- case 165 /* PropertyDeclaration */:
- case 164 /* PropertySignature */:
+ case 163 /* Parameter */:
+ case 297 /* EnumMember */:
+ case 166 /* PropertyDeclaration */:
+ case 165 /* PropertySignature */:
return context.currentTokenSpan.kind === 63 /* EqualsToken */ || context.nextTokenSpan.kind === 63 /* EqualsToken */;
// "in" keyword in for (let x in []) { }
- case 241 /* ForInStatement */:
+ case 242 /* ForInStatement */:
// "in" keyword in [P in keyof T]: T[P]
// falls through
- case 161 /* TypeParameter */:
+ case 162 /* TypeParameter */:
return context.currentTokenSpan.kind === 101 /* InKeyword */ || context.nextTokenSpan.kind === 101 /* InKeyword */ || context.currentTokenSpan.kind === 63 /* EqualsToken */ || context.nextTokenSpan.kind === 63 /* EqualsToken */;
// Technically, "of" is not a binary operator, but format it the same way as "in"
- case 242 /* ForOfStatement */:
- return context.currentTokenSpan.kind === 158 /* OfKeyword */ || context.nextTokenSpan.kind === 158 /* OfKeyword */;
+ case 243 /* ForOfStatement */:
+ return context.currentTokenSpan.kind === 159 /* OfKeyword */ || context.nextTokenSpan.kind === 159 /* OfKeyword */;
}
return false;
}
@@ -139742,22 +142489,22 @@ var ts;
}
function isTypeAnnotationContext(context) {
var contextKind = context.contextNode.kind;
- return contextKind === 165 /* PropertyDeclaration */ ||
- contextKind === 164 /* PropertySignature */ ||
- contextKind === 162 /* Parameter */ ||
- contextKind === 252 /* VariableDeclaration */ ||
+ return contextKind === 166 /* PropertyDeclaration */ ||
+ contextKind === 165 /* PropertySignature */ ||
+ contextKind === 163 /* Parameter */ ||
+ contextKind === 253 /* VariableDeclaration */ ||
ts.isFunctionLikeKind(contextKind);
}
function isConditionalOperatorContext(context) {
- return context.contextNode.kind === 220 /* ConditionalExpression */ ||
- context.contextNode.kind === 187 /* ConditionalType */;
+ return context.contextNode.kind === 221 /* ConditionalExpression */ ||
+ context.contextNode.kind === 188 /* ConditionalType */;
}
function isSameLineTokenOrBeforeBlockContext(context) {
return context.TokensAreOnSameLine() || isBeforeBlockContext(context);
}
function isBraceWrappedContext(context) {
- return context.contextNode.kind === 199 /* ObjectBindingPattern */ ||
- context.contextNode.kind === 193 /* MappedType */ ||
+ return context.contextNode.kind === 200 /* ObjectBindingPattern */ ||
+ context.contextNode.kind === 194 /* MappedType */ ||
isSingleLineBlockContext(context);
}
// This check is done before an open brace in a control construct, a function, or a typescript block declaration
@@ -139783,34 +142530,34 @@ var ts;
return true;
}
switch (node.kind) {
- case 233 /* Block */:
- case 261 /* CaseBlock */:
- case 203 /* ObjectLiteralExpression */:
- case 260 /* ModuleBlock */:
+ case 234 /* Block */:
+ case 262 /* CaseBlock */:
+ case 204 /* ObjectLiteralExpression */:
+ case 261 /* ModuleBlock */:
return true;
}
return false;
}
function isFunctionDeclContext(context) {
switch (context.contextNode.kind) {
- case 254 /* FunctionDeclaration */:
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
+ case 255 /* FunctionDeclaration */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
// case SyntaxKind.MemberFunctionDeclaration:
// falls through
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
// case SyntaxKind.MethodSignature:
// falls through
- case 172 /* CallSignature */:
- case 211 /* FunctionExpression */:
- case 169 /* Constructor */:
- case 212 /* ArrowFunction */:
+ case 173 /* CallSignature */:
+ case 212 /* FunctionExpression */:
+ case 170 /* Constructor */:
+ case 213 /* ArrowFunction */:
// case SyntaxKind.ConstructorDeclaration:
// case SyntaxKind.SimpleArrowFunctionExpression:
// case SyntaxKind.ParenthesizedArrowFunctionExpression:
// falls through
- case 256 /* InterfaceDeclaration */: // This one is not truly a function, but for formatting purposes, it acts just like one
+ case 257 /* InterfaceDeclaration */: // This one is not truly a function, but for formatting purposes, it acts just like one
return true;
}
return false;
@@ -139819,40 +142566,40 @@ var ts;
return !isFunctionDeclContext(context);
}
function isFunctionDeclarationOrFunctionExpressionContext(context) {
- return context.contextNode.kind === 254 /* FunctionDeclaration */ || context.contextNode.kind === 211 /* FunctionExpression */;
+ return context.contextNode.kind === 255 /* FunctionDeclaration */ || context.contextNode.kind === 212 /* FunctionExpression */;
}
function isTypeScriptDeclWithBlockContext(context) {
return nodeIsTypeScriptDeclWithBlockContext(context.contextNode);
}
function nodeIsTypeScriptDeclWithBlockContext(node) {
switch (node.kind) {
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
- case 256 /* InterfaceDeclaration */:
- case 258 /* EnumDeclaration */:
- case 180 /* TypeLiteral */:
- case 259 /* ModuleDeclaration */:
- case 270 /* ExportDeclaration */:
- case 271 /* NamedExports */:
- case 264 /* ImportDeclaration */:
- case 267 /* NamedImports */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
+ case 257 /* InterfaceDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 181 /* TypeLiteral */:
+ case 260 /* ModuleDeclaration */:
+ case 271 /* ExportDeclaration */:
+ case 272 /* NamedExports */:
+ case 265 /* ImportDeclaration */:
+ case 268 /* NamedImports */:
return true;
}
return false;
}
function isAfterCodeBlockContext(context) {
switch (context.currentTokenParent.kind) {
- case 255 /* ClassDeclaration */:
- case 259 /* ModuleDeclaration */:
- case 258 /* EnumDeclaration */:
- case 290 /* CatchClause */:
- case 260 /* ModuleBlock */:
- case 247 /* SwitchStatement */:
+ case 256 /* ClassDeclaration */:
+ case 260 /* ModuleDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 291 /* CatchClause */:
+ case 261 /* ModuleBlock */:
+ case 248 /* SwitchStatement */:
return true;
- case 233 /* Block */: {
+ case 234 /* Block */: {
var blockParent = context.currentTokenParent.parent;
// In a codefix scenario, we can't rely on parents being set. So just always return true.
- if (!blockParent || blockParent.kind !== 212 /* ArrowFunction */ && blockParent.kind !== 211 /* FunctionExpression */) {
+ if (!blockParent || blockParent.kind !== 213 /* ArrowFunction */ && blockParent.kind !== 212 /* FunctionExpression */) {
return true;
}
}
@@ -139861,32 +142608,32 @@ var ts;
}
function isControlDeclContext(context) {
switch (context.contextNode.kind) {
- case 237 /* IfStatement */:
- case 247 /* SwitchStatement */:
- case 240 /* ForStatement */:
- case 241 /* ForInStatement */:
- case 242 /* ForOfStatement */:
- case 239 /* WhileStatement */:
- case 250 /* TryStatement */:
- case 238 /* DoStatement */:
- case 246 /* WithStatement */:
+ case 238 /* IfStatement */:
+ case 248 /* SwitchStatement */:
+ case 241 /* ForStatement */:
+ case 242 /* ForInStatement */:
+ case 243 /* ForOfStatement */:
+ case 240 /* WhileStatement */:
+ case 251 /* TryStatement */:
+ case 239 /* DoStatement */:
+ case 247 /* WithStatement */:
// TODO
// case SyntaxKind.ElseClause:
// falls through
- case 290 /* CatchClause */:
+ case 291 /* CatchClause */:
return true;
default:
return false;
}
}
function isObjectContext(context) {
- return context.contextNode.kind === 203 /* ObjectLiteralExpression */;
+ return context.contextNode.kind === 204 /* ObjectLiteralExpression */;
}
function isFunctionCallContext(context) {
- return context.contextNode.kind === 206 /* CallExpression */;
+ return context.contextNode.kind === 207 /* CallExpression */;
}
function isNewContext(context) {
- return context.contextNode.kind === 207 /* NewExpression */;
+ return context.contextNode.kind === 208 /* NewExpression */;
}
function isFunctionCallOrNewContext(context) {
return isFunctionCallContext(context) || isNewContext(context);
@@ -139901,10 +142648,10 @@ var ts;
return context.nextTokenSpan.kind !== 21 /* CloseParenToken */;
}
function isArrowFunctionContext(context) {
- return context.contextNode.kind === 212 /* ArrowFunction */;
+ return context.contextNode.kind === 213 /* ArrowFunction */;
}
function isImportTypeContext(context) {
- return context.contextNode.kind === 198 /* ImportType */;
+ return context.contextNode.kind === 199 /* ImportType */;
}
function isNonJsxSameLineTokenContext(context) {
return context.TokensAreOnSameLine() && context.contextNode.kind !== 11 /* JsxText */;
@@ -139913,19 +142660,19 @@ var ts;
return context.contextNode.kind !== 11 /* JsxText */;
}
function isNonJsxElementOrFragmentContext(context) {
- return context.contextNode.kind !== 276 /* JsxElement */ && context.contextNode.kind !== 280 /* JsxFragment */;
+ return context.contextNode.kind !== 277 /* JsxElement */ && context.contextNode.kind !== 281 /* JsxFragment */;
}
function isJsxExpressionContext(context) {
- return context.contextNode.kind === 286 /* JsxExpression */ || context.contextNode.kind === 285 /* JsxSpreadAttribute */;
+ return context.contextNode.kind === 287 /* JsxExpression */ || context.contextNode.kind === 286 /* JsxSpreadAttribute */;
}
function isNextTokenParentJsxAttribute(context) {
- return context.nextTokenParent.kind === 283 /* JsxAttribute */;
+ return context.nextTokenParent.kind === 284 /* JsxAttribute */;
}
function isJsxAttributeContext(context) {
- return context.contextNode.kind === 283 /* JsxAttribute */;
+ return context.contextNode.kind === 284 /* JsxAttribute */;
}
function isJsxSelfClosingElementContext(context) {
- return context.contextNode.kind === 277 /* JsxSelfClosingElement */;
+ return context.contextNode.kind === 278 /* JsxSelfClosingElement */;
}
function isNotBeforeBlockInFunctionDeclarationContext(context) {
return !isFunctionDeclContext(context) && !isBeforeBlockContext(context);
@@ -139940,45 +142687,45 @@ var ts;
while (ts.isExpressionNode(node)) {
node = node.parent;
}
- return node.kind === 163 /* Decorator */;
+ return node.kind === 164 /* Decorator */;
}
function isStartOfVariableDeclarationList(context) {
- return context.currentTokenParent.kind === 253 /* VariableDeclarationList */ &&
+ return context.currentTokenParent.kind === 254 /* VariableDeclarationList */ &&
context.currentTokenParent.getStart(context.sourceFile) === context.currentTokenSpan.pos;
}
function isNotFormatOnEnter(context) {
return context.formattingRequestKind !== 2 /* FormatOnEnter */;
}
function isModuleDeclContext(context) {
- return context.contextNode.kind === 259 /* ModuleDeclaration */;
+ return context.contextNode.kind === 260 /* ModuleDeclaration */;
}
function isObjectTypeContext(context) {
- return context.contextNode.kind === 180 /* TypeLiteral */; // && context.contextNode.parent.kind !== SyntaxKind.InterfaceDeclaration;
+ return context.contextNode.kind === 181 /* TypeLiteral */; // && context.contextNode.parent.kind !== SyntaxKind.InterfaceDeclaration;
}
function isConstructorSignatureContext(context) {
- return context.contextNode.kind === 173 /* ConstructSignature */;
+ return context.contextNode.kind === 174 /* ConstructSignature */;
}
function isTypeArgumentOrParameterOrAssertion(token, parent) {
if (token.kind !== 29 /* LessThanToken */ && token.kind !== 31 /* GreaterThanToken */) {
return false;
}
switch (parent.kind) {
- case 176 /* TypeReference */:
- case 209 /* TypeAssertionExpression */:
- case 257 /* TypeAliasDeclaration */:
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
- case 256 /* InterfaceDeclaration */:
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
- case 172 /* CallSignature */:
- case 173 /* ConstructSignature */:
- case 206 /* CallExpression */:
- case 207 /* NewExpression */:
- case 226 /* ExpressionWithTypeArguments */:
+ case 177 /* TypeReference */:
+ case 210 /* TypeAssertionExpression */:
+ case 258 /* TypeAliasDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
+ case 257 /* InterfaceDeclaration */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
+ case 173 /* CallSignature */:
+ case 174 /* ConstructSignature */:
+ case 207 /* CallExpression */:
+ case 208 /* NewExpression */:
+ case 227 /* ExpressionWithTypeArguments */:
return true;
default:
return false;
@@ -139989,28 +142736,28 @@ var ts;
isTypeArgumentOrParameterOrAssertion(context.nextTokenSpan, context.nextTokenParent);
}
function isTypeAssertionContext(context) {
- return context.contextNode.kind === 209 /* TypeAssertionExpression */;
+ return context.contextNode.kind === 210 /* TypeAssertionExpression */;
}
function isVoidOpContext(context) {
- return context.currentTokenSpan.kind === 114 /* VoidKeyword */ && context.currentTokenParent.kind === 215 /* VoidExpression */;
+ return context.currentTokenSpan.kind === 114 /* VoidKeyword */ && context.currentTokenParent.kind === 216 /* VoidExpression */;
}
function isYieldOrYieldStarWithOperand(context) {
- return context.contextNode.kind === 222 /* YieldExpression */ && context.contextNode.expression !== undefined;
+ return context.contextNode.kind === 223 /* YieldExpression */ && context.contextNode.expression !== undefined;
}
function isNonNullAssertionContext(context) {
- return context.contextNode.kind === 228 /* NonNullExpression */;
+ return context.contextNode.kind === 229 /* NonNullExpression */;
}
function isNotStatementConditionContext(context) {
return !isStatementConditionContext(context);
}
function isStatementConditionContext(context) {
switch (context.contextNode.kind) {
- case 237 /* IfStatement */:
- case 240 /* ForStatement */:
- case 241 /* ForInStatement */:
- case 242 /* ForOfStatement */:
- case 238 /* DoStatement */:
- case 239 /* WhileStatement */:
+ case 238 /* IfStatement */:
+ case 241 /* ForStatement */:
+ case 242 /* ForInStatement */:
+ case 243 /* ForOfStatement */:
+ case 239 /* DoStatement */:
+ case 240 /* WhileStatement */:
return true;
default:
return false;
@@ -140035,12 +142782,12 @@ var ts;
return nextTokenKind === 19 /* CloseBraceToken */
|| nextTokenKind === 1 /* EndOfFileToken */;
}
- if (nextTokenKind === 232 /* SemicolonClassElement */ ||
+ if (nextTokenKind === 233 /* SemicolonClassElement */ ||
nextTokenKind === 26 /* SemicolonToken */) {
return false;
}
- if (context.contextNode.kind === 256 /* InterfaceDeclaration */ ||
- context.contextNode.kind === 257 /* TypeAliasDeclaration */) {
+ if (context.contextNode.kind === 257 /* InterfaceDeclaration */ ||
+ context.contextNode.kind === 258 /* TypeAliasDeclaration */) {
// Can’t remove semicolon after `foo`; it would parse as a method declaration:
//
// interface I {
@@ -140054,9 +142801,9 @@ var ts;
if (ts.isPropertyDeclaration(context.currentTokenParent)) {
return !context.currentTokenParent.initializer;
}
- return context.currentTokenParent.kind !== 240 /* ForStatement */
- && context.currentTokenParent.kind !== 234 /* EmptyStatement */
- && context.currentTokenParent.kind !== 232 /* SemicolonClassElement */
+ return context.currentTokenParent.kind !== 241 /* ForStatement */
+ && context.currentTokenParent.kind !== 235 /* EmptyStatement */
+ && context.currentTokenParent.kind !== 233 /* SemicolonClassElement */
&& nextTokenKind !== 22 /* OpenBracketToken */
&& nextTokenKind !== 20 /* OpenParenToken */
&& nextTokenKind !== 39 /* PlusToken */
@@ -140064,7 +142811,7 @@ var ts;
&& nextTokenKind !== 43 /* SlashToken */
&& nextTokenKind !== 13 /* RegularExpressionLiteral */
&& nextTokenKind !== 27 /* CommaToken */
- && nextTokenKind !== 221 /* TemplateExpression */
+ && nextTokenKind !== 222 /* TemplateExpression */
&& nextTokenKind !== 15 /* TemplateHead */
&& nextTokenKind !== 14 /* NoSubstitutionTemplateLiteral */
&& nextTokenKind !== 24 /* DotToken */;
@@ -140155,12 +142902,12 @@ var ts;
return map;
}
function getRuleBucketIndex(row, column) {
- ts.Debug.assert(row <= 158 /* LastKeyword */ && column <= 158 /* LastKeyword */, "Must compute formatting context from tokens");
+ ts.Debug.assert(row <= 159 /* LastKeyword */ && column <= 159 /* LastKeyword */, "Must compute formatting context from tokens");
return (row * mapRowLength) + column;
}
var maskBitSize = 5;
var mask = 31; // MaskBitSize bits
- var mapRowLength = 158 /* LastToken */ + 1;
+ var mapRowLength = 159 /* LastToken */ + 1;
var RulesPosition;
(function (RulesPosition) {
RulesPosition[RulesPosition["StopRulesSpecific"] = 0] = "StopRulesSpecific";
@@ -140348,17 +143095,17 @@ var ts;
// i.e. parent is class declaration with the list of members and node is one of members.
function isListElement(parent, node) {
switch (parent.kind) {
- case 255 /* ClassDeclaration */:
- case 256 /* InterfaceDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 257 /* InterfaceDeclaration */:
return ts.rangeContainsRange(parent.members, node);
- case 259 /* ModuleDeclaration */:
+ case 260 /* ModuleDeclaration */:
var body = parent.body;
- return !!body && body.kind === 260 /* ModuleBlock */ && ts.rangeContainsRange(body.statements, node);
- case 300 /* SourceFile */:
- case 233 /* Block */:
- case 260 /* ModuleBlock */:
+ return !!body && body.kind === 261 /* ModuleBlock */ && ts.rangeContainsRange(body.statements, node);
+ case 303 /* SourceFile */:
+ case 234 /* Block */:
+ case 261 /* ModuleBlock */:
return ts.rangeContainsRange(parent.statements, node);
- case 290 /* CatchClause */:
+ case 291 /* CatchClause */:
return ts.rangeContainsRange(parent.block.statements, node);
}
return false;
@@ -140518,11 +143265,11 @@ var ts;
var leadingTrivia = formattingScanner.getCurrentLeadingTrivia();
if (leadingTrivia) {
indentTriviaItems(leadingTrivia, indentation, /*indentNextTokenOrTrivia*/ false, function (item) { return processRange(item, sourceFile.getLineAndCharacterOfPosition(item.pos), enclosingNode, enclosingNode, /*dynamicIndentation*/ undefined); });
+ if (options.trimTrailingWhitespace !== false) {
+ trimTrailingWhitespacesForRemainingRange(leadingTrivia);
+ }
}
}
- if (options.trimTrailingWhitespace !== false) {
- trimTrailingWhitespacesForRemainingRange();
- }
return edits;
// local functions
/** Tries to compute the indentation for a list element.
@@ -140587,19 +143334,19 @@ var ts;
return node.modifiers[0].kind;
}
switch (node.kind) {
- case 255 /* ClassDeclaration */: return 84 /* ClassKeyword */;
- case 256 /* InterfaceDeclaration */: return 118 /* InterfaceKeyword */;
- case 254 /* FunctionDeclaration */: return 98 /* FunctionKeyword */;
- case 258 /* EnumDeclaration */: return 258 /* EnumDeclaration */;
- case 170 /* GetAccessor */: return 135 /* GetKeyword */;
- case 171 /* SetAccessor */: return 147 /* SetKeyword */;
- case 167 /* MethodDeclaration */:
+ case 256 /* ClassDeclaration */: return 84 /* ClassKeyword */;
+ case 257 /* InterfaceDeclaration */: return 118 /* InterfaceKeyword */;
+ case 255 /* FunctionDeclaration */: return 98 /* FunctionKeyword */;
+ case 259 /* EnumDeclaration */: return 259 /* EnumDeclaration */;
+ case 171 /* GetAccessor */: return 136 /* GetKeyword */;
+ case 172 /* SetAccessor */: return 148 /* SetKeyword */;
+ case 168 /* MethodDeclaration */:
if (node.asteriskToken) {
return 41 /* AsteriskToken */;
}
// falls through
- case 165 /* PropertyDeclaration */:
- case 162 /* Parameter */:
+ case 166 /* PropertyDeclaration */:
+ case 163 /* Parameter */:
var name = ts.getNameOfDeclaration(node);
if (name) {
return name.kind;
@@ -140656,16 +143403,16 @@ var ts;
case 43 /* SlashToken */:
case 31 /* GreaterThanToken */:
switch (container.kind) {
- case 278 /* JsxOpeningElement */:
- case 279 /* JsxClosingElement */:
- case 277 /* JsxSelfClosingElement */:
- case 226 /* ExpressionWithTypeArguments */:
+ case 279 /* JsxOpeningElement */:
+ case 280 /* JsxClosingElement */:
+ case 278 /* JsxSelfClosingElement */:
+ case 227 /* ExpressionWithTypeArguments */:
return false;
}
break;
case 22 /* OpenBracketToken */:
case 23 /* CloseBracketToken */:
- if (container.kind !== 193 /* MappedType */) {
+ if (container.kind !== 194 /* MappedType */) {
return false;
}
break;
@@ -140768,11 +143515,11 @@ var ts;
return inheritedIndentation;
}
}
- var effectiveParentStartLine = child.kind === 163 /* Decorator */ ? childStartLine : undecoratedParentStartLine;
+ var effectiveParentStartLine = child.kind === 164 /* Decorator */ ? childStartLine : undecoratedParentStartLine;
var childIndentation = computeIndentation(child, childStartLine, childIndentationAmount, node, parentDynamicIndentation, effectiveParentStartLine);
processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta);
childContextNode = node;
- if (isFirstListItem && parent.kind === 202 /* ArrayLiteralExpression */ && inheritedIndentation === -1 /* Unknown */) {
+ if (isFirstListItem && parent.kind === 203 /* ArrayLiteralExpression */ && inheritedIndentation === -1 /* Unknown */) {
inheritedIndentation = childIndentation.indentation;
}
return inheritedIndentation;
@@ -141091,12 +143838,27 @@ var ts;
return -1;
}
/**
- * Trimming will be done for lines after the previous range
+ * Trimming will be done for lines after the previous range.
+ * Exclude comments as they had been previously processed.
*/
- function trimTrailingWhitespacesForRemainingRange() {
- var startPosition = previousRange ? previousRange.end : originalRange.pos;
- var startLine = sourceFile.getLineAndCharacterOfPosition(startPosition).line;
- var endLine = sourceFile.getLineAndCharacterOfPosition(originalRange.end).line;
+ function trimTrailingWhitespacesForRemainingRange(trivias) {
+ var startPos = previousRange ? previousRange.end : originalRange.pos;
+ for (var _i = 0, trivias_1 = trivias; _i < trivias_1.length; _i++) {
+ var trivia = trivias_1[_i];
+ if (ts.isComment(trivia.kind)) {
+ if (startPos < trivia.pos) {
+ trimTrailingWitespacesForPositions(startPos, trivia.pos - 1, previousRange);
+ }
+ startPos = trivia.end + 1;
+ }
+ }
+ if (startPos < originalRange.end) {
+ trimTrailingWitespacesForPositions(startPos, originalRange.end, previousRange);
+ }
+ }
+ function trimTrailingWitespacesForPositions(startPos, endPos, previousRange) {
+ var startLine = sourceFile.getLineAndCharacterOfPosition(startPos).line;
+ var endLine = sourceFile.getLineAndCharacterOfPosition(endPos).line;
trimTrailingWhitespacesForLines(startLine, endLine + 1, previousRange);
}
function recordDelete(start, len) {
@@ -141205,12 +143967,12 @@ var ts;
formatting.getRangeOfEnclosingComment = getRangeOfEnclosingComment;
function getOpenTokenForList(node, list) {
switch (node.kind) {
- case 169 /* Constructor */:
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
- case 212 /* ArrowFunction */:
+ case 170 /* Constructor */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
+ case 213 /* ArrowFunction */:
if (node.typeParameters === list) {
return 29 /* LessThanToken */;
}
@@ -141218,8 +143980,8 @@ var ts;
return 20 /* OpenParenToken */;
}
break;
- case 206 /* CallExpression */:
- case 207 /* NewExpression */:
+ case 207 /* CallExpression */:
+ case 208 /* NewExpression */:
if (node.typeArguments === list) {
return 29 /* LessThanToken */;
}
@@ -141227,12 +143989,12 @@ var ts;
return 20 /* OpenParenToken */;
}
break;
- case 176 /* TypeReference */:
+ case 177 /* TypeReference */:
if (node.typeArguments === list) {
return 29 /* LessThanToken */;
}
break;
- case 180 /* TypeLiteral */:
+ case 181 /* TypeLiteral */:
return 18 /* OpenBraceToken */;
}
return 0 /* Unknown */;
@@ -141350,7 +144112,7 @@ var ts;
if (options.indentStyle === ts.IndentStyle.Block) {
return getBlockIndent(sourceFile, position, options);
}
- if (precedingToken.kind === 27 /* CommaToken */ && precedingToken.parent.kind !== 219 /* BinaryExpression */) {
+ if (precedingToken.kind === 27 /* CommaToken */ && precedingToken.parent.kind !== 220 /* BinaryExpression */) {
// previous token is comma that separates items in list - find the previous item and try to derive indentation from it
var actualIndentation = getActualIndentationForListItemBeforeComma(precedingToken, sourceFile, options);
if (actualIndentation !== -1 /* Unknown */) {
@@ -141523,7 +144285,7 @@ var ts;
// - parent is SourceFile - by default immediate children of SourceFile are not indented except when user indents them manually
// - parent and child are not on the same line
var useActualIndentation = (ts.isDeclaration(current) || ts.isStatementButNotDeclaration(current)) &&
- (parent.kind === 300 /* SourceFile */ || !parentAndChildShareLine);
+ (parent.kind === 303 /* SourceFile */ || !parentAndChildShareLine);
if (!useActualIndentation) {
return -1 /* Unknown */;
}
@@ -141571,7 +144333,7 @@ var ts;
}
SmartIndenter.isArgumentAndStartLineOverlapsExpressionBeingCalled = isArgumentAndStartLineOverlapsExpressionBeingCalled;
function childStartsOnTheSameLineWithElseInIfStatement(parent, child, childStartLine, sourceFile) {
- if (parent.kind === 237 /* IfStatement */ && parent.elseStatement === child) {
+ if (parent.kind === 238 /* IfStatement */ && parent.elseStatement === child) {
var elseKeyword = ts.findChildOfKind(parent, 91 /* ElseKeyword */, sourceFile);
ts.Debug.assert(elseKeyword !== undefined);
var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line;
@@ -141652,40 +144414,40 @@ var ts;
}
function getListByRange(start, end, node, sourceFile) {
switch (node.kind) {
- case 176 /* TypeReference */:
+ case 177 /* TypeReference */:
return getList(node.typeArguments);
- case 203 /* ObjectLiteralExpression */:
+ case 204 /* ObjectLiteralExpression */:
return getList(node.properties);
- case 202 /* ArrayLiteralExpression */:
+ case 203 /* ArrayLiteralExpression */:
return getList(node.elements);
- case 180 /* TypeLiteral */:
+ case 181 /* TypeLiteral */:
return getList(node.members);
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
- case 172 /* CallSignature */:
- case 169 /* Constructor */:
- case 178 /* ConstructorType */:
- case 173 /* ConstructSignature */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
+ case 173 /* CallSignature */:
+ case 170 /* Constructor */:
+ case 179 /* ConstructorType */:
+ case 174 /* ConstructSignature */:
return getList(node.typeParameters) || getList(node.parameters);
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
- case 256 /* InterfaceDeclaration */:
- case 257 /* TypeAliasDeclaration */:
- case 339 /* JSDocTemplateTag */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
+ case 257 /* InterfaceDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
+ case 342 /* JSDocTemplateTag */:
return getList(node.typeParameters);
- case 207 /* NewExpression */:
- case 206 /* CallExpression */:
+ case 208 /* NewExpression */:
+ case 207 /* CallExpression */:
return getList(node.typeArguments) || getList(node.arguments);
- case 253 /* VariableDeclarationList */:
+ case 254 /* VariableDeclarationList */:
return getList(node.declarations);
- case 267 /* NamedImports */:
- case 271 /* NamedExports */:
+ case 268 /* NamedImports */:
+ case 272 /* NamedExports */:
return getList(node.elements);
- case 199 /* ObjectBindingPattern */:
- case 200 /* ArrayBindingPattern */:
+ case 200 /* ObjectBindingPattern */:
+ case 201 /* ArrayBindingPattern */:
return getList(node.elements);
}
function getList(list) {
@@ -141708,7 +144470,7 @@ var ts;
return findColumnForFirstNonWhitespaceCharacterInLine(sourceFile.getLineAndCharacterOfPosition(list.pos), sourceFile, options);
}
function getActualIndentationForListItem(node, sourceFile, options, listIndentsChild) {
- if (node.parent && node.parent.kind === 253 /* VariableDeclarationList */) {
+ if (node.parent && node.parent.kind === 254 /* VariableDeclarationList */) {
// VariableDeclarationList has no wrapping tokens
return -1 /* Unknown */;
}
@@ -141781,91 +144543,96 @@ var ts;
function nodeWillIndentChild(settings, parent, child, sourceFile, indentByDefault) {
var childKind = child ? child.kind : 0 /* Unknown */;
switch (parent.kind) {
- case 236 /* ExpressionStatement */:
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
- case 256 /* InterfaceDeclaration */:
- case 258 /* EnumDeclaration */:
- case 257 /* TypeAliasDeclaration */:
- case 202 /* ArrayLiteralExpression */:
- case 233 /* Block */:
- case 260 /* ModuleBlock */:
- case 203 /* ObjectLiteralExpression */:
- case 180 /* TypeLiteral */:
- case 193 /* MappedType */:
- case 182 /* TupleType */:
- case 261 /* CaseBlock */:
- case 288 /* DefaultClause */:
- case 287 /* CaseClause */:
- case 210 /* ParenthesizedExpression */:
- case 204 /* PropertyAccessExpression */:
- case 206 /* CallExpression */:
- case 207 /* NewExpression */:
- case 235 /* VariableStatement */:
- case 269 /* ExportAssignment */:
- case 245 /* ReturnStatement */:
- case 220 /* ConditionalExpression */:
- case 200 /* ArrayBindingPattern */:
- case 199 /* ObjectBindingPattern */:
- case 278 /* JsxOpeningElement */:
- case 281 /* JsxOpeningFragment */:
- case 277 /* JsxSelfClosingElement */:
- case 286 /* JsxExpression */:
- case 166 /* MethodSignature */:
- case 172 /* CallSignature */:
- case 173 /* ConstructSignature */:
- case 162 /* Parameter */:
- case 177 /* FunctionType */:
- case 178 /* ConstructorType */:
- case 189 /* ParenthesizedType */:
- case 208 /* TaggedTemplateExpression */:
- case 216 /* AwaitExpression */:
- case 271 /* NamedExports */:
- case 267 /* NamedImports */:
- case 273 /* ExportSpecifier */:
- case 268 /* ImportSpecifier */:
- case 165 /* PropertyDeclaration */:
+ case 237 /* ExpressionStatement */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
+ case 257 /* InterfaceDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
+ case 203 /* ArrayLiteralExpression */:
+ case 234 /* Block */:
+ case 261 /* ModuleBlock */:
+ case 204 /* ObjectLiteralExpression */:
+ case 181 /* TypeLiteral */:
+ case 194 /* MappedType */:
+ case 183 /* TupleType */:
+ case 262 /* CaseBlock */:
+ case 289 /* DefaultClause */:
+ case 288 /* CaseClause */:
+ case 211 /* ParenthesizedExpression */:
+ case 205 /* PropertyAccessExpression */:
+ case 207 /* CallExpression */:
+ case 208 /* NewExpression */:
+ case 236 /* VariableStatement */:
+ case 270 /* ExportAssignment */:
+ case 246 /* ReturnStatement */:
+ case 221 /* ConditionalExpression */:
+ case 201 /* ArrayBindingPattern */:
+ case 200 /* ObjectBindingPattern */:
+ case 279 /* JsxOpeningElement */:
+ case 282 /* JsxOpeningFragment */:
+ case 278 /* JsxSelfClosingElement */:
+ case 287 /* JsxExpression */:
+ case 167 /* MethodSignature */:
+ case 173 /* CallSignature */:
+ case 174 /* ConstructSignature */:
+ case 163 /* Parameter */:
+ case 178 /* FunctionType */:
+ case 179 /* ConstructorType */:
+ case 190 /* ParenthesizedType */:
+ case 209 /* TaggedTemplateExpression */:
+ case 217 /* AwaitExpression */:
+ case 272 /* NamedExports */:
+ case 268 /* NamedImports */:
+ case 274 /* ExportSpecifier */:
+ case 269 /* ImportSpecifier */:
+ case 166 /* PropertyDeclaration */:
return true;
- case 252 /* VariableDeclaration */:
- case 291 /* PropertyAssignment */:
- case 219 /* BinaryExpression */:
- if (!settings.indentMultiLineObjectLiteralBeginningOnBlankLine && sourceFile && childKind === 203 /* ObjectLiteralExpression */) { // TODO: GH#18217
+ case 253 /* VariableDeclaration */:
+ case 294 /* PropertyAssignment */:
+ case 220 /* BinaryExpression */:
+ if (!settings.indentMultiLineObjectLiteralBeginningOnBlankLine && sourceFile && childKind === 204 /* ObjectLiteralExpression */) { // TODO: GH#18217
return rangeIsOnOneLine(sourceFile, child);
}
- if (parent.kind !== 219 /* BinaryExpression */) {
+ if (parent.kind === 220 /* BinaryExpression */ && sourceFile && child && childKind === 277 /* JsxElement */) {
+ var parentStartLine = sourceFile.getLineAndCharacterOfPosition(ts.skipTrivia(sourceFile.text, parent.pos)).line;
+ var childStartLine = sourceFile.getLineAndCharacterOfPosition(ts.skipTrivia(sourceFile.text, child.pos)).line;
+ return parentStartLine !== childStartLine;
+ }
+ if (parent.kind !== 220 /* BinaryExpression */) {
return true;
}
break;
- case 238 /* DoStatement */:
- case 239 /* WhileStatement */:
- case 241 /* ForInStatement */:
- case 242 /* ForOfStatement */:
- case 240 /* ForStatement */:
- case 237 /* IfStatement */:
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
- case 167 /* MethodDeclaration */:
- case 169 /* Constructor */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
- return childKind !== 233 /* Block */;
- case 212 /* ArrowFunction */:
- if (sourceFile && childKind === 210 /* ParenthesizedExpression */) {
+ case 239 /* DoStatement */:
+ case 240 /* WhileStatement */:
+ case 242 /* ForInStatement */:
+ case 243 /* ForOfStatement */:
+ case 241 /* ForStatement */:
+ case 238 /* IfStatement */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 168 /* MethodDeclaration */:
+ case 170 /* Constructor */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
+ return childKind !== 234 /* Block */;
+ case 213 /* ArrowFunction */:
+ if (sourceFile && childKind === 211 /* ParenthesizedExpression */) {
return rangeIsOnOneLine(sourceFile, child);
}
- return childKind !== 233 /* Block */;
- case 270 /* ExportDeclaration */:
- return childKind !== 271 /* NamedExports */;
- case 264 /* ImportDeclaration */:
- return childKind !== 265 /* ImportClause */ ||
- (!!child.namedBindings && child.namedBindings.kind !== 267 /* NamedImports */);
- case 276 /* JsxElement */:
- return childKind !== 279 /* JsxClosingElement */;
- case 280 /* JsxFragment */:
- return childKind !== 282 /* JsxClosingFragment */;
- case 186 /* IntersectionType */:
- case 185 /* UnionType */:
- if (childKind === 180 /* TypeLiteral */ || childKind === 182 /* TupleType */) {
+ return childKind !== 234 /* Block */;
+ case 271 /* ExportDeclaration */:
+ return childKind !== 272 /* NamedExports */;
+ case 265 /* ImportDeclaration */:
+ return childKind !== 266 /* ImportClause */ ||
+ (!!child.namedBindings && child.namedBindings.kind !== 268 /* NamedImports */);
+ case 277 /* JsxElement */:
+ return childKind !== 280 /* JsxClosingElement */;
+ case 281 /* JsxFragment */:
+ return childKind !== 283 /* JsxClosingFragment */;
+ case 187 /* IntersectionType */:
+ case 186 /* UnionType */:
+ if (childKind === 181 /* TypeLiteral */ || childKind === 183 /* TupleType */) {
return false;
}
break;
@@ -141876,11 +144643,11 @@ var ts;
SmartIndenter.nodeWillIndentChild = nodeWillIndentChild;
function isControlFlowEndingStatement(kind, parent) {
switch (kind) {
- case 245 /* ReturnStatement */:
- case 249 /* ThrowStatement */:
- case 243 /* ContinueStatement */:
- case 244 /* BreakStatement */:
- return parent.kind !== 233 /* Block */;
+ case 246 /* ReturnStatement */:
+ case 250 /* ThrowStatement */:
+ case 244 /* ContinueStatement */:
+ case 245 /* BreakStatement */:
+ return parent.kind !== 234 /* Block */;
default:
return false;
}
@@ -142097,7 +144864,7 @@ var ts;
* Checks if 'candidate' argument is a legal separator in the list that contains 'node' as an element
*/
function isSeparator(node, candidate) {
- return !!candidate && !!node.parent && (candidate.kind === 27 /* CommaToken */ || (candidate.kind === 26 /* SemicolonToken */ && node.parent.kind === 203 /* ObjectLiteralExpression */));
+ return !!candidate && !!node.parent && (candidate.kind === 27 /* CommaToken */ || (candidate.kind === 26 /* SemicolonToken */ && node.parent.kind === 204 /* ObjectLiteralExpression */));
}
function isThisTypeAnnotatable(containingFunction) {
return ts.isFunctionExpression(containingFunction) || ts.isFunctionDeclaration(containingFunction);
@@ -142304,7 +145071,7 @@ var ts;
}
}
else {
- endNode = (_a = (node.kind === 252 /* VariableDeclaration */ ? node.exclamationToken : node.questionToken)) !== null && _a !== void 0 ? _a : node.name;
+ endNode = (_a = (node.kind === 253 /* VariableDeclaration */ ? node.exclamationToken : node.questionToken)) !== null && _a !== void 0 ? _a : node.name;
}
this.insertNodeAt(sourceFile, endNode.end, type, { prefix: ": " });
return true;
@@ -142470,18 +145237,18 @@ var ts;
};
ChangeTracker.prototype.getInsertNodeAfterOptionsWorker = function (node) {
switch (node.kind) {
- case 255 /* ClassDeclaration */:
- case 259 /* ModuleDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 260 /* ModuleDeclaration */:
return { prefix: this.newLineCharacter, suffix: this.newLineCharacter };
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
case 10 /* StringLiteral */:
case 79 /* Identifier */:
return { prefix: ", " };
- case 291 /* PropertyAssignment */:
+ case 294 /* PropertyAssignment */:
return { suffix: "," + this.newLineCharacter };
case 93 /* ExportKeyword */:
return { prefix: " " };
- case 162 /* Parameter */:
+ case 163 /* Parameter */:
return {};
default:
ts.Debug.assert(ts.isStatement(node) || ts.isClassOrTypeElement(node)); // Else we haven't handled this kind of node yet -- add it
@@ -142490,7 +145257,7 @@ var ts;
};
ChangeTracker.prototype.insertName = function (sourceFile, node, name) {
ts.Debug.assert(!node.name);
- if (node.kind === 212 /* ArrowFunction */) {
+ if (node.kind === 213 /* ArrowFunction */) {
var arrow = ts.findChildOfKind(node, 38 /* EqualsGreaterThanToken */, sourceFile);
var lparen = ts.findChildOfKind(node, 20 /* OpenParenToken */, sourceFile);
if (lparen) {
@@ -142504,14 +145271,14 @@ var ts;
// Replacing full range of arrow to get rid of the leading space -- replace ` =>` with `)`
this.replaceRange(sourceFile, arrow, ts.factory.createToken(21 /* CloseParenToken */));
}
- if (node.body.kind !== 233 /* Block */) {
+ if (node.body.kind !== 234 /* Block */) {
// `() => 0` => `function f() { return 0; }`
this.insertNodesAt(sourceFile, node.body.getStart(sourceFile), [ts.factory.createToken(18 /* OpenBraceToken */), ts.factory.createToken(105 /* ReturnKeyword */)], { joiner: " ", suffix: " " });
this.insertNodesAt(sourceFile, node.body.end, [ts.factory.createToken(26 /* SemicolonToken */), ts.factory.createToken(19 /* CloseBraceToken */)], { joiner: " " });
}
}
else {
- var pos = ts.findChildOfKind(node, node.kind === 211 /* FunctionExpression */ ? 98 /* FunctionKeyword */ : 84 /* ClassKeyword */, sourceFile).end;
+ var pos = ts.findChildOfKind(node, node.kind === 212 /* FunctionExpression */ ? 98 /* FunctionKeyword */ : 84 /* ClassKeyword */, sourceFile).end;
this.insertNodeAt(sourceFile, pos, ts.factory.createIdentifier(name), { prefix: " " });
}
};
@@ -142630,7 +145397,7 @@ var ts;
ChangeTracker.prototype.finishDeleteDeclarations = function () {
var _this = this;
var deletedNodesInLists = new ts.Set(); // Stores nodes in lists that we already deleted. Used to avoid deleting `, ` twice in `a, b`.
- var _loop_10 = function (sourceFile, node) {
+ var _loop_11 = function (sourceFile, node) {
if (!this_1.deletedNodes.some(function (d) { return d.sourceFile === sourceFile && ts.rangeContainsRangeExclusive(d.node, node); })) {
if (ts.isArray(node)) {
this_1.deleteRange(sourceFile, ts.rangeOfTypeParameters(sourceFile, node));
@@ -142643,7 +145410,7 @@ var ts;
var this_1 = this;
for (var _i = 0, _a = this.deletedNodes; _i < _a.length; _i++) {
var _b = _a[_i], sourceFile = _b.sourceFile, node = _b.node;
- _loop_10(sourceFile, node);
+ _loop_11(sourceFile, node);
}
deletedNodesInLists.forEach(function (node) {
var sourceFile = node.getSourceFile();
@@ -142702,14 +145469,14 @@ var ts;
// order changes by start position
// If the start position is the same, put the shorter range first, since an empty range (x, x) may precede (x, y) but not vice-versa.
var normalized = ts.stableSort(changesInFile, function (a, b) { return (a.range.pos - b.range.pos) || (a.range.end - b.range.end); });
- var _loop_11 = function (i) {
+ var _loop_12 = function (i) {
ts.Debug.assert(normalized[i].range.end <= normalized[i + 1].range.pos, "Changes overlap", function () {
return JSON.stringify(normalized[i].range) + " and " + JSON.stringify(normalized[i + 1].range);
});
};
// verify that change intervals do not overlap, except possibly at end points.
for (var i = 0; i < normalized.length - 1; i++) {
- _loop_11(i);
+ _loop_12(i);
}
var textChanges = ts.mapDefined(normalized, function (c) {
var span = ts.createTextSpanFromRange(c.range);
@@ -142775,14 +145542,19 @@ var ts;
if (delta === undefined) {
delta = ts.formatting.SmartIndenter.shouldIndentChildNode(formatOptions, nodeIn) ? (formatOptions.indentSize || 0) : 0;
}
- var file = { text: text, getLineAndCharacterOfPosition: function (pos) { return ts.getLineAndCharacterOfPosition(this, pos); } };
+ var file = {
+ text: text,
+ getLineAndCharacterOfPosition: function (pos) {
+ return ts.getLineAndCharacterOfPosition(this, pos);
+ }
+ };
var changes = ts.formatting.formatNodeGivenIndentation(node, file, sourceFile.languageVariant, initialIndentation, delta, __assign(__assign({}, formatContext), { options: formatOptions }));
return applyChanges(text, changes);
}
/** Note: output node may be mutated input node. */
function getNonformattedText(node, sourceFile, newLineCharacter) {
var writer = createWriter(newLineCharacter);
- var newLine = newLineCharacter === "\n" ? 1 /* LineFeed */ : 0 /* CarriageReturnLineFeed */;
+ var newLine = ts.getNewLineKind(newLineCharacter);
ts.createPrinter({
newLine: newLine,
neverAsciiEscape: true,
@@ -143064,14 +145836,14 @@ var ts;
}
textChanges_3.isValidLocationToAddComment = isValidLocationToAddComment;
function needSemicolonBetween(a, b) {
- return (ts.isPropertySignature(a) || ts.isPropertyDeclaration(a)) && ts.isClassOrTypeElement(b) && b.name.kind === 160 /* ComputedPropertyName */
+ return (ts.isPropertySignature(a) || ts.isPropertyDeclaration(a)) && ts.isClassOrTypeElement(b) && b.name.kind === 161 /* ComputedPropertyName */
|| ts.isStatementButNotDeclaration(a) && ts.isStatementButNotDeclaration(b); // TODO: only if b would start with a `(` or `[`
}
var deleteDeclaration;
(function (deleteDeclaration_1) {
function deleteDeclaration(changes, deletedNodesInLists, sourceFile, node) {
switch (node.kind) {
- case 162 /* Parameter */: {
+ case 163 /* Parameter */: {
var oldFunction = node.parent;
if (ts.isArrowFunction(oldFunction) &&
oldFunction.parameters.length === 1 &&
@@ -143086,17 +145858,17 @@ var ts;
}
break;
}
- case 264 /* ImportDeclaration */:
- case 263 /* ImportEqualsDeclaration */:
+ case 265 /* ImportDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
var isFirstImport = sourceFile.imports.length && node === ts.first(sourceFile.imports).parent || node === ts.find(sourceFile.statements, ts.isAnyImportSyntax);
// For first import, leave header comment in place, otherwise only delete JSDoc comments
deleteNode(changes, sourceFile, node, {
leadingTriviaOption: isFirstImport ? LeadingTriviaOption.Exclude : ts.hasJSDocNodes(node) ? LeadingTriviaOption.JSDoc : LeadingTriviaOption.StartLine,
});
break;
- case 201 /* BindingElement */:
+ case 202 /* BindingElement */:
var pattern = node.parent;
- var preserveComma = pattern.kind === 200 /* ArrayBindingPattern */ && node !== ts.last(pattern.elements);
+ var preserveComma = pattern.kind === 201 /* ArrayBindingPattern */ && node !== ts.last(pattern.elements);
if (preserveComma) {
deleteNode(changes, sourceFile, node);
}
@@ -143104,13 +145876,13 @@ var ts;
deleteNodeInList(changes, deletedNodesInLists, sourceFile, node);
}
break;
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
deleteVariableDeclaration(changes, deletedNodesInLists, sourceFile, node);
break;
- case 161 /* TypeParameter */:
+ case 162 /* TypeParameter */:
deleteNodeInList(changes, deletedNodesInLists, sourceFile, node);
break;
- case 268 /* ImportSpecifier */:
+ case 269 /* ImportSpecifier */:
var namedImports = node.parent;
if (namedImports.elements.length === 1) {
deleteImportBinding(changes, sourceFile, namedImports);
@@ -143119,7 +145891,7 @@ var ts;
deleteNodeInList(changes, deletedNodesInLists, sourceFile, node);
}
break;
- case 266 /* NamespaceImport */:
+ case 267 /* NamespaceImport */:
deleteImportBinding(changes, sourceFile, node);
break;
case 26 /* SemicolonToken */:
@@ -143128,8 +145900,8 @@ var ts;
case 98 /* FunctionKeyword */:
deleteNode(changes, sourceFile, node, { leadingTriviaOption: LeadingTriviaOption.Exclude });
break;
- case 255 /* ClassDeclaration */:
- case 254 /* FunctionDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 255 /* FunctionDeclaration */:
deleteNode(changes, sourceFile, node, { leadingTriviaOption: ts.hasJSDocNodes(node) ? LeadingTriviaOption.JSDoc : LeadingTriviaOption.StartLine });
break;
default:
@@ -143180,13 +145952,13 @@ var ts;
// Delete the entire import declaration
// |import * as ns from './file'|
// |import { a } from './file'|
- var importDecl = ts.getAncestor(node, 264 /* ImportDeclaration */);
+ var importDecl = ts.getAncestor(node, 265 /* ImportDeclaration */);
deleteNode(changes, sourceFile, importDecl);
}
}
function deleteVariableDeclaration(changes, deletedNodesInLists, sourceFile, node) {
var parent = node.parent;
- if (parent.kind === 290 /* CatchClause */) {
+ if (parent.kind === 291 /* CatchClause */) {
// TODO: There's currently no unused diagnostic for this, could be a suggestion
changes.deleteNodeRange(sourceFile, ts.findChildOfKind(parent, 20 /* OpenParenToken */, sourceFile), ts.findChildOfKind(parent, 21 /* CloseParenToken */, sourceFile));
return;
@@ -143197,14 +145969,14 @@ var ts;
}
var gp = parent.parent;
switch (gp.kind) {
- case 242 /* ForOfStatement */:
- case 241 /* ForInStatement */:
+ case 243 /* ForOfStatement */:
+ case 242 /* ForInStatement */:
changes.replaceNode(sourceFile, node, ts.factory.createObjectLiteralExpression());
break;
- case 240 /* ForStatement */:
+ case 241 /* ForStatement */:
deleteNode(changes, sourceFile, parent);
break;
- case 235 /* VariableStatement */:
+ case 236 /* VariableStatement */:
deleteNode(changes, sourceFile, gp, { leadingTriviaOption: ts.hasJSDocNodes(gp) ? LeadingTriviaOption.JSDoc : LeadingTriviaOption.StartLine });
break;
default:
@@ -143247,21 +146019,16 @@ var ts;
(function (codefix) {
var errorCodeToFixes = ts.createMultiMap();
var fixIdToRegistration = new ts.Map();
- function diagnosticToString(diag) {
- return ts.isArray(diag)
- ? ts.formatStringFromArgs(ts.getLocaleSpecificMessage(diag[0]), diag.slice(1))
- : ts.getLocaleSpecificMessage(diag);
- }
function createCodeFixActionWithoutFixAll(fixName, changes, description) {
- return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, /*fixId*/ undefined, /*fixAllDescription*/ undefined);
+ return createCodeFixActionWorker(fixName, ts.diagnosticToString(description), changes, /*fixId*/ undefined, /*fixAllDescription*/ undefined);
}
codefix.createCodeFixActionWithoutFixAll = createCodeFixActionWithoutFixAll;
function createCodeFixAction(fixName, changes, description, fixId, fixAllDescription, command) {
- return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, fixId, diagnosticToString(fixAllDescription), command);
+ return createCodeFixActionWorker(fixName, ts.diagnosticToString(description), changes, fixId, ts.diagnosticToString(fixAllDescription), command);
}
codefix.createCodeFixAction = createCodeFixAction;
function createCodeFixActionMaybeFixAll(fixName, changes, description, fixId, fixAllDescription, command) {
- return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, fixId, fixAllDescription && diagnosticToString(fixAllDescription), command);
+ return createCodeFixActionWorker(fixName, ts.diagnosticToString(description), changes, fixId, fixAllDescription && ts.diagnosticToString(fixAllDescription), command);
}
codefix.createCodeFixActionMaybeFixAll = createCodeFixActionMaybeFixAll;
function createCodeFixActionWorker(fixName, description, changes, fixId, fixAllDescription, command) {
@@ -143390,8 +146157,8 @@ var ts;
var token = ts.getTokenAtPosition(sourceFile, pos);
var assertion = ts.Debug.checkDefined(ts.findAncestor(token, function (n) { return ts.isAsExpression(n) || ts.isTypeAssertionExpression(n); }), "Expected to find an assertion expression");
var replacement = ts.isAsExpression(assertion)
- ? ts.factory.createAsExpression(assertion.expression, ts.factory.createKeywordTypeNode(153 /* UnknownKeyword */))
- : ts.factory.createTypeAssertion(ts.factory.createKeywordTypeNode(153 /* UnknownKeyword */), assertion.expression);
+ ? ts.factory.createAsExpression(assertion.expression, ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */))
+ : ts.factory.createTypeAssertion(ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */), assertion.expression);
changeTracker.replaceNode(sourceFile, assertion.expression, replacement);
}
})(codefix = ts.codefix || (ts.codefix = {}));
@@ -143534,7 +146301,7 @@ var ts;
errorCodes: errorCodes,
getCodeActions: function (context) {
var sourceFile = context.sourceFile, errorCode = context.errorCode, span = context.span, cancellationToken = context.cancellationToken, program = context.program;
- var expression = getFixableErrorSpanExpression(sourceFile, errorCode, span, cancellationToken, program);
+ var expression = getAwaitErrorSpanExpression(sourceFile, errorCode, span, cancellationToken, program);
if (!expression) {
return;
}
@@ -143550,7 +146317,7 @@ var ts;
var checker = context.program.getTypeChecker();
var fixedDeclarations = new ts.Set();
return codefix.codeFixAll(context, errorCodes, function (t, diagnostic) {
- var expression = getFixableErrorSpanExpression(sourceFile, diagnostic.code, diagnostic, cancellationToken, program);
+ var expression = getAwaitErrorSpanExpression(sourceFile, diagnostic.code, diagnostic, cancellationToken, program);
if (!expression) {
return;
}
@@ -143560,6 +146327,12 @@ var ts;
});
},
});
+ function getAwaitErrorSpanExpression(sourceFile, errorCode, span, cancellationToken, program) {
+ var expression = ts.getFixableErrorSpanExpression(sourceFile, span);
+ return expression
+ && isMissingAwaitError(sourceFile, errorCode, span, cancellationToken, program)
+ && isInsideAwaitableBody(expression) ? expression : undefined;
+ }
function getDeclarationSiteFix(context, expression, errorCode, checker, trackChanges, fixedDeclarations) {
var sourceFile = context.sourceFile, program = context.program, cancellationToken = context.cancellationToken;
var awaitableInitializers = findAwaitableInitializers(expression, sourceFile, cancellationToken, program, checker);
@@ -143595,21 +146368,6 @@ var ts;
ts.some(relatedInformation, function (related) { return related.code === ts.Diagnostics.Did_you_forget_to_use_await.code; });
});
}
- function getFixableErrorSpanExpression(sourceFile, errorCode, span, cancellationToken, program) {
- var token = ts.getTokenAtPosition(sourceFile, span.start);
- // Checker has already done work to determine that await might be possible, and has attached
- // related info to the node, so start by finding the expression that exactly matches up
- // with the diagnostic range.
- var expression = ts.findAncestor(token, function (node) {
- if (node.getStart(sourceFile) < span.start || node.getEnd() > ts.textSpanEnd(span)) {
- return "quit";
- }
- return ts.isExpression(node) && ts.textSpansEqual(span, ts.createTextSpanFromNode(node, sourceFile));
- });
- return expression
- && isMissingAwaitError(sourceFile, errorCode, span, cancellationToken, program)
- && isInsideAwaitableBody(expression) ? expression : undefined;
- }
function findAwaitableInitializers(expression, sourceFile, cancellationToken, program, checker) {
var identifiers = getIdentifiersFromErrorSpanExpression(expression, checker);
if (!identifiers) {
@@ -143617,14 +146375,14 @@ var ts;
}
var isCompleteFix = identifiers.isCompleteFix;
var initializers;
- var _loop_12 = function (identifier) {
+ var _loop_13 = function (identifier) {
var symbol = checker.getSymbolAtLocation(identifier);
if (!symbol) {
return "continue";
}
var declaration = ts.tryCast(symbol.valueDeclaration, ts.isVariableDeclaration);
var variableName = declaration && ts.tryCast(declaration.name, ts.isIdentifier);
- var variableStatement = ts.getAncestor(declaration, 235 /* VariableStatement */);
+ var variableStatement = ts.getAncestor(declaration, 236 /* VariableStatement */);
if (!declaration || !variableStatement ||
declaration.type ||
!declaration.initializer ||
@@ -143650,7 +146408,7 @@ var ts;
};
for (var _i = 0, _a = identifiers.identifiers; _i < _a.length; _i++) {
var identifier = _a[_i];
- _loop_12(identifier);
+ _loop_13(identifier);
}
return initializers && {
initializers: initializers,
@@ -143702,10 +146460,10 @@ var ts;
function isInsideAwaitableBody(node) {
return node.kind & 32768 /* AwaitContext */ || !!ts.findAncestor(node, function (ancestor) {
return ancestor.parent && ts.isArrowFunction(ancestor.parent) && ancestor.parent.body === ancestor ||
- ts.isBlock(ancestor) && (ancestor.parent.kind === 254 /* FunctionDeclaration */ ||
- ancestor.parent.kind === 211 /* FunctionExpression */ ||
- ancestor.parent.kind === 212 /* ArrowFunction */ ||
- ancestor.parent.kind === 167 /* MethodDeclaration */);
+ ts.isBlock(ancestor) && (ancestor.parent.kind === 255 /* FunctionDeclaration */ ||
+ ancestor.parent.kind === 212 /* FunctionExpression */ ||
+ ancestor.parent.kind === 213 /* ArrowFunction */ ||
+ ancestor.parent.kind === 168 /* MethodDeclaration */);
});
}
function makeChange(changeTracker, errorCode, sourceFile, checker, insertionSite, fixedDeclarations) {
@@ -143824,10 +146582,10 @@ var ts;
function isPossiblyPartOfDestructuring(node) {
switch (node.kind) {
case 79 /* Identifier */:
- case 202 /* ArrayLiteralExpression */:
- case 203 /* ObjectLiteralExpression */:
- case 291 /* PropertyAssignment */:
- case 292 /* ShorthandPropertyAssignment */:
+ case 203 /* ArrayLiteralExpression */:
+ case 204 /* ObjectLiteralExpression */:
+ case 294 /* PropertyAssignment */:
+ case 295 /* ShorthandPropertyAssignment */:
return true;
default:
return false;
@@ -143842,7 +146600,7 @@ var ts;
function isPossiblyPartOfCommaSeperatedInitializer(node) {
switch (node.kind) {
case 79 /* Identifier */:
- case 219 /* BinaryExpression */:
+ case 220 /* BinaryExpression */:
case 27 /* CommaToken */:
return true;
default:
@@ -143891,9 +146649,9 @@ var ts;
return;
}
var declaration = token.parent;
- if (declaration.kind === 165 /* PropertyDeclaration */ &&
+ if (declaration.kind === 166 /* PropertyDeclaration */ &&
(!fixedNodes || ts.tryAddToSet(fixedNodes, declaration))) {
- changeTracker.insertModifierBefore(sourceFile, 134 /* DeclareKeyword */, declaration);
+ changeTracker.insertModifierBefore(sourceFile, 135 /* DeclareKeyword */, declaration);
}
}
})(codefix = ts.codefix || (ts.codefix = {}));
@@ -143941,9 +146699,6 @@ var ts;
});
function makeChange(changeTracker, sourceFile, pos) {
var token = ts.getTokenAtPosition(sourceFile, pos);
- if (!ts.isIdentifier(token)) {
- return ts.Debug.fail("add-name-to-nameless-parameter operates on identifiers, but got a " + ts.Debug.formatSyntaxKind(token.kind));
- }
var param = token.parent;
if (!ts.isParameter(param)) {
return ts.Debug.fail("Tried to add a parameter name to a non-parameter: " + ts.Debug.formatSyntaxKind(token.kind));
@@ -143951,9 +146706,112 @@ var ts;
var i = param.parent.parameters.indexOf(param);
ts.Debug.assert(!param.type, "Tried to add a parameter name to a parameter that already had one.");
ts.Debug.assert(i > -1, "Parameter not found in parent parameter list.");
+ var typeNode = ts.factory.createTypeReferenceNode(param.name, /*typeArguments*/ undefined);
var replacement = ts.factory.createParameterDeclaration(
- /*decorators*/ undefined, param.modifiers, param.dotDotDotToken, "arg" + i, param.questionToken, ts.factory.createTypeReferenceNode(token, /*typeArguments*/ undefined), param.initializer);
- changeTracker.replaceNode(sourceFile, token, replacement);
+ /*decorators*/ undefined, param.modifiers, param.dotDotDotToken, "arg" + i, param.questionToken, param.dotDotDotToken ? ts.factory.createArrayTypeNode(typeNode) : typeNode, param.initializer);
+ changeTracker.replaceNode(sourceFile, param, replacement);
+ }
+ })(codefix = ts.codefix || (ts.codefix = {}));
+})(ts || (ts = {}));
+/* @internal */
+var ts;
+(function (ts) {
+ var codefix;
+ (function (codefix) {
+ var addOptionalPropertyUndefined = "addOptionalPropertyUndefined";
+ var errorCodes = [
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_type_of_the_target.code,
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties.code,
+ ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties.code,
+ ];
+ codefix.registerCodeFix({
+ errorCodes: errorCodes,
+ getCodeActions: function (context) {
+ var typeChecker = context.program.getTypeChecker();
+ var toAdd = getPropertiesToAdd(context.sourceFile, context.span, typeChecker);
+ if (!toAdd.length) {
+ return undefined;
+ }
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addUndefinedToOptionalProperty(t, toAdd); });
+ return [codefix.createCodeFixActionWithoutFixAll(addOptionalPropertyUndefined, changes, ts.Diagnostics.Add_undefined_to_optional_property_type)];
+ },
+ fixIds: [addOptionalPropertyUndefined],
+ });
+ function getPropertiesToAdd(file, span, checker) {
+ var _a, _b;
+ var sourceTarget = getSourceTarget(ts.getFixableErrorSpanExpression(file, span), checker);
+ if (!sourceTarget) {
+ return ts.emptyArray;
+ }
+ var sourceNode = sourceTarget.source, targetNode = sourceTarget.target;
+ var target = shouldUseParentTypeOfProperty(sourceNode, targetNode, checker)
+ ? checker.getTypeAtLocation(targetNode.expression)
+ : checker.getTypeAtLocation(targetNode);
+ if ((_b = (_a = target.symbol) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b.some(function (d) { return ts.getSourceFileOfNode(d).fileName.match(/\.d\.ts$/); })) {
+ return ts.emptyArray;
+ }
+ return checker.getExactOptionalProperties(target);
+ }
+ function shouldUseParentTypeOfProperty(sourceNode, targetNode, checker) {
+ return ts.isPropertyAccessExpression(targetNode)
+ && !!checker.getExactOptionalProperties(checker.getTypeAtLocation(targetNode.expression)).length
+ && checker.getTypeAtLocation(sourceNode) === checker.getUndefinedType();
+ }
+ /**
+ * Find the source and target of the incorrect assignment.
+ * The call is recursive for property assignments.
+ */
+ function getSourceTarget(errorNode, checker) {
+ var _a;
+ if (!errorNode) {
+ return undefined;
+ }
+ else if (ts.isBinaryExpression(errorNode.parent) && errorNode.parent.operatorToken.kind === 63 /* EqualsToken */) {
+ return { source: errorNode.parent.right, target: errorNode.parent.left };
+ }
+ else if (ts.isVariableDeclaration(errorNode.parent) && errorNode.parent.initializer) {
+ return { source: errorNode.parent.initializer, target: errorNode.parent.name };
+ }
+ else if (ts.isCallExpression(errorNode.parent)) {
+ var n = checker.getSymbolAtLocation(errorNode.parent.expression);
+ if (!(n === null || n === void 0 ? void 0 : n.valueDeclaration) || !ts.isFunctionLikeKind(n.valueDeclaration.kind))
+ return undefined;
+ if (!ts.isExpression(errorNode))
+ return undefined;
+ var i = errorNode.parent.arguments.indexOf(errorNode);
+ if (i === -1)
+ return undefined;
+ var name = n.valueDeclaration.parameters[i].name;
+ if (ts.isIdentifier(name))
+ return { source: errorNode, target: name };
+ }
+ else if (ts.isPropertyAssignment(errorNode.parent) && ts.isIdentifier(errorNode.parent.name) ||
+ ts.isShorthandPropertyAssignment(errorNode.parent)) {
+ var parentTarget = getSourceTarget(errorNode.parent.parent, checker);
+ if (!parentTarget)
+ return undefined;
+ var prop = checker.getPropertyOfType(checker.getTypeAtLocation(parentTarget.target), errorNode.parent.name.text);
+ var declaration = (_a = prop === null || prop === void 0 ? void 0 : prop.declarations) === null || _a === void 0 ? void 0 : _a[0];
+ if (!declaration)
+ return undefined;
+ return {
+ source: ts.isPropertyAssignment(errorNode.parent) ? errorNode.parent.initializer : errorNode.parent.name,
+ target: declaration
+ };
+ }
+ return undefined;
+ }
+ function addUndefinedToOptionalProperty(changes, toAdd) {
+ for (var _i = 0, toAdd_1 = toAdd; _i < toAdd_1.length; _i++) {
+ var add = toAdd_1[_i];
+ var d = add.valueDeclaration;
+ if (d && (ts.isPropertySignature(d) || ts.isPropertyDeclaration(d)) && d.type) {
+ var t = ts.factory.createUnionTypeNode(__spreadArray(__spreadArray([], d.type.kind === 186 /* UnionType */ ? d.type.types : [d.type], true), [
+ ts.factory.createTypeReferenceNode("undefined")
+ ], false));
+ changes.replaceNode(d.getSourceFile(), d.type, t);
+ }
+ }
}
})(codefix = ts.codefix || (ts.codefix = {}));
})(ts || (ts = {}));
@@ -144028,26 +146886,26 @@ var ts;
}
function isDeclarationWithType(node) {
return ts.isFunctionLikeDeclaration(node) ||
- node.kind === 252 /* VariableDeclaration */ ||
- node.kind === 164 /* PropertySignature */ ||
- node.kind === 165 /* PropertyDeclaration */;
+ node.kind === 253 /* VariableDeclaration */ ||
+ node.kind === 165 /* PropertySignature */ ||
+ node.kind === 166 /* PropertyDeclaration */;
}
function transformJSDocType(node) {
switch (node.kind) {
- case 307 /* JSDocAllType */:
- case 308 /* JSDocUnknownType */:
+ case 310 /* JSDocAllType */:
+ case 311 /* JSDocUnknownType */:
return ts.factory.createTypeReferenceNode("any", ts.emptyArray);
- case 311 /* JSDocOptionalType */:
+ case 314 /* JSDocOptionalType */:
return transformJSDocOptionalType(node);
- case 310 /* JSDocNonNullableType */:
+ case 313 /* JSDocNonNullableType */:
return transformJSDocType(node.type);
- case 309 /* JSDocNullableType */:
+ case 312 /* JSDocNullableType */:
return transformJSDocNullableType(node);
- case 313 /* JSDocVariadicType */:
+ case 316 /* JSDocVariadicType */:
return transformJSDocVariadicType(node);
- case 312 /* JSDocFunctionType */:
+ case 315 /* JSDocFunctionType */:
return transformJSDocFunctionType(node);
- case 176 /* TypeReference */:
+ case 177 /* TypeReference */:
return transformJSDocTypeReference(node);
default:
var visited = ts.visitEachChild(node, transformJSDocType, ts.nullTransformationContext);
@@ -144068,11 +146926,11 @@ var ts;
var _a;
// TODO: This does not properly handle `function(new:C, string)` per https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System#the-javascript-type-language
// however we do handle it correctly in `serializeTypeForDeclaration` in checker.ts
- return ts.factory.createFunctionTypeNode(ts.emptyArray, node.parameters.map(transformJSDocParameter), (_a = node.type) !== null && _a !== void 0 ? _a : ts.factory.createKeywordTypeNode(129 /* AnyKeyword */));
+ return ts.factory.createFunctionTypeNode(ts.emptyArray, node.parameters.map(transformJSDocParameter), (_a = node.type) !== null && _a !== void 0 ? _a : ts.factory.createKeywordTypeNode(130 /* AnyKeyword */));
}
function transformJSDocParameter(node) {
var index = node.parent.parameters.indexOf(node);
- var isRest = node.type.kind === 313 /* JSDocVariadicType */ && index === node.parent.parameters.length - 1; // TODO: GH#18217
+ var isRest = node.type.kind === 316 /* JSDocVariadicType */ && index === node.parent.parameters.length - 1; // TODO: GH#18217
var name = node.name || (isRest ? "rest" : "arg" + index);
var dotdotdot = isRest ? ts.factory.createToken(25 /* DotDotDotToken */) : node.dotDotDotToken;
return ts.factory.createParameterDeclaration(node.decorators, node.modifiers, dotdotdot, name, node.questionToken, ts.visitNode(node.type, transformJSDocType), node.initializer);
@@ -144112,8 +146970,8 @@ var ts;
var index = ts.factory.createParameterDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
- /*dotDotDotToken*/ undefined, node.typeArguments[0].kind === 145 /* NumberKeyword */ ? "n" : "s",
- /*questionToken*/ undefined, ts.factory.createTypeReferenceNode(node.typeArguments[0].kind === 145 /* NumberKeyword */ ? "number" : "string", []),
+ /*dotDotDotToken*/ undefined, node.typeArguments[0].kind === 146 /* NumberKeyword */ ? "n" : "s",
+ /*questionToken*/ undefined, ts.factory.createTypeReferenceNode(node.typeArguments[0].kind === 146 /* NumberKeyword */ ? "number" : "string", []),
/*initializer*/ undefined);
var indexSignature = ts.factory.createTypeLiteralNode([ts.factory.createIndexSignature(/*decorators*/ undefined, /*modifiers*/ undefined, [index], node.typeArguments[1])]);
ts.setEmitFlags(indexSignature, 1 /* SingleLine */);
@@ -144246,7 +147104,7 @@ var ts;
return members;
}
// delete the entire statement if this expression is the sole expression to take care of the semicolon at the end
- var nodeToDelete = assignmentBinaryExpression.parent && assignmentBinaryExpression.parent.kind === 236 /* ExpressionStatement */
+ var nodeToDelete = assignmentBinaryExpression.parent && assignmentBinaryExpression.parent.kind === 237 /* ExpressionStatement */
? assignmentBinaryExpression.parent : assignmentBinaryExpression;
changes.delete(sourceFile, nodeToDelete);
if (!assignmentExpr) {
@@ -144297,7 +147155,7 @@ var ts;
return createArrowFunctionExpressionMember(members, expression, name);
}
function createFunctionExpressionMember(members, functionExpression, name) {
- var fullModifiers = ts.concatenate(modifiers, getModifierKindFromSource(functionExpression, 130 /* AsyncKeyword */));
+ var fullModifiers = ts.concatenate(modifiers, getModifierKindFromSource(functionExpression, 131 /* AsyncKeyword */));
var method = ts.factory.createMethodDeclaration(/*decorators*/ undefined, fullModifiers, /*asteriskToken*/ undefined, name, /*questionToken*/ undefined,
/*typeParameters*/ undefined, functionExpression.parameters, /*type*/ undefined, functionExpression.body);
ts.copyLeadingComments(assignmentBinaryExpression, method, sourceFile);
@@ -144307,14 +147165,14 @@ var ts;
var arrowFunctionBody = arrowFunction.body;
var bodyBlock;
// case 1: () => { return [1,2,3] }
- if (arrowFunctionBody.kind === 233 /* Block */) {
+ if (arrowFunctionBody.kind === 234 /* Block */) {
bodyBlock = arrowFunctionBody;
}
// case 2: () => [1,2,3]
else {
bodyBlock = ts.factory.createBlock([ts.factory.createReturnStatement(arrowFunctionBody)]);
}
- var fullModifiers = ts.concatenate(modifiers, getModifierKindFromSource(arrowFunction, 130 /* AsyncKeyword */));
+ var fullModifiers = ts.concatenate(modifiers, getModifierKindFromSource(arrowFunction, 131 /* AsyncKeyword */));
var method = ts.factory.createMethodDeclaration(/*decorators*/ undefined, fullModifiers, /*asteriskToken*/ undefined, name, /*questionToken*/ undefined,
/*typeParameters*/ undefined, arrowFunction.parameters, /*type*/ undefined, bodyBlock);
ts.copyLeadingComments(assignmentBinaryExpression, method, sourceFile);
@@ -144368,7 +147226,7 @@ var ts;
return propName;
}
if (ts.isStringLiteralLike(propName)) {
- return ts.isIdentifierText(propName.text, compilerOptions.target) ? ts.factory.createIdentifier(propName.text)
+ return ts.isIdentifierText(propName.text, ts.getEmitScriptTarget(compilerOptions)) ? ts.factory.createIdentifier(propName.text)
: ts.isNoSubstitutionTemplateLiteral(propName) ? ts.factory.createStringLiteral(propName.text, quotePreference === 0 /* Single */)
: propName;
}
@@ -144430,21 +147288,32 @@ var ts;
functionToConvert.decorators ? ts.skipTrivia(sourceFile.text, functionToConvert.decorators.end) :
functionToConvert.getStart(sourceFile);
var options = functionToConvert.modifiers ? { prefix: " " } : { suffix: " " };
- changes.insertModifierAt(sourceFile, pos, 130 /* AsyncKeyword */, options);
- var _loop_13 = function (returnStatement) {
+ changes.insertModifierAt(sourceFile, pos, 131 /* AsyncKeyword */, options);
+ var _loop_14 = function (returnStatement) {
ts.forEachChild(returnStatement, function visit(node) {
if (ts.isCallExpression(node)) {
- var newNodes = transformExpression(node, transformer);
+ var newNodes = transformExpression(node, node, transformer, /*hasContinuation*/ false);
+ if (hasFailed()) {
+ return true; // return something truthy to shortcut out of more work
+ }
changes.replaceNodeWithNodes(sourceFile, returnStatement, newNodes);
}
else if (!ts.isFunctionLike(node)) {
ts.forEachChild(node, visit);
+ if (hasFailed()) {
+ return true; // return something truthy to shortcut out of more work
+ }
}
});
+ if (hasFailed()) {
+ return { value: void 0 };
+ }
};
for (var _i = 0, returnStatements_1 = returnStatements; _i < returnStatements_1.length; _i++) {
var returnStatement = returnStatements_1[_i];
- _loop_13(returnStatement);
+ var state_5 = _loop_14(returnStatement);
+ if (typeof state_5 === "object")
+ return state_5.value;
}
}
function getReturnStatementsWithPromiseHandlers(body, checker) {
@@ -144468,9 +147337,10 @@ var ts;
setOfExpressionsToReturn.add(ts.getNodeId(node));
ts.forEach(node.arguments, visit);
}
- else if (isPromiseReturningCallExpression(node, checker, "catch")) {
+ else if (isPromiseReturningCallExpression(node, checker, "catch") ||
+ isPromiseReturningCallExpression(node, checker, "finally")) {
setOfExpressionsToReturn.add(ts.getNodeId(node));
- // if .catch() is the last call in the chain, move leftward in the chain until we hit something else that should be returned
+ // if .catch() or .finally() is the last call in the chain, move leftward in the chain until we hit something else that should be returned
ts.forEachChild(node, visit);
}
else if (isPromiseTypedExpression(node, checker)) {
@@ -144490,6 +147360,38 @@ var ts;
var nodeType = isExpressionOfName && checker.getTypeAtLocation(node);
return !!(nodeType && checker.getPromisedTypeOfPromise(nodeType));
}
+ // NOTE: this is a mostly copy of `isReferenceToType` from checker.ts. While this violates DRY, it keeps
+ // `isReferenceToType` in checker local to the checker to avoid the cost of a property lookup on `ts`.
+ function isReferenceToType(type, target) {
+ return (ts.getObjectFlags(type) & 4 /* Reference */) !== 0
+ && type.target === target;
+ }
+ function getExplicitPromisedTypeOfPromiseReturningCallExpression(node, callback, checker) {
+ if (node.expression.name.escapedText === "finally") {
+ // for a `finally`, there's no type argument
+ return undefined;
+ }
+ // If the call to `then` or `catch` comes from the global `Promise` or `PromiseLike` type, we can safely use the
+ // type argument supplied for the callback. For other promise types we would need a more complex heuristic to determine
+ // which type argument is safe to use as an annotation.
+ var promiseType = checker.getTypeAtLocation(node.expression.expression);
+ if (isReferenceToType(promiseType, checker.getPromiseType()) ||
+ isReferenceToType(promiseType, checker.getPromiseLikeType())) {
+ if (node.expression.name.escapedText === "then") {
+ if (callback === ts.elementAt(node.arguments, 0)) {
+ // for the `onfulfilled` callback, use the first type argument
+ return ts.elementAt(node.typeArguments, 0);
+ }
+ else if (callback === ts.elementAt(node.arguments, 1)) {
+ // for the `onrejected` callback, use the second type argument
+ return ts.elementAt(node.typeArguments, 1);
+ }
+ }
+ else {
+ return ts.elementAt(node.typeArguments, 0);
+ }
+ }
+ }
function isPromiseTypedExpression(node, checker) {
if (!ts.isExpression(node))
return false;
@@ -144570,104 +147472,189 @@ var ts;
var identifier = numVarsSameName === 0 ? name : ts.factory.createIdentifier(name.text + "_" + numVarsSameName);
return createSynthIdentifier(identifier);
}
+ function hasFailed() {
+ return !codeActionSucceeded;
+ }
function silentFail() {
codeActionSucceeded = false;
return ts.emptyArray;
}
// dispatch function to recursively build the refactoring
// should be kept up to date with isFixablePromiseHandler in suggestionDiagnostics.ts
- function transformExpression(node, transformer, prevArgName) {
+ /**
+ * @param hasContinuation Whether another `then`, `catch`, or `finally` continuation follows the continuation to which this expression belongs.
+ * @param continuationArgName The argument name for the continuation that follows this call.
+ */
+ function transformExpression(returnContextNode, node, transformer, hasContinuation, continuationArgName) {
if (isPromiseReturningCallExpression(node, transformer.checker, "then")) {
- if (node.arguments.length === 0)
- return silentFail();
- return transformThen(node, transformer, prevArgName);
+ return transformThen(node, ts.elementAt(node.arguments, 0), ts.elementAt(node.arguments, 1), transformer, hasContinuation, continuationArgName);
}
if (isPromiseReturningCallExpression(node, transformer.checker, "catch")) {
- return transformCatch(node, transformer, prevArgName);
+ return transformCatch(node, ts.elementAt(node.arguments, 0), transformer, hasContinuation, continuationArgName);
+ }
+ if (isPromiseReturningCallExpression(node, transformer.checker, "finally")) {
+ return transformFinally(node, ts.elementAt(node.arguments, 0), transformer, hasContinuation, continuationArgName);
}
if (ts.isPropertyAccessExpression(node)) {
- return transformExpression(node.expression, transformer, prevArgName);
+ return transformExpression(returnContextNode, node.expression, transformer, hasContinuation, continuationArgName);
}
var nodeType = transformer.checker.getTypeAtLocation(node);
if (nodeType && transformer.checker.getPromisedTypeOfPromise(nodeType)) {
- ts.Debug.assertNode(node.original.parent, ts.isPropertyAccessExpression);
- return transformPromiseExpressionOfPropertyAccess(node, transformer, prevArgName);
+ ts.Debug.assertNode(ts.getOriginalNode(node).parent, ts.isPropertyAccessExpression);
+ return transformPromiseExpressionOfPropertyAccess(returnContextNode, node, transformer, hasContinuation, continuationArgName);
}
return silentFail();
}
- function transformCatch(node, transformer, prevArgName) {
- var func = ts.singleOrUndefined(node.arguments);
- var argName = func ? getArgBindingName(func, transformer) : undefined;
+ function isNullOrUndefined(_a, node) {
+ var checker = _a.checker;
+ if (node.kind === 104 /* NullKeyword */)
+ return true;
+ if (ts.isIdentifier(node) && !ts.isGeneratedIdentifier(node) && ts.idText(node) === "undefined") {
+ var symbol = checker.getSymbolAtLocation(node);
+ return !symbol || checker.isUndefinedSymbol(symbol);
+ }
+ return false;
+ }
+ function createUniqueSynthName(prevArgName) {
+ var renamedPrevArg = ts.factory.createUniqueName(prevArgName.identifier.text, 16 /* Optimistic */);
+ return createSynthIdentifier(renamedPrevArg);
+ }
+ function getPossibleNameForVarDecl(node, transformer, continuationArgName) {
var possibleNameForVarDecl;
- // If there is another call in the chain after the .catch() we are transforming, we will need to save the result of both paths (try block and catch block)
- // To do this, we will need to synthesize a variable that we were not aware of while we were adding identifiers to the synthNamesMap
- // We will use the prevArgName and then update the synthNamesMap with a new variable name for the next transformation step
- if (prevArgName && !shouldReturn(node, transformer)) {
- if (isSynthIdentifier(prevArgName)) {
- possibleNameForVarDecl = prevArgName;
+ // If there is another call in the chain after the .catch() or .finally() we are transforming, we will need to save the result of both paths
+ // (try block and catch/finally block). To do this, we will need to synthesize a variable that we were not aware of while we were adding
+ // identifiers to the synthNamesMap. We will use the continuationArgName and then update the synthNamesMap with a new variable name for
+ // the next transformation step
+ if (continuationArgName && !shouldReturn(node, transformer)) {
+ if (isSynthIdentifier(continuationArgName)) {
+ possibleNameForVarDecl = continuationArgName;
transformer.synthNamesMap.forEach(function (val, key) {
- if (val.identifier.text === prevArgName.identifier.text) {
- var newSynthName = createUniqueSynthName(prevArgName);
+ if (val.identifier.text === continuationArgName.identifier.text) {
+ var newSynthName = createUniqueSynthName(continuationArgName);
transformer.synthNamesMap.set(key, newSynthName);
}
});
}
else {
- possibleNameForVarDecl = createSynthIdentifier(ts.factory.createUniqueName("result", 16 /* Optimistic */), prevArgName.types);
+ possibleNameForVarDecl = createSynthIdentifier(ts.factory.createUniqueName("result", 16 /* Optimistic */), continuationArgName.types);
}
// We are about to write a 'let' variable declaration, but `transformExpression` for both
- // the try block and catch block will assign to this name. Setting this flag indicates
+ // the try block and catch/finally block will assign to this name. Setting this flag indicates
// that future assignments should be written as `name = value` instead of `const name = value`.
- possibleNameForVarDecl.hasBeenDeclared = true;
+ declareSynthIdentifier(possibleNameForVarDecl);
}
- var tryBlock = ts.factory.createBlock(transformExpression(node.expression, transformer, possibleNameForVarDecl));
- var transformationBody = func ? getTransformationBody(func, possibleNameForVarDecl, argName, node, transformer) : ts.emptyArray;
- var catchArg = argName ? isSynthIdentifier(argName) ? argName.identifier.text : argName.bindingPattern : "e";
- var catchVariableDeclaration = ts.factory.createVariableDeclaration(catchArg);
- var catchClause = ts.factory.createCatchClause(catchVariableDeclaration, ts.factory.createBlock(transformationBody));
+ return possibleNameForVarDecl;
+ }
+ function finishCatchOrFinallyTransform(node, transformer, tryStatement, possibleNameForVarDecl, continuationArgName) {
+ var statements = [];
// In order to avoid an implicit any, we will synthesize a type for the declaration using the unions of the types of both paths (try block and catch block)
- var varDeclList;
var varDeclIdentifier;
if (possibleNameForVarDecl && !shouldReturn(node, transformer)) {
- varDeclIdentifier = ts.getSynthesizedDeepClone(possibleNameForVarDecl.identifier);
+ varDeclIdentifier = ts.getSynthesizedDeepClone(declareSynthIdentifier(possibleNameForVarDecl));
var typeArray = possibleNameForVarDecl.types;
var unionType = transformer.checker.getUnionType(typeArray, 2 /* Subtype */);
var unionTypeNode = transformer.isInJSFile ? undefined : transformer.checker.typeToTypeNode(unionType, /*enclosingDeclaration*/ undefined, /*flags*/ undefined);
var varDecl = [ts.factory.createVariableDeclaration(varDeclIdentifier, /*exclamationToken*/ undefined, unionTypeNode)];
- varDeclList = ts.factory.createVariableStatement(/*modifiers*/ undefined, ts.factory.createVariableDeclarationList(varDecl, 1 /* Let */));
+ var varDeclList = ts.factory.createVariableStatement(/*modifiers*/ undefined, ts.factory.createVariableDeclarationList(varDecl, 1 /* Let */));
+ statements.push(varDeclList);
}
- var tryStatement = ts.factory.createTryStatement(tryBlock, catchClause, /*finallyBlock*/ undefined);
- var destructuredResult = prevArgName && varDeclIdentifier && isSynthBindingPattern(prevArgName)
- && ts.factory.createVariableStatement(/*modifiers*/ undefined, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(ts.getSynthesizedDeepClone(prevArgName.bindingPattern), /*exclamationToken*/ undefined, /*type*/ undefined, varDeclIdentifier)], 2 /* Const */));
- return ts.compact([varDeclList, tryStatement, destructuredResult]);
+ statements.push(tryStatement);
+ if (continuationArgName && varDeclIdentifier && isSynthBindingPattern(continuationArgName)) {
+ statements.push(ts.factory.createVariableStatement(
+ /*modifiers*/ undefined, ts.factory.createVariableDeclarationList([
+ ts.factory.createVariableDeclaration(ts.getSynthesizedDeepClone(declareSynthBindingPattern(continuationArgName)),
+ /*exclamationToken*/ undefined,
+ /*type*/ undefined, varDeclIdentifier)
+ ], 2 /* Const */)));
+ }
+ return statements;
}
- function createUniqueSynthName(prevArgName) {
- var renamedPrevArg = ts.factory.createUniqueName(prevArgName.identifier.text, 16 /* Optimistic */);
- return createSynthIdentifier(renamedPrevArg);
+ /**
+ * @param hasContinuation Whether another `then`, `catch`, or `finally` continuation follows this continuation.
+ * @param continuationArgName The argument name for the continuation that follows this call.
+ */
+ function transformFinally(node, onFinally, transformer, hasContinuation, continuationArgName) {
+ if (!onFinally || isNullOrUndefined(transformer, onFinally)) {
+ // Ignore this call as it has no effect on the result
+ return transformExpression(/* returnContextNode */ node, node.expression.expression, transformer, hasContinuation, continuationArgName);
+ }
+ var possibleNameForVarDecl = getPossibleNameForVarDecl(node, transformer, continuationArgName);
+ // Transform the left-hand-side of `.finally` into an array of inlined statements. We pass `true` for hasContinuation as `node` is the outer continuation.
+ var inlinedLeftHandSide = transformExpression(/*returnContextNode*/ node, node.expression.expression, transformer, /*hasContinuation*/ true, possibleNameForVarDecl);
+ if (hasFailed())
+ return silentFail(); // shortcut out of more work
+ // Transform the callback argument into an array of inlined statements. We pass whether we have an outer continuation here
+ // as that indicates whether `return` is valid.
+ var inlinedCallback = transformCallbackArgument(onFinally, hasContinuation, /*continuationArgName*/ undefined, /*argName*/ undefined, node, transformer);
+ if (hasFailed())
+ return silentFail(); // shortcut out of more work
+ var tryBlock = ts.factory.createBlock(inlinedLeftHandSide);
+ var finallyBlock = ts.factory.createBlock(inlinedCallback);
+ var tryStatement = ts.factory.createTryStatement(tryBlock, /*catchClause*/ undefined, finallyBlock);
+ return finishCatchOrFinallyTransform(node, transformer, tryStatement, possibleNameForVarDecl, continuationArgName);
+ }
+ /**
+ * @param hasContinuation Whether another `then`, `catch`, or `finally` continuation follows this continuation.
+ * @param continuationArgName The argument name for the continuation that follows this call.
+ */
+ function transformCatch(node, onRejected, transformer, hasContinuation, continuationArgName) {
+ if (!onRejected || isNullOrUndefined(transformer, onRejected)) {
+ // Ignore this call as it has no effect on the result
+ return transformExpression(/* returnContextNode */ node, node.expression.expression, transformer, hasContinuation, continuationArgName);
+ }
+ var inputArgName = getArgBindingName(onRejected, transformer);
+ var possibleNameForVarDecl = getPossibleNameForVarDecl(node, transformer, continuationArgName);
+ // Transform the left-hand-side of `.then`/`.catch` into an array of inlined statements. We pass `true` for hasContinuation as `node` is the outer continuation.
+ var inlinedLeftHandSide = transformExpression(/*returnContextNode*/ node, node.expression.expression, transformer, /*hasContinuation*/ true, possibleNameForVarDecl);
+ if (hasFailed())
+ return silentFail(); // shortcut out of more work
+ // Transform the callback argument into an array of inlined statements. We pass whether we have an outer continuation here
+ // as that indicates whether `return` is valid.
+ var inlinedCallback = transformCallbackArgument(onRejected, hasContinuation, possibleNameForVarDecl, inputArgName, node, transformer);
+ if (hasFailed())
+ return silentFail(); // shortcut out of more work
+ var tryBlock = ts.factory.createBlock(inlinedLeftHandSide);
+ var catchClause = ts.factory.createCatchClause(inputArgName && ts.getSynthesizedDeepClone(declareSynthBindingName(inputArgName)), ts.factory.createBlock(inlinedCallback));
+ var tryStatement = ts.factory.createTryStatement(tryBlock, catchClause, /*finallyBlock*/ undefined);
+ return finishCatchOrFinallyTransform(node, transformer, tryStatement, possibleNameForVarDecl, continuationArgName);
}
- function transformThen(node, transformer, prevArgName) {
- var _a = node.arguments, onFulfilled = _a[0], onRejected = _a[1];
- var onFulfilledArgumentName = getArgBindingName(onFulfilled, transformer);
- var transformationBody = getTransformationBody(onFulfilled, prevArgName, onFulfilledArgumentName, node, transformer);
- if (onRejected) {
- var onRejectedArgumentName = getArgBindingName(onRejected, transformer);
- var tryBlock = ts.factory.createBlock(transformExpression(node.expression, transformer, onFulfilledArgumentName).concat(transformationBody));
- var transformationBody2 = getTransformationBody(onRejected, prevArgName, onRejectedArgumentName, node, transformer);
- var catchArg = onRejectedArgumentName ? isSynthIdentifier(onRejectedArgumentName) ? onRejectedArgumentName.identifier.text : onRejectedArgumentName.bindingPattern : "e";
- var catchVariableDeclaration = ts.factory.createVariableDeclaration(catchArg);
- var catchClause = ts.factory.createCatchClause(catchVariableDeclaration, ts.factory.createBlock(transformationBody2));
- return [ts.factory.createTryStatement(tryBlock, catchClause, /* finallyBlock */ undefined)];
+ /**
+ * @param hasContinuation Whether another `then`, `catch`, or `finally` continuation follows this continuation.
+ * @param continuationArgName The argument name for the continuation that follows this call.
+ */
+ function transformThen(node, onFulfilled, onRejected, transformer, hasContinuation, continuationArgName) {
+ if (!onFulfilled || isNullOrUndefined(transformer, onFulfilled)) {
+ // If we don't have an `onfulfilled` callback, try treating this as a `.catch`.
+ return transformCatch(node, onRejected, transformer, hasContinuation, continuationArgName);
}
- return transformExpression(node.expression, transformer, onFulfilledArgumentName).concat(transformationBody);
+ // We don't currently support transforming a `.then` with both onfulfilled and onrejected handlers, per GH#38152.
+ if (onRejected && !isNullOrUndefined(transformer, onRejected)) {
+ return silentFail();
+ }
+ var inputArgName = getArgBindingName(onFulfilled, transformer);
+ // Transform the left-hand-side of `.then` into an array of inlined statements. We pass `true` for hasContinuation as `node` is the outer continuation.
+ var inlinedLeftHandSide = transformExpression(node.expression.expression, node.expression.expression, transformer, /*hasContinuation*/ true, inputArgName);
+ if (hasFailed())
+ return silentFail(); // shortcut out of more work
+ // Transform the callback argument into an array of inlined statements. We pass whether we have an outer continuation here
+ // as that indicates whether `return` is valid.
+ var inlinedCallback = transformCallbackArgument(onFulfilled, hasContinuation, continuationArgName, inputArgName, node, transformer);
+ if (hasFailed())
+ return silentFail(); // shortcut out of more work
+ return ts.concatenate(inlinedLeftHandSide, inlinedCallback);
}
/**
* Transforms the 'x' part of `x.then(...)`, or the 'y()' part of `y().catch(...)`, where 'x' and 'y()' are Promises.
*/
- function transformPromiseExpressionOfPropertyAccess(node, transformer, prevArgName) {
- if (shouldReturn(node, transformer)) {
- return [ts.factory.createReturnStatement(ts.getSynthesizedDeepClone(node))];
+ function transformPromiseExpressionOfPropertyAccess(returnContextNode, node, transformer, hasContinuation, continuationArgName) {
+ if (shouldReturn(returnContextNode, transformer)) {
+ var returnValue = ts.getSynthesizedDeepClone(node);
+ if (hasContinuation) {
+ returnValue = ts.factory.createAwaitExpression(returnValue);
+ }
+ return [ts.factory.createReturnStatement(returnValue)];
}
- return createVariableOrAssignmentOrExpressionStatement(prevArgName, ts.factory.createAwaitExpression(node), /*typeAnnotation*/ undefined);
+ return createVariableOrAssignmentOrExpressionStatement(continuationArgName, ts.factory.createAwaitExpression(node), /*typeAnnotation*/ undefined);
}
function createVariableOrAssignmentOrExpressionStatement(variableName, rightHandSide, typeAnnotation) {
if (!variableName || isEmptyBindingName(variableName)) {
@@ -144676,12 +147663,12 @@ var ts;
}
if (isSynthIdentifier(variableName) && variableName.hasBeenDeclared) {
// if the variable has already been declared, we don't need "let" or "const"
- return [ts.factory.createExpressionStatement(ts.factory.createAssignment(ts.getSynthesizedDeepClone(variableName.identifier), rightHandSide))];
+ return [ts.factory.createExpressionStatement(ts.factory.createAssignment(ts.getSynthesizedDeepClone(referenceSynthIdentifier(variableName)), rightHandSide))];
}
return [
ts.factory.createVariableStatement(
/*modifiers*/ undefined, ts.factory.createVariableDeclarationList([
- ts.factory.createVariableDeclaration(ts.getSynthesizedDeepClone(getNode(variableName)),
+ ts.factory.createVariableDeclaration(ts.getSynthesizedDeepClone(declareSynthBindingName(variableName)),
/*exclamationToken*/ undefined, typeAnnotation, rightHandSide)
], 2 /* Const */))
];
@@ -144696,21 +147683,26 @@ var ts;
return [ts.factory.createReturnStatement(expressionToReturn)];
}
// should be kept up to date with isFixablePromiseArgument in suggestionDiagnostics.ts
- function getTransformationBody(func, prevArgName, argName, parent, transformer) {
- var _a, _b, _c, _d, _e;
+ /**
+ * @param hasContinuation Whether another `then`, `catch`, or `finally` continuation follows the continuation to which this callback belongs.
+ * @param continuationArgName The argument name for the continuation that follows this call.
+ * @param inputArgName The argument name provided to this call
+ */
+ function transformCallbackArgument(func, hasContinuation, continuationArgName, inputArgName, parent, transformer) {
+ var _a;
switch (func.kind) {
case 104 /* NullKeyword */:
// do not produce a transformed statement for a null argument
break;
- case 204 /* PropertyAccessExpression */:
+ case 205 /* PropertyAccessExpression */:
case 79 /* Identifier */: // identifier includes undefined
- if (!argName) {
+ if (!inputArgName) {
// undefined was argument passed to promise handler
break;
}
- var synthCall = ts.factory.createCallExpression(ts.getSynthesizedDeepClone(func), /*typeArguments*/ undefined, isSynthIdentifier(argName) ? [argName.identifier] : []);
+ var synthCall = ts.factory.createCallExpression(ts.getSynthesizedDeepClone(func), /*typeArguments*/ undefined, isSynthIdentifier(inputArgName) ? [referenceSynthIdentifier(inputArgName)] : []);
if (shouldReturn(parent, transformer)) {
- return maybeAnnotateAndReturn(synthCall, (_a = parent.typeArguments) === null || _a === void 0 ? void 0 : _a[0]);
+ return maybeAnnotateAndReturn(synthCall, getExplicitPromisedTypeOfPromiseReturningCallExpression(parent, func, transformer.checker));
}
var type = transformer.checker.getTypeAtLocation(func);
var callSignatures = transformer.checker.getSignaturesOfType(type, 0 /* Call */);
@@ -144719,56 +147711,96 @@ var ts;
return silentFail();
}
var returnType = callSignatures[0].getReturnType();
- var varDeclOrAssignment = createVariableOrAssignmentOrExpressionStatement(prevArgName, ts.factory.createAwaitExpression(synthCall), (_b = parent.typeArguments) === null || _b === void 0 ? void 0 : _b[0]);
- if (prevArgName) {
- prevArgName.types.push(returnType);
+ var varDeclOrAssignment = createVariableOrAssignmentOrExpressionStatement(continuationArgName, ts.factory.createAwaitExpression(synthCall), getExplicitPromisedTypeOfPromiseReturningCallExpression(parent, func, transformer.checker));
+ if (continuationArgName) {
+ continuationArgName.types.push(transformer.checker.getAwaitedType(returnType) || returnType);
}
return varDeclOrAssignment;
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */: {
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */: {
var funcBody = func.body;
- var returnType_1 = (_c = getLastCallSignature(transformer.checker.getTypeAtLocation(func), transformer.checker)) === null || _c === void 0 ? void 0 : _c.getReturnType();
+ var returnType_1 = (_a = getLastCallSignature(transformer.checker.getTypeAtLocation(func), transformer.checker)) === null || _a === void 0 ? void 0 : _a.getReturnType();
// Arrow functions with block bodies { } will enter this control flow
if (ts.isBlock(funcBody)) {
var refactoredStmts = [];
var seenReturnStatement = false;
- for (var _i = 0, _f = funcBody.statements; _i < _f.length; _i++) {
- var statement = _f[_i];
+ for (var _i = 0, _b = funcBody.statements; _i < _b.length; _i++) {
+ var statement = _b[_i];
if (ts.isReturnStatement(statement)) {
seenReturnStatement = true;
if (ts.isReturnStatementWithFixablePromiseHandler(statement, transformer.checker)) {
- refactoredStmts = refactoredStmts.concat(getInnerTransformationBody(transformer, [statement], prevArgName));
+ refactoredStmts = refactoredStmts.concat(transformReturnStatementWithFixablePromiseHandler(transformer, statement, hasContinuation, continuationArgName));
}
else {
var possiblyAwaitedRightHandSide = returnType_1 && statement.expression ? getPossiblyAwaitedRightHandSide(transformer.checker, returnType_1, statement.expression) : statement.expression;
- refactoredStmts.push.apply(refactoredStmts, maybeAnnotateAndReturn(possiblyAwaitedRightHandSide, (_d = parent.typeArguments) === null || _d === void 0 ? void 0 : _d[0]));
+ refactoredStmts.push.apply(refactoredStmts, maybeAnnotateAndReturn(possiblyAwaitedRightHandSide, getExplicitPromisedTypeOfPromiseReturningCallExpression(parent, func, transformer.checker)));
}
}
+ else if (hasContinuation && ts.forEachReturnStatement(statement, ts.returnTrue)) {
+ // If there is a nested `return` in a callback that has a trailing continuation, we don't transform it as the resulting complexity is too great. For example:
+ //
+ // source | result
+ // -------------------------------------| ---------------------------------------
+ // function f(): Promise { | async function f9(): Promise {
+ // return foo().then(() => { | await foo();
+ // if (Math.random()) { | if (Math.random()) {
+ // return 1; | return 1; // incorrect early return
+ // } | }
+ // return 2; | return 2; // incorrect early return
+ // }).then(a => { | const a = undefined;
+ // return a + 1; | return a + 1;
+ // }); | }
+ // } |
+ //
+ // However, branching returns in the outermost continuation are acceptable as no other continuation follows it:
+ //
+ // source | result
+ //--------------------------------------|---------------------------------------
+ // function f() { | async function f() {
+ // return foo().then(res => { | const res = await foo();
+ // if (res.ok) { | if (res.ok) {
+ // return 1; | return 1;
+ // } | }
+ // else { | else {
+ // if (res.buffer.length > 5) { | if (res.buffer.length > 5) {
+ // return 2; | return 2;
+ // } | }
+ // else { | else {
+ // return 3; | return 3;
+ // } | }
+ // } | }
+ // }); | }
+ // } |
+ //
+ // We may improve this in the future, but for now the heuristics are too complex
+ return silentFail();
+ }
else {
refactoredStmts.push(statement);
}
}
return shouldReturn(parent, transformer)
? refactoredStmts.map(function (s) { return ts.getSynthesizedDeepClone(s); })
- : removeReturns(refactoredStmts, prevArgName, transformer, seenReturnStatement);
+ : removeReturns(refactoredStmts, continuationArgName, transformer, seenReturnStatement);
}
else {
- var innerRetStmts = ts.isFixablePromiseHandler(funcBody, transformer.checker) ? [ts.factory.createReturnStatement(funcBody)] : ts.emptyArray;
- var innerCbBody = getInnerTransformationBody(transformer, innerRetStmts, prevArgName);
- if (innerCbBody.length > 0) {
- return innerCbBody;
+ var inlinedStatements = ts.isFixablePromiseHandler(funcBody, transformer.checker) ?
+ transformReturnStatementWithFixablePromiseHandler(transformer, ts.factory.createReturnStatement(funcBody), hasContinuation, continuationArgName) :
+ ts.emptyArray;
+ if (inlinedStatements.length > 0) {
+ return inlinedStatements;
}
if (returnType_1) {
var possiblyAwaitedRightHandSide = getPossiblyAwaitedRightHandSide(transformer.checker, returnType_1, funcBody);
if (!shouldReturn(parent, transformer)) {
- var transformedStatement = createVariableOrAssignmentOrExpressionStatement(prevArgName, possiblyAwaitedRightHandSide, /*typeAnnotation*/ undefined);
- if (prevArgName) {
- prevArgName.types.push(returnType_1);
+ var transformedStatement = createVariableOrAssignmentOrExpressionStatement(continuationArgName, possiblyAwaitedRightHandSide, /*typeAnnotation*/ undefined);
+ if (continuationArgName) {
+ continuationArgName.types.push(transformer.checker.getAwaitedType(returnType_1) || returnType_1);
}
return transformedStatement;
}
else {
- return maybeAnnotateAndReturn(possiblyAwaitedRightHandSide, (_e = parent.typeArguments) === null || _e === void 0 ? void 0 : _e[0]);
+ return maybeAnnotateAndReturn(possiblyAwaitedRightHandSide, getExplicitPromisedTypeOfPromiseReturningCallExpression(parent, func, transformer.checker));
}
}
else {
@@ -144800,8 +147832,11 @@ var ts;
if (prevArgName === undefined) {
ret.push(ts.factory.createExpressionStatement(possiblyAwaitedExpression));
}
+ else if (isSynthIdentifier(prevArgName) && prevArgName.hasBeenDeclared) {
+ ret.push(ts.factory.createExpressionStatement(ts.factory.createAssignment(referenceSynthIdentifier(prevArgName), possiblyAwaitedExpression)));
+ }
else {
- ret.push(ts.factory.createVariableStatement(/*modifiers*/ undefined, (ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(getNode(prevArgName), /*exclamationToken*/ undefined, /*type*/ undefined, possiblyAwaitedExpression)], 2 /* Const */))));
+ ret.push(ts.factory.createVariableStatement(/*modifiers*/ undefined, (ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(declareSynthBindingName(prevArgName), /*exclamationToken*/ undefined, /*type*/ undefined, possiblyAwaitedExpression)], 2 /* Const */))));
}
}
}
@@ -144811,27 +147846,28 @@ var ts;
}
// if block has no return statement, need to define prevArgName as undefined to prevent undeclared variables
if (!seenReturnStatement && prevArgName !== undefined) {
- ret.push(ts.factory.createVariableStatement(/*modifiers*/ undefined, (ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(getNode(prevArgName), /*exclamationToken*/ undefined, /*type*/ undefined, ts.factory.createIdentifier("undefined"))], 2 /* Const */))));
+ ret.push(ts.factory.createVariableStatement(/*modifiers*/ undefined, (ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(declareSynthBindingName(prevArgName), /*exclamationToken*/ undefined, /*type*/ undefined, ts.factory.createIdentifier("undefined"))], 2 /* Const */))));
}
return ret;
}
- function getInnerTransformationBody(transformer, innerRetStmts, prevArgName) {
+ /**
+ * @param hasContinuation Whether another `then`, `catch`, or `finally` continuation follows the continuation to which this statement belongs.
+ * @param continuationArgName The argument name for the continuation that follows this call.
+ */
+ function transformReturnStatementWithFixablePromiseHandler(transformer, innerRetStmt, hasContinuation, continuationArgName) {
var innerCbBody = [];
- for (var _i = 0, innerRetStmts_1 = innerRetStmts; _i < innerRetStmts_1.length; _i++) {
- var stmt = innerRetStmts_1[_i];
- ts.forEachChild(stmt, function visit(node) {
- if (ts.isCallExpression(node)) {
- var temp = transformExpression(node, transformer, prevArgName);
- innerCbBody = innerCbBody.concat(temp);
- if (innerCbBody.length > 0) {
- return;
- }
- }
- else if (!ts.isFunctionLike(node)) {
- ts.forEachChild(node, visit);
+ ts.forEachChild(innerRetStmt, function visit(node) {
+ if (ts.isCallExpression(node)) {
+ var temp = transformExpression(node, node, transformer, hasContinuation, continuationArgName);
+ innerCbBody = innerCbBody.concat(temp);
+ if (innerCbBody.length > 0) {
+ return;
}
- });
- }
+ }
+ else if (!ts.isFunctionLike(node)) {
+ ts.forEachChild(node, visit);
+ }
+ });
return innerCbBody;
}
function getArgBindingName(funcNode, transformer) {
@@ -144890,18 +147926,33 @@ var ts;
}
return ts.every(bindingName.elements, isEmptyBindingName);
}
- function getNode(bindingName) {
- return isSynthIdentifier(bindingName) ? bindingName.identifier : bindingName.bindingPattern;
- }
function createSynthIdentifier(identifier, types) {
if (types === void 0) { types = []; }
- return { kind: 0 /* Identifier */, identifier: identifier, types: types, hasBeenDeclared: false };
+ return { kind: 0 /* Identifier */, identifier: identifier, types: types, hasBeenDeclared: false, hasBeenReferenced: false };
}
function createSynthBindingPattern(bindingPattern, elements, types) {
if (elements === void 0) { elements = ts.emptyArray; }
if (types === void 0) { types = []; }
return { kind: 1 /* BindingPattern */, bindingPattern: bindingPattern, elements: elements, types: types };
}
+ function referenceSynthIdentifier(synthId) {
+ synthId.hasBeenReferenced = true;
+ return synthId.identifier;
+ }
+ function declareSynthBindingName(synthName) {
+ return isSynthIdentifier(synthName) ? declareSynthIdentifier(synthName) : declareSynthBindingPattern(synthName);
+ }
+ function declareSynthBindingPattern(synthPattern) {
+ for (var _i = 0, _a = synthPattern.elements; _i < _a.length; _i++) {
+ var element = _a[_i];
+ declareSynthBindingName(element);
+ }
+ return synthPattern.bindingPattern;
+ }
+ function declareSynthIdentifier(synthId) {
+ synthId.hasBeenDeclared = true;
+ return synthId.identifier;
+ }
function isSynthIdentifier(bindingName) {
return bindingName.kind === 0 /* Identifier */;
}
@@ -144919,11 +147970,11 @@ var ts;
var codefix;
(function (codefix) {
codefix.registerCodeFix({
- errorCodes: [ts.Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module.code],
+ errorCodes: [ts.Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES_module.code],
getCodeActions: function (context) {
var sourceFile = context.sourceFile, program = context.program, preferences = context.preferences;
var changes = ts.textChanges.ChangeTracker.with(context, function (changes) {
- var moduleExportsChangedToDefault = convertFileToEs6Module(sourceFile, program.getTypeChecker(), changes, program.getCompilerOptions().target, ts.getQuotePreference(sourceFile, preferences));
+ var moduleExportsChangedToDefault = convertFileToEsModule(sourceFile, program.getTypeChecker(), changes, ts.getEmitScriptTarget(program.getCompilerOptions()), ts.getQuotePreference(sourceFile, preferences));
if (moduleExportsChangedToDefault) {
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var importingFile = _a[_i];
@@ -144932,22 +147983,22 @@ var ts;
}
});
// No support for fix-all since this applies to the whole file at once anyway.
- return [codefix.createCodeFixActionWithoutFixAll("convertToEs6Module", changes, ts.Diagnostics.Convert_to_ES6_module)];
+ return [codefix.createCodeFixActionWithoutFixAll("convertToEsModule", changes, ts.Diagnostics.Convert_to_ES_module)];
},
});
function fixImportOfModuleExports(importingFile, exportingFile, changes, quotePreference) {
for (var _i = 0, _a = importingFile.imports; _i < _a.length; _i++) {
var moduleSpecifier = _a[_i];
- var imported = ts.getResolvedModule(importingFile, moduleSpecifier.text);
+ var imported = ts.getResolvedModule(importingFile, moduleSpecifier.text, ts.getModeForUsageLocation(importingFile, moduleSpecifier));
if (!imported || imported.resolvedFileName !== exportingFile.fileName) {
continue;
}
var importNode = ts.importFromModuleSpecifier(moduleSpecifier);
switch (importNode.kind) {
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
changes.replaceNode(importingFile, importNode, ts.makeImport(importNode.name, /*namedImports*/ undefined, moduleSpecifier, quotePreference));
break;
- case 206 /* CallExpression */:
+ case 207 /* CallExpression */:
if (ts.isRequireCall(importNode, /*checkArgumentIsStringLiteralLike*/ false)) {
changes.replaceNode(importingFile, importNode, ts.factory.createPropertyAccessExpression(ts.getSynthesizedDeepClone(importNode), "default"));
}
@@ -144956,7 +148007,7 @@ var ts;
}
}
/** @returns Whether we converted a `module.exports =` to a default export. */
- function convertFileToEs6Module(sourceFile, checker, changes, target, quotePreference) {
+ function convertFileToEsModule(sourceFile, checker, changes, target, quotePreference) {
var identifiers = { original: collectFreeIdentifiers(sourceFile), additional: new ts.Set() };
var exports = collectExportRenames(sourceFile, checker, identifiers);
convertExportsAccesses(sourceFile, exports, changes);
@@ -145014,20 +148065,20 @@ var ts;
}
function convertStatement(sourceFile, statement, checker, changes, identifiers, target, exports, useSitesToUnqualify, quotePreference) {
switch (statement.kind) {
- case 235 /* VariableStatement */:
+ case 236 /* VariableStatement */:
convertVariableStatement(sourceFile, statement, changes, checker, identifiers, target, quotePreference);
return false;
- case 236 /* ExpressionStatement */: {
+ case 237 /* ExpressionStatement */: {
var expression = statement.expression;
switch (expression.kind) {
- case 206 /* CallExpression */: {
+ case 207 /* CallExpression */: {
if (ts.isRequireCall(expression, /*checkArgumentIsStringLiteralLike*/ true)) {
// For side-effecting require() call, just make a side-effecting import.
changes.replaceNode(sourceFile, statement, ts.makeImport(/*name*/ undefined, /*namedImports*/ undefined, expression.arguments[0], quotePreference));
}
return false;
}
- case 219 /* BinaryExpression */: {
+ case 220 /* BinaryExpression */: {
var operatorToken = expression.operatorToken;
return operatorToken.kind === 63 /* EqualsToken */ && convertAssignment(sourceFile, checker, expression, changes, exports, useSitesToUnqualify);
}
@@ -145076,8 +148127,8 @@ var ts;
/** Converts `const name = require("moduleSpecifier").propertyName` */
function convertPropertyAccessImport(name, propertyName, moduleSpecifier, identifiers, quotePreference) {
switch (name.kind) {
- case 199 /* ObjectBindingPattern */:
- case 200 /* ArrayBindingPattern */: {
+ case 200 /* ObjectBindingPattern */:
+ case 201 /* ArrayBindingPattern */: {
// `const [a, b] = require("c").d` --> `import { d } from "c"; const [a, b] = d;`
var tmp = makeUniqueName(propertyName, identifiers);
return convertedImports([
@@ -145089,7 +148140,7 @@ var ts;
// `const a = require("b").c` --> `import { c as a } from "./b";
return convertedImports([makeSingleImport(name.text, propertyName, moduleSpecifier, quotePreference)]);
default:
- return ts.Debug.assertNever(name, "Convert to ES6 module got invalid syntax form " + name.kind);
+ return ts.Debug.assertNever(name, "Convert to ES module got invalid syntax form " + name.kind);
}
}
function convertAssignment(sourceFile, checker, assignment, changes, exports, useSitesToUnqualify) {
@@ -145128,16 +148179,16 @@ var ts;
function tryChangeModuleExportsObject(object, useSitesToUnqualify) {
var statements = ts.mapAllOrFail(object.properties, function (prop) {
switch (prop.kind) {
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
// TODO: Maybe we should handle this? See fourslash test `refactorConvertToEs6Module_export_object_shorthand.ts`.
// falls through
- case 292 /* ShorthandPropertyAssignment */:
- case 293 /* SpreadAssignment */:
+ case 295 /* ShorthandPropertyAssignment */:
+ case 296 /* SpreadAssignment */:
return undefined;
- case 291 /* PropertyAssignment */:
+ case 294 /* PropertyAssignment */:
return !ts.isIdentifier(prop.name) ? undefined : convertExportsDotXEquals_replaceNode(prop.name.text, prop.initializer, useSitesToUnqualify);
- case 167 /* MethodDeclaration */:
+ case 168 /* MethodDeclaration */:
return !ts.isIdentifier(prop.name) ? undefined : functionExpressionToDeclaration(prop.name.text, [ts.factory.createToken(93 /* ExportKeyword */)], prop, useSitesToUnqualify);
default:
ts.Debug.assertNever(prop, "Convert to ES6 got invalid prop kind " + prop.kind);
@@ -145156,7 +148207,7 @@ var ts;
*/
var newNodes = [
makeConst(/*modifiers*/ undefined, rename, assignment.right),
- makeExportDeclaration([ts.factory.createExportSpecifier(rename, text)]),
+ makeExportDeclaration([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, rename, text)]),
];
changes.replaceNodeWithNodes(sourceFile, assignment.parent, newNodes);
}
@@ -145178,7 +148229,7 @@ var ts;
return makeExportDeclaration(/*exportClause*/ undefined, moduleSpecifier);
}
function reExportDefault(moduleSpecifier) {
- return makeExportDeclaration([ts.factory.createExportSpecifier(/*propertyName*/ undefined, "default")], moduleSpecifier);
+ return makeExportDeclaration([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, "default")], moduleSpecifier);
}
function convertExportsPropertyAssignment(_a, sourceFile, changes) {
var left = _a.left, right = _a.right, parent = _a.parent;
@@ -145201,7 +148252,7 @@ var ts;
function convertExportsDotXEquals_replaceNode(name, exported, useSitesToUnqualify) {
var modifiers = [ts.factory.createToken(93 /* ExportKeyword */)];
switch (exported.kind) {
- case 211 /* FunctionExpression */: {
+ case 212 /* FunctionExpression */: {
var expressionName = exported.name;
if (expressionName && expressionName.text !== name) {
// `exports.f = function g() {}` -> `export const f = function g() {}`
@@ -145209,10 +148260,10 @@ var ts;
}
}
// falls through
- case 212 /* ArrowFunction */:
+ case 213 /* ArrowFunction */:
// `exports.f = function() {}` --> `export function f() {}`
return functionExpressionToDeclaration(name, modifiers, exported, useSitesToUnqualify);
- case 224 /* ClassExpression */:
+ case 225 /* ClassExpression */:
// `exports.C = class {}` --> `export class C {}`
return classExpressionToDeclaration(name, modifiers, exported, useSitesToUnqualify);
default:
@@ -145232,7 +148283,7 @@ var ts;
: ts.getSynthesizedDeepCloneWithReplacements(nodeOrNodes, /*includeTrivia*/ true, replaceNode);
function replaceNode(original) {
// We are replacing `mod.SomeExport` wih `SomeExport`, so we only need to look at PropertyAccessExpressions
- if (original.kind === 204 /* PropertyAccessExpression */) {
+ if (original.kind === 205 /* PropertyAccessExpression */) {
var replacement = useSitesToUnqualify.get(original);
// Remove entry from `useSitesToUnqualify` so the refactor knows it's taken care of by the parent statement we're replacing
useSitesToUnqualify.delete(original);
@@ -145247,7 +148298,7 @@ var ts;
*/
function convertSingleImport(name, moduleSpecifier, checker, identifiers, target, quotePreference) {
switch (name.kind) {
- case 199 /* ObjectBindingPattern */: {
+ case 200 /* ObjectBindingPattern */: {
var importSpecifiers = ts.mapAllOrFail(name.elements, function (e) {
return e.dotDotDotToken || e.initializer || e.propertyName && !ts.isIdentifier(e.propertyName) || !ts.isIdentifier(e.name)
? undefined
@@ -145260,7 +148311,7 @@ var ts;
}
}
// falls through -- object destructuring has an interesting pattern and must be a variable declaration
- case 200 /* ArrayBindingPattern */: {
+ case 201 /* ArrayBindingPattern */: {
/*
import x from "x";
const [a, b, c] = x;
@@ -145274,7 +148325,7 @@ var ts;
case 79 /* Identifier */:
return convertSingleIdentifierImport(name, moduleSpecifier, checker, identifiers, quotePreference);
default:
- return ts.Debug.assertNever(name, "Convert to ES6 module got invalid name kind " + name.kind);
+ return ts.Debug.assertNever(name, "Convert to ES module got invalid name kind " + name.kind);
}
}
/**
@@ -145320,7 +148371,7 @@ var ts;
}
var namedBindings = namedBindingsNames.size === 0 ? undefined : ts.arrayFrom(ts.mapIterator(namedBindingsNames.entries(), function (_a) {
var propertyName = _a[0], idName = _a[1];
- return ts.factory.createImportSpecifier(propertyName === idName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(idName));
+ return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName === idName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(idName));
}));
if (!namedBindings) {
// If it was unused, ensure that we at least import *something*.
@@ -145353,11 +148404,11 @@ var ts;
function isFreeIdentifier(node) {
var parent = node.parent;
switch (parent.kind) {
- case 204 /* PropertyAccessExpression */:
+ case 205 /* PropertyAccessExpression */:
return parent.name !== node;
- case 201 /* BindingElement */:
+ case 202 /* BindingElement */:
return parent.propertyName !== node;
- case 268 /* ImportSpecifier */:
+ case 269 /* ImportSpecifier */:
return parent.propertyName !== node;
default:
return true;
@@ -145378,7 +148429,7 @@ var ts;
: ts.makeImport(/*name*/ undefined, [makeImportSpecifier(propertyName, localName)], moduleSpecifier, quotePreference);
}
function makeImportSpecifier(propertyName, name) {
- return ts.factory.createImportSpecifier(propertyName !== undefined && propertyName !== name ? ts.factory.createIdentifier(propertyName) : undefined, ts.factory.createIdentifier(name));
+ return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName !== undefined && propertyName !== name ? ts.factory.createIdentifier(propertyName) : undefined, ts.factory.createIdentifier(name));
}
function makeConst(modifiers, name, init) {
return ts.factory.createVariableStatement(modifiers, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(name, /*exclamationToken*/ undefined, /*type*/ undefined, init)], 2 /* Const */));
@@ -145471,15 +148522,17 @@ var ts;
var exportDeclaration = exportClause.parent;
var typeExportSpecifiers = getTypeExportSpecifiers(exportSpecifier, context);
if (typeExportSpecifiers.length === exportClause.elements.length) {
- changes.insertModifierBefore(context.sourceFile, 150 /* TypeKeyword */, exportClause);
+ changes.insertModifierBefore(context.sourceFile, 151 /* TypeKeyword */, exportClause);
}
else {
var valueExportDeclaration = ts.factory.updateExportDeclaration(exportDeclaration, exportDeclaration.decorators, exportDeclaration.modifiers,
- /*isTypeOnly*/ false, ts.factory.updateNamedExports(exportClause, ts.filter(exportClause.elements, function (e) { return !ts.contains(typeExportSpecifiers, e); })), exportDeclaration.moduleSpecifier);
+ /*isTypeOnly*/ false, ts.factory.updateNamedExports(exportClause, ts.filter(exportClause.elements, function (e) { return !ts.contains(typeExportSpecifiers, e); })), exportDeclaration.moduleSpecifier,
+ /*assertClause*/ undefined);
var typeExportDeclaration = ts.factory.createExportDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
- /*isTypeOnly*/ true, ts.factory.createNamedExports(typeExportSpecifiers), exportDeclaration.moduleSpecifier);
+ /*isTypeOnly*/ true, ts.factory.createNamedExports(typeExportSpecifiers), exportDeclaration.moduleSpecifier,
+ /*assertClause*/ undefined);
changes.replaceNode(context.sourceFile, exportDeclaration, valueExportDeclaration, {
leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll,
trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Exclude
@@ -145543,7 +148596,8 @@ var ts;
/*decorators*/ undefined,
/*modifiers*/ undefined, ts.factory.createImportClause(
/*isTypeOnly*/ true, importClause.name,
- /*namedBindings*/ undefined), importDeclaration.moduleSpecifier));
+ /*namedBindings*/ undefined), importDeclaration.moduleSpecifier,
+ /*assertClause*/ undefined));
}
}
})(codefix = ts.codefix || (ts.codefix = {}));
@@ -145591,7 +148645,11 @@ var ts;
}
function doChange(changes, sourceFile, _a) {
var container = _a.container, typeNode = _a.typeNode, constraint = _a.constraint, name = _a.name;
- changes.replaceNode(sourceFile, container, ts.factory.createMappedTypeNode(/*readonlyToken*/ undefined, ts.factory.createTypeParameterDeclaration(name, ts.factory.createTypeReferenceNode(constraint)), /*nameType*/ undefined, /*questionToken*/ undefined, typeNode));
+ changes.replaceNode(sourceFile, container, ts.factory.createMappedTypeNode(
+ /*readonlyToken*/ undefined, ts.factory.createTypeParameterDeclaration(name, ts.factory.createTypeReferenceNode(constraint)),
+ /*nameType*/ undefined,
+ /*questionToken*/ undefined, typeNode,
+ /*members*/ undefined));
}
})(codefix = ts.codefix || (ts.codefix = {}));
})(ts || (ts = {}));
@@ -145700,13 +148758,13 @@ var ts;
codefix.registerCodeFix({
errorCodes: errorCodes,
getCodeActions: function (context) {
- var errorCode = context.errorCode, preferences = context.preferences, sourceFile = context.sourceFile, span = context.span;
+ var errorCode = context.errorCode, preferences = context.preferences, sourceFile = context.sourceFile, span = context.span, program = context.program;
var info = getFixesInfo(context, errorCode, span.start, /*useAutoImportProvider*/ true);
if (!info)
return undefined;
var fixes = info.fixes, symbolName = info.symbolName;
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
- return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference); });
+ return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, program.getCompilerOptions()); });
},
fixIds: [importFixId],
getAllCodeActions: function (context) {
@@ -145725,77 +148783,77 @@ var ts;
// Namespace fixes don't conflict, so just build a list.
var addToNamespace = [];
var importType = [];
- // Keys are import clause node IDs.
+ /** Keys are import clause node IDs. */
var addToExisting = new ts.Map();
+ /** Use `getNewImportEntry` for access */
var newImports = new ts.Map();
- return { addImportFromDiagnostic: addImportFromDiagnostic, addImportFromExportedSymbol: addImportFromExportedSymbol, writeFixes: writeFixes };
+ return { addImportFromDiagnostic: addImportFromDiagnostic, addImportFromExportedSymbol: addImportFromExportedSymbol, writeFixes: writeFixes, hasFixes: hasFixes };
function addImportFromDiagnostic(diagnostic, context) {
var info = getFixesInfo(context, diagnostic.code, diagnostic.start, useAutoImportProvider);
if (!info || !info.fixes.length)
return;
addImport(info);
}
- function addImportFromExportedSymbol(exportedSymbol, usageIsTypeOnly) {
+ function addImportFromExportedSymbol(exportedSymbol, isValidTypeOnlyUseSite) {
var moduleSymbol = ts.Debug.checkDefined(exportedSymbol.parent);
var symbolName = ts.getNameForExportedSymbol(exportedSymbol, ts.getEmitScriptTarget(compilerOptions));
var checker = program.getTypeChecker();
var symbol = checker.getMergedSymbol(ts.skipAlias(exportedSymbol, checker));
var exportInfos = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, host, program, preferences, useAutoImportProvider);
- var preferTypeOnlyImport = !!usageIsTypeOnly && compilerOptions.importsNotUsedAsValues === 2 /* Error */;
var useRequire = shouldUseRequire(sourceFile, program);
- var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined, preferTypeOnlyImport, useRequire, host, preferences);
+ var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
if (fix) {
addImport({ fixes: [fix], symbolName: symbolName });
}
}
function addImport(info) {
+ var _a, _b;
var fixes = info.fixes, symbolName = info.symbolName;
var fix = ts.first(fixes);
switch (fix.kind) {
case 0 /* UseNamespace */:
addToNamespace.push(fix);
break;
- case 1 /* ImportType */:
+ case 1 /* JsdocTypeImport */:
importType.push(fix);
break;
case 2 /* AddToExisting */: {
- var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, canUseTypeOnlyImport = fix.canUseTypeOnlyImport;
+ var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly;
var key = String(ts.getNodeId(importClauseOrBindingPattern));
var entry = addToExisting.get(key);
if (!entry) {
- addToExisting.set(key, entry = { importClauseOrBindingPattern: importClauseOrBindingPattern, defaultImport: undefined, namedImports: [], canUseTypeOnlyImport: canUseTypeOnlyImport });
+ addToExisting.set(key, entry = { importClauseOrBindingPattern: importClauseOrBindingPattern, defaultImport: undefined, namedImports: new ts.Map() });
}
if (importKind === 0 /* Named */) {
- ts.pushIfUnique(entry.namedImports, symbolName);
+ var prevValue = entry === null || entry === void 0 ? void 0 : entry.namedImports.get(symbolName);
+ entry.namedImports.set(symbolName, reduceAddAsTypeOnlyValues(prevValue, addAsTypeOnly));
}
else {
- ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport === symbolName, "(Add to Existing) Default import should be missing or match symbolName");
- entry.defaultImport = symbolName;
+ ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport.name === symbolName, "(Add to Existing) Default import should be missing or match symbolName");
+ entry.defaultImport = {
+ name: symbolName,
+ addAsTypeOnly: reduceAddAsTypeOnlyValues((_a = entry.defaultImport) === null || _a === void 0 ? void 0 : _a.addAsTypeOnly, addAsTypeOnly),
+ };
}
break;
}
case 3 /* AddNew */: {
- var moduleSpecifier = fix.moduleSpecifier, importKind = fix.importKind, useRequire = fix.useRequire, typeOnly = fix.typeOnly;
- var entry = newImports.get(moduleSpecifier);
- if (!entry) {
- newImports.set(moduleSpecifier, entry = { namedImports: [], namespaceLikeImport: undefined, typeOnly: typeOnly, useRequire: useRequire });
- }
- else {
- // An import clause can only be type-only if every import fix contributing to it can be type-only.
- entry.typeOnly = entry.typeOnly && typeOnly;
- }
+ var moduleSpecifier = fix.moduleSpecifier, importKind = fix.importKind, useRequire = fix.useRequire, addAsTypeOnly = fix.addAsTypeOnly;
+ var entry = getNewImportEntry(moduleSpecifier, importKind, useRequire, addAsTypeOnly);
+ ts.Debug.assert(entry.useRequire === useRequire, "(Add new) Tried to add an `import` and a `require` for the same module");
switch (importKind) {
case 1 /* Default */:
- ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport === symbolName, "(Add new) Default import should be missing or match symbolName");
- entry.defaultImport = symbolName;
+ ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport.name === symbolName, "(Add new) Default import should be missing or match symbolName");
+ entry.defaultImport = { name: symbolName, addAsTypeOnly: reduceAddAsTypeOnlyValues((_b = entry.defaultImport) === null || _b === void 0 ? void 0 : _b.addAsTypeOnly, addAsTypeOnly) };
break;
case 0 /* Named */:
- ts.pushIfUnique(entry.namedImports || (entry.namedImports = []), symbolName);
+ var prevValue = (entry.namedImports || (entry.namedImports = new ts.Map())).get(symbolName);
+ entry.namedImports.set(symbolName, reduceAddAsTypeOnlyValues(prevValue, addAsTypeOnly));
break;
case 3 /* CommonJS */:
case 2 /* Namespace */:
ts.Debug.assert(entry.namespaceLikeImport === undefined || entry.namespaceLikeImport.name === symbolName, "Namespacelike import shoudl be missing or match symbolName");
- entry.namespaceLikeImport = { importKind: importKind, name: symbolName };
+ entry.namespaceLikeImport = { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly };
break;
}
break;
@@ -145803,6 +148861,50 @@ var ts;
default:
ts.Debug.assertNever(fix, "fix wasn't never - got kind " + fix.kind);
}
+ function reduceAddAsTypeOnlyValues(prevValue, newValue) {
+ // `NotAllowed` overrides `Required` because one addition of a new import might be required to be type-only
+ // because of `--importsNotUsedAsValues=error`, but if a second addition of the same import is `NotAllowed`
+ // to be type-only, the reason the first one was `Required` - the unused runtime dependency - is now moot.
+ // Alternatively, if one addition is `Required` because it has no value meaning under `--preserveValueImports`
+ // and `--isolatedModules`, it should be impossible for another addition to be `NotAllowed` since that would
+ // mean a type is being referenced in a value location.
+ return Math.max(prevValue !== null && prevValue !== void 0 ? prevValue : 0, newValue);
+ }
+ function getNewImportEntry(moduleSpecifier, importKind, useRequire, addAsTypeOnly) {
+ // A default import that requires type-only makes the whole import type-only.
+ // (We could add `default` as a named import, but that style seems undesirable.)
+ // Under `--preserveValueImports` and `--importsNotUsedAsValues=error`, if a
+ // module default-exports a type but named-exports some values (weird), you would
+ // have to use a type-only default import and non-type-only named imports. These
+ // require two separate import declarations, so we build this into the map key.
+ var typeOnlyKey = newImportsKey(moduleSpecifier, /*topLevelTypeOnly*/ true);
+ var nonTypeOnlyKey = newImportsKey(moduleSpecifier, /*topLevelTypeOnly*/ false);
+ var typeOnlyEntry = newImports.get(typeOnlyKey);
+ var nonTypeOnlyEntry = newImports.get(nonTypeOnlyKey);
+ var newEntry = {
+ defaultImport: undefined,
+ namedImports: undefined,
+ namespaceLikeImport: undefined,
+ useRequire: useRequire
+ };
+ if (importKind === 1 /* Default */ && addAsTypeOnly === 2 /* Required */) {
+ if (typeOnlyEntry)
+ return typeOnlyEntry;
+ newImports.set(typeOnlyKey, newEntry);
+ return newEntry;
+ }
+ if (addAsTypeOnly === 1 /* Allowed */ && (typeOnlyEntry || nonTypeOnlyEntry)) {
+ return (typeOnlyEntry || nonTypeOnlyEntry);
+ }
+ if (nonTypeOnlyEntry) {
+ return nonTypeOnlyEntry;
+ }
+ newImports.set(nonTypeOnlyKey, newEntry);
+ return newEntry;
+ }
+ function newImportsKey(moduleSpecifier, topLevelTypeOnly) {
+ return (topLevelTypeOnly ? 1 : 0) + "|" + moduleSpecifier;
+ }
}
function writeFixes(changeTracker) {
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
@@ -145815,42 +148917,66 @@ var ts;
addImportType(changeTracker, sourceFile, fix, quotePreference);
}
addToExisting.forEach(function (_a) {
- var importClauseOrBindingPattern = _a.importClauseOrBindingPattern, defaultImport = _a.defaultImport, namedImports = _a.namedImports, canUseTypeOnlyImport = _a.canUseTypeOnlyImport;
- doAddExistingFix(changeTracker, sourceFile, importClauseOrBindingPattern, defaultImport, namedImports, canUseTypeOnlyImport);
+ var importClauseOrBindingPattern = _a.importClauseOrBindingPattern, defaultImport = _a.defaultImport, namedImports = _a.namedImports;
+ doAddExistingFix(changeTracker, sourceFile, importClauseOrBindingPattern, defaultImport, ts.arrayFrom(namedImports.entries(), function (_a) {
+ var name = _a[0], addAsTypeOnly = _a[1];
+ return ({ addAsTypeOnly: addAsTypeOnly, name: name });
+ }), compilerOptions);
});
var newDeclarations;
- newImports.forEach(function (_a, moduleSpecifier) {
- var useRequire = _a.useRequire, imports = __rest(_a, ["useRequire"]);
+ newImports.forEach(function (_a, key) {
+ var useRequire = _a.useRequire, defaultImport = _a.defaultImport, namedImports = _a.namedImports, namespaceLikeImport = _a.namespaceLikeImport;
+ var moduleSpecifier = key.slice(2); // From `${0 | 1}|${moduleSpecifier}` format
var getDeclarations = useRequire ? getNewRequires : getNewImports;
- newDeclarations = ts.combine(newDeclarations, getDeclarations(moduleSpecifier, quotePreference, imports));
+ var declarations = getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports && ts.arrayFrom(namedImports.entries(), function (_a) {
+ var name = _a[0], addAsTypeOnly = _a[1];
+ return ({ addAsTypeOnly: addAsTypeOnly, name: name });
+ }), namespaceLikeImport);
+ newDeclarations = ts.combine(newDeclarations, declarations);
});
if (newDeclarations) {
ts.insertImports(changeTracker, sourceFile, newDeclarations, /*blankLineBetween*/ true);
}
}
+ function hasFixes() {
+ return addToNamespace.length > 0 || importType.length > 0 || addToExisting.size > 0 || newImports.size > 0;
+ }
}
// Sorted with the preferred fix coming first.
var ImportFixKind;
(function (ImportFixKind) {
ImportFixKind[ImportFixKind["UseNamespace"] = 0] = "UseNamespace";
- ImportFixKind[ImportFixKind["ImportType"] = 1] = "ImportType";
+ ImportFixKind[ImportFixKind["JsdocTypeImport"] = 1] = "JsdocTypeImport";
ImportFixKind[ImportFixKind["AddToExisting"] = 2] = "AddToExisting";
ImportFixKind[ImportFixKind["AddNew"] = 3] = "AddNew";
})(ImportFixKind || (ImportFixKind = {}));
- function getImportCompletionAction(exportedSymbol, moduleSymbol, sourceFile, symbolName, host, program, formatContext, position, preferences) {
+ // These should not be combined as bitflags, but are given powers of 2 values to
+ // easily detect conflicts between `NotAllowed` and `Required` by giving them a unique sum.
+ // They're also ordered in terms of increasing priority for a fix-all scenario (see
+ // `reduceAddAsTypeOnlyValues`).
+ var AddAsTypeOnly;
+ (function (AddAsTypeOnly) {
+ AddAsTypeOnly[AddAsTypeOnly["Allowed"] = 1] = "Allowed";
+ AddAsTypeOnly[AddAsTypeOnly["Required"] = 2] = "Required";
+ AddAsTypeOnly[AddAsTypeOnly["NotAllowed"] = 4] = "NotAllowed";
+ })(AddAsTypeOnly || (AddAsTypeOnly = {}));
+ function getImportCompletionAction(targetSymbol, moduleSymbol, sourceFile, symbolName, host, program, formatContext, position, preferences) {
var compilerOptions = program.getCompilerOptions();
var exportInfos = ts.pathIsBareSpecifier(ts.stripQuotes(moduleSymbol.name))
- ? [getSymbolExportInfoForSymbol(exportedSymbol, moduleSymbol, program, host)]
- : getAllReExportingModules(sourceFile, exportedSymbol, moduleSymbol, symbolName, host, program, preferences, /*useAutoImportProvider*/ true);
+ ? [getSymbolExportInfoForSymbol(targetSymbol, moduleSymbol, program, host)]
+ : getAllReExportingModules(sourceFile, targetSymbol, moduleSymbol, symbolName, host, program, preferences, /*useAutoImportProvider*/ true);
var useRequire = shouldUseRequire(sourceFile, program);
- var preferTypeOnlyImport = compilerOptions.importsNotUsedAsValues === 2 /* Error */ && !ts.isSourceFileJS(sourceFile) && ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
- var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, preferTypeOnlyImport, useRequire, host, preferences));
- return { moduleSpecifier: fix.moduleSpecifier, codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, ts.getQuotePreference(sourceFile, preferences))) };
+ var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
+ var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
+ return {
+ moduleSpecifier: fix.moduleSpecifier,
+ codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, ts.getQuotePreference(sourceFile, preferences), compilerOptions))
+ };
}
codefix.getImportCompletionAction = getImportCompletionAction;
- function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, preferTypeOnlyImport, useRequire, host, preferences) {
+ function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
- return getBestFix(getImportFixes(exportInfos, symbolName, position, preferTypeOnlyImport, useRequire, program, sourceFile, host, preferences), sourceFile, program, host, preferences);
+ return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, host, preferences);
}
function codeFixActionToCodeAction(_a) {
var description = _a.description, changes = _a.changes, commands = _a.commands;
@@ -145876,7 +149002,7 @@ var ts;
}
}
}
- function getAllReExportingModules(importingFile, exportedSymbol, exportingModuleSymbol, symbolName, host, program, preferences, useAutoImportProvider) {
+ function getAllReExportingModules(importingFile, targetSymbol, exportingModuleSymbol, symbolName, host, program, preferences, useAutoImportProvider) {
var result = [];
var compilerOptions = program.getCompilerOptions();
var getModuleSpecifierResolutionHost = ts.memoizeOne(function (isFromPackageJson) {
@@ -145889,12 +149015,12 @@ var ts;
return;
}
var defaultInfo = ts.getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
- if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, compilerOptions.target) === symbolName) && ts.skipAlias(defaultInfo.symbol, checker) === exportedSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
+ if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions)) === symbolName) && ts.skipAlias(defaultInfo.symbol, checker) === targetSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
result.push({ symbol: defaultInfo.symbol, moduleSymbol: moduleSymbol, moduleFileName: moduleFile === null || moduleFile === void 0 ? void 0 : moduleFile.fileName, exportKind: defaultInfo.exportKind, targetFlags: ts.skipAlias(defaultInfo.symbol, checker).flags, isFromPackageJson: isFromPackageJson });
}
for (var _i = 0, _a = checker.getExportsAndPropertiesOfModule(moduleSymbol); _i < _a.length; _i++) {
var exported = _a[_i];
- if (exported.name === symbolName && ts.skipAlias(exported, checker) === exportedSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
+ if (exported.name === symbolName && checker.getMergedSymbol(ts.skipAlias(exported, checker)) === targetSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
result.push({ symbol: exported, moduleSymbol: moduleSymbol, moduleFileName: moduleFile === null || moduleFile === void 0 ? void 0 : moduleFile.fileName, exportKind: 0 /* Named */, targetFlags: ts.skipAlias(exported, checker).flags, isFromPackageJson: isFromPackageJson });
}
}
@@ -145908,24 +149034,21 @@ var ts;
function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, fromCacheOnly) {
var _a = getNewImportFixes(program, importingFile,
/*position*/ undefined,
- /*preferTypeOnlyImport*/ false,
+ /*isValidTypeOnlyUseSite*/ false,
/*useRequire*/ false, exportInfo, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
var result = getBestFix(fixes, importingFile, program, host, preferences);
return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
}
codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
- function isTypeOnlyPosition(sourceFile, position) {
- return ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
- }
function getImportFixes(exportInfos, symbolName,
/** undefined only for missing JSX namespace */
- position, preferTypeOnlyImport, useRequire, program, sourceFile, host, preferences) {
+ position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences) {
var checker = program.getTypeChecker();
var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
var useNamespace = position === undefined ? undefined : tryUseExistingNamespaceImport(existingImports, symbolName, position, checker);
- var addToExisting = tryAddToExistingImport(existingImports, position !== undefined && isTypeOnlyPosition(sourceFile, position));
+ var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
// Don't bother providing an action to add a new import if we can add to an existing one.
- var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, preferTypeOnlyImport, useRequire, host, preferences);
+ var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences);
return __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), addImport, true);
}
function tryUseExistingNamespaceImport(existingImports, symbolName, position, checker) {
@@ -145956,11 +149079,11 @@ var ts;
function getTargetModuleFromNamespaceLikeImport(declaration, checker) {
var _a;
switch (declaration.kind) {
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
return checker.resolveExternalModuleName(declaration.initializer.arguments[0]);
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return checker.getAliasedSymbol(declaration.symbol);
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
var namespaceImport = ts.tryCast((_a = declaration.importClause) === null || _a === void 0 ? void 0 : _a.namedBindings, ts.isNamespaceImport);
return namespaceImport && checker.getAliasedSymbol(namespaceImport.symbol);
default:
@@ -145970,24 +149093,44 @@ var ts;
function getNamespaceLikeImportText(declaration) {
var _a, _b, _c;
switch (declaration.kind) {
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
return (_a = ts.tryCast(declaration.name, ts.isIdentifier)) === null || _a === void 0 ? void 0 : _a.text;
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return declaration.name.text;
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
return (_c = ts.tryCast((_b = declaration.importClause) === null || _b === void 0 ? void 0 : _b.namedBindings, ts.isNamespaceImport)) === null || _c === void 0 ? void 0 : _c.name.text;
default:
return ts.Debug.assertNever(declaration);
}
}
- function tryAddToExistingImport(existingImports, canUseTypeOnlyImport) {
+ function getAddAsTypeOnly(isValidTypeOnlyUseSite, isForNewImportDeclaration, symbol, targetFlags, checker, compilerOptions) {
+ if (!isValidTypeOnlyUseSite) {
+ // Can't use a type-only import if the usage is an emitting position
+ return 4 /* NotAllowed */;
+ }
+ if (isForNewImportDeclaration && compilerOptions.importsNotUsedAsValues === 2 /* Error */) {
+ // Not writing a (top-level) type-only import here would create an error because the runtime dependency is unnecessary
+ return 2 /* Required */;
+ }
+ if (compilerOptions.isolatedModules && compilerOptions.preserveValueImports &&
+ (!(targetFlags & 111551 /* Value */) || !!checker.getTypeOnlyAliasDeclaration(symbol))) {
+ // A type-only import is required for this symbol if under these settings if the symbol will
+ // be erased, which will happen if the target symbol is purely a type or if it was exported/imported
+ // as type-only already somewhere between this import and the target.
+ return 2 /* Required */;
+ }
+ return 1 /* Allowed */;
+ }
+ function tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, compilerOptions) {
return ts.firstDefined(existingImports, function (_a) {
- var declaration = _a.declaration, importKind = _a.importKind;
- if (declaration.kind === 263 /* ImportEqualsDeclaration */)
+ var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
+ if (importKind === 3 /* CommonJS */ || importKind === 2 /* Namespace */ || declaration.kind === 264 /* ImportEqualsDeclaration */) {
+ // These kinds of imports are not combinable with anything
return undefined;
- if (declaration.kind === 252 /* VariableDeclaration */) {
- return (importKind === 0 /* Named */ || importKind === 1 /* Default */) && declaration.name.kind === 199 /* ObjectBindingPattern */
- ? { kind: 2 /* AddToExisting */, importClauseOrBindingPattern: declaration.name, importKind: importKind, moduleSpecifier: declaration.initializer.arguments[0].text, canUseTypeOnlyImport: false }
+ }
+ if (declaration.kind === 253 /* VariableDeclaration */) {
+ return (importKind === 0 /* Named */ || importKind === 1 /* Default */) && declaration.name.kind === 200 /* ObjectBindingPattern */
+ ? { kind: 2 /* AddToExisting */, importClauseOrBindingPattern: declaration.name, importKind: importKind, moduleSpecifier: declaration.initializer.arguments[0].text, addAsTypeOnly: 4 /* NotAllowed */ }
: undefined;
}
var importClause = declaration.importClause;
@@ -145998,13 +149141,29 @@ var ts;
// be added to an existing type-only import is adding a named import to existing named bindings.
if (importClause.isTypeOnly && !(importKind === 0 /* Named */ && namedBindings))
return undefined;
- return importKind === 1 /* Default */ && !name || importKind === 0 /* Named */ && (!namedBindings || namedBindings.kind === 267 /* NamedImports */)
- ? { kind: 2 /* AddToExisting */, importClauseOrBindingPattern: importClause, importKind: importKind, moduleSpecifier: declaration.moduleSpecifier.text, canUseTypeOnlyImport: canUseTypeOnlyImport }
- : undefined;
+ // N.B. we don't have to figure out whether to use the main program checker
+ // or the AutoImportProvider checker because we're adding to an existing import; the existence of
+ // the import guarantees the symbol came from the main program.
+ var addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ false, symbol, targetFlags, checker, compilerOptions);
+ if (importKind === 1 /* Default */ && (name || // Cannot add a default import to a declaration that already has one
+ addAsTypeOnly === 2 /* Required */ && namedBindings // Cannot add a default import as type-only if the import already has named bindings
+ ))
+ return undefined;
+ if (importKind === 0 /* Named */ &&
+ (namedBindings === null || namedBindings === void 0 ? void 0 : namedBindings.kind) === 267 /* NamespaceImport */ // Cannot add a named import to a declaration that has a namespace import
+ )
+ return undefined;
+ return {
+ kind: 2 /* AddToExisting */,
+ importClauseOrBindingPattern: importClause,
+ importKind: importKind,
+ moduleSpecifier: declaration.moduleSpecifier.text,
+ addAsTypeOnly: addAsTypeOnly,
+ };
});
}
function getExistingImportDeclarations(_a, checker, importingFile, compilerOptions) {
- var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags;
+ var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
// Can't use an es6 import for a type in JS.
if (!(targetFlags & 111551 /* Value */) && ts.isSourceFileJS(importingFile))
return ts.emptyArray;
@@ -146012,10 +149171,10 @@ var ts;
return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
var i = ts.importFromModuleSpecifier(moduleSpecifier);
if (ts.isRequireVariableDeclaration(i.parent)) {
- return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind } : undefined;
+ return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
}
- if (i.kind === 264 /* ImportDeclaration */ || i.kind === 263 /* ImportEqualsDeclaration */) {
- return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind } : undefined;
+ if (i.kind === 265 /* ImportDeclaration */ || i.kind === 264 /* ImportEqualsDeclaration */) {
+ return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
}
});
}
@@ -146047,44 +149206,50 @@ var ts;
// 5. Literally nothing to go on
return true;
}
- function getNewImportFixes(program, sourceFile, position, preferTypeOnlyImport, useRequire, moduleSymbols, host, preferences, fromCacheOnly) {
+ function getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, moduleSymbols, host, preferences, fromCacheOnly) {
var isJs = ts.isSourceFileJS(sourceFile);
var compilerOptions = program.getCompilerOptions();
var moduleSpecifierResolutionHost = ts.createModuleSpecifierResolutionHost(program, host);
- var checker = program.getTypeChecker();
+ var getChecker = ts.memoizeOne(function (isFromPackageJson) { return isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker(); });
var getModuleSpecifiers = fromCacheOnly
? function (moduleSymbol) { return ({ moduleSpecifiers: ts.moduleSpecifiers.tryGetModuleSpecifiersFromCache(moduleSymbol, sourceFile, moduleSpecifierResolutionHost, preferences), computedWithoutCache: false }); }
- : function (moduleSymbol) { return ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); };
+ : function (moduleSymbol, checker) { return ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); };
var computedWithoutCacheCount = 0;
var fixes = ts.flatMap(moduleSymbols, function (exportInfo) {
- var _a = getModuleSpecifiers(exportInfo.moduleSymbol), computedWithoutCache = _a.computedWithoutCache, moduleSpecifiers = _a.moduleSpecifiers;
+ var checker = getChecker(exportInfo.isFromPackageJson);
+ var _a = getModuleSpecifiers(exportInfo.moduleSymbol, checker), computedWithoutCache = _a.computedWithoutCache, moduleSpecifiers = _a.moduleSpecifiers;
+ var importedSymbolHasValueMeaning = !!(exportInfo.targetFlags & 111551 /* Value */);
+ var addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, exportInfo.symbol, exportInfo.targetFlags, checker, compilerOptions);
computedWithoutCacheCount += computedWithoutCache ? 1 : 0;
return moduleSpecifiers === null || moduleSpecifiers === void 0 ? void 0 : moduleSpecifiers.map(function (moduleSpecifier) {
// `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types.
- return !(exportInfo.targetFlags & 111551 /* Value */) && isJs && position !== undefined
- ? { kind: 1 /* ImportType */, moduleSpecifier: moduleSpecifier, position: position, exportInfo: exportInfo }
+ return !importedSymbolHasValueMeaning && isJs && position !== undefined
+ ? { kind: 1 /* JsdocTypeImport */, moduleSpecifier: moduleSpecifier, position: position, exportInfo: exportInfo }
: {
kind: 3 /* AddNew */,
moduleSpecifier: moduleSpecifier,
importKind: getImportKind(sourceFile, exportInfo.exportKind, compilerOptions),
useRequire: useRequire,
- typeOnly: preferTypeOnlyImport,
+ addAsTypeOnly: addAsTypeOnly,
exportInfo: exportInfo,
};
});
});
return { computedWithoutCacheCount: computedWithoutCacheCount, fixes: fixes };
}
- function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, preferTypeOnlyImport, useRequire, host, preferences) {
- var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info, preferTypeOnlyImport, useRequire); });
- return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position, preferTypeOnlyImport, useRequire, exportInfos, host, preferences).fixes;
+ function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
+ var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info, isValidTypeOnlyUseSite, useRequire, program.getTypeChecker(), program.getCompilerOptions()); });
+ return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences).fixes;
}
- function newImportInfoFromExistingSpecifier(_a, preferTypeOnlyImport, useRequire) {
- var declaration = _a.declaration, importKind = _a.importKind;
+ function newImportInfoFromExistingSpecifier(_a, isValidTypeOnlyUseSite, useRequire, checker, compilerOptions) {
+ var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
var moduleSpecifier = ts.tryGetModuleSpecifierFromDeclaration(declaration);
- return moduleSpecifier
- ? { kind: 3 /* AddNew */, moduleSpecifier: moduleSpecifier, importKind: importKind, typeOnly: preferTypeOnlyImport, useRequire: useRequire }
- : undefined;
+ if (moduleSpecifier) {
+ var addAsTypeOnly = useRequire
+ ? 4 /* NotAllowed */
+ : getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, symbol, targetFlags, checker, compilerOptions);
+ return { kind: 3 /* AddNew */, moduleSpecifier: moduleSpecifier, importKind: importKind, addAsTypeOnly: addAsTypeOnly, useRequire: useRequire };
+ }
}
function getFixesInfo(context, errorCode, pos, useAutoImportProvider) {
var symbolToken = ts.getTokenAtPosition(context.sourceFile, pos);
@@ -146106,12 +149271,14 @@ var ts;
}
var allowsImportingSpecifier = ts.createPackageJsonImportFilter(sourceFile, preferences, host).allowsImportingSpecifier;
return fixes.reduce(function (best, fix) {
+ // Takes true branch of conditional if `fix` is better than `best`
return compareModuleSpecifiers(fix, best, sourceFile, program, allowsImportingSpecifier) === -1 /* LessThan */ ? fix : best;
});
}
+ /** @returns `Comparison.LessThan` if `a` is better than `b`. */
function compareModuleSpecifiers(a, b, importingFile, program, allowsImportingSpecifier) {
if (a.kind !== 0 /* UseNamespace */ && b.kind !== 0 /* UseNamespace */) {
- return ts.compareBooleans(allowsImportingSpecifier(a.moduleSpecifier), allowsImportingSpecifier(b.moduleSpecifier))
+ return ts.compareBooleans(allowsImportingSpecifier(b.moduleSpecifier), allowsImportingSpecifier(a.moduleSpecifier))
|| compareNodeCoreModuleSpecifiers(a.moduleSpecifier, b.moduleSpecifier, importingFile, program)
|| ts.compareNumberOfDirectorySeparators(a.moduleSpecifier, b.moduleSpecifier);
}
@@ -146134,7 +149301,7 @@ var ts;
var symbolName = umdSymbol.name;
var exportInfos = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: 3 /* UMD */, targetFlags: symbol.flags, isFromPackageJson: false }];
var useRequire = shouldUseRequire(sourceFile, program);
- var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*preferTypeOnlyImport*/ false, useRequire, program, sourceFile, host, preferences);
+ var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
return { fixes: fixes, symbolName: symbolName };
}
function getUmdSymbol(token, checker) {
@@ -146180,10 +149347,14 @@ var ts;
case ts.ModuleKind.System:
case ts.ModuleKind.ES2015:
case ts.ModuleKind.ES2020:
+ case ts.ModuleKind.ES2022:
case ts.ModuleKind.ESNext:
case ts.ModuleKind.None:
// Fall back to the `import * as ns` style import.
return 2 /* Namespace */;
+ case ts.ModuleKind.Node12:
+ case ts.ModuleKind.NodeNext:
+ return importingFile.impliedNodeFormat === ts.ModuleKind.ESNext ? 2 /* Namespace */ : 3 /* CommonJS */;
default:
return ts.Debug.assertNever(moduleKind, "Unexpected moduleKind " + moduleKind);
}
@@ -146195,18 +149366,21 @@ var ts;
var symbolName = getSymbolName(sourceFile, checker, symbolToken, compilerOptions);
// "default" is a keyword and not a legal identifier for the import, so we don't expect it here
ts.Debug.assert(symbolName !== "default" /* Default */, "'default' isn't a legal identifier and couldn't occur here");
- var preferTypeOnlyImport = compilerOptions.importsNotUsedAsValues === 2 /* Error */ && ts.isValidTypeOnlyAliasUseSite(symbolToken);
+ var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(symbolToken);
var useRequire = shouldUseRequire(sourceFile, program);
var exportInfos = getExportInfos(symbolName, ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
var fixes = ts.arrayFrom(ts.flatMapIterator(exportInfos.entries(), function (_a) {
var _ = _a[0], exportInfos = _a[1];
- return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), preferTypeOnlyImport, useRequire, program, sourceFile, host, preferences);
+ return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences);
}));
return { fixes: fixes, symbolName: symbolName };
}
+ function jsxModeNeedsExplicitImport(jsx) {
+ return jsx === 2 /* React */ || jsx === 3 /* ReactNative */;
+ }
function getSymbolName(sourceFile, checker, symbolToken, compilerOptions) {
var parent = symbolToken.parent;
- if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && compilerOptions.jsx !== 4 /* ReactJSX */ && compilerOptions.jsx !== 5 /* ReactJSXDev */) {
+ if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && jsxModeNeedsExplicitImport(compilerOptions.jsx)) {
var jsxNamespace = checker.getJsxNamespace(sourceFile);
if (ts.isIntrinsicJsxName(symbolToken.text) || !checker.resolveName(jsxNamespace, parent, 111551 /* Value */, /*excludeGlobals*/ true)) {
return jsxNamespace;
@@ -146238,7 +149412,7 @@ var ts;
cancellationToken.throwIfCancellationRequested();
var compilerOptions = program.getCompilerOptions();
var defaultInfo = ts.getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
- if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, compilerOptions.target) === symbolName) && symbolHasMeaning(defaultInfo.symbolForMeaning, currentTokenMeaning)) {
+ if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions)) === symbolName) && symbolHasMeaning(defaultInfo.symbolForMeaning, currentTokenMeaning)) {
addSymbol(moduleSymbol, sourceFile, defaultInfo.symbol, defaultInfo.exportKind, program, isFromPackageJson);
}
// check exports with the same name
@@ -146278,63 +149452,81 @@ var ts;
// allowSyntheticDefaultImports/esModuleInterop is enabled.
return allowSyntheticDefaults ? 1 /* Default */ : 3 /* CommonJS */;
}
- function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference) {
+ function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
var diag;
var changes = ts.textChanges.ChangeTracker.with(context, function (tracker) {
- diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference);
+ diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference, compilerOptions);
});
return codefix.createCodeFixAction(codefix.importFixName, changes, diag, importFixId, ts.Diagnostics.Add_all_missing_imports);
}
- function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference) {
+ function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
switch (fix.kind) {
case 0 /* UseNamespace */:
addNamespaceQualifier(changes, sourceFile, fix);
return [ts.Diagnostics.Change_0_to_1, symbolName, fix.namespacePrefix + "." + symbolName];
- case 1 /* ImportType */:
+ case 1 /* JsdocTypeImport */:
addImportType(changes, sourceFile, fix, quotePreference);
return [ts.Diagnostics.Change_0_to_1, symbolName, getImportTypePrefix(fix.moduleSpecifier, quotePreference) + symbolName];
case 2 /* AddToExisting */: {
- var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, canUseTypeOnlyImport = fix.canUseTypeOnlyImport, moduleSpecifier = fix.moduleSpecifier;
- doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? symbolName : undefined, importKind === 0 /* Named */ ? [symbolName] : ts.emptyArray, canUseTypeOnlyImport);
+ var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly, moduleSpecifier = fix.moduleSpecifier;
+ doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined, importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : ts.emptyArray, compilerOptions);
var moduleSpecifierWithoutQuotes = ts.stripQuotes(moduleSpecifier);
- return [importKind === 1 /* Default */ ? ts.Diagnostics.Add_default_import_0_to_existing_import_declaration_from_1 : ts.Diagnostics.Add_0_to_existing_import_declaration_from_1, symbolName, moduleSpecifierWithoutQuotes]; // you too!
+ return [
+ importKind === 1 /* Default */ ? ts.Diagnostics.Add_default_import_0_to_existing_import_declaration_from_1 : ts.Diagnostics.Add_0_to_existing_import_declaration_from_1,
+ symbolName,
+ moduleSpecifierWithoutQuotes
+ ]; // you too!
}
case 3 /* AddNew */: {
- var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier, typeOnly = fix.typeOnly, useRequire = fix.useRequire;
+ var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier, addAsTypeOnly = fix.addAsTypeOnly, useRequire = fix.useRequire;
var getDeclarations = useRequire ? getNewRequires : getNewImports;
- var importsCollection = importKind === 1 /* Default */ ? { defaultImport: symbolName, typeOnly: typeOnly } :
- importKind === 0 /* Named */ ? { namedImports: [symbolName], typeOnly: typeOnly } :
- { namespaceLikeImport: { importKind: importKind, name: symbolName }, typeOnly: typeOnly };
- ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, importsCollection), /*blankLineBetween*/ true);
+ var defaultImport = importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
+ var namedImports = importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : undefined;
+ var namespaceLikeImport = importKind === 2 /* Namespace */ || importKind === 3 /* CommonJS */ ? { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
+ ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport), /*blankLineBetween*/ true);
return [importKind === 1 /* Default */ ? ts.Diagnostics.Import_default_0_from_module_1 : ts.Diagnostics.Import_0_from_module_1, symbolName, moduleSpecifier];
}
default:
return ts.Debug.assertNever(fix, "Unexpected fix kind " + fix.kind);
}
}
- function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, canUseTypeOnlyImport) {
- if (clause.kind === 199 /* ObjectBindingPattern */) {
+ function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, compilerOptions) {
+ var _a;
+ if (clause.kind === 200 /* ObjectBindingPattern */) {
if (defaultImport) {
- addElementToBindingPattern(clause, defaultImport, "default");
+ addElementToBindingPattern(clause, defaultImport.name, "default");
}
for (var _i = 0, namedImports_1 = namedImports; _i < namedImports_1.length; _i++) {
var specifier = namedImports_1[_i];
- addElementToBindingPattern(clause, specifier, /*propertyName*/ undefined);
+ addElementToBindingPattern(clause, specifier.name, /*propertyName*/ undefined);
}
return;
}
- var convertTypeOnlyToRegular = !canUseTypeOnlyImport && clause.isTypeOnly;
+ var promoteFromTypeOnly = clause.isTypeOnly && ts.some(__spreadArray([defaultImport], namedImports, true), function (i) { return (i === null || i === void 0 ? void 0 : i.addAsTypeOnly) === 4 /* NotAllowed */; });
+ var existingSpecifiers = clause.namedBindings && ((_a = ts.tryCast(clause.namedBindings, ts.isNamedImports)) === null || _a === void 0 ? void 0 : _a.elements);
+ // If we are promoting from a type-only import and `--isolatedModules` and `--preserveValueImports`
+ // are enabled, we need to make every existing import specifier type-only. It may be possible that
+ // some of them don't strictly need to be marked type-only (if they have a value meaning and are
+ // never used in an emitting position). These are allowed to be imported without being type-only,
+ // but the user has clearly already signified that they don't need them to be present at runtime
+ // by placing them in a type-only import. So, just mark each specifier as type-only.
+ var convertExistingToTypeOnly = promoteFromTypeOnly && compilerOptions.preserveValueImports && compilerOptions.isolatedModules;
if (defaultImport) {
ts.Debug.assert(!clause.name, "Cannot add a default import to an import clause that already has one");
- changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), ts.factory.createIdentifier(defaultImport), { suffix: ", " });
+ changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), ts.factory.createIdentifier(defaultImport.name), { suffix: ", " });
}
if (namedImports.length) {
- var existingSpecifiers = clause.namedBindings && ts.cast(clause.namedBindings, ts.isNamedImports).elements;
- var newSpecifiers = ts.stableSort(namedImports.map(function (name) { return ts.factory.createImportSpecifier(/*propertyName*/ undefined, ts.factory.createIdentifier(name)); }), ts.OrganizeImports.compareImportOrExportSpecifiers);
+ var newSpecifiers = ts.stableSort(namedImports.map(function (namedImport) { return ts.factory.createImportSpecifier((!clause.isTypeOnly || promoteFromTypeOnly) && needsTypeOnly(namedImport),
+ /*propertyName*/ undefined, ts.factory.createIdentifier(namedImport.name)); }), ts.OrganizeImports.compareImportOrExportSpecifiers);
if ((existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) && ts.OrganizeImports.importSpecifiersAreSorted(existingSpecifiers)) {
- for (var _a = 0, newSpecifiers_1 = newSpecifiers; _a < newSpecifiers_1.length; _a++) {
- var spec = newSpecifiers_1[_a];
- var insertionIndex = ts.OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec);
+ for (var _b = 0, newSpecifiers_1 = newSpecifiers; _b < newSpecifiers_1.length; _b++) {
+ var spec = newSpecifiers_1[_b];
+ // Organize imports puts type-only import specifiers last, so if we're
+ // adding a non-type-only specifier and converting all the other ones to
+ // type-only, there's no need to ask for the insertion index - it's 0.
+ var insertionIndex = convertExistingToTypeOnly && !spec.isTypeOnly
+ ? 0
+ : ts.OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec);
var prevSpecifier = clause.namedBindings.elements[insertionIndex - 1];
if (prevSpecifier) {
changes.insertNodeInListAfter(sourceFile, prevSpecifier, spec);
@@ -146345,8 +149537,8 @@ var ts;
}
}
else if (existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) {
- for (var _b = 0, newSpecifiers_2 = newSpecifiers; _b < newSpecifiers_2.length; _b++) {
- var spec = newSpecifiers_2[_b];
+ for (var _c = 0, newSpecifiers_2 = newSpecifiers; _c < newSpecifiers_2.length; _c++) {
+ var spec = newSpecifiers_2[_c];
changes.insertNodeInListAfter(sourceFile, ts.last(existingSpecifiers), spec, existingSpecifiers);
}
}
@@ -146362,8 +149554,14 @@ var ts;
}
}
}
- if (convertTypeOnlyToRegular) {
+ if (promoteFromTypeOnly) {
changes.delete(sourceFile, ts.getTypeKeywordOfTypeOnlyImport(clause, sourceFile));
+ if (convertExistingToTypeOnly && existingSpecifiers) {
+ for (var _d = 0, existingSpecifiers_1 = existingSpecifiers; _d < existingSpecifiers_1.length; _d++) {
+ var specifier = existingSpecifiers_1[_d];
+ changes.insertModifierBefore(sourceFile, 151 /* TypeKeyword */, specifier);
+ }
+ }
}
function addElementToBindingPattern(bindingPattern, name, propertyName) {
var element = ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, propertyName, name);
@@ -146387,43 +149585,53 @@ var ts;
var quote = ts.getQuoteFromPreference(quotePreference);
return "import(" + quote + moduleSpecifier + quote + ").";
}
- function getNewImports(moduleSpecifier, quotePreference, imports) {
- var _a, _b;
+ function needsTypeOnly(_a) {
+ var addAsTypeOnly = _a.addAsTypeOnly;
+ return addAsTypeOnly === 2 /* Required */;
+ }
+ function getNewImports(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport) {
var quotedModuleSpecifier = ts.makeStringLiteral(moduleSpecifier, quotePreference);
var statements;
- if (imports.defaultImport !== undefined || ((_a = imports.namedImports) === null || _a === void 0 ? void 0 : _a.length)) {
- statements = ts.combine(statements, ts.makeImport(imports.defaultImport === undefined ? undefined : ts.factory.createIdentifier(imports.defaultImport), (_b = imports.namedImports) === null || _b === void 0 ? void 0 : _b.map(function (n) { return ts.factory.createImportSpecifier(/*propertyName*/ undefined, ts.factory.createIdentifier(n)); }), moduleSpecifier, quotePreference, imports.typeOnly));
+ if (defaultImport !== undefined || (namedImports === null || namedImports === void 0 ? void 0 : namedImports.length)) {
+ var topLevelTypeOnly_1 = (!defaultImport || needsTypeOnly(defaultImport)) && ts.every(namedImports, needsTypeOnly);
+ statements = ts.combine(statements, ts.makeImport(defaultImport && ts.factory.createIdentifier(defaultImport.name), namedImports === null || namedImports === void 0 ? void 0 : namedImports.map(function (_a) {
+ var addAsTypeOnly = _a.addAsTypeOnly, name = _a.name;
+ return ts.factory.createImportSpecifier(!topLevelTypeOnly_1 && addAsTypeOnly === 2 /* Required */,
+ /*propertyName*/ undefined, ts.factory.createIdentifier(name));
+ }), moduleSpecifier, quotePreference, topLevelTypeOnly_1));
}
- var namespaceLikeImport = imports.namespaceLikeImport, typeOnly = imports.typeOnly;
if (namespaceLikeImport) {
var declaration = namespaceLikeImport.importKind === 3 /* CommonJS */
? ts.factory.createImportEqualsDeclaration(
/*decorators*/ undefined,
- /*modifiers*/ undefined, typeOnly, ts.factory.createIdentifier(namespaceLikeImport.name), ts.factory.createExternalModuleReference(quotedModuleSpecifier))
+ /*modifiers*/ undefined, needsTypeOnly(namespaceLikeImport), ts.factory.createIdentifier(namespaceLikeImport.name), ts.factory.createExternalModuleReference(quotedModuleSpecifier))
: ts.factory.createImportDeclaration(
/*decorators*/ undefined,
- /*modifiers*/ undefined, ts.factory.createImportClause(typeOnly,
- /*name*/ undefined, ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceLikeImport.name))), quotedModuleSpecifier);
+ /*modifiers*/ undefined, ts.factory.createImportClause(needsTypeOnly(namespaceLikeImport),
+ /*name*/ undefined, ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceLikeImport.name))), quotedModuleSpecifier,
+ /*assertClause*/ undefined);
statements = ts.combine(statements, declaration);
}
return ts.Debug.checkDefined(statements);
}
- function getNewRequires(moduleSpecifier, quotePreference, imports) {
- var _a, _b;
+ function getNewRequires(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport) {
var quotedModuleSpecifier = ts.makeStringLiteral(moduleSpecifier, quotePreference);
var statements;
// const { default: foo, bar, etc } = require('./mod');
- if (imports.defaultImport || ((_a = imports.namedImports) === null || _a === void 0 ? void 0 : _a.length)) {
- var bindingElements = ((_b = imports.namedImports) === null || _b === void 0 ? void 0 : _b.map(function (name) { return ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, /*propertyName*/ undefined, name); })) || [];
- if (imports.defaultImport) {
- bindingElements.unshift(ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, "default", imports.defaultImport));
+ if (defaultImport || (namedImports === null || namedImports === void 0 ? void 0 : namedImports.length)) {
+ var bindingElements = (namedImports === null || namedImports === void 0 ? void 0 : namedImports.map(function (_a) {
+ var name = _a.name;
+ return ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, /*propertyName*/ undefined, name);
+ })) || [];
+ if (defaultImport) {
+ bindingElements.unshift(ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, "default", defaultImport.name));
}
var declaration = createConstEqualsRequireDeclaration(ts.factory.createObjectBindingPattern(bindingElements), quotedModuleSpecifier);
statements = ts.combine(statements, declaration);
}
// const foo = require('./mod');
- if (imports.namespaceLikeImport) {
- var declaration = createConstEqualsRequireDeclaration(imports.namespaceLikeImport.name, quotedModuleSpecifier);
+ if (namespaceLikeImport) {
+ var declaration = createConstEqualsRequireDeclaration(namespaceLikeImport.name, quotedModuleSpecifier);
statements = ts.combine(statements, declaration);
}
return ts.Debug.checkDefined(statements);
@@ -146557,23 +149765,23 @@ var ts;
accessibilityModifier ? accessibilityModifier.end :
classElement.decorators ? ts.skipTrivia(sourceFile.text, classElement.decorators.end) : classElement.getStart(sourceFile);
var options = accessibilityModifier || staticModifier || abstractModifier ? { prefix: " " } : { suffix: " " };
- changeTracker.insertModifierAt(sourceFile, modifierPos, 157 /* OverrideKeyword */, options);
+ changeTracker.insertModifierAt(sourceFile, modifierPos, 158 /* OverrideKeyword */, options);
}
function doRemoveOverrideModifierChange(changeTracker, sourceFile, pos) {
var classElement = findContainerClassElementLike(sourceFile, pos);
- var overrideModifier = classElement.modifiers && ts.find(classElement.modifiers, function (modifier) { return modifier.kind === 157 /* OverrideKeyword */; });
+ var overrideModifier = classElement.modifiers && ts.find(classElement.modifiers, function (modifier) { return modifier.kind === 158 /* OverrideKeyword */; });
ts.Debug.assertIsDefined(overrideModifier);
changeTracker.deleteModifier(sourceFile, overrideModifier);
}
function isClassElementLikeHasJSDoc(node) {
switch (node.kind) {
- case 169 /* Constructor */:
- case 165 /* PropertyDeclaration */:
- case 167 /* MethodDeclaration */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
+ case 170 /* Constructor */:
+ case 166 /* PropertyDeclaration */:
+ case 168 /* MethodDeclaration */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
return true;
- case 162 /* Parameter */:
+ case 163 /* Parameter */:
return ts.isParameterPropertyDeclaration(node, node.parent);
default:
return false;
@@ -146704,7 +149912,7 @@ var ts;
});
function getNamedTupleMember(sourceFile, pos) {
var token = ts.getTokenAtPosition(sourceFile, pos);
- return ts.findAncestor(token, function (t) { return t.kind === 195 /* NamedTupleMember */; });
+ return ts.findAncestor(token, function (t) { return t.kind === 196 /* NamedTupleMember */; });
}
function doChange(changes, sourceFile, namedTupleMember) {
if (!namedTupleMember) {
@@ -146713,11 +149921,11 @@ var ts;
var unwrappedType = namedTupleMember.type;
var sawOptional = false;
var sawRest = false;
- while (unwrappedType.kind === 183 /* OptionalType */ || unwrappedType.kind === 184 /* RestType */ || unwrappedType.kind === 189 /* ParenthesizedType */) {
- if (unwrappedType.kind === 183 /* OptionalType */) {
+ while (unwrappedType.kind === 184 /* OptionalType */ || unwrappedType.kind === 185 /* RestType */ || unwrappedType.kind === 190 /* ParenthesizedType */) {
+ if (unwrappedType.kind === 184 /* OptionalType */) {
sawOptional = true;
}
- else if (unwrappedType.kind === 184 /* RestType */) {
+ else if (unwrappedType.kind === 185 /* RestType */) {
sawRest = true;
}
unwrappedType = unwrappedType.type;
@@ -146741,10 +149949,12 @@ var ts;
ts.Diagnostics.Property_0_may_not_exist_on_type_1_Did_you_mean_2.code,
ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1.code,
ts.Diagnostics.Could_not_find_name_0_Did_you_mean_1.code,
+ ts.Diagnostics.Cannot_find_namespace_0_Did_you_mean_1.code,
ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code,
ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code,
ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2.code,
ts.Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1.code,
+ ts.Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1.code,
// for JSX class components
ts.Diagnostics.No_overload_matches_this_call.code,
// for JSX FC
@@ -146758,14 +149968,14 @@ var ts;
if (!info)
return undefined;
var node = info.node, suggestedSymbol = info.suggestedSymbol;
- var target = context.host.getCompilationSettings().target;
+ var target = ts.getEmitScriptTarget(context.host.getCompilationSettings());
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(t, sourceFile, node, suggestedSymbol, target); });
return [codefix.createCodeFixAction("spelling", changes, [ts.Diagnostics.Change_spelling_to_0, ts.symbolName(suggestedSymbol)], fixId, ts.Diagnostics.Fix_all_detected_spelling_errors)];
},
fixIds: [fixId],
getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
var info = getInfo(diag.file, diag.start, context, diag.code);
- var target = context.host.getCompilationSettings().target;
+ var target = ts.getEmitScriptTarget(context.host.getCompilationSettings());
if (info)
doChange(changes, context.sourceFile, info.node, info.suggestedSymbol, target);
}); },
@@ -146791,6 +150001,10 @@ var ts;
}
suggestedSymbol = checker.getSuggestedSymbolForNonexistentProperty(node, containingType);
}
+ else if (ts.isBinaryExpression(parent) && parent.operatorToken.kind === 101 /* InKeyword */ && parent.left === node && ts.isPrivateIdentifier(node)) {
+ var receiverType = checker.getTypeAtLocation(parent.right);
+ suggestedSymbol = checker.getSuggestedSymbolForNonexistentProperty(node, receiverType);
+ }
else if (ts.isQualifiedName(parent) && parent.right === node) {
var symbol = checker.getSymbolAtLocation(parent.left);
if (symbol && symbol.flags & 1536 /* Module */) {
@@ -146858,7 +150072,7 @@ var ts;
function getResolvedSourceFileFromImportDeclaration(sourceFile, context, importDeclaration) {
if (!importDeclaration || !ts.isStringLiteralLike(importDeclaration.moduleSpecifier))
return undefined;
- var resolvedModule = ts.getResolvedModule(sourceFile, importDeclaration.moduleSpecifier.text);
+ var resolvedModule = ts.getResolvedModule(sourceFile, importDeclaration.moduleSpecifier.text, ts.getModeForUsageLocation(sourceFile, importDeclaration.moduleSpecifier));
if (!resolvedModule)
return undefined;
return context.program.getSourceFile(resolvedModule.resolvedFileName);
@@ -147026,19 +150240,19 @@ var ts;
}
function getVariableLikeInitializer(declaration) {
switch (declaration.kind) {
- case 252 /* VariableDeclaration */:
- case 162 /* Parameter */:
- case 201 /* BindingElement */:
- case 165 /* PropertyDeclaration */:
- case 291 /* PropertyAssignment */:
+ case 253 /* VariableDeclaration */:
+ case 163 /* Parameter */:
+ case 202 /* BindingElement */:
+ case 166 /* PropertyDeclaration */:
+ case 294 /* PropertyAssignment */:
return declaration.initializer;
- case 283 /* JsxAttribute */:
+ case 284 /* JsxAttribute */:
return declaration.initializer && (ts.isJsxExpression(declaration.initializer) ? declaration.initializer.expression : undefined);
- case 292 /* ShorthandPropertyAssignment */:
- case 164 /* PropertySignature */:
- case 294 /* EnumMember */:
- case 342 /* JSDocPropertyTag */:
- case 335 /* JSDocParameterTag */:
+ case 295 /* ShorthandPropertyAssignment */:
+ case 165 /* PropertySignature */:
+ case 297 /* EnumMember */:
+ case 345 /* JSDocPropertyTag */:
+ case 338 /* JSDocParameterTag */:
return undefined;
}
}
@@ -147089,13 +150303,14 @@ var ts;
ts.Diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2.code,
ts.Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2.code,
ts.Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more.code,
+ ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code,
ts.Diagnostics.Cannot_find_name_0.code
];
codefix.registerCodeFix({
errorCodes: errorCodes,
getCodeActions: function (context) {
var typeChecker = context.program.getTypeChecker();
- var info = getInfo(context.sourceFile, context.span.start, typeChecker, context.program);
+ var info = getInfo(context.sourceFile, context.span.start, context.errorCode, typeChecker, context.program);
if (!info) {
return undefined;
}
@@ -147125,7 +150340,7 @@ var ts;
var typeDeclToMembers = new ts.Map();
return codefix.createCombinedCodeActions(ts.textChanges.ChangeTracker.with(context, function (changes) {
codefix.eachDiagnostic(context, errorCodes, function (diag) {
- var info = getInfo(diag.file, diag.start, checker, context.program);
+ var info = getInfo(diag.file, diag.start, diag.code, checker, context.program);
if (!info || !ts.addToSeen(seen, ts.getNodeId(info.parentDeclaration) + "#" + info.token.text)) {
return;
}
@@ -147153,7 +150368,7 @@ var ts;
});
typeDeclToMembers.forEach(function (infos, classDeclaration) {
var supers = codefix.getAllSupers(classDeclaration, checker);
- var _loop_14 = function (info) {
+ var _loop_15 = function (info) {
// If some superclass added this property, don't add it again.
if (supers.some(function (superClassOrInterface) {
var superInfos = typeDeclToMembers.get(superClassOrInterface);
@@ -147180,7 +150395,7 @@ var ts;
};
for (var _i = 0, infos_1 = infos; _i < infos_1.length; _i++) {
var info = infos_1[_i];
- _loop_14(info);
+ _loop_15(info);
}
});
}));
@@ -147194,38 +150409,52 @@ var ts;
InfoKind[InfoKind["ObjectLiteral"] = 3] = "ObjectLiteral";
InfoKind[InfoKind["JsxAttributes"] = 4] = "JsxAttributes";
})(InfoKind || (InfoKind = {}));
- function getInfo(sourceFile, tokenPos, checker, program) {
+ function getInfo(sourceFile, tokenPos, errorCode, checker, program) {
// The identifier of the missing property. eg:
// this.missing = 1;
// ^^^^^^^
var token = ts.getTokenAtPosition(sourceFile, tokenPos);
- if (!ts.isIdentifier(token) && !ts.isPrivateIdentifier(token)) {
- return undefined;
- }
var parent = token.parent;
+ if (errorCode === ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code) {
+ if (!(token.kind === 18 /* OpenBraceToken */ && ts.isObjectLiteralExpression(parent) && ts.isCallExpression(parent.parent)))
+ return undefined;
+ var argIndex = ts.findIndex(parent.parent.arguments, function (arg) { return arg === parent; });
+ if (argIndex < 0)
+ return undefined;
+ var signature = ts.singleOrUndefined(checker.getSignaturesOfType(checker.getTypeAtLocation(parent.parent.expression), 0 /* Call */));
+ if (!(signature && signature.declaration && signature.parameters[argIndex]))
+ return undefined;
+ var param = signature.parameters[argIndex].valueDeclaration;
+ if (!(param && ts.isParameter(param) && ts.isIdentifier(param.name)))
+ return undefined;
+ var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent), checker.getTypeAtLocation(param), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
+ if (!ts.length(properties))
+ return undefined;
+ return { kind: 3 /* ObjectLiteral */, token: param.name, properties: properties, indentation: 0, parentDeclaration: parent };
+ }
+ if (!ts.isMemberName(token))
+ return undefined;
if (ts.isIdentifier(token) && ts.hasInitializer(parent) && parent.initializer && ts.isObjectLiteralExpression(parent.initializer)) {
var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent.initializer), checker.getTypeAtLocation(token), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
- if (ts.length(properties)) {
- return { kind: 3 /* ObjectLiteral */, token: token, properties: properties, parentDeclaration: parent.initializer };
- }
+ if (!ts.length(properties))
+ return undefined;
+ return { kind: 3 /* ObjectLiteral */, token: token, properties: properties, indentation: undefined, parentDeclaration: parent.initializer };
}
if (ts.isIdentifier(token) && ts.isJsxOpeningLikeElement(token.parent)) {
var attributes = getUnmatchedAttributes(checker, token.parent);
- if (ts.length(attributes)) {
- return { kind: 4 /* JsxAttributes */, token: token, attributes: attributes, parentDeclaration: token.parent };
- }
+ if (!ts.length(attributes))
+ return undefined;
+ return { kind: 4 /* JsxAttributes */, token: token, attributes: attributes, parentDeclaration: token.parent };
}
if (ts.isIdentifier(token) && ts.isCallExpression(parent)) {
return { kind: 2 /* Function */, token: token, call: parent, sourceFile: sourceFile, modifierFlags: 0 /* None */, parentDeclaration: sourceFile };
}
- if (!ts.isPropertyAccessExpression(parent)) {
+ if (!ts.isPropertyAccessExpression(parent))
return undefined;
- }
var leftExpressionType = ts.skipConstraint(checker.getTypeAtLocation(parent.expression));
var symbol = leftExpressionType.symbol;
- if (!symbol || !symbol.declarations) {
+ if (!symbol || !symbol.declarations)
return undefined;
- }
if (ts.isIdentifier(token) && ts.isCallExpression(parent.parent)) {
var moduleDeclaration = ts.find(symbol.declarations, ts.isModuleDeclaration);
var moduleDeclarationSourceFile = moduleDeclaration === null || moduleDeclaration === void 0 ? void 0 : moduleDeclaration.getSourceFile();
@@ -147233,25 +150462,22 @@ var ts;
return { kind: 2 /* Function */, token: token, call: parent.parent, sourceFile: sourceFile, modifierFlags: 1 /* Export */, parentDeclaration: moduleDeclaration };
}
var moduleSourceFile = ts.find(symbol.declarations, ts.isSourceFile);
- if (sourceFile.commonJsModuleIndicator) {
- return;
- }
+ if (sourceFile.commonJsModuleIndicator)
+ return undefined;
if (moduleSourceFile && !isSourceFileFromLibrary(program, moduleSourceFile)) {
return { kind: 2 /* Function */, token: token, call: parent.parent, sourceFile: moduleSourceFile, modifierFlags: 1 /* Export */, parentDeclaration: moduleSourceFile };
}
}
var classDeclaration = ts.find(symbol.declarations, ts.isClassLike);
// Don't suggest adding private identifiers to anything other than a class.
- if (!classDeclaration && ts.isPrivateIdentifier(token)) {
+ if (!classDeclaration && ts.isPrivateIdentifier(token))
return undefined;
- }
// Prefer to change the class instead of the interface if they are merged
var classOrInterface = classDeclaration || ts.find(symbol.declarations, ts.isInterfaceDeclaration);
if (classOrInterface && !isSourceFileFromLibrary(program, classOrInterface.getSourceFile())) {
var makeStatic = (leftExpressionType.target || leftExpressionType) !== checker.getDeclaredTypeOfSymbol(symbol);
- if (makeStatic && (ts.isPrivateIdentifier(token) || ts.isInterfaceDeclaration(classOrInterface))) {
+ if (makeStatic && (ts.isPrivateIdentifier(token) || ts.isInterfaceDeclaration(classOrInterface)))
return undefined;
- }
var declSourceFile = classOrInterface.getSourceFile();
var modifierFlags = (makeStatic ? 32 /* Static */ : 0) | (ts.startsWithUnderscore(token.text) ? 8 /* Private */ : 0);
var isJSFile = ts.isSourceFileJS(declSourceFile);
@@ -147287,7 +150513,7 @@ var ts;
function addMissingMemberInJs(changeTracker, declSourceFile, classDeclaration, token, makeStatic) {
var tokenName = token.text;
if (makeStatic) {
- if (classDeclaration.kind === 224 /* ClassExpression */) {
+ if (classDeclaration.kind === 225 /* ClassExpression */) {
return;
}
var className = classDeclaration.name.getText();
@@ -147339,7 +150565,7 @@ var ts;
}
function getTypeNode(checker, classDeclaration, token) {
var typeNode;
- if (token.parent.parent.kind === 219 /* BinaryExpression */) {
+ if (token.parent.parent.kind === 220 /* BinaryExpression */) {
var binaryExpression = token.parent.parent;
var otherExpression = token.parent === binaryExpression.left ? binaryExpression.right : binaryExpression.left;
var widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(otherExpression)));
@@ -147349,7 +150575,7 @@ var ts;
var contextualType = checker.getContextualType(token.parent);
typeNode = contextualType ? checker.typeToTypeNode(contextualType, /*enclosingDeclaration*/ undefined, 1 /* NoTruncation */) : undefined;
}
- return typeNode || ts.factory.createKeywordTypeNode(129 /* AnyKeyword */);
+ return typeNode || ts.factory.createKeywordTypeNode(130 /* AnyKeyword */);
}
function addPropertyDeclaration(changeTracker, declSourceFile, classDeclaration, tokenName, typeNode, modifierFlags) {
var property = ts.factory.createPropertyDeclaration(
@@ -147378,7 +150604,7 @@ var ts;
}
function createAddIndexSignatureAction(context, declSourceFile, classDeclaration, tokenName, typeNode) {
// Index signatures cannot have the static modifier.
- var stringTypeNode = ts.factory.createKeywordTypeNode(148 /* StringKeyword */);
+ var stringTypeNode = ts.factory.createKeywordTypeNode(149 /* StringKeyword */);
var indexingParameter = ts.factory.createParameterDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
@@ -147411,7 +150637,7 @@ var ts;
}
function addMethodDeclaration(context, changes, callExpression, name, modifierFlags, parentDeclaration, sourceFile) {
var importAdder = codefix.createImportAdder(sourceFile, context.program, context.preferences, context.host);
- var methodDeclaration = codefix.createSignatureDeclarationFromCallExpression(167 /* MethodDeclaration */, context, importAdder, callExpression, name, modifierFlags, parentDeclaration);
+ var methodDeclaration = codefix.createSignatureDeclarationFromCallExpression(168 /* MethodDeclaration */, context, importAdder, callExpression, name, modifierFlags, parentDeclaration);
var containingMethodDeclaration = ts.findAncestor(callExpression, function (n) { return ts.isMethodDeclaration(n) || ts.isConstructorDeclaration(n); });
if (containingMethodDeclaration && containingMethodDeclaration.parent === parentDeclaration) {
changes.insertNodeAfter(sourceFile, containingMethodDeclaration, methodDeclaration);
@@ -147440,7 +150666,7 @@ var ts;
}
function addFunctionDeclaration(changes, context, info) {
var importAdder = codefix.createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
- var functionDeclaration = codefix.createSignatureDeclarationFromCallExpression(254 /* FunctionDeclaration */, context, importAdder, info.call, ts.idText(info.token), info.modifierFlags, info.parentDeclaration);
+ var functionDeclaration = codefix.createSignatureDeclarationFromCallExpression(255 /* FunctionDeclaration */, context, importAdder, info.call, ts.idText(info.token), info.modifierFlags, info.parentDeclaration);
changes.insertNodeAtEndOfScope(info.sourceFile, info.parentDeclaration, functionDeclaration);
}
function addJsxAttributes(changes, context, info) {
@@ -147465,7 +150691,12 @@ var ts;
var initializer = prop.valueDeclaration ? tryGetValueFromType(context, checker, importAdder, quotePreference, checker.getTypeAtLocation(prop.valueDeclaration)) : createUndefined();
return ts.factory.createPropertyAssignment(prop.name, initializer);
});
- changes.replaceNode(context.sourceFile, info.parentDeclaration, ts.factory.createObjectLiteralExpression(__spreadArray(__spreadArray([], info.parentDeclaration.properties, true), props, true), /*multiLine*/ true));
+ var options = {
+ leadingTriviaOption: ts.textChanges.LeadingTriviaOption.Exclude,
+ trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Exclude,
+ indentation: info.indentation
+ };
+ changes.replaceNode(context.sourceFile, info.parentDeclaration, ts.factory.createObjectLiteralExpression(__spreadArray(__spreadArray([], info.parentDeclaration.properties, true), props, true), /*multiLine*/ true), options);
}
function tryGetValueFromType(context, checker, importAdder, quotePreference, type) {
if (type.flags & 3 /* AnyOrUnknown */) {
@@ -147524,7 +150755,7 @@ var ts;
var signature = checker.getSignaturesOfType(type, 0 /* Call */);
if (signature === undefined)
return createUndefined();
- var func = codefix.createSignatureDeclarationFromSignature(211 /* FunctionExpression */, context, quotePreference, signature[0], codefix.createStubbedBody(ts.Diagnostics.Function_not_implemented.message, quotePreference), /*name*/ undefined, /*modifiers*/ undefined, /*optional*/ undefined, /*enclosingDeclaration*/ undefined, importAdder);
+ var func = codefix.createSignatureDeclarationFromSignature(212 /* FunctionExpression */, context, quotePreference, signature[0], codefix.createStubbedBody(ts.Diagnostics.Function_not_implemented.message, quotePreference), /*name*/ undefined, /*modifiers*/ undefined, /*optional*/ undefined, /*enclosingDeclaration*/ undefined, importAdder);
return func !== null && func !== void 0 ? func : createUndefined();
}
if (ts.getObjectFlags(type) & 1 /* Class */) {
@@ -147888,8 +151119,8 @@ var ts;
(function (codefix) {
codefix.registerCodeFix({
errorCodes: [
- ts.Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher.code,
- ts.Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher.code,
+ ts.Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher.code,
+ ts.Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher.code,
],
getCodeActions: function (context) {
var compilerOptions = context.program.getCompilerOptions();
@@ -148018,7 +151249,7 @@ var ts;
var didYouMeanStaticMemberCode = ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code;
var errorCodes = [
ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code,
- ts.Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies.code,
+ ts.Diagnostics.Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression.code,
didYouMeanStaticMemberCode,
];
codefix.registerCodeFix({
@@ -148041,7 +151272,7 @@ var ts;
});
function getInfo(sourceFile, pos, diagCode) {
var node = ts.getTokenAtPosition(sourceFile, pos);
- if (ts.isIdentifier(node)) {
+ if (ts.isIdentifier(node) || ts.isPrivateIdentifier(node)) {
return { node: node, className: diagCode === didYouMeanStaticMemberCode ? ts.getContainingClass(node).name.text : undefined };
}
}
@@ -148169,7 +151400,7 @@ var ts;
];
}
var result = [];
- if (token.kind === 136 /* InferKeyword */) {
+ if (token.kind === 137 /* InferKeyword */) {
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return changeInferToUnknown(t, sourceFile, token); });
var name = ts.cast(token.parent, ts.isInferTypeNode).typeParameter.name.text;
result.push(codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Replace_infer_0_with_unknown, name], fixIdInfer, ts.Diagnostics.Replace_all_unused_infer_with_unknown));
@@ -148211,7 +151442,7 @@ var ts;
break;
}
case fixIdDelete: {
- if (token.kind === 136 /* InferKeyword */ || isImport(token)) {
+ if (token.kind === 137 /* InferKeyword */ || isImport(token)) {
break; // Can't delete
}
else if (ts.isJSDocTemplateTag(token)) {
@@ -148240,7 +151471,7 @@ var ts;
break;
}
case fixIdInfer:
- if (token.kind === 136 /* InferKeyword */) {
+ if (token.kind === 137 /* InferKeyword */) {
changeInferToUnknown(changes, sourceFile, token);
}
break;
@@ -148251,7 +151482,7 @@ var ts;
},
});
function changeInferToUnknown(changes, sourceFile, token) {
- changes.replaceNode(sourceFile, token.parent, ts.factory.createKeywordTypeNode(153 /* UnknownKeyword */));
+ changes.replaceNode(sourceFile, token.parent, ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */));
}
function createDeleteFix(changes, diag) {
return codefix.createCodeFixAction(fixName, changes, diag, fixIdDelete, ts.Diagnostics.Delete_all_unused_declarations);
@@ -148261,7 +151492,7 @@ var ts;
}
function isImport(token) {
return token.kind === 100 /* ImportKeyword */
- || token.kind === 79 /* Identifier */ && (token.parent.kind === 268 /* ImportSpecifier */ || token.parent.kind === 265 /* ImportClause */);
+ || token.kind === 79 /* Identifier */ && (token.parent.kind === 269 /* ImportSpecifier */ || token.parent.kind === 266 /* ImportClause */);
}
/** Sometimes the diagnostic span is an entire ImportDeclaration, so we should remove the whole thing. */
function tryGetFullImport(token) {
@@ -148271,7 +151502,7 @@ var ts;
return ts.isVariableDeclarationList(token.parent) && ts.first(token.parent.getChildren(sourceFile)) === token;
}
function deleteEntireVariableStatement(changes, sourceFile, node) {
- changes.delete(sourceFile, node.parent.kind === 235 /* VariableStatement */ ? node.parent : node);
+ changes.delete(sourceFile, node.parent.kind === 236 /* VariableStatement */ ? node.parent : node);
}
function deleteDestructuringElements(changes, sourceFile, node) {
ts.forEach(node.elements, function (n) { return changes.delete(sourceFile, n); });
@@ -148280,7 +151511,7 @@ var ts;
// Don't offer to prefix a property.
if (errorCode === ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read.code)
return;
- if (token.kind === 136 /* InferKeyword */) {
+ if (token.kind === 137 /* InferKeyword */) {
token = ts.cast(token.parent, ts.isInferTypeNode).typeParameter.name;
}
if (ts.isIdentifier(token) && canPrefix(token)) {
@@ -148296,14 +151527,14 @@ var ts;
}
function canPrefix(token) {
switch (token.parent.kind) {
- case 162 /* Parameter */:
- case 161 /* TypeParameter */:
+ case 163 /* Parameter */:
+ case 162 /* TypeParameter */:
return true;
- case 252 /* VariableDeclaration */: {
+ case 253 /* VariableDeclaration */: {
var varDecl = token.parent;
switch (varDecl.parent.parent.kind) {
- case 242 /* ForOfStatement */:
- case 241 /* ForInStatement */:
+ case 243 /* ForOfStatement */:
+ case 242 /* ForInStatement */:
return true;
}
}
@@ -148353,8 +151584,8 @@ var ts;
function mayDeleteParameter(checker, sourceFile, parameter, sourceFiles, program, cancellationToken, isFixAll) {
var parent = parameter.parent;
switch (parent.kind) {
- case 167 /* MethodDeclaration */:
- case 169 /* Constructor */:
+ case 168 /* MethodDeclaration */:
+ case 170 /* Constructor */:
var index = parent.parameters.indexOf(parameter);
var referent = ts.isMethodDeclaration(parent) ? parent.name : parent;
var entries = ts.FindAllReferences.Core.getReferencedSymbolsForNode(parent.pos, referent, program, sourceFiles, cancellationToken);
@@ -148384,17 +151615,17 @@ var ts;
}
}
return true;
- case 254 /* FunctionDeclaration */: {
+ case 255 /* FunctionDeclaration */: {
if (parent.name && isCallbackLike(checker, sourceFile, parent.name)) {
return isLastParameter(parent, parameter, isFixAll);
}
return true;
}
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
// Can't remove a non-last parameter in a callback. Can remove a parameter in code-fix-all if future parameters are also unused.
return isLastParameter(parent, parameter, isFixAll);
- case 171 /* SetAccessor */:
+ case 172 /* SetAccessor */:
// Setter must have a parameter
return false;
default:
@@ -148452,7 +151683,7 @@ var ts;
var container = (ts.isBlock(statement.parent) ? statement.parent : statement).parent;
if (!ts.isBlock(statement.parent) || statement === ts.first(statement.parent.statements)) {
switch (container.kind) {
- case 237 /* IfStatement */:
+ case 238 /* IfStatement */:
if (container.elseStatement) {
if (ts.isBlock(statement.parent)) {
break;
@@ -148463,8 +151694,8 @@ var ts;
return;
}
// falls through
- case 239 /* WhileStatement */:
- case 240 /* ForStatement */:
+ case 240 /* WhileStatement */:
+ case 241 /* ForStatement */:
changes.delete(sourceFile, container);
return;
}
@@ -148537,7 +151768,7 @@ var ts;
var typeNode = info.typeNode, type = info.type;
var original = typeNode.getText(sourceFile);
var actions = [fix(type, fixIdPlain, ts.Diagnostics.Change_all_jsdoc_style_types_to_TypeScript)];
- if (typeNode.kind === 309 /* JSDocNullableType */) {
+ if (typeNode.kind === 312 /* JSDocNullableType */) {
// for nullable types, suggest the flow-compatible `T | null | undefined`
// in addition to the jsdoc/closure-compatible `T | null`
actions.push(fix(checker.getNullableType(type, 32768 /* Undefined */), fixIdNullable, ts.Diagnostics.Change_all_jsdoc_style_types_to_TypeScript_and_add_undefined_to_nullable_types));
@@ -148557,7 +151788,7 @@ var ts;
if (!info)
return;
var typeNode = info.typeNode, type = info.type;
- var fixedType = typeNode.kind === 309 /* JSDocNullableType */ && fixId === fixIdNullable ? checker.getNullableType(type, 32768 /* Undefined */) : type;
+ var fixedType = typeNode.kind === 312 /* JSDocNullableType */ && fixId === fixIdNullable ? checker.getNullableType(type, 32768 /* Undefined */) : type;
doChange(changes, sourceFile, typeNode, fixedType, checker);
});
}
@@ -148574,22 +151805,22 @@ var ts;
// NOTE: Some locations are not handled yet:
// MappedTypeNode.typeParameters and SignatureDeclaration.typeParameters, as well as CallExpression.typeArguments
switch (node.kind) {
- case 227 /* AsExpression */:
- case 172 /* CallSignature */:
- case 173 /* ConstructSignature */:
- case 254 /* FunctionDeclaration */:
- case 170 /* GetAccessor */:
- case 174 /* IndexSignature */:
- case 193 /* MappedType */:
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
- case 162 /* Parameter */:
- case 165 /* PropertyDeclaration */:
- case 164 /* PropertySignature */:
- case 171 /* SetAccessor */:
- case 257 /* TypeAliasDeclaration */:
- case 209 /* TypeAssertionExpression */:
- case 252 /* VariableDeclaration */:
+ case 228 /* AsExpression */:
+ case 173 /* CallSignature */:
+ case 174 /* ConstructSignature */:
+ case 255 /* FunctionDeclaration */:
+ case 171 /* GetAccessor */:
+ case 175 /* IndexSignature */:
+ case 194 /* MappedType */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
+ case 163 /* Parameter */:
+ case 166 /* PropertyDeclaration */:
+ case 165 /* PropertySignature */:
+ case 172 /* SetAccessor */:
+ case 258 /* TypeAliasDeclaration */:
+ case 210 /* TypeAssertionExpression */:
+ case 253 /* VariableDeclaration */:
return true;
default:
return false;
@@ -148691,15 +151922,16 @@ var ts;
}
var insertBefore;
switch (containingFunction.kind) {
- case 167 /* MethodDeclaration */:
+ case 168 /* MethodDeclaration */:
insertBefore = containingFunction.name;
break;
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
insertBefore = ts.findChildOfKind(containingFunction, 98 /* FunctionKeyword */, sourceFile);
break;
- case 212 /* ArrowFunction */:
- insertBefore = ts.findChildOfKind(containingFunction, 20 /* OpenParenToken */, sourceFile) || ts.first(containingFunction.parameters);
+ case 213 /* ArrowFunction */:
+ var kind = containingFunction.typeParameters ? 29 /* LessThanToken */ : 20 /* OpenParenToken */;
+ insertBefore = ts.findChildOfKind(containingFunction, kind, sourceFile) || ts.first(containingFunction.parameters);
break;
default:
return;
@@ -148717,7 +151949,7 @@ var ts;
changes.replaceNode(sourceFile, returnType, ts.factory.createTypeReferenceNode("Promise", ts.factory.createNodeArray([returnType])));
}
}
- changes.insertModifierBefore(sourceFile, 130 /* AsyncKeyword */, insertBefore);
+ changes.insertModifierBefore(sourceFile, 131 /* AsyncKeyword */, insertBefore);
}
})(codefix = ts.codefix || (ts.codefix = {}));
})(ts || (ts = {}));
@@ -148826,7 +152058,9 @@ var ts;
var sourceFile = context.sourceFile, program = context.program, start = context.span.start, errorCode = context.errorCode, cancellationToken = context.cancellationToken, host = context.host, preferences = context.preferences;
var token = ts.getTokenAtPosition(sourceFile, start);
var declaration;
- var changes = ts.textChanges.ChangeTracker.with(context, function (changes) { declaration = doChange(changes, sourceFile, token, errorCode, program, cancellationToken, /*markSeen*/ ts.returnTrue, host, preferences); });
+ var changes = ts.textChanges.ChangeTracker.with(context, function (changes) {
+ declaration = doChange(changes, sourceFile, token, errorCode, program, cancellationToken, /*markSeen*/ ts.returnTrue, host, preferences);
+ });
var name = declaration && ts.getNameOfDeclaration(declaration);
return !name || changes.length === 0 ? undefined
: [codefix.createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), name.getText(sourceFile)], fixId, ts.Diagnostics.Infer_all_types_from_usage)];
@@ -149031,7 +152265,7 @@ var ts;
function annotate(changes, importAdder, sourceFile, declaration, type, program, host) {
var typeNode = ts.getTypeNodeIfAccessible(type, declaration, program, host);
if (typeNode) {
- if (ts.isInJSFile(sourceFile) && declaration.kind !== 164 /* PropertySignature */) {
+ if (ts.isInJSFile(sourceFile) && declaration.kind !== 165 /* PropertySignature */) {
var parent = ts.isVariableDeclaration(declaration) ? ts.tryCast(declaration.parent.parent, ts.isVariableStatement) : declaration;
if (!parent) {
return;
@@ -149107,14 +152341,14 @@ var ts;
return !!merged;
}); });
var tag = ts.factory.createJSDocComment(ts.factory.createNodeArray(ts.intersperse(comments, ts.factory.createJSDocText("\n"))), ts.factory.createNodeArray(__spreadArray(__spreadArray([], (oldTags || ts.emptyArray), true), unmergedNewTags, true)));
- var jsDocNode = parent.kind === 212 /* ArrowFunction */ ? getJsDocNodeForArrowFunction(parent) : parent;
+ var jsDocNode = parent.kind === 213 /* ArrowFunction */ ? getJsDocNodeForArrowFunction(parent) : parent;
jsDocNode.jsDoc = parent.jsDoc;
jsDocNode.jsDocCache = parent.jsDocCache;
changes.insertJsdocCommentBefore(sourceFile, jsDocNode, tag);
}
codefix.addJSDocTags = addJSDocTags;
function getJsDocNodeForArrowFunction(signature) {
- if (signature.parent.kind === 165 /* PropertyDeclaration */) {
+ if (signature.parent.kind === 166 /* PropertyDeclaration */) {
return signature.parent;
}
return signature.parent.parent;
@@ -149124,14 +152358,14 @@ var ts;
return undefined;
}
switch (oldTag.kind) {
- case 335 /* JSDocParameterTag */: {
+ case 338 /* JSDocParameterTag */: {
var oldParam = oldTag;
var newParam = newTag;
return ts.isIdentifier(oldParam.name) && ts.isIdentifier(newParam.name) && oldParam.name.escapedText === newParam.name.escapedText
? ts.factory.createJSDocParameterTag(/*tagName*/ undefined, newParam.name, /*isBracketed*/ false, newParam.typeExpression, newParam.isNameFirst, oldParam.comment)
: undefined;
}
- case 336 /* JSDocReturnTag */:
+ case 339 /* JSDocReturnTag */:
return ts.factory.createJSDocReturnTag(/*tagName*/ undefined, newTag.typeExpression, oldTag.comment);
}
}
@@ -149156,19 +152390,19 @@ var ts;
function getFunctionReferences(containingFunction, sourceFile, program, cancellationToken) {
var searchToken;
switch (containingFunction.kind) {
- case 169 /* Constructor */:
- searchToken = ts.findChildOfKind(containingFunction, 133 /* ConstructorKeyword */, sourceFile);
+ case 170 /* Constructor */:
+ searchToken = ts.findChildOfKind(containingFunction, 134 /* ConstructorKeyword */, sourceFile);
break;
- case 212 /* ArrowFunction */:
- case 211 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
+ case 212 /* FunctionExpression */:
var parent = containingFunction.parent;
searchToken = (ts.isVariableDeclaration(parent) || ts.isPropertyDeclaration(parent)) && ts.isIdentifier(parent.name) ?
parent.name :
containingFunction.name;
break;
- case 254 /* FunctionDeclaration */:
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
+ case 255 /* FunctionDeclaration */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
searchToken = containingFunction.name;
break;
}
@@ -149310,24 +152544,24 @@ var ts;
node = node.parent;
}
switch (node.parent.kind) {
- case 236 /* ExpressionStatement */:
+ case 237 /* ExpressionStatement */:
inferTypeFromExpressionStatement(node, usage);
break;
- case 218 /* PostfixUnaryExpression */:
+ case 219 /* PostfixUnaryExpression */:
usage.isNumber = true;
break;
- case 217 /* PrefixUnaryExpression */:
+ case 218 /* PrefixUnaryExpression */:
inferTypeFromPrefixUnaryExpression(node.parent, usage);
break;
- case 219 /* BinaryExpression */:
+ case 220 /* BinaryExpression */:
inferTypeFromBinaryExpression(node, node.parent, usage);
break;
- case 287 /* CaseClause */:
- case 288 /* DefaultClause */:
+ case 288 /* CaseClause */:
+ case 289 /* DefaultClause */:
inferTypeFromSwitchStatementLabel(node.parent, usage);
break;
- case 206 /* CallExpression */:
- case 207 /* NewExpression */:
+ case 207 /* CallExpression */:
+ case 208 /* NewExpression */:
if (node.parent.expression === node) {
inferTypeFromCallExpression(node.parent, usage);
}
@@ -149335,20 +152569,20 @@ var ts;
inferTypeFromContextualType(node, usage);
}
break;
- case 204 /* PropertyAccessExpression */:
+ case 205 /* PropertyAccessExpression */:
inferTypeFromPropertyAccessExpression(node.parent, usage);
break;
- case 205 /* ElementAccessExpression */:
+ case 206 /* ElementAccessExpression */:
inferTypeFromPropertyElementExpression(node.parent, node, usage);
break;
- case 291 /* PropertyAssignment */:
- case 292 /* ShorthandPropertyAssignment */:
+ case 294 /* PropertyAssignment */:
+ case 295 /* ShorthandPropertyAssignment */:
inferTypeFromPropertyAssignment(node.parent, usage);
break;
- case 165 /* PropertyDeclaration */:
+ case 166 /* PropertyDeclaration */:
inferTypeFromPropertyDeclaration(node.parent, usage);
break;
- case 252 /* VariableDeclaration */: {
+ case 253 /* VariableDeclaration */: {
var _a = node.parent, name = _a.name, initializer = _a.initializer;
if (node === name) {
if (initializer) { // This can happen for `let x = null;` which still has an implicit-any error.
@@ -149470,7 +152704,7 @@ var ts;
case 56 /* BarBarToken */:
case 60 /* QuestionQuestionToken */:
if (node === parent.left &&
- (node.parent.parent.kind === 252 /* VariableDeclaration */ || ts.isAssignmentExpression(node.parent.parent, /*excludeCompoundAssignment*/ true))) {
+ (node.parent.parent.kind === 253 /* VariableDeclaration */ || ts.isAssignmentExpression(node.parent.parent, /*excludeCompoundAssignment*/ true))) {
// var x = x || {};
// TODO: use getFalsyflagsOfType
addCandidateType(usage, checker.getTypeAtLocation(parent.right));
@@ -149498,7 +152732,7 @@ var ts;
}
}
calculateUsageOfNode(parent, call.return_);
- if (parent.kind === 206 /* CallExpression */) {
+ if (parent.kind === 207 /* CallExpression */) {
(usage.calls || (usage.calls = [])).push(call);
}
else {
@@ -149769,7 +153003,7 @@ var ts;
function getSignatureFromCalls(calls) {
var parameters = [];
var length = Math.max.apply(Math, calls.map(function (c) { return c.argumentTypes.length; }));
- var _loop_15 = function (i) {
+ var _loop_16 = function (i) {
var symbol = checker.createSymbol(1 /* FunctionScopedVariable */, ts.escapeLeadingUnderscores("arg" + i));
symbol.type = combineTypes(calls.map(function (call) { return call.argumentTypes[i] || checker.getUndefinedType(); }));
if (calls.some(function (call) { return call.argumentTypes[i] === undefined; })) {
@@ -149778,7 +153012,7 @@ var ts;
parameters.push(symbol);
};
for (var i = 0; i < length; i++) {
- _loop_15(i);
+ _loop_16(i);
}
var returnType = combineFromUsage(combineUsages(calls.map(function (call) { return call.return_; })));
return checker.createSignature(/*declaration*/ undefined, /*typeParameters*/ undefined, /*thisParameter*/ undefined, parameters, returnType, /*typePredicate*/ undefined, length, 0 /* None */);
@@ -149917,7 +153151,7 @@ var ts;
for (var _i = 0, possiblyMissingSymbols_1 = possiblyMissingSymbols; _i < possiblyMissingSymbols_1.length; _i++) {
var symbol = possiblyMissingSymbols_1[_i];
if (!classMembers.has(symbol.escapedName)) {
- addNewNodeForMemberSymbol(symbol, classDeclaration, sourceFile, context, preferences, importAdder, addClassElement);
+ addNewNodeForMemberSymbol(symbol, classDeclaration, sourceFile, context, preferences, importAdder, addClassElement, /* body */ undefined);
}
}
}
@@ -149929,10 +153163,19 @@ var ts;
};
}
codefix.getNoopSymbolTrackerWithResolver = getNoopSymbolTrackerWithResolver;
- /**
- * @returns Empty string iff there we can't figure out a representation for `symbol` in `enclosingDeclaration`.
- */
- function addNewNodeForMemberSymbol(symbol, enclosingDeclaration, sourceFile, context, preferences, importAdder, addClassElement) {
+ var PreserveOptionalFlags;
+ (function (PreserveOptionalFlags) {
+ PreserveOptionalFlags[PreserveOptionalFlags["Method"] = 1] = "Method";
+ PreserveOptionalFlags[PreserveOptionalFlags["Property"] = 2] = "Property";
+ PreserveOptionalFlags[PreserveOptionalFlags["All"] = 3] = "All";
+ })(PreserveOptionalFlags = codefix.PreserveOptionalFlags || (codefix.PreserveOptionalFlags = {}));
+ /**
+ * `addClassElement` will not be called if we can't figure out a representation for `symbol` in `enclosingDeclaration`.
+ * @param body If defined, this will be the body of the member node passed to `addClassElement`. Otherwise, the body will default to a stub.
+ */
+ function addNewNodeForMemberSymbol(symbol, enclosingDeclaration, sourceFile, context, preferences, importAdder, addClassElement, body, preserveOptional, isAmbient) {
+ if (preserveOptional === void 0) { preserveOptional = 3 /* All */; }
+ if (isAmbient === void 0) { isAmbient = false; }
var declarations = symbol.getDeclarations();
if (!(declarations && declarations.length)) {
return undefined;
@@ -149945,11 +153188,11 @@ var ts;
var modifiers = visibilityModifier ? ts.factory.createNodeArray([visibilityModifier]) : undefined;
var type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
var optional = !!(symbol.flags & 16777216 /* Optional */);
- var ambient = !!(enclosingDeclaration.flags & 8388608 /* Ambient */);
+ var ambient = !!(enclosingDeclaration.flags & 8388608 /* Ambient */) || isAmbient;
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
switch (declaration.kind) {
- case 164 /* PropertySignature */:
- case 165 /* PropertyDeclaration */:
+ case 165 /* PropertySignature */:
+ case 166 /* PropertyDeclaration */:
var flags = quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : undefined;
var typeNode = checker.typeToTypeNode(type, enclosingDeclaration, flags, getNoopSymbolTrackerWithResolver(context));
if (importAdder) {
@@ -149960,11 +153203,11 @@ var ts;
}
}
addClassElement(ts.factory.createPropertyDeclaration(
- /*decorators*/ undefined, modifiers, name, optional ? ts.factory.createToken(57 /* QuestionToken */) : undefined, typeNode,
+ /*decorators*/ undefined, modifiers, name, optional && (preserveOptional & 2 /* Property */) ? ts.factory.createToken(57 /* QuestionToken */) : undefined, typeNode,
/*initializer*/ undefined));
break;
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */: {
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */: {
var typeNode_1 = checker.typeToTypeNode(type, enclosingDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context));
var allAccessors = ts.getAllAccessorDeclarations(declarations, declaration);
var orderedAccessors = allAccessors.secondAccessor
@@ -149981,20 +153224,20 @@ var ts;
var accessor = orderedAccessors_1[_i];
if (ts.isGetAccessorDeclaration(accessor)) {
addClassElement(ts.factory.createGetAccessorDeclaration(
- /*decorators*/ undefined, modifiers, name, ts.emptyArray, typeNode_1, ambient ? undefined : createStubbedMethodBody(quotePreference)));
+ /*decorators*/ undefined, modifiers, name, ts.emptyArray, typeNode_1, ambient ? undefined : body || createStubbedMethodBody(quotePreference)));
}
else {
ts.Debug.assertNode(accessor, ts.isSetAccessorDeclaration, "The counterpart to a getter should be a setter");
var parameter = ts.getSetAccessorValueParameter(accessor);
var parameterName = parameter && ts.isIdentifier(parameter.name) ? ts.idText(parameter.name) : undefined;
addClassElement(ts.factory.createSetAccessorDeclaration(
- /*decorators*/ undefined, modifiers, name, createDummyParameters(1, [parameterName], [typeNode_1], 1, /*inJs*/ false), ambient ? undefined : createStubbedMethodBody(quotePreference)));
+ /*decorators*/ undefined, modifiers, name, createDummyParameters(1, [parameterName], [typeNode_1], 1, /*inJs*/ false), ambient ? undefined : body || createStubbedMethodBody(quotePreference)));
}
}
break;
}
- case 166 /* MethodSignature */:
- case 167 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
+ case 168 /* MethodDeclaration */:
// The signature for the implementation appears as an entry in `signatures` iff
// there is only one signature.
// If there are overloads and an implementation signature, it appears as an
@@ -150009,7 +153252,7 @@ var ts;
if (declarations.length === 1) {
ts.Debug.assert(signatures.length === 1, "One declaration implies one signature");
var signature = signatures[0];
- outputMethod(quotePreference, signature, modifiers, name, ambient ? undefined : createStubbedMethodBody(quotePreference));
+ outputMethod(quotePreference, signature, modifiers, name, ambient ? undefined : body || createStubbedMethodBody(quotePreference));
break;
}
for (var _a = 0, signatures_1 = signatures; _a < signatures_1.length; _a++) {
@@ -150020,21 +153263,22 @@ var ts;
if (!ambient) {
if (declarations.length > signatures.length) {
var signature = checker.getSignatureFromDeclaration(declarations[declarations.length - 1]);
- outputMethod(quotePreference, signature, modifiers, name, createStubbedMethodBody(quotePreference));
+ outputMethod(quotePreference, signature, modifiers, name, body || createStubbedMethodBody(quotePreference));
}
else {
ts.Debug.assert(declarations.length === signatures.length, "Declarations and signatures should match count");
- addClassElement(createMethodImplementingSignatures(checker, context, enclosingDeclaration, signatures, name, optional, modifiers, quotePreference));
+ addClassElement(createMethodImplementingSignatures(checker, context, enclosingDeclaration, signatures, name, optional && !!(preserveOptional & 1 /* Method */), modifiers, quotePreference, body));
}
}
break;
}
function outputMethod(quotePreference, signature, modifiers, name, body) {
- var method = createSignatureDeclarationFromSignature(167 /* MethodDeclaration */, context, quotePreference, signature, body, name, modifiers, optional, enclosingDeclaration, importAdder);
+ var method = createSignatureDeclarationFromSignature(168 /* MethodDeclaration */, context, quotePreference, signature, body, name, modifiers, optional && !!(preserveOptional & 1 /* Method */), enclosingDeclaration, importAdder);
if (method)
addClassElement(method);
}
}
+ codefix.addNewNodeForMemberSymbol = addNewNodeForMemberSymbol;
function createSignatureDeclarationFromSignature(kind, context, quotePreference, signature, body, name, modifiers, optional, enclosingDeclaration, importAdder) {
var program = context.program;
var checker = program.getTypeChecker();
@@ -150135,7 +153379,7 @@ var ts;
var type = isJs || contextualType === undefined
? undefined
: checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker);
- if (kind === 167 /* MethodDeclaration */) {
+ if (kind === 168 /* MethodDeclaration */) {
return ts.factory.createMethodDeclaration(
/*decorators*/ undefined, modifiers, asteriskToken, name,
/*questionToken*/ undefined, typeParameters, parameters, type, ts.isInterfaceDeclaration(contextNode) ? undefined : createStubbedMethodBody(quotePreference));
@@ -150166,13 +153410,13 @@ var ts;
/*dotDotDotToken*/ undefined,
/*name*/ names && names[i] || "arg" + i,
/*questionToken*/ minArgumentCount !== undefined && i >= minArgumentCount ? ts.factory.createToken(57 /* QuestionToken */) : undefined,
- /*type*/ inJs ? undefined : types && types[i] || ts.factory.createKeywordTypeNode(129 /* AnyKeyword */),
+ /*type*/ inJs ? undefined : types && types[i] || ts.factory.createKeywordTypeNode(130 /* AnyKeyword */),
/*initializer*/ undefined);
parameters.push(newParameter);
}
return parameters;
}
- function createMethodImplementingSignatures(checker, context, enclosingDeclaration, signatures, name, optional, modifiers, quotePreference) {
+ function createMethodImplementingSignatures(checker, context, enclosingDeclaration, signatures, name, optional, modifiers, quotePreference, body) {
/** This is *a* signature with the maximal number of arguments,
* such that if there is a "maximal" signature without rest arguments,
* this is one of them.
@@ -150194,7 +153438,7 @@ var ts;
var maxArgsParameterSymbolNames = maxArgsSignature.parameters.map(function (symbol) { return symbol.name; });
var parameters = createDummyParameters(maxNonRestArgs, maxArgsParameterSymbolNames, /* types */ undefined, minArgumentCount, /*inJs*/ false);
if (someSigHasRestParameter) {
- var anyArrayType = ts.factory.createArrayTypeNode(ts.factory.createKeywordTypeNode(129 /* AnyKeyword */));
+ var anyArrayType = ts.factory.createArrayTypeNode(ts.factory.createKeywordTypeNode(130 /* AnyKeyword */));
var restParameter = ts.factory.createParameterDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined, ts.factory.createToken(25 /* DotDotDotToken */), maxArgsParameterSymbolNames[maxNonRestArgs] || "rest",
@@ -150203,7 +153447,7 @@ var ts;
parameters.push(restParameter);
}
return createStubbedMethod(modifiers, name, optional,
- /*typeParameters*/ undefined, parameters, getReturnTypeFromSignatures(signatures, checker, context, enclosingDeclaration), quotePreference);
+ /*typeParameters*/ undefined, parameters, getReturnTypeFromSignatures(signatures, checker, context, enclosingDeclaration), quotePreference, body);
}
function getReturnTypeFromSignatures(signatures, checker, context, enclosingDeclaration) {
if (ts.length(signatures)) {
@@ -150211,10 +153455,10 @@ var ts;
return checker.typeToTypeNode(type, enclosingDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context));
}
}
- function createStubbedMethod(modifiers, name, optional, typeParameters, parameters, returnType, quotePreference) {
+ function createStubbedMethod(modifiers, name, optional, typeParameters, parameters, returnType, quotePreference, body) {
return ts.factory.createMethodDeclaration(
/*decorators*/ undefined, modifiers,
- /*asteriskToken*/ undefined, name, optional ? ts.factory.createToken(57 /* QuestionToken */) : undefined, typeParameters, parameters, returnType, createStubbedMethodBody(quotePreference));
+ /*asteriskToken*/ undefined, name, optional ? ts.factory.createToken(57 /* QuestionToken */) : undefined, typeParameters, parameters, returnType, body || createStubbedMethodBody(quotePreference));
}
function createStubbedMethodBody(quotePreference) {
return createStubbedBody(ts.Diagnostics.Method_not_implemented.message, quotePreference);
@@ -150311,7 +153555,7 @@ var ts;
return ts.factory.createQualifiedName(replaceFirstIdentifierOfEntityName(name.left, newIdentifier), name.right);
}
function importSymbols(importAdder, symbols) {
- symbols.forEach(function (s) { return importAdder.addImportFromExportedSymbol(s, /*usageIsTypeOnly*/ true); });
+ symbols.forEach(function (s) { return importAdder.addImportFromExportedSymbol(s, /*isValidTypeOnlyUseSite*/ true); });
}
codefix.importSymbols = importSymbols;
})(codefix = ts.codefix || (ts.codefix = {}));
@@ -150421,7 +153665,7 @@ var ts;
isStatic: ts.hasStaticModifier(declaration),
isReadonly: ts.hasEffectiveReadonlyModifier(declaration),
type: getDeclarationType(declaration, program),
- container: declaration.kind === 162 /* Parameter */ ? declaration.parent.parent : declaration.parent,
+ container: declaration.kind === 163 /* Parameter */ ? declaration.parent.parent : declaration.parent,
originalName: declaration.name.text,
declaration: declaration,
fieldName: fieldName,
@@ -150498,7 +153742,7 @@ var ts;
var type = typeChecker.getTypeFromTypeNode(typeNode);
if (!typeChecker.isTypeAssignableTo(typeChecker.getUndefinedType(), type)) {
var types = ts.isUnionTypeNode(typeNode) ? typeNode.types : [typeNode];
- return ts.factory.createUnionTypeNode(__spreadArray(__spreadArray([], types, true), [ts.factory.createKeywordTypeNode(151 /* UndefinedKeyword */)], false));
+ return ts.factory.createUnionTypeNode(__spreadArray(__spreadArray([], types, true), [ts.factory.createKeywordTypeNode(152 /* UndefinedKeyword */)], false));
}
}
return typeNode;
@@ -150557,7 +153801,7 @@ var ts;
});
function getActionsForUsageOfInvalidImport(context) {
var sourceFile = context.sourceFile;
- var targetKind = ts.Diagnostics.This_expression_is_not_callable.code === context.errorCode ? 206 /* CallExpression */ : 207 /* NewExpression */;
+ var targetKind = ts.Diagnostics.This_expression_is_not_callable.code === context.errorCode ? 207 /* CallExpression */ : 208 /* NewExpression */;
var node = ts.findAncestor(ts.getTokenAtPosition(sourceFile, context.span.start), function (a) { return a.kind === targetKind; });
if (!node) {
return [];
@@ -150675,7 +153919,7 @@ var ts;
return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_undefined_type_to_property_0, propertyDeclaration.name.getText()], fixIdAddUndefinedType, ts.Diagnostics.Add_undefined_type_to_all_uninitialized_properties);
}
function addUndefinedType(changeTracker, propertyDeclarationSourceFile, propertyDeclaration) {
- var undefinedTypeNode = ts.factory.createKeywordTypeNode(151 /* UndefinedKeyword */);
+ var undefinedTypeNode = ts.factory.createKeywordTypeNode(152 /* UndefinedKeyword */);
var type = propertyDeclaration.type; // TODO: GH#18217
var types = ts.isUnionTypeNode(type) ? type.types.concat(undefinedTypeNode) : [type, undefinedTypeNode];
changeTracker.replaceNode(propertyDeclarationSourceFile, type, ts.factory.createUnionTypeNode(types));
@@ -150756,7 +154000,7 @@ var ts;
var allowSyntheticDefaults = info.allowSyntheticDefaults, defaultImportName = info.defaultImportName, namedImports = info.namedImports, statement = info.statement, required = info.required;
changes.replaceNode(sourceFile, statement, defaultImportName && !allowSyntheticDefaults
? ts.factory.createImportEqualsDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, /*isTypeOnly*/ false, defaultImportName, ts.factory.createExternalModuleReference(required))
- : ts.factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, namedImports), required));
+ : ts.factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, namedImports), required, /*assertClause*/ undefined));
}
function getInfo(sourceFile, program, pos) {
var parent = ts.getTokenAtPosition(sourceFile, pos).parent;
@@ -150783,7 +154027,7 @@ var ts;
if (!ts.isIdentifier(element.name) || element.initializer) {
return undefined;
}
- importSpecifiers.push(ts.factory.createImportSpecifier(ts.tryCast(element.propertyName, ts.isIdentifier), element.name));
+ importSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, ts.tryCast(element.propertyName, ts.isIdentifier), element.name));
}
if (importSpecifiers.length) {
return ts.factory.createNamedImports(importSpecifiers);
@@ -150890,7 +154134,7 @@ var ts;
function getImportTypeNode(sourceFile, pos) {
var token = ts.getTokenAtPosition(sourceFile, pos);
ts.Debug.assert(token.kind === 100 /* ImportKeyword */, "This token should be an ImportKeyword");
- ts.Debug.assert(token.parent.kind === 198 /* ImportType */, "Token parent should be an ImportType");
+ ts.Debug.assert(token.parent.kind === 199 /* ImportType */, "Token parent should be an ImportType");
return token.parent;
}
function doChange(changes, sourceFile, importType) {
@@ -151018,8 +154262,9 @@ var ts;
var otherMembers = members.filter(function (member) { return !ts.isIndexSignatureDeclaration(member); });
var parameter = ts.first(indexSignature.parameters);
var mappedTypeParameter = ts.factory.createTypeParameterDeclaration(ts.cast(parameter.name, ts.isIdentifier), parameter.type);
- var mappedIntersectionType = ts.factory.createMappedTypeNode(ts.hasEffectiveReadonlyModifier(indexSignature) ? ts.factory.createModifier(143 /* ReadonlyKeyword */) : undefined, mappedTypeParameter,
- /*nameType*/ undefined, indexSignature.questionToken, indexSignature.type);
+ var mappedIntersectionType = ts.factory.createMappedTypeNode(ts.hasEffectiveReadonlyModifier(indexSignature) ? ts.factory.createModifier(144 /* ReadonlyKeyword */) : undefined, mappedTypeParameter,
+ /*nameType*/ undefined, indexSignature.questionToken, indexSignature.type,
+ /*members*/ undefined);
var intersectionType = ts.factory.createIntersectionTypeNode(__spreadArray(__spreadArray(__spreadArray([], ts.getAllSuperTypeNodes(container), true), [
mappedIntersectionType
], false), (otherMembers.length ? [ts.factory.createTypeLiteralNode(otherMembers)] : ts.emptyArray), true));
@@ -151075,7 +154320,7 @@ var ts;
},
});
function makeChange(changeTracker, sourceFile, span) {
- var awaitKeyword = ts.tryCast(ts.getTokenAtPosition(sourceFile, span.start), function (node) { return node.kind === 131 /* AwaitKeyword */; });
+ var awaitKeyword = ts.tryCast(ts.getTokenAtPosition(sourceFile, span.start), function (node) { return node.kind === 132 /* AwaitKeyword */; });
var awaitExpression = awaitKeyword && ts.tryCast(awaitKeyword.parent, ts.isAwaitExpression);
if (!awaitExpression) {
return;
@@ -151125,10 +154370,10 @@ var ts;
return;
}
var importClause = ts.Debug.checkDefined(importDeclaration.importClause);
- changes.replaceNode(context.sourceFile, importDeclaration, ts.factory.updateImportDeclaration(importDeclaration, importDeclaration.decorators, importDeclaration.modifiers, ts.factory.updateImportClause(importClause, importClause.isTypeOnly, importClause.name, /*namedBindings*/ undefined), importDeclaration.moduleSpecifier));
+ changes.replaceNode(context.sourceFile, importDeclaration, ts.factory.updateImportDeclaration(importDeclaration, importDeclaration.decorators, importDeclaration.modifiers, ts.factory.updateImportClause(importClause, importClause.isTypeOnly, importClause.name, /*namedBindings*/ undefined), importDeclaration.moduleSpecifier, importDeclaration.assertClause));
changes.insertNodeAfter(context.sourceFile, importDeclaration, ts.factory.createImportDeclaration(
/*decorators*/ undefined,
- /*modifiers*/ undefined, ts.factory.updateImportClause(importClause, importClause.isTypeOnly, /*name*/ undefined, importClause.namedBindings), importDeclaration.moduleSpecifier));
+ /*modifiers*/ undefined, ts.factory.updateImportClause(importClause, importClause.isTypeOnly, /*name*/ undefined, importClause.namedBindings), importDeclaration.moduleSpecifier, importDeclaration.assertClause));
}
})(codefix = ts.codefix || (ts.codefix = {}));
})(ts || (ts = {}));
@@ -151181,9 +154426,8 @@ var ts;
getCodeActions: function (context) {
var sourceFile = context.sourceFile;
var info = getInfo(sourceFile, context.span.start, context.errorCode);
- if (!info) {
+ if (!info)
return undefined;
- }
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(t, sourceFile, info); });
return [codefix.createCodeFixAction(fixId, changes, [ts.Diagnostics.Change_0_to_1, ";", ","], fixId, [ts.Diagnostics.Change_0_to_1, ";", ","])];
},
@@ -151362,19 +154606,19 @@ var ts;
: { error: ts.getLocaleSpecificMessage(ts.Diagnostics.Can_only_convert_named_export) };
};
switch (exportNode.kind) {
- case 254 /* FunctionDeclaration */:
- case 255 /* ClassDeclaration */:
- case 256 /* InterfaceDeclaration */:
- case 258 /* EnumDeclaration */:
- case 257 /* TypeAliasDeclaration */:
- case 259 /* ModuleDeclaration */: {
+ case 255 /* FunctionDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 257 /* InterfaceDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
+ case 260 /* ModuleDeclaration */: {
var node = exportNode;
if (!node.name)
return undefined;
return noSymbolError(node.name)
|| { exportNode: node, exportName: node.name, wasDefault: wasDefault, exportingModuleSymbol: exportingModuleSymbol };
}
- case 235 /* VariableStatement */: {
+ case 236 /* VariableStatement */: {
var vs = exportNode;
// Must be `export const x = something;`.
if (!(vs.declarationList.flags & 2 /* Const */) || vs.declarationList.declarations.length !== 1) {
@@ -151387,7 +154631,7 @@ var ts;
return noSymbolError(decl.name)
|| { exportNode: vs, exportName: decl.name, wasDefault: wasDefault, exportingModuleSymbol: exportingModuleSymbol };
}
- case 269 /* ExportAssignment */: {
+ case 270 /* ExportAssignment */: {
var node = exportNode;
if (node.isExportEquals)
return undefined;
@@ -151417,12 +154661,12 @@ var ts;
else {
var exportKeyword = ts.Debug.checkDefined(ts.findModifier(exportNode, 93 /* ExportKeyword */), "Should find an export keyword in modifier list");
switch (exportNode.kind) {
- case 254 /* FunctionDeclaration */:
- case 255 /* ClassDeclaration */:
- case 256 /* InterfaceDeclaration */:
+ case 255 /* FunctionDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 257 /* InterfaceDeclaration */:
changes.insertNodeAfter(exportingSourceFile, exportKeyword, ts.factory.createToken(88 /* DefaultKeyword */));
break;
- case 235 /* VariableStatement */:
+ case 236 /* VariableStatement */:
// If 'x' isn't used in this file and doesn't have type definition, `export const x = 0;` --> `export default 0;`
var decl = ts.first(exportNode.declarationList.declarations);
if (!ts.FindAllReferences.Core.isSymbolReferencedInFile(exportName, checker, exportingSourceFile) && !decl.type) {
@@ -151431,9 +154675,9 @@ var ts;
break;
}
// falls through
- case 258 /* EnumDeclaration */:
- case 257 /* TypeAliasDeclaration */:
- case 259 /* ModuleDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
+ case 260 /* ModuleDeclaration */:
// `export type T = number;` -> `type T = number; export default T;`
changes.deleteModifier(exportingSourceFile, exportKeyword);
changes.insertNodeAfter(exportingSourceFile, exportNode, ts.factory.createExportDefault(ts.factory.createIdentifier(exportName.text)));
@@ -151460,18 +154704,18 @@ var ts;
function changeDefaultToNamedImport(importingSourceFile, ref, changes, exportName) {
var parent = ref.parent;
switch (parent.kind) {
- case 204 /* PropertyAccessExpression */:
+ case 205 /* PropertyAccessExpression */:
// `a.default` --> `a.foo`
changes.replaceNode(importingSourceFile, ref, ts.factory.createIdentifier(exportName));
break;
- case 268 /* ImportSpecifier */:
- case 273 /* ExportSpecifier */: {
+ case 269 /* ImportSpecifier */:
+ case 274 /* ExportSpecifier */: {
var spec = parent;
// `default as foo` --> `foo`, `default as bar` --> `foo as bar`
changes.replaceNode(importingSourceFile, spec, makeImportSpecifier(exportName, spec.name.text));
break;
}
- case 265 /* ImportClause */: {
+ case 266 /* ImportClause */: {
var clause = parent;
ts.Debug.assert(clause.name === ref, "Import clause name should match provided ref");
var spec = makeImportSpecifier(exportName, ref.text);
@@ -151480,7 +154724,7 @@ var ts;
// `import foo from "./a";` --> `import { foo } from "./a";`
changes.replaceNode(importingSourceFile, ref, ts.factory.createNamedImports([spec]));
}
- else if (namedBindings.kind === 266 /* NamespaceImport */) {
+ else if (namedBindings.kind === 267 /* NamespaceImport */) {
// `import foo, * as a from "./a";` --> `import * as a from ".a/"; import { foo } from "./a";`
changes.deleteRange(importingSourceFile, { pos: ref.getStart(importingSourceFile), end: namedBindings.getStart(importingSourceFile) });
var quotePreference = ts.isStringLiteral(clause.parent.moduleSpecifier) ? ts.quotePreferenceFromString(clause.parent.moduleSpecifier, importingSourceFile) : 1 /* Double */;
@@ -151501,11 +154745,11 @@ var ts;
function changeNamedToDefaultImport(importingSourceFile, ref, changes) {
var parent = ref.parent;
switch (parent.kind) {
- case 204 /* PropertyAccessExpression */:
+ case 205 /* PropertyAccessExpression */:
// `a.foo` --> `a.default`
changes.replaceNode(importingSourceFile, ref, ts.factory.createIdentifier("default"));
break;
- case 268 /* ImportSpecifier */: {
+ case 269 /* ImportSpecifier */: {
// `import { foo } from "./a";` --> `import foo from "./a";`
// `import { foo as bar } from "./a";` --> `import bar from "./a";`
var defaultImport = ts.factory.createIdentifier(parent.name.text);
@@ -151518,7 +154762,7 @@ var ts;
}
break;
}
- case 273 /* ExportSpecifier */: {
+ case 274 /* ExportSpecifier */: {
// `export { foo } from "./a";` --> `export { default as foo } from "./a";`
// `export { foo as bar } from "./a";` --> `export { default as bar } from "./a";`
// `export { foo as default } from "./a";` --> `export { default } from "./a";`
@@ -151531,10 +154775,10 @@ var ts;
}
}
function makeImportSpecifier(propertyName, name) {
- return ts.factory.createImportSpecifier(propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
+ return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
}
function makeExportSpecifier(propertyName, name) {
- return ts.factory.createExportSpecifier(propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
+ return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
}
})(refactor = ts.refactor || (ts.refactor = {}));
})(ts || (ts = {}));
@@ -151564,7 +154808,7 @@ var ts;
if (!info)
return ts.emptyArray;
if (!refactor.isRefactorErrorInfo(info)) {
- var namespaceImport = info.kind === 266 /* NamespaceImport */;
+ var namespaceImport = info.kind === 267 /* NamespaceImport */;
var action = namespaceImport ? namespaceToNamedAction : namedToNamespaceAction;
return [{ name: refactorName, description: action.description, actions: [action] }];
}
@@ -151595,7 +154839,9 @@ var ts;
var importDecl = considerPartialSpans ? ts.findAncestor(token, ts.isImportDeclaration) : ts.getParentNodeInSpan(token, file, span);
if (!importDecl || !ts.isImportDeclaration(importDecl))
return { error: "Selection is not an import declaration." };
- if (importDecl.getEnd() < span.start + span.length)
+ var end = span.start + span.length;
+ var nextToken = ts.findNextToken(importDecl, importDecl.parent, file);
+ if (nextToken && end > nextToken.getStart())
return undefined;
var importClause = importDecl.importClause;
if (!importClause) {
@@ -151608,7 +154854,7 @@ var ts;
}
function doChange(sourceFile, program, changes, toConvert) {
var checker = program.getTypeChecker();
- if (toConvert.kind === 266 /* NamespaceImport */) {
+ if (toConvert.kind === 267 /* NamespaceImport */) {
doChangeNamespaceToNamed(sourceFile, checker, changes, toConvert, ts.getAllowSyntheticDefaultImports(program.getCompilerOptions()));
}
else {
@@ -151645,7 +154891,7 @@ var ts;
}
var importSpecifiers = [];
exportNameToImportName.forEach(function (name, propertyName) {
- importSpecifiers.push(ts.factory.createImportSpecifier(name === propertyName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name)));
+ importSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, name === propertyName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name)));
});
var importDecl = toConvert.parent.parent;
if (usedAsNamespaceOrDefault && !allowSyntheticDefaultImports) {
@@ -151694,7 +154940,7 @@ var ts;
// Imports that need to be kept as named imports in the refactored code, to avoid changing the semantics.
// More specifically, those are named imports that appear in named exports in the original code, e.g. `a` in `import { a } from "m"; export { a }`.
var neededNamedImports = new ts.Set();
- var _loop_16 = function (element) {
+ var _loop_17 = function (element) {
var propertyName = (element.propertyName || element.name).text;
ts.FindAllReferences.Core.eachSymbolReferenceInFile(element.name, checker, sourceFile, function (id) {
var access = ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(namespaceImportName), propertyName);
@@ -151711,18 +154957,18 @@ var ts;
};
for (var _i = 0, _a = toConvert.elements; _i < _a.length; _i++) {
var element = _a[_i];
- _loop_16(element);
+ _loop_17(element);
}
changes.replaceNode(sourceFile, toConvert, ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceImportName)));
if (neededNamedImports.size) {
var newNamedImports = ts.arrayFrom(neededNamedImports.values()).map(function (element) {
- return ts.factory.createImportSpecifier(element.propertyName && ts.factory.createIdentifier(element.propertyName.text), ts.factory.createIdentifier(element.name.text));
+ return ts.factory.createImportSpecifier(element.isTypeOnly, element.propertyName && ts.factory.createIdentifier(element.propertyName.text), ts.factory.createIdentifier(element.name.text));
});
changes.insertNodeAfter(sourceFile, toConvert.parent.parent, updateImport(importDecl, /*defaultImportName*/ undefined, newNamedImports));
}
}
function updateImport(old, defaultImportName, elements) {
- return ts.factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, elements && elements.length ? ts.factory.createNamedImports(elements) : undefined), old.moduleSpecifier);
+ return ts.factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, elements && elements.length ? ts.factory.createNamedImports(elements) : undefined), old.moduleSpecifier, /*assertClause*/ undefined);
}
})(refactor = ts.refactor || (ts.refactor = {}));
})(ts || (ts = {}));
@@ -152031,27 +155277,27 @@ var ts;
var lastDeclaration = signatureDecls[signatureDecls.length - 1];
var updated = lastDeclaration;
switch (lastDeclaration.kind) {
- case 166 /* MethodSignature */: {
+ case 167 /* MethodSignature */: {
updated = ts.factory.updateMethodSignature(lastDeclaration, lastDeclaration.modifiers, lastDeclaration.name, lastDeclaration.questionToken, lastDeclaration.typeParameters, getNewParametersForCombinedSignature(signatureDecls), lastDeclaration.type);
break;
}
- case 167 /* MethodDeclaration */: {
+ case 168 /* MethodDeclaration */: {
updated = ts.factory.updateMethodDeclaration(lastDeclaration, lastDeclaration.decorators, lastDeclaration.modifiers, lastDeclaration.asteriskToken, lastDeclaration.name, lastDeclaration.questionToken, lastDeclaration.typeParameters, getNewParametersForCombinedSignature(signatureDecls), lastDeclaration.type, lastDeclaration.body);
break;
}
- case 172 /* CallSignature */: {
+ case 173 /* CallSignature */: {
updated = ts.factory.updateCallSignature(lastDeclaration, lastDeclaration.typeParameters, getNewParametersForCombinedSignature(signatureDecls), lastDeclaration.type);
break;
}
- case 169 /* Constructor */: {
+ case 170 /* Constructor */: {
updated = ts.factory.updateConstructorDeclaration(lastDeclaration, lastDeclaration.decorators, lastDeclaration.modifiers, getNewParametersForCombinedSignature(signatureDecls), lastDeclaration.body);
break;
}
- case 173 /* ConstructSignature */: {
+ case 174 /* ConstructSignature */: {
updated = ts.factory.updateConstructSignature(lastDeclaration, lastDeclaration.typeParameters, getNewParametersForCombinedSignature(signatureDecls), lastDeclaration.type);
break;
}
- case 254 /* FunctionDeclaration */: {
+ case 255 /* FunctionDeclaration */: {
updated = ts.factory.updateFunctionDeclaration(lastDeclaration, lastDeclaration.decorators, lastDeclaration.modifiers, lastDeclaration.asteriskToken, lastDeclaration.name, lastDeclaration.typeParameters, getNewParametersForCombinedSignature(signatureDecls), lastDeclaration.type, lastDeclaration.body);
break;
}
@@ -152083,7 +155329,7 @@ var ts;
}
function convertParameterToNamedTupleMember(p) {
ts.Debug.assert(ts.isIdentifier(p.name)); // This is checked during refactoring applicability checking
- var result = ts.setTextRange(ts.factory.createNamedTupleMember(p.dotDotDotToken, p.name, p.questionToken, p.type || ts.factory.createKeywordTypeNode(129 /* AnyKeyword */)), p);
+ var result = ts.setTextRange(ts.factory.createNamedTupleMember(p.dotDotDotToken, p.name, p.questionToken, p.type || ts.factory.createKeywordTypeNode(130 /* AnyKeyword */)), p);
var parameterDocComment = p.symbol && p.symbol.getDocumentationComment(checker);
if (parameterDocComment) {
var newComment = ts.displayPartsToString(parameterDocComment);
@@ -152103,12 +155349,12 @@ var ts;
}
function isConvertableSignatureDeclaration(d) {
switch (d.kind) {
- case 166 /* MethodSignature */:
- case 167 /* MethodDeclaration */:
- case 172 /* CallSignature */:
- case 169 /* Constructor */:
- case 173 /* ConstructSignature */:
- case 254 /* FunctionDeclaration */:
+ case 167 /* MethodSignature */:
+ case 168 /* MethodDeclaration */:
+ case 173 /* CallSignature */:
+ case 170 /* Constructor */:
+ case 174 /* ConstructSignature */:
+ case 255 /* FunctionDeclaration */:
return true;
}
return false;
@@ -152497,20 +155743,20 @@ var ts;
function checkForStaticContext(nodeToCheck, containingClass) {
var current = nodeToCheck;
while (current !== containingClass) {
- if (current.kind === 165 /* PropertyDeclaration */) {
+ if (current.kind === 166 /* PropertyDeclaration */) {
if (ts.isStatic(current)) {
rangeFacts |= RangeFacts.InStaticRegion;
}
break;
}
- else if (current.kind === 162 /* Parameter */) {
+ else if (current.kind === 163 /* Parameter */) {
var ctorOrMethod = ts.getContainingFunction(current);
- if (ctorOrMethod.kind === 169 /* Constructor */) {
+ if (ctorOrMethod.kind === 170 /* Constructor */) {
rangeFacts |= RangeFacts.InStaticRegion;
}
break;
}
- else if (current.kind === 167 /* MethodDeclaration */) {
+ else if (current.kind === 168 /* MethodDeclaration */) {
if (ts.isStatic(current)) {
rangeFacts |= RangeFacts.InStaticRegion;
}
@@ -152553,7 +155799,7 @@ var ts;
return true;
}
if (ts.isDeclaration(node)) {
- var declaringNode = (node.kind === 252 /* VariableDeclaration */) ? node.parent.parent : node;
+ var declaringNode = (node.kind === 253 /* VariableDeclaration */) ? node.parent.parent : node;
if (ts.hasSyntacticModifier(declaringNode, 1 /* Export */)) {
// TODO: GH#18217 Silly to use `errors ||` since it's definitely not defined (see top of `visit`)
// Also, if we're only pushing one error, just use `let error: Diagnostic | undefined`!
@@ -152565,16 +155811,16 @@ var ts;
}
// Some things can't be extracted in certain situations
switch (node.kind) {
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
(errors || (errors = [])).push(ts.createDiagnosticForNode(node, Messages.cannotExtractImport));
return true;
- case 269 /* ExportAssignment */:
+ case 270 /* ExportAssignment */:
(errors || (errors = [])).push(ts.createDiagnosticForNode(node, Messages.cannotExtractExportedEntity));
return true;
case 106 /* SuperKeyword */:
// For a super *constructor call*, we have to be extracting the entire class,
// but a super *method call* simply implies a 'this' reference
- if (node.parent.kind === 206 /* CallExpression */) {
+ if (node.parent.kind === 207 /* CallExpression */) {
// Super constructor call
var containingClass_1 = ts.getContainingClass(node); // TODO:GH#18217
if (containingClass_1.pos < span.start || containingClass_1.end >= (span.start + span.length)) {
@@ -152586,7 +155832,7 @@ var ts;
rangeFacts |= RangeFacts.UsesThis;
}
break;
- case 212 /* ArrowFunction */:
+ case 213 /* ArrowFunction */:
// check if arrow function uses this
ts.forEachChild(node, function check(n) {
if (ts.isThis(n)) {
@@ -152600,39 +155846,39 @@ var ts;
}
});
// falls through
- case 255 /* ClassDeclaration */:
- case 254 /* FunctionDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 255 /* FunctionDeclaration */:
if (ts.isSourceFile(node.parent) && node.parent.externalModuleIndicator === undefined) {
// You cannot extract global declarations
(errors || (errors = [])).push(ts.createDiagnosticForNode(node, Messages.functionWillNotBeVisibleInTheNewScope));
}
// falls through
- case 224 /* ClassExpression */:
- case 211 /* FunctionExpression */:
- case 167 /* MethodDeclaration */:
- case 169 /* Constructor */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
+ case 225 /* ClassExpression */:
+ case 212 /* FunctionExpression */:
+ case 168 /* MethodDeclaration */:
+ case 170 /* Constructor */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
// do not dive into functions or classes
return false;
}
var savedPermittedJumps = permittedJumps;
switch (node.kind) {
- case 237 /* IfStatement */:
+ case 238 /* IfStatement */:
permittedJumps = 0 /* None */;
break;
- case 250 /* TryStatement */:
+ case 251 /* TryStatement */:
// forbid all jumps inside try blocks
permittedJumps = 0 /* None */;
break;
- case 233 /* Block */:
- if (node.parent && node.parent.kind === 250 /* TryStatement */ && node.parent.finallyBlock === node) {
+ case 234 /* Block */:
+ if (node.parent && node.parent.kind === 251 /* TryStatement */ && node.parent.finallyBlock === node) {
// allow unconditional returns from finally blocks
permittedJumps = 4 /* Return */;
}
break;
- case 288 /* DefaultClause */:
- case 287 /* CaseClause */:
+ case 289 /* DefaultClause */:
+ case 288 /* CaseClause */:
// allow unlabeled break inside case clauses
permittedJumps |= 1 /* Break */;
break;
@@ -152644,19 +155890,19 @@ var ts;
break;
}
switch (node.kind) {
- case 190 /* ThisType */:
+ case 191 /* ThisType */:
case 108 /* ThisKeyword */:
rangeFacts |= RangeFacts.UsesThis;
break;
- case 248 /* LabeledStatement */: {
+ case 249 /* LabeledStatement */: {
var label = node.label;
(seenLabels || (seenLabels = [])).push(label.escapedText);
ts.forEachChild(node, visit);
seenLabels.pop();
break;
}
- case 244 /* BreakStatement */:
- case 243 /* ContinueStatement */: {
+ case 245 /* BreakStatement */:
+ case 244 /* ContinueStatement */: {
var label = node.label;
if (label) {
if (!ts.contains(seenLabels, label.escapedText)) {
@@ -152665,20 +155911,20 @@ var ts;
}
}
else {
- if (!(permittedJumps & (node.kind === 244 /* BreakStatement */ ? 1 /* Break */ : 2 /* Continue */))) {
+ if (!(permittedJumps & (node.kind === 245 /* BreakStatement */ ? 1 /* Break */ : 2 /* Continue */))) {
// attempt to break or continue in a forbidden context
(errors || (errors = [])).push(ts.createDiagnosticForNode(node, Messages.cannotExtractRangeContainingConditionalBreakOrContinueStatements));
}
}
break;
}
- case 216 /* AwaitExpression */:
+ case 217 /* AwaitExpression */:
rangeFacts |= RangeFacts.IsAsyncFunction;
break;
- case 222 /* YieldExpression */:
+ case 223 /* YieldExpression */:
rangeFacts |= RangeFacts.IsGenerator;
break;
- case 245 /* ReturnStatement */:
+ case 246 /* ReturnStatement */:
if (permittedJumps & 4 /* Return */) {
rangeFacts |= RangeFacts.HasReturn;
}
@@ -152744,7 +155990,7 @@ var ts;
while (true) {
current = current.parent;
// A function parameter's initializer is actually in the outer scope, not the function declaration
- if (current.kind === 162 /* Parameter */) {
+ if (current.kind === 163 /* Parameter */) {
// Skip all the way to the outer scope of the function that declared this parameter
current = ts.findAncestor(current, function (parent) { return ts.isFunctionLikeDeclaration(parent); }).parent;
}
@@ -152755,7 +156001,7 @@ var ts;
// * Module/namespace or source file
if (isScope(current)) {
scopes.push(current);
- if (current.kind === 300 /* SourceFile */) {
+ if (current.kind === 303 /* SourceFile */) {
return scopes;
}
}
@@ -152845,32 +156091,32 @@ var ts;
}
function getDescriptionForFunctionLikeDeclaration(scope) {
switch (scope.kind) {
- case 169 /* Constructor */:
+ case 170 /* Constructor */:
return "constructor";
- case 211 /* FunctionExpression */:
- case 254 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 255 /* FunctionDeclaration */:
return scope.name
? "function '" + scope.name.text + "'"
: ts.ANONYMOUS;
- case 212 /* ArrowFunction */:
+ case 213 /* ArrowFunction */:
return "arrow function";
- case 167 /* MethodDeclaration */:
+ case 168 /* MethodDeclaration */:
return "method '" + scope.name.getText() + "'";
- case 170 /* GetAccessor */:
+ case 171 /* GetAccessor */:
return "'get " + scope.name.getText() + "'";
- case 171 /* SetAccessor */:
+ case 172 /* SetAccessor */:
return "'set " + scope.name.getText() + "'";
default:
throw ts.Debug.assertNever(scope, "Unexpected scope kind " + scope.kind);
}
}
function getDescriptionForClassLikeDeclaration(scope) {
- return scope.kind === 255 /* ClassDeclaration */
+ return scope.kind === 256 /* ClassDeclaration */
? scope.name ? "class '" + scope.name.text + "'" : "anonymous class declaration"
: scope.name ? "class expression '" + scope.name.text + "'" : "anonymous class expression";
}
function getDescriptionForModuleLikeDeclaration(scope) {
- return scope.kind === 260 /* ModuleBlock */
+ return scope.kind === 261 /* ModuleBlock */
? "namespace '" + scope.parent.name.getText() + "'"
: scope.externalModuleIndicator ? 0 /* Module */ : 1 /* Global */;
}
@@ -152943,7 +156189,7 @@ var ts;
modifiers.push(ts.factory.createModifier(124 /* StaticKeyword */));
}
if (range.facts & RangeFacts.IsAsyncFunction) {
- modifiers.push(ts.factory.createModifier(130 /* AsyncKeyword */));
+ modifiers.push(ts.factory.createModifier(131 /* AsyncKeyword */));
}
newFunction = ts.factory.createMethodDeclaration(
/*decorators*/ undefined, modifiers.length ? modifiers : undefined, range.facts & RangeFacts.IsGenerator ? ts.factory.createToken(41 /* AsteriskToken */) : undefined, functionName,
@@ -152951,7 +156197,7 @@ var ts;
}
else {
newFunction = ts.factory.createFunctionDeclaration(
- /*decorators*/ undefined, range.facts & RangeFacts.IsAsyncFunction ? [ts.factory.createToken(130 /* AsyncKeyword */)] : undefined, range.facts & RangeFacts.IsGenerator ? ts.factory.createToken(41 /* AsteriskToken */) : undefined, functionName, typeParameters, parameters, returnType, body);
+ /*decorators*/ undefined, range.facts & RangeFacts.IsAsyncFunction ? [ts.factory.createToken(131 /* AsyncKeyword */)] : undefined, range.facts & RangeFacts.IsGenerator ? ts.factory.createToken(41 /* AsteriskToken */) : undefined, functionName, typeParameters, parameters, returnType, body);
}
var changeTracker = ts.textChanges.ChangeTracker.fromContext(context);
var minInsertionPos = (isReadonlyArray(range.range) ? ts.last(range.range) : range.range).end;
@@ -153096,9 +156342,9 @@ var ts;
while (ts.isParenthesizedTypeNode(withoutParens)) {
withoutParens = withoutParens.type;
}
- return ts.isUnionTypeNode(withoutParens) && ts.find(withoutParens.types, function (t) { return t.kind === 151 /* UndefinedKeyword */; })
+ return ts.isUnionTypeNode(withoutParens) && ts.find(withoutParens.types, function (t) { return t.kind === 152 /* UndefinedKeyword */; })
? clone
- : ts.factory.createUnionTypeNode([clone, ts.factory.createKeywordTypeNode(151 /* UndefinedKeyword */)]);
+ : ts.factory.createUnionTypeNode([clone, ts.factory.createKeywordTypeNode(152 /* UndefinedKeyword */)]);
}
}
/**
@@ -153116,7 +156362,7 @@ var ts;
var variableType = isJS || !checker.isContextSensitive(node)
? undefined
: checker.typeToTypeNode(checker.getContextualType(node), scope, 1 /* NoTruncation */); // TODO: GH#18217
- var initializer = transformConstantInitializer(node, substitutions);
+ var initializer = transformConstantInitializer(ts.skipParentheses(node), substitutions);
(_b = transformFunctionInitializerAndType(variableType, initializer), variableType = _b.variableType, initializer = _b.initializer);
ts.suppressLeadingAndTrailingTrivia(initializer);
var changeTracker = ts.textChanges.ChangeTracker.fromContext(context);
@@ -153127,7 +156373,7 @@ var ts;
if (rangeFacts & RangeFacts.InStaticRegion) {
modifiers.push(ts.factory.createModifier(124 /* StaticKeyword */));
}
- modifiers.push(ts.factory.createModifier(143 /* ReadonlyKeyword */));
+ modifiers.push(ts.factory.createModifier(144 /* ReadonlyKeyword */));
var newVariable = ts.factory.createPropertyDeclaration(
/*decorators*/ undefined, modifiers, localNameText,
/*questionToken*/ undefined, variableType, initializer);
@@ -153159,7 +156405,7 @@ var ts;
var localReference = ts.factory.createIdentifier(localNameText);
changeTracker.replaceNode(context.file, node, localReference);
}
- else if (node.parent.kind === 236 /* ExpressionStatement */ && scope === ts.findAncestor(node, isScope)) {
+ else if (node.parent.kind === 237 /* ExpressionStatement */ && scope === ts.findAncestor(node, isScope)) {
// If the parent is an expression statement and the target scope is the immediately enclosing one,
// replace the statement with the declaration.
var newVariableStatement = ts.factory.createVariableStatement(
@@ -153178,7 +156424,7 @@ var ts;
changeTracker.insertNodeBefore(context.file, nodeToInsertBefore, newVariableStatement, /*blankLineBetween*/ false);
}
// Consume
- if (node.parent.kind === 236 /* ExpressionStatement */) {
+ if (node.parent.kind === 237 /* ExpressionStatement */) {
// If the parent is an expression statement, delete it.
changeTracker.delete(context.file, node.parent);
}
@@ -153306,7 +156552,7 @@ var ts;
}
var returnValueProperty;
var ignoreReturns = false;
- var statements = ts.factory.createNodeArray(ts.isBlock(body) ? body.statements.slice(0) : [ts.isStatement(body) ? body : ts.factory.createReturnStatement(body)]);
+ var statements = ts.factory.createNodeArray(ts.isBlock(body) ? body.statements.slice(0) : [ts.isStatement(body) ? body : ts.factory.createReturnStatement(ts.skipParentheses(body))]);
// rewrite body if either there are writes that should be propagated back via return statements or there are substitutions
if (hasWritesOrVariableDeclarations || substitutions.size) {
var rewrittenStatements = ts.visitNodes(statements, visitor).slice();
@@ -153566,7 +156812,7 @@ var ts;
: ts.getEnclosingBlockScopeContainer(scopes[0]);
ts.forEachChild(containingLexicalScopeOfExtraction, checkForUsedDeclarations);
}
- var _loop_17 = function (i) {
+ var _loop_18 = function (i) {
var scopeUsages = usagesPerScope[i];
// Special case: in the innermost scope, all usages are available.
// (The computed value reflects the value at the top-level of the scope, but the
@@ -153606,7 +156852,7 @@ var ts;
}
};
for (var i = 0; i < scopes.length; i++) {
- _loop_17(i);
+ _loop_18(i);
}
return { target: target, usagesPerScope: usagesPerScope, functionErrorsPerScope: functionErrorsPerScope, constantErrorsPerScope: constantErrorsPerScope, exposedVariableDeclarations: exposedVariableDeclarations };
function isInGenericContext(node) {
@@ -153822,30 +157068,30 @@ var ts;
function isExtractableExpression(node) {
var parent = node.parent;
switch (parent.kind) {
- case 294 /* EnumMember */:
+ case 297 /* EnumMember */:
return false;
}
switch (node.kind) {
case 10 /* StringLiteral */:
- return parent.kind !== 264 /* ImportDeclaration */ &&
- parent.kind !== 268 /* ImportSpecifier */;
- case 223 /* SpreadElement */:
- case 199 /* ObjectBindingPattern */:
- case 201 /* BindingElement */:
+ return parent.kind !== 265 /* ImportDeclaration */ &&
+ parent.kind !== 269 /* ImportSpecifier */;
+ case 224 /* SpreadElement */:
+ case 200 /* ObjectBindingPattern */:
+ case 202 /* BindingElement */:
return false;
case 79 /* Identifier */:
- return parent.kind !== 201 /* BindingElement */ &&
- parent.kind !== 268 /* ImportSpecifier */ &&
- parent.kind !== 273 /* ExportSpecifier */;
+ return parent.kind !== 202 /* BindingElement */ &&
+ parent.kind !== 269 /* ImportSpecifier */ &&
+ parent.kind !== 274 /* ExportSpecifier */;
}
return true;
}
function isBlockLike(node) {
switch (node.kind) {
- case 233 /* Block */:
- case 300 /* SourceFile */:
- case 260 /* ModuleBlock */:
- case 287 /* CaseClause */:
+ case 234 /* Block */:
+ case 303 /* SourceFile */:
+ case 261 /* ModuleBlock */:
+ case 288 /* CaseClause */:
return true;
default:
return false;
@@ -154230,11 +157476,11 @@ var ts;
}
function isPureImport(node) {
switch (node.kind) {
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
return true;
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return !ts.hasSyntacticModifier(node, 1 /* Export */);
- case 235 /* VariableStatement */:
+ case 236 /* VariableStatement */:
return node.declarationList.declarations.every(function (d) { return !!d.initializer && ts.isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ true); });
default:
return false;
@@ -154261,17 +157507,17 @@ var ts;
deleteMovedStatements(oldFile, toMove.ranges, changes);
return __spreadArray(__spreadArray([], prologueDirectives, true), toMove.all, true);
}
- var useEs6ModuleSyntax = !!oldFile.externalModuleIndicator;
+ var useEsModuleSyntax = !!oldFile.externalModuleIndicator;
var quotePreference = ts.getQuotePreference(oldFile, preferences);
- var importsFromNewFile = createOldFileImportsFromNewFile(usage.oldFileImportsFromNewFile, newModuleName, useEs6ModuleSyntax, quotePreference);
+ var importsFromNewFile = createOldFileImportsFromNewFile(usage.oldFileImportsFromNewFile, newModuleName, useEsModuleSyntax, quotePreference);
if (importsFromNewFile) {
ts.insertImports(changes, oldFile, importsFromNewFile, /*blankLineBetween*/ true);
}
deleteUnusedOldImports(oldFile, toMove.all, changes, usage.unusedImportsFromOldFile, checker);
deleteMovedStatements(oldFile, toMove.ranges, changes);
updateImportsInOtherFiles(changes, program, oldFile, usage.movedSymbols, newModuleName);
- var imports = getNewFileImportsAndAddExportInOldFile(oldFile, usage.oldImportsNeededByNewFile, usage.newFileImportsFromOldFile, changes, checker, useEs6ModuleSyntax, quotePreference);
- var body = addExports(oldFile, toMove.all, usage.oldFileImportsFromNewFile, useEs6ModuleSyntax);
+ var imports = getNewFileImportsAndAddExportInOldFile(oldFile, usage.oldImportsNeededByNewFile, usage.newFileImportsFromOldFile, changes, checker, useEsModuleSyntax, quotePreference);
+ var body = addExports(oldFile, toMove.all, usage.oldFileImportsFromNewFile, useEsModuleSyntax);
if (imports.length && body.length) {
return __spreadArray(__spreadArray(__spreadArray(__spreadArray([], prologueDirectives, true), imports, true), [
4 /* NewLineTrivia */
@@ -154295,10 +157541,10 @@ var ts;
}
function updateImportsInOtherFiles(changes, program, oldFile, movedSymbols, newModuleName) {
var checker = program.getTypeChecker();
- var _loop_18 = function (sourceFile) {
+ var _loop_19 = function (sourceFile) {
if (sourceFile === oldFile)
return "continue";
- var _loop_19 = function (statement) {
+ var _loop_20 = function (statement) {
forEachImportInStatement(statement, function (importNode) {
if (checker.getSymbolAtLocation(moduleSpecifierFromImport(importNode)) !== oldFile.symbol)
return;
@@ -154320,22 +157566,22 @@ var ts;
};
for (var _b = 0, _c = sourceFile.statements; _b < _c.length; _b++) {
var statement = _c[_b];
- _loop_19(statement);
+ _loop_20(statement);
}
};
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var sourceFile = _a[_i];
- _loop_18(sourceFile);
+ _loop_19(sourceFile);
}
}
function getNamespaceLikeImport(node) {
switch (node.kind) {
- case 264 /* ImportDeclaration */:
- return node.importClause && node.importClause.namedBindings && node.importClause.namedBindings.kind === 266 /* NamespaceImport */ ?
+ case 265 /* ImportDeclaration */:
+ return node.importClause && node.importClause.namedBindings && node.importClause.namedBindings.kind === 267 /* NamespaceImport */ ?
node.importClause.namedBindings.name : undefined;
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return node.name;
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
return ts.tryCast(node.name, ts.isIdentifier);
default:
return ts.Debug.assertNever(node, "Unexpected node kind " + node.kind);
@@ -154366,20 +157612,21 @@ var ts;
var newNamespaceId = ts.factory.createIdentifier(newNamespaceName);
var newModuleString = ts.factory.createStringLiteral(newModuleSpecifier);
switch (node.kind) {
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
return ts.factory.createImportDeclaration(
- /*decorators*/ undefined, /*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamespaceImport(newNamespaceId)), newModuleString);
- case 263 /* ImportEqualsDeclaration */:
+ /*decorators*/ undefined, /*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamespaceImport(newNamespaceId)), newModuleString,
+ /*assertClause*/ undefined);
+ case 264 /* ImportEqualsDeclaration */:
return ts.factory.createImportEqualsDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, /*isTypeOnly*/ false, newNamespaceId, ts.factory.createExternalModuleReference(newModuleString));
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
return ts.factory.createVariableDeclaration(newNamespaceId, /*exclamationToken*/ undefined, /*type*/ undefined, createRequireCall(newModuleString));
default:
return ts.Debug.assertNever(node, "Unexpected node kind " + node.kind);
}
}
function moduleSpecifierFromImport(i) {
- return (i.kind === 264 /* ImportDeclaration */ ? i.moduleSpecifier
- : i.kind === 263 /* ImportEqualsDeclaration */ ? i.moduleReference.expression
+ return (i.kind === 265 /* ImportDeclaration */ ? i.moduleSpecifier
+ : i.kind === 264 /* ImportEqualsDeclaration */ ? i.moduleReference.expression
: i.initializer.arguments[0]);
}
function forEachImportInStatement(statement, cb) {
@@ -154417,7 +157664,7 @@ var ts;
function makeImportOrRequire(defaultImport, imports, path, useEs6Imports, quotePreference) {
path = ts.ensurePathIsNonModuleName(path);
if (useEs6Imports) {
- var specifiers = imports.map(function (i) { return ts.factory.createImportSpecifier(/*propertyName*/ undefined, ts.factory.createIdentifier(i)); });
+ var specifiers = imports.map(function (i) { return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, ts.factory.createIdentifier(i)); });
return ts.makeImportIfNecessary(defaultImport, specifiers, path, quotePreference);
}
else {
@@ -154449,15 +157696,15 @@ var ts;
}
function deleteUnusedImports(sourceFile, importDecl, changes, isUnused) {
switch (importDecl.kind) {
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
deleteUnusedImportsInDeclaration(sourceFile, importDecl, changes, isUnused);
break;
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
if (isUnused(importDecl.name)) {
changes.delete(sourceFile, importDecl);
}
break;
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
deleteUnusedImportsInVariableDeclaration(sourceFile, importDecl, changes, isUnused);
break;
default:
@@ -154470,7 +157717,7 @@ var ts;
var _a = importDecl.importClause, name = _a.name, namedBindings = _a.namedBindings;
var defaultUnused = !name || isUnused(name);
var namedBindingsUnused = !namedBindings ||
- (namedBindings.kind === 266 /* NamespaceImport */ ? isUnused(namedBindings.name) : namedBindings.elements.length !== 0 && namedBindings.elements.every(function (e) { return isUnused(e.name); }));
+ (namedBindings.kind === 267 /* NamespaceImport */ ? isUnused(namedBindings.name) : namedBindings.elements.length !== 0 && namedBindings.elements.every(function (e) { return isUnused(e.name); }));
if (defaultUnused && namedBindingsUnused) {
changes.delete(sourceFile, importDecl);
}
@@ -154482,7 +157729,7 @@ var ts;
if (namedBindingsUnused) {
changes.replaceNode(sourceFile, importDecl.importClause, ts.factory.updateImportClause(importDecl.importClause, importDecl.importClause.isTypeOnly, name, /*namedBindings*/ undefined));
}
- else if (namedBindings.kind === 267 /* NamedImports */) {
+ else if (namedBindings.kind === 268 /* NamedImports */) {
for (var _i = 0, _b = namedBindings.elements; _i < _b.length; _i++) {
var element = _b[_i];
if (isUnused(element.name))
@@ -154500,9 +157747,9 @@ var ts;
changes.delete(sourceFile, name);
}
break;
- case 200 /* ArrayBindingPattern */:
+ case 201 /* ArrayBindingPattern */:
break;
- case 199 /* ObjectBindingPattern */:
+ case 200 /* ObjectBindingPattern */:
if (name.elements.every(function (e) { return ts.isIdentifier(e.name) && isUnused(e.name); })) {
changes.delete(sourceFile, ts.isVariableDeclarationList(varDecl.parent) && varDecl.parent.declarations.length === 1 ? varDecl.parent.parent : varDecl);
}
@@ -154517,7 +157764,7 @@ var ts;
break;
}
}
- function getNewFileImportsAndAddExportInOldFile(oldFile, importsToCopy, newFileImportsFromOldFile, changes, checker, useEs6ModuleSyntax, quotePreference) {
+ function getNewFileImportsAndAddExportInOldFile(oldFile, importsToCopy, newFileImportsFromOldFile, changes, checker, useEsModuleSyntax, quotePreference) {
var copiedOldImports = [];
for (var _i = 0, _a = oldFile.statements; _i < _a.length; _i++) {
var oldStatement = _a[_i];
@@ -154542,7 +157789,7 @@ var ts;
continue;
var top = getTopLevelDeclarationStatement(decl);
if (markSeenTop(top)) {
- addExportToChanges(oldFile, top, name, changes, useEs6ModuleSyntax);
+ addExportToChanges(oldFile, top, name, changes, useEsModuleSyntax);
}
if (ts.hasSyntacticModifier(decl, 512 /* Default */)) {
oldFileDefault = name;
@@ -154552,7 +157799,7 @@ var ts;
}
}
});
- ts.append(copiedOldImports, makeImportOrRequire(oldFileDefault, oldFileNamedImports, ts.removeFileExtension(ts.getBaseFileName(oldFile.fileName)), useEs6ModuleSyntax, quotePreference));
+ ts.append(copiedOldImports, makeImportOrRequire(oldFileDefault, oldFileNamedImports, ts.removeFileExtension(ts.getBaseFileName(oldFile.fileName)), useEsModuleSyntax, quotePreference));
return copiedOldImports;
}
function makeUniqueModuleName(moduleName, extension, inDirectory, host) {
@@ -154632,14 +157879,14 @@ var ts;
// Below should all be utilities
function isInImport(decl) {
switch (decl.kind) {
- case 263 /* ImportEqualsDeclaration */:
- case 268 /* ImportSpecifier */:
- case 265 /* ImportClause */:
- case 266 /* NamespaceImport */:
+ case 264 /* ImportEqualsDeclaration */:
+ case 269 /* ImportSpecifier */:
+ case 266 /* ImportClause */:
+ case 267 /* NamespaceImport */:
return true;
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
return isVariableDeclarationInImport(decl);
- case 201 /* BindingElement */:
+ case 202 /* BindingElement */:
return ts.isVariableDeclaration(decl.parent.parent) && isVariableDeclarationInImport(decl.parent.parent);
default:
return false;
@@ -154651,19 +157898,19 @@ var ts;
}
function filterImport(i, moduleSpecifier, keep) {
switch (i.kind) {
- case 264 /* ImportDeclaration */: {
+ case 265 /* ImportDeclaration */: {
var clause = i.importClause;
if (!clause)
return undefined;
var defaultImport = clause.name && keep(clause.name) ? clause.name : undefined;
var namedBindings = clause.namedBindings && filterNamedBindings(clause.namedBindings, keep);
return defaultImport || namedBindings
- ? ts.factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, defaultImport, namedBindings), moduleSpecifier)
+ ? ts.factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, defaultImport, namedBindings), moduleSpecifier, /*assertClause*/ undefined)
: undefined;
}
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return keep(i.name) ? i : undefined;
- case 252 /* VariableDeclaration */: {
+ case 253 /* VariableDeclaration */: {
var name = filterBindingName(i.name, keep);
return name ? makeVariableStatement(name, i.type, createRequireCall(moduleSpecifier), i.parent.flags) : undefined;
}
@@ -154672,7 +157919,7 @@ var ts;
}
}
function filterNamedBindings(namedBindings, keep) {
- if (namedBindings.kind === 266 /* NamespaceImport */) {
+ if (namedBindings.kind === 267 /* NamespaceImport */) {
return keep(namedBindings.name) ? namedBindings : undefined;
}
else {
@@ -154684,9 +157931,9 @@ var ts;
switch (name.kind) {
case 79 /* Identifier */:
return keep(name) ? name : undefined;
- case 200 /* ArrayBindingPattern */:
+ case 201 /* ArrayBindingPattern */:
return name;
- case 199 /* ObjectBindingPattern */: {
+ case 200 /* ObjectBindingPattern */: {
// We can't handle nested destructurings or property names well here, so just copy them all.
var newElements = name.elements.filter(function (prop) { return prop.propertyName || !ts.isIdentifier(prop.name) || keep(prop.name); });
return newElements.length ? ts.factory.createObjectBindingPattern(newElements) : undefined;
@@ -154743,13 +157990,13 @@ var ts;
}
function isNonVariableTopLevelDeclaration(node) {
switch (node.kind) {
- case 254 /* FunctionDeclaration */:
- case 255 /* ClassDeclaration */:
- case 259 /* ModuleDeclaration */:
- case 258 /* EnumDeclaration */:
- case 257 /* TypeAliasDeclaration */:
- case 256 /* InterfaceDeclaration */:
- case 263 /* ImportEqualsDeclaration */:
+ case 255 /* FunctionDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 260 /* ModuleDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
+ case 257 /* InterfaceDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return true;
default:
return false;
@@ -154757,17 +158004,17 @@ var ts;
}
function forEachTopLevelDeclaration(statement, cb) {
switch (statement.kind) {
- case 254 /* FunctionDeclaration */:
- case 255 /* ClassDeclaration */:
- case 259 /* ModuleDeclaration */:
- case 258 /* EnumDeclaration */:
- case 257 /* TypeAliasDeclaration */:
- case 256 /* InterfaceDeclaration */:
- case 263 /* ImportEqualsDeclaration */:
+ case 255 /* FunctionDeclaration */:
+ case 256 /* ClassDeclaration */:
+ case 260 /* ModuleDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
+ case 257 /* InterfaceDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return cb(statement);
- case 235 /* VariableStatement */:
+ case 236 /* VariableStatement */:
return ts.firstDefined(statement.declarationList.declarations, function (decl) { return forEachTopLevelDeclarationInBindingName(decl.name, cb); });
- case 236 /* ExpressionStatement */: {
+ case 237 /* ExpressionStatement */: {
var expression = statement.expression;
return ts.isBinaryExpression(expression) && ts.getAssignmentDeclarationKind(expression) === 1 /* ExportsProperty */
? cb(statement)
@@ -154779,8 +158026,8 @@ var ts;
switch (name.kind) {
case 79 /* Identifier */:
return cb(ts.cast(name.parent, function (x) { return ts.isVariableDeclaration(x) || ts.isBindingElement(x); }));
- case 200 /* ArrayBindingPattern */:
- case 199 /* ObjectBindingPattern */:
+ case 201 /* ArrayBindingPattern */:
+ case 200 /* ObjectBindingPattern */:
return ts.firstDefined(name.elements, function (em) { return ts.isOmittedExpression(em) ? undefined : forEachTopLevelDeclarationInBindingName(em.name, cb); });
default:
return ts.Debug.assertNever(name, "Unexpected name kind " + name.kind);
@@ -154791,9 +158038,9 @@ var ts;
}
function getTopLevelDeclarationStatement(d) {
switch (d.kind) {
- case 252 /* VariableDeclaration */:
+ case 253 /* VariableDeclaration */:
return d.parent.parent;
- case 201 /* BindingElement */:
+ case 202 /* BindingElement */:
return getTopLevelDeclarationStatement(ts.cast(d.parent.parent, function (p) { return ts.isVariableDeclaration(p) || ts.isBindingElement(p); }));
default:
return d;
@@ -154825,23 +158072,23 @@ var ts;
function addEs6Export(d) {
var modifiers = ts.concatenate([ts.factory.createModifier(93 /* ExportKeyword */)], d.modifiers);
switch (d.kind) {
- case 254 /* FunctionDeclaration */:
+ case 255 /* FunctionDeclaration */:
return ts.factory.updateFunctionDeclaration(d, d.decorators, modifiers, d.asteriskToken, d.name, d.typeParameters, d.parameters, d.type, d.body);
- case 255 /* ClassDeclaration */:
+ case 256 /* ClassDeclaration */:
return ts.factory.updateClassDeclaration(d, d.decorators, modifiers, d.name, d.typeParameters, d.heritageClauses, d.members);
- case 235 /* VariableStatement */:
+ case 236 /* VariableStatement */:
return ts.factory.updateVariableStatement(d, modifiers, d.declarationList);
- case 259 /* ModuleDeclaration */:
+ case 260 /* ModuleDeclaration */:
return ts.factory.updateModuleDeclaration(d, d.decorators, modifiers, d.name, d.body);
- case 258 /* EnumDeclaration */:
+ case 259 /* EnumDeclaration */:
return ts.factory.updateEnumDeclaration(d, d.decorators, modifiers, d.name, d.members);
- case 257 /* TypeAliasDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
return ts.factory.updateTypeAliasDeclaration(d, d.decorators, modifiers, d.name, d.typeParameters, d.type);
- case 256 /* InterfaceDeclaration */:
+ case 257 /* InterfaceDeclaration */:
return ts.factory.updateInterfaceDeclaration(d, d.decorators, modifiers, d.name, d.typeParameters, d.heritageClauses, d.members);
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return ts.factory.updateImportEqualsDeclaration(d, d.decorators, modifiers, d.isTypeOnly, d.name, d.moduleReference);
- case 236 /* ExpressionStatement */:
+ case 237 /* ExpressionStatement */:
return ts.Debug.fail(); // Shouldn't try to add 'export' keyword to `exports.x = ...`
default:
return ts.Debug.assertNever(d, "Unexpected declaration kind " + d.kind);
@@ -154852,18 +158099,18 @@ var ts;
}
function getNamesToExportInCommonJS(decl) {
switch (decl.kind) {
- case 254 /* FunctionDeclaration */:
- case 255 /* ClassDeclaration */:
+ case 255 /* FunctionDeclaration */:
+ case 256 /* ClassDeclaration */:
return [decl.name.text]; // TODO: GH#18217
- case 235 /* VariableStatement */:
+ case 236 /* VariableStatement */:
return ts.mapDefined(decl.declarationList.declarations, function (d) { return ts.isIdentifier(d.name) ? d.name.text : undefined; });
- case 259 /* ModuleDeclaration */:
- case 258 /* EnumDeclaration */:
- case 257 /* TypeAliasDeclaration */:
- case 256 /* InterfaceDeclaration */:
- case 263 /* ImportEqualsDeclaration */:
+ case 260 /* ModuleDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
+ case 257 /* InterfaceDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
return ts.emptyArray;
- case 236 /* ExpressionStatement */:
+ case 237 /* ExpressionStatement */:
return ts.Debug.fail("Can't export an ExpressionStatement"); // Shouldn't try to add 'export' keyword to `exports.x = ...`
default:
return ts.Debug.assertNever(decl, "Unexpected decl kind " + decl.kind);
@@ -154934,13 +158181,11 @@ var ts;
if (actionName === addBracesAction.name) {
var returnStatement_1 = ts.factory.createReturnStatement(expression);
body = ts.factory.createBlock([returnStatement_1], /* multiLine */ true);
- ts.suppressLeadingAndTrailingTrivia(body);
ts.copyLeadingComments(expression, returnStatement_1, file, 3 /* MultiLineCommentTrivia */, /* hasTrailingNewLine */ true);
}
else if (actionName === removeBracesAction.name && returnStatement) {
var actualExpression = expression || ts.factory.createVoidZero();
body = ts.needsParentheses(actualExpression) ? ts.factory.createParenthesizedExpression(actualExpression) : actualExpression;
- ts.suppressLeadingAndTrailingTrivia(body);
ts.copyTrailingAsLeadingComments(returnStatement, body, file, 3 /* MultiLineCommentTrivia */, /* hasTrailingNewLine */ false);
ts.copyLeadingComments(returnStatement, body, file, 3 /* MultiLineCommentTrivia */, /* hasTrailingNewLine */ false);
ts.copyTrailingComments(returnStatement, body, file, 3 /* MultiLineCommentTrivia */, /* hasTrailingNewLine */ false);
@@ -155206,15 +158451,15 @@ var ts;
var parent = functionReference.parent;
switch (parent.kind) {
// foo(...) or super(...) or new Foo(...)
- case 206 /* CallExpression */:
- case 207 /* NewExpression */:
+ case 207 /* CallExpression */:
+ case 208 /* NewExpression */:
var callOrNewExpression = ts.tryCast(parent, ts.isCallOrNewExpression);
if (callOrNewExpression && callOrNewExpression.expression === functionReference) {
return callOrNewExpression;
}
break;
// x.foo(...)
- case 204 /* PropertyAccessExpression */:
+ case 205 /* PropertyAccessExpression */:
var propertyAccessExpression = ts.tryCast(parent, ts.isPropertyAccessExpression);
if (propertyAccessExpression && propertyAccessExpression.parent && propertyAccessExpression.name === functionReference) {
var callOrNewExpression_1 = ts.tryCast(propertyAccessExpression.parent, ts.isCallOrNewExpression);
@@ -155224,7 +158469,7 @@ var ts;
}
break;
// x["foo"](...)
- case 205 /* ElementAccessExpression */:
+ case 206 /* ElementAccessExpression */:
var elementAccessExpression = ts.tryCast(parent, ts.isElementAccessExpression);
if (elementAccessExpression && elementAccessExpression.parent && elementAccessExpression.argumentExpression === functionReference) {
var callOrNewExpression_2 = ts.tryCast(elementAccessExpression.parent, ts.isCallOrNewExpression);
@@ -155243,14 +158488,14 @@ var ts;
var parent = reference.parent;
switch (parent.kind) {
// `C.foo`
- case 204 /* PropertyAccessExpression */:
+ case 205 /* PropertyAccessExpression */:
var propertyAccessExpression = ts.tryCast(parent, ts.isPropertyAccessExpression);
if (propertyAccessExpression && propertyAccessExpression.expression === reference) {
return propertyAccessExpression;
}
break;
// `C["foo"]`
- case 205 /* ElementAccessExpression */:
+ case 206 /* ElementAccessExpression */:
var elementAccessExpression = ts.tryCast(parent, ts.isElementAccessExpression);
if (elementAccessExpression && elementAccessExpression.expression === reference) {
return elementAccessExpression;
@@ -155296,16 +158541,16 @@ var ts;
if (!isValidParameterNodeArray(functionDeclaration.parameters, checker))
return false;
switch (functionDeclaration.kind) {
- case 254 /* FunctionDeclaration */:
+ case 255 /* FunctionDeclaration */:
return hasNameOrDefault(functionDeclaration) && isSingleImplementation(functionDeclaration, checker);
- case 167 /* MethodDeclaration */:
+ case 168 /* MethodDeclaration */:
if (ts.isObjectLiteralExpression(functionDeclaration.parent)) {
var contextualSymbol = getSymbolForContextualType(functionDeclaration.name, checker);
// don't offer the refactor when there are multiple signatures since we won't know which ones the user wants to change
return ((_a = contextualSymbol === null || contextualSymbol === void 0 ? void 0 : contextualSymbol.declarations) === null || _a === void 0 ? void 0 : _a.length) === 1 && isSingleImplementation(functionDeclaration, checker);
}
return isSingleImplementation(functionDeclaration, checker);
- case 169 /* Constructor */:
+ case 170 /* Constructor */:
if (ts.isClassDeclaration(functionDeclaration.parent)) {
return hasNameOrDefault(functionDeclaration.parent) && isSingleImplementation(functionDeclaration, checker);
}
@@ -155313,8 +158558,8 @@ var ts;
return isValidVariableDeclaration(functionDeclaration.parent.parent)
&& isSingleImplementation(functionDeclaration, checker);
}
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
return isValidVariableDeclaration(functionDeclaration.parent);
}
return false;
@@ -155464,7 +158709,7 @@ var ts;
}
function getClassNames(constructorDeclaration) {
switch (constructorDeclaration.parent.kind) {
- case 255 /* ClassDeclaration */:
+ case 256 /* ClassDeclaration */:
var classDeclaration = constructorDeclaration.parent;
if (classDeclaration.name)
return [classDeclaration.name];
@@ -155472,7 +158717,7 @@ var ts;
// We validated this in `isValidFunctionDeclaration` through `hasNameOrDefault`
var defaultModifier = ts.Debug.checkDefined(ts.findModifier(classDeclaration, 88 /* DefaultKeyword */), "Nameless class declaration should be a default export");
return [defaultModifier];
- case 224 /* ClassExpression */:
+ case 225 /* ClassExpression */:
var classExpression = constructorDeclaration.parent;
var variableDeclaration = constructorDeclaration.parent.parent;
var className = classExpression.name;
@@ -155483,25 +158728,25 @@ var ts;
}
function getFunctionNames(functionDeclaration) {
switch (functionDeclaration.kind) {
- case 254 /* FunctionDeclaration */:
+ case 255 /* FunctionDeclaration */:
if (functionDeclaration.name)
return [functionDeclaration.name];
// If the function declaration doesn't have a name, it should have a default modifier.
// We validated this in `isValidFunctionDeclaration` through `hasNameOrDefault`
var defaultModifier = ts.Debug.checkDefined(ts.findModifier(functionDeclaration, 88 /* DefaultKeyword */), "Nameless function declaration should be a default export");
return [defaultModifier];
- case 167 /* MethodDeclaration */:
+ case 168 /* MethodDeclaration */:
return [functionDeclaration.name];
- case 169 /* Constructor */:
- var ctrKeyword = ts.Debug.checkDefined(ts.findChildOfKind(functionDeclaration, 133 /* ConstructorKeyword */, functionDeclaration.getSourceFile()), "Constructor declaration should have constructor keyword");
- if (functionDeclaration.parent.kind === 224 /* ClassExpression */) {
+ case 170 /* Constructor */:
+ var ctrKeyword = ts.Debug.checkDefined(ts.findChildOfKind(functionDeclaration, 134 /* ConstructorKeyword */, functionDeclaration.getSourceFile()), "Constructor declaration should have constructor keyword");
+ if (functionDeclaration.parent.kind === 225 /* ClassExpression */) {
var variableDeclaration = functionDeclaration.parent.parent;
return [variableDeclaration.name, ctrKeyword];
}
return [ctrKeyword];
- case 212 /* ArrowFunction */:
+ case 213 /* ArrowFunction */:
return [functionDeclaration.parent.name];
- case 211 /* FunctionExpression */:
+ case 212 /* FunctionExpression */:
if (functionDeclaration.name)
return [functionDeclaration.name, functionDeclaration.parent.name];
return [functionDeclaration.parent.name];
@@ -155592,11 +158837,11 @@ var ts;
function getParentBinaryExpression(expr) {
var container = ts.findAncestor(expr.parent, function (n) {
switch (n.kind) {
- case 204 /* PropertyAccessExpression */:
- case 205 /* ElementAccessExpression */:
+ case 205 /* PropertyAccessExpression */:
+ case 206 /* ElementAccessExpression */:
return false;
- case 221 /* TemplateExpression */:
- case 219 /* BinaryExpression */:
+ case 222 /* TemplateExpression */:
+ case 220 /* BinaryExpression */:
return !(ts.isBinaryExpression(n.parent) && isNotEqualsOperator(n.parent));
default:
return "quit";
@@ -155690,7 +158935,7 @@ var ts;
var templateSpans = [];
var templateHead = ts.factory.createTemplateHead(headText, rawHeadText);
copyCommentFromStringLiterals(headIndexes, templateHead);
- var _loop_20 = function (i) {
+ var _loop_21 = function (i) {
var currentNode = getExpressionFromParenthesesOrExpression(nodes[i]);
copyOperatorComments(i, currentNode);
var _c = concatConsecutiveString(i + 1, nodes), newIndex = _c[0], subsequentText = _c[1], rawSubsequentText = _c[2], stringIndexes = _c[3];
@@ -155719,7 +158964,7 @@ var ts;
};
var out_i_1;
for (var i = begin; i < nodes.length; i++) {
- _loop_20(i);
+ _loop_21(i);
i = out_i_1;
}
return ts.factory.createTemplateExpression(templateHead, templateSpans);
@@ -156044,10 +159289,10 @@ var ts;
}
function isConvertibleDeclaration(node) {
switch (node.kind) {
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
- case 167 /* MethodDeclaration */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
+ case 168 /* MethodDeclaration */:
return true;
default:
return false;
@@ -156149,8 +159394,8 @@ var ts;
if (!children.length) {
return undefined;
}
- var child = ts.find(children, function (kid) { return kid.kind < 304 /* FirstJSDocNode */ || kid.kind > 342 /* LastJSDocNode */; });
- return child.kind < 159 /* FirstNode */ ?
+ var child = ts.find(children, function (kid) { return kid.kind < 307 /* FirstJSDocNode */ || kid.kind > 345 /* LastJSDocNode */; });
+ return child.kind < 160 /* FirstNode */ ?
child :
child.getFirstToken(sourceFile);
};
@@ -156161,7 +159406,7 @@ var ts;
if (!child) {
return undefined;
}
- return child.kind < 159 /* FirstNode */ ? child : child.getLastToken(sourceFile);
+ return child.kind < 160 /* FirstNode */ ? child : child.getLastToken(sourceFile);
};
NodeObject.prototype.forEachChild = function (cbNode, cbNodeArray) {
return ts.forEachChild(this, cbNode, cbNodeArray);
@@ -156175,7 +159420,9 @@ var ts;
var children = [];
if (ts.isJSDocCommentContainingNode(node)) {
/** Don't add trivia for "tokens" since this is in a comment. */
- node.forEachChild(function (child) { children.push(child); });
+ node.forEachChild(function (child) {
+ children.push(child);
+ });
return children;
}
ts.scanner.setText((sourceFile || node.getSourceFile()).text);
@@ -156219,7 +159466,7 @@ var ts;
}
}
function createSyntaxList(nodes, parent) {
- var list = createNode(343 /* SyntaxList */, nodes.pos, nodes.end, parent);
+ var list = createNode(346 /* SyntaxList */, nodes.pos, nodes.end, parent);
list._children = [];
var pos = nodes.pos;
for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
@@ -156330,13 +159577,13 @@ var ts;
};
SymbolObject.prototype.getContextualDocumentationComment = function (context, checker) {
switch (context === null || context === void 0 ? void 0 : context.kind) {
- case 170 /* GetAccessor */:
+ case 171 /* GetAccessor */:
if (!this.contextualGetAccessorDocumentationComment) {
this.contextualGetAccessorDocumentationComment = ts.emptyArray;
this.contextualGetAccessorDocumentationComment = getDocumentationComment(ts.filter(this.declarations, ts.isGetAccessor), checker);
}
return this.contextualGetAccessorDocumentationComment;
- case 171 /* SetAccessor */:
+ case 172 /* SetAccessor */:
if (!this.contextualSetAccessorDocumentationComment) {
this.contextualSetAccessorDocumentationComment = ts.emptyArray;
this.contextualSetAccessorDocumentationComment = getDocumentationComment(ts.filter(this.declarations, ts.isSetAccessor), checker);
@@ -156556,7 +159803,7 @@ var ts;
}
function findBaseOfDeclaration(checker, declaration, cb) {
var _a;
- var classOrInterfaceDeclaration = ((_a = declaration.parent) === null || _a === void 0 ? void 0 : _a.kind) === 169 /* Constructor */ ? declaration.parent.parent : declaration.parent;
+ var classOrInterfaceDeclaration = ((_a = declaration.parent) === null || _a === void 0 ? void 0 : _a.kind) === 170 /* Constructor */ ? declaration.parent.parent : declaration.parent;
if (!classOrInterfaceDeclaration) {
return;
}
@@ -156569,7 +159816,7 @@ var ts;
__extends(SourceFileObject, _super);
function SourceFileObject(kind, pos, end) {
var _this = _super.call(this, kind, pos, end) || this;
- _this.kind = 300 /* SourceFile */;
+ _this.kind = 303 /* SourceFile */;
return _this;
}
SourceFileObject.prototype.update = function (newText, textChangeRange) {
@@ -156628,10 +159875,10 @@ var ts;
}
function visit(node) {
switch (node.kind) {
- case 254 /* FunctionDeclaration */:
- case 211 /* FunctionExpression */:
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
+ case 255 /* FunctionDeclaration */:
+ case 212 /* FunctionExpression */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
var functionDeclaration = node;
var declarationName = getDeclarationName(functionDeclaration);
if (declarationName) {
@@ -156651,31 +159898,31 @@ var ts;
}
ts.forEachChild(node, visit);
break;
- case 255 /* ClassDeclaration */:
- case 224 /* ClassExpression */:
- case 256 /* InterfaceDeclaration */:
- case 257 /* TypeAliasDeclaration */:
- case 258 /* EnumDeclaration */:
- case 259 /* ModuleDeclaration */:
- case 263 /* ImportEqualsDeclaration */:
- case 273 /* ExportSpecifier */:
- case 268 /* ImportSpecifier */:
- case 265 /* ImportClause */:
- case 266 /* NamespaceImport */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
- case 180 /* TypeLiteral */:
+ case 256 /* ClassDeclaration */:
+ case 225 /* ClassExpression */:
+ case 257 /* InterfaceDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 260 /* ModuleDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
+ case 274 /* ExportSpecifier */:
+ case 269 /* ImportSpecifier */:
+ case 266 /* ImportClause */:
+ case 267 /* NamespaceImport */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
+ case 181 /* TypeLiteral */:
addDeclaration(node);
ts.forEachChild(node, visit);
break;
- case 162 /* Parameter */:
+ case 163 /* Parameter */:
// Only consider parameter properties
if (!ts.hasSyntacticModifier(node, 16476 /* ParameterPropertyModifier */)) {
break;
}
// falls through
- case 252 /* VariableDeclaration */:
- case 201 /* BindingElement */: {
+ case 253 /* VariableDeclaration */:
+ case 202 /* BindingElement */: {
var decl = node;
if (ts.isBindingPattern(decl.name)) {
ts.forEachChild(decl.name, visit);
@@ -156686,12 +159933,12 @@ var ts;
}
}
// falls through
- case 294 /* EnumMember */:
- case 165 /* PropertyDeclaration */:
- case 164 /* PropertySignature */:
+ case 297 /* EnumMember */:
+ case 166 /* PropertyDeclaration */:
+ case 165 /* PropertySignature */:
addDeclaration(node);
break;
- case 270 /* ExportDeclaration */:
+ case 271 /* ExportDeclaration */:
// Handle named exports case e.g.:
// export {a, b as B} from "mod";
var exportDeclaration = node;
@@ -156704,7 +159951,7 @@ var ts;
}
}
break;
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
var importClause = node.importClause;
if (importClause) {
// Handle default import case e.g.:
@@ -156716,7 +159963,7 @@ var ts;
// import * as NS from "mod";
// import {a, b as B} from "mod";
if (importClause.namedBindings) {
- if (importClause.namedBindings.kind === 266 /* NamespaceImport */) {
+ if (importClause.namedBindings.kind === 267 /* NamespaceImport */) {
addDeclaration(importClause.namedBindings);
}
else {
@@ -156725,7 +159972,7 @@ var ts;
}
}
break;
- case 219 /* BinaryExpression */:
+ case 220 /* BinaryExpression */:
if (ts.getAssignmentDeclarationKind(node) !== 0 /* None */) {
addDeclaration(node);
}
@@ -157432,14 +160679,14 @@ var ts;
switch (node.kind) {
case 79 /* Identifier */:
return !ts.isLabelName(node) && !ts.isTagName(node) && !ts.isConstTypeReference(node.parent);
- case 204 /* PropertyAccessExpression */:
- case 159 /* QualifiedName */:
+ case 205 /* PropertyAccessExpression */:
+ case 160 /* QualifiedName */:
// Don't return quickInfo if inside the comment in `a/**/.b`
return !ts.isInComment(sourceFile, position);
case 108 /* ThisKeyword */:
- case 190 /* ThisType */:
+ case 191 /* ThisType */:
case 106 /* SuperKeyword */:
- case 195 /* NamedTupleMember */:
+ case 196 /* NamedTupleMember */:
return true;
default:
return false;
@@ -157479,6 +160726,8 @@ var ts;
synchronizeHostData();
var sourceFile = getValidSourceFile(fileName);
var node = ts.getAdjustedRenameLocation(ts.getTouchingPropertyName(sourceFile, position));
+ if (!ts.Rename.nodeIsEligibleForRename(node))
+ return undefined;
if (ts.isIdentifier(node) && (ts.isJsxOpeningElement(node.parent) || ts.isJsxClosingElement(node.parent)) && ts.isIntrinsicJsxName(node.escapedText)) {
var _a = node.parent.parent, openingElement = _a.openingElement, closingElement = _a.closingElement;
return [openingElement, closingElement].map(function (node) {
@@ -157492,7 +160741,7 @@ var ts;
}
function getReferencesAtPosition(fileName, position) {
synchronizeHostData();
- return getReferencesWorker(ts.getTouchingPropertyName(getValidSourceFile(fileName), position), position, { use: 1 /* References */ }, ts.FindAllReferences.toReferenceEntry);
+ return getReferencesWorker(ts.getTouchingPropertyName(getValidSourceFile(fileName), position), position, { use: 1 /* References */ }, function (entry, node, checker) { return ts.FindAllReferences.toReferenceEntry(entry, checker.getSymbolAtLocation(node)); });
}
function getReferencesWorker(node, position, options, cb) {
synchronizeHostData();
@@ -157507,8 +160756,10 @@ var ts;
return ts.FindAllReferences.findReferencedSymbols(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position);
}
function getFileReferences(fileName) {
+ var _a;
synchronizeHostData();
- return ts.FindAllReferences.Core.getReferencesForFileName(fileName, program, program.getSourceFiles()).map(ts.FindAllReferences.toReferenceEntry);
+ var moduleSymbol = (_a = program.getSourceFile(fileName)) === null || _a === void 0 ? void 0 : _a.symbol;
+ return ts.FindAllReferences.Core.getReferencesForFileName(fileName, program, program.getSourceFiles()).map(function (r) { return ts.FindAllReferences.toReferenceEntry(r, moduleSymbol); });
}
function getNavigateToItems(searchValue, maxResultCount, fileName, excludeDtsFiles) {
if (excludeDtsFiles === void 0) { excludeDtsFiles = false; }
@@ -157544,15 +160795,15 @@ var ts;
return undefined;
}
switch (node.kind) {
- case 204 /* PropertyAccessExpression */:
- case 159 /* QualifiedName */:
+ case 205 /* PropertyAccessExpression */:
+ case 160 /* QualifiedName */:
case 10 /* StringLiteral */:
case 95 /* FalseKeyword */:
case 110 /* TrueKeyword */:
case 104 /* NullKeyword */:
case 106 /* SuperKeyword */:
case 108 /* ThisKeyword */:
- case 190 /* ThisType */:
+ case 191 /* ThisType */:
case 79 /* Identifier */:
break;
// Cant create the text span
@@ -157569,7 +160820,7 @@ var ts;
// If this is name of a module declarations, check if this is right side of dotted module name
// If parent of the module declaration which is parent of this node is module declaration and its body is the module declaration that this node is name of
// Then this name is name from dotted module
- if (nodeForStartPos.parent.parent.kind === 259 /* ModuleDeclaration */ &&
+ if (nodeForStartPos.parent.parent.kind === 260 /* ModuleDeclaration */ &&
nodeForStartPos.parent.parent.body === nodeForStartPos.parent) {
// Use parent module declarations name for start pos
nodeForStartPos = nodeForStartPos.parent.parent.name;
@@ -157759,10 +161010,15 @@ var ts;
if (!token)
return undefined;
var element = token.kind === 31 /* GreaterThanToken */ && ts.isJsxOpeningElement(token.parent) ? token.parent.parent
- : ts.isJsxText(token) ? token.parent : undefined;
+ : ts.isJsxText(token) && ts.isJsxElement(token.parent) ? token.parent : undefined;
if (element && isUnclosedTag(element)) {
return { newText: "" + element.openingElement.tagName.getText(sourceFile) + ">" };
}
+ var fragment = token.kind === 31 /* GreaterThanToken */ && ts.isJsxOpeningFragment(token.parent) ? token.parent.parent
+ : ts.isJsxText(token) && ts.isJsxFragment(token.parent) ? token.parent : undefined;
+ if (fragment && isUnclosedFragment(fragment)) {
+ return { newText: ">" };
+ }
}
function getLinesForRange(sourceFile, textRange) {
return {
@@ -157974,6 +161230,10 @@ var ts;
return !ts.tagNamesAreEquivalent(openingElement.tagName, closingElement.tagName) ||
ts.isJsxElement(parent) && ts.tagNamesAreEquivalent(openingElement.tagName, parent.openingElement.tagName) && isUnclosedTag(parent);
}
+ function isUnclosedFragment(_a) {
+ var closingFragment = _a.closingFragment, parent = _a.parent;
+ return !!(closingFragment.flags & 65536 /* ThisNodeHasError */) || (ts.isJsxFragment(parent) && isUnclosedFragment(parent));
+ }
function getSpanOfEnclosingComment(fileName, position, onlyMultiLine) {
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
var range = ts.formatting.getRangeOfEnclosingComment(sourceFile, position);
@@ -158307,7 +161567,7 @@ var ts;
*/
function literalIsName(node) {
return ts.isDeclarationName(node) ||
- node.parent.kind === 275 /* ExternalModuleReference */ ||
+ node.parent.kind === 276 /* ExternalModuleReference */ ||
isArgumentOfElementAccessExpression(node) ||
ts.isLiteralComputedPropertyDeclarationName(node);
}
@@ -158325,13 +161585,13 @@ var ts;
case 10 /* StringLiteral */:
case 14 /* NoSubstitutionTemplateLiteral */:
case 8 /* NumericLiteral */:
- if (node.parent.kind === 160 /* ComputedPropertyName */) {
+ if (node.parent.kind === 161 /* ComputedPropertyName */) {
return ts.isObjectLiteralElement(node.parent.parent) ? node.parent.parent : undefined;
}
// falls through
case 79 /* Identifier */:
return ts.isObjectLiteralElement(node.parent) &&
- (node.parent.parent.kind === 203 /* ObjectLiteralExpression */ || node.parent.parent.kind === 284 /* JsxAttributes */) &&
+ (node.parent.parent.kind === 204 /* ObjectLiteralExpression */ || node.parent.parent.kind === 285 /* JsxAttributes */) &&
node.parent.name === node ? node.parent : undefined;
}
return undefined;
@@ -158373,7 +161633,7 @@ var ts;
function isArgumentOfElementAccessExpression(node) {
return node &&
node.parent &&
- node.parent.kind === 205 /* ElementAccessExpression */ &&
+ node.parent.kind === 206 /* ElementAccessExpression */ &&
node.parent.argumentExpression === node;
}
/**
@@ -158453,114 +161713,114 @@ var ts;
if (node) {
var parent = node.parent;
switch (node.kind) {
- case 235 /* VariableStatement */:
+ case 236 /* VariableStatement */:
// Span on first variable declaration
return spanInVariableDeclaration(node.declarationList.declarations[0]);
- case 252 /* VariableDeclaration */:
- case 165 /* PropertyDeclaration */:
- case 164 /* PropertySignature */:
+ case 253 /* VariableDeclaration */:
+ case 166 /* PropertyDeclaration */:
+ case 165 /* PropertySignature */:
return spanInVariableDeclaration(node);
- case 162 /* Parameter */:
+ case 163 /* Parameter */:
return spanInParameterDeclaration(node);
- case 254 /* FunctionDeclaration */:
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
- case 169 /* Constructor */:
- case 211 /* FunctionExpression */:
- case 212 /* ArrowFunction */:
+ case 255 /* FunctionDeclaration */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
+ case 170 /* Constructor */:
+ case 212 /* FunctionExpression */:
+ case 213 /* ArrowFunction */:
return spanInFunctionDeclaration(node);
- case 233 /* Block */:
+ case 234 /* Block */:
if (ts.isFunctionBlock(node)) {
return spanInFunctionBlock(node);
}
// falls through
- case 260 /* ModuleBlock */:
+ case 261 /* ModuleBlock */:
return spanInBlock(node);
- case 290 /* CatchClause */:
+ case 291 /* CatchClause */:
return spanInBlock(node.block);
- case 236 /* ExpressionStatement */:
+ case 237 /* ExpressionStatement */:
// span on the expression
return textSpan(node.expression);
- case 245 /* ReturnStatement */:
+ case 246 /* ReturnStatement */:
// span on return keyword and expression if present
return textSpan(node.getChildAt(0), node.expression);
- case 239 /* WhileStatement */:
+ case 240 /* WhileStatement */:
// Span on while(...)
return textSpanEndingAtNextToken(node, node.expression);
- case 238 /* DoStatement */:
+ case 239 /* DoStatement */:
// span in statement of the do statement
return spanInNode(node.statement);
- case 251 /* DebuggerStatement */:
+ case 252 /* DebuggerStatement */:
// span on debugger keyword
return textSpan(node.getChildAt(0));
- case 237 /* IfStatement */:
+ case 238 /* IfStatement */:
// set on if(..) span
return textSpanEndingAtNextToken(node, node.expression);
- case 248 /* LabeledStatement */:
+ case 249 /* LabeledStatement */:
// span in statement
return spanInNode(node.statement);
- case 244 /* BreakStatement */:
- case 243 /* ContinueStatement */:
+ case 245 /* BreakStatement */:
+ case 244 /* ContinueStatement */:
// On break or continue keyword and label if present
return textSpan(node.getChildAt(0), node.label);
- case 240 /* ForStatement */:
+ case 241 /* ForStatement */:
return spanInForStatement(node);
- case 241 /* ForInStatement */:
+ case 242 /* ForInStatement */:
// span of for (a in ...)
return textSpanEndingAtNextToken(node, node.expression);
- case 242 /* ForOfStatement */:
+ case 243 /* ForOfStatement */:
// span in initializer
return spanInInitializerOfForLike(node);
- case 247 /* SwitchStatement */:
+ case 248 /* SwitchStatement */:
// span on switch(...)
return textSpanEndingAtNextToken(node, node.expression);
- case 287 /* CaseClause */:
- case 288 /* DefaultClause */:
+ case 288 /* CaseClause */:
+ case 289 /* DefaultClause */:
// span in first statement of the clause
return spanInNode(node.statements[0]);
- case 250 /* TryStatement */:
+ case 251 /* TryStatement */:
// span in try block
return spanInBlock(node.tryBlock);
- case 249 /* ThrowStatement */:
+ case 250 /* ThrowStatement */:
// span in throw ...
return textSpan(node, node.expression);
- case 269 /* ExportAssignment */:
+ case 270 /* ExportAssignment */:
// span on export = id
return textSpan(node, node.expression);
- case 263 /* ImportEqualsDeclaration */:
+ case 264 /* ImportEqualsDeclaration */:
// import statement without including semicolon
return textSpan(node, node.moduleReference);
- case 264 /* ImportDeclaration */:
+ case 265 /* ImportDeclaration */:
// import statement without including semicolon
return textSpan(node, node.moduleSpecifier);
- case 270 /* ExportDeclaration */:
+ case 271 /* ExportDeclaration */:
// import statement without including semicolon
return textSpan(node, node.moduleSpecifier);
- case 259 /* ModuleDeclaration */:
+ case 260 /* ModuleDeclaration */:
// span on complete module if it is instantiated
if (ts.getModuleInstanceState(node) !== 1 /* Instantiated */) {
return undefined;
}
// falls through
- case 255 /* ClassDeclaration */:
- case 258 /* EnumDeclaration */:
- case 294 /* EnumMember */:
- case 201 /* BindingElement */:
+ case 256 /* ClassDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 297 /* EnumMember */:
+ case 202 /* BindingElement */:
// span on complete node
return textSpan(node);
- case 246 /* WithStatement */:
+ case 247 /* WithStatement */:
// span in statement
return spanInNode(node.statement);
- case 163 /* Decorator */:
+ case 164 /* Decorator */:
return spanInNodeArray(parent.decorators);
- case 199 /* ObjectBindingPattern */:
- case 200 /* ArrayBindingPattern */:
+ case 200 /* ObjectBindingPattern */:
+ case 201 /* ArrayBindingPattern */:
return spanInBindingPattern(node);
// No breakpoint in interface, type alias
- case 256 /* InterfaceDeclaration */:
- case 257 /* TypeAliasDeclaration */:
+ case 257 /* InterfaceDeclaration */:
+ case 258 /* TypeAliasDeclaration */:
return undefined;
// Tokens:
case 26 /* SemicolonToken */:
@@ -158590,7 +161850,7 @@ var ts;
case 83 /* CatchKeyword */:
case 96 /* FinallyKeyword */:
return spanInNextNode(node);
- case 158 /* OfKeyword */:
+ case 159 /* OfKeyword */:
return spanInOfKeyword(node);
default:
// Destructuring pattern in destructuring assignment
@@ -158603,13 +161863,13 @@ var ts;
// `a` or `...c` or `d: x` from
// `[a, b, ...c]` or `{ a, b }` or `{ d: x }` from destructuring pattern
if ((node.kind === 79 /* Identifier */ ||
- node.kind === 223 /* SpreadElement */ ||
- node.kind === 291 /* PropertyAssignment */ ||
- node.kind === 292 /* ShorthandPropertyAssignment */) &&
+ node.kind === 224 /* SpreadElement */ ||
+ node.kind === 294 /* PropertyAssignment */ ||
+ node.kind === 295 /* ShorthandPropertyAssignment */) &&
ts.isArrayLiteralOrObjectLiteralDestructuringPattern(parent)) {
return textSpan(node);
}
- if (node.kind === 219 /* BinaryExpression */) {
+ if (node.kind === 220 /* BinaryExpression */) {
var _a = node, left = _a.left, operatorToken = _a.operatorToken;
// Set breakpoint in destructuring pattern if its destructuring assignment
// [a, b, c] or {a, b, c} of
@@ -158631,22 +161891,22 @@ var ts;
}
if (ts.isExpressionNode(node)) {
switch (parent.kind) {
- case 238 /* DoStatement */:
+ case 239 /* DoStatement */:
// Set span as if on while keyword
return spanInPreviousNode(node);
- case 163 /* Decorator */:
+ case 164 /* Decorator */:
// Set breakpoint on the decorator emit
return spanInNode(node.parent);
- case 240 /* ForStatement */:
- case 242 /* ForOfStatement */:
+ case 241 /* ForStatement */:
+ case 243 /* ForOfStatement */:
return textSpan(node);
- case 219 /* BinaryExpression */:
+ case 220 /* BinaryExpression */:
if (node.parent.operatorToken.kind === 27 /* CommaToken */) {
// If this is a comma expression, the breakpoint is possible in this expression
return textSpan(node);
}
break;
- case 212 /* ArrowFunction */:
+ case 213 /* ArrowFunction */:
if (node.parent.body === node) {
// If this is body of arrow function, it is allowed to have the breakpoint
return textSpan(node);
@@ -158655,21 +161915,21 @@ var ts;
}
}
switch (node.parent.kind) {
- case 291 /* PropertyAssignment */:
+ case 294 /* PropertyAssignment */:
// If this is name of property assignment, set breakpoint in the initializer
if (node.parent.name === node &&
!ts.isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent.parent)) {
return spanInNode(node.parent.initializer);
}
break;
- case 209 /* TypeAssertionExpression */:
+ case 210 /* TypeAssertionExpression */:
// Breakpoint in type assertion goes to its operand
if (node.parent.type === node) {
return spanInNextNode(node.parent.type);
}
break;
- case 252 /* VariableDeclaration */:
- case 162 /* Parameter */: {
+ case 253 /* VariableDeclaration */:
+ case 163 /* Parameter */: {
// initializer of variable/parameter declaration go to previous node
var _b = node.parent, initializer = _b.initializer, type = _b.type;
if (initializer === node || type === node || ts.isAssignmentOperator(node.kind)) {
@@ -158677,7 +161937,7 @@ var ts;
}
break;
}
- case 219 /* BinaryExpression */: {
+ case 220 /* BinaryExpression */: {
var left = node.parent.left;
if (ts.isArrayLiteralOrObjectLiteralDestructuringPattern(left) && node !== left) {
// If initializer of destructuring assignment move to previous token
@@ -158707,7 +161967,7 @@ var ts;
}
function spanInVariableDeclaration(variableDeclaration) {
// If declaration of for in statement, just set the span in parent
- if (variableDeclaration.parent.parent.kind === 241 /* ForInStatement */) {
+ if (variableDeclaration.parent.parent.kind === 242 /* ForInStatement */) {
return spanInNode(variableDeclaration.parent.parent);
}
var parent = variableDeclaration.parent;
@@ -158719,7 +161979,7 @@ var ts;
// or its declaration from 'for of'
if (variableDeclaration.initializer ||
ts.hasSyntacticModifier(variableDeclaration, 1 /* Export */) ||
- parent.parent.kind === 242 /* ForOfStatement */) {
+ parent.parent.kind === 243 /* ForOfStatement */) {
return textSpanFromVariableDeclaration(variableDeclaration);
}
if (ts.isVariableDeclarationList(variableDeclaration.parent) &&
@@ -158760,7 +162020,7 @@ var ts;
}
function canFunctionHaveSpanInWholeDeclaration(functionDeclaration) {
return ts.hasSyntacticModifier(functionDeclaration, 1 /* Export */) ||
- (functionDeclaration.parent.kind === 255 /* ClassDeclaration */ && functionDeclaration.kind !== 169 /* Constructor */);
+ (functionDeclaration.parent.kind === 256 /* ClassDeclaration */ && functionDeclaration.kind !== 170 /* Constructor */);
}
function spanInFunctionDeclaration(functionDeclaration) {
// No breakpoints in the function signature
@@ -158783,26 +162043,26 @@ var ts;
}
function spanInBlock(block) {
switch (block.parent.kind) {
- case 259 /* ModuleDeclaration */:
+ case 260 /* ModuleDeclaration */:
if (ts.getModuleInstanceState(block.parent) !== 1 /* Instantiated */) {
return undefined;
}
// Set on parent if on same line otherwise on first statement
// falls through
- case 239 /* WhileStatement */:
- case 237 /* IfStatement */:
- case 241 /* ForInStatement */:
+ case 240 /* WhileStatement */:
+ case 238 /* IfStatement */:
+ case 242 /* ForInStatement */:
return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]);
// Set span on previous token if it starts on same line otherwise on the first statement of the block
- case 240 /* ForStatement */:
- case 242 /* ForOfStatement */:
+ case 241 /* ForStatement */:
+ case 243 /* ForOfStatement */:
return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(block.pos, sourceFile, block.parent), block.statements[0]);
}
// Default action is to set on first statement
return spanInNode(block.statements[0]);
}
function spanInInitializerOfForLike(forLikeStatement) {
- if (forLikeStatement.initializer.kind === 253 /* VariableDeclarationList */) {
+ if (forLikeStatement.initializer.kind === 254 /* VariableDeclarationList */) {
// Declaration list - set breakpoint in first declaration
var variableDeclarationList = forLikeStatement.initializer;
if (variableDeclarationList.declarations.length > 0) {
@@ -158827,21 +162087,21 @@ var ts;
}
function spanInBindingPattern(bindingPattern) {
// Set breakpoint in first binding element
- var firstBindingElement = ts.forEach(bindingPattern.elements, function (element) { return element.kind !== 225 /* OmittedExpression */ ? element : undefined; });
+ var firstBindingElement = ts.forEach(bindingPattern.elements, function (element) { return element.kind !== 226 /* OmittedExpression */ ? element : undefined; });
if (firstBindingElement) {
return spanInNode(firstBindingElement);
}
// Empty binding pattern of binding element, set breakpoint on binding element
- if (bindingPattern.parent.kind === 201 /* BindingElement */) {
+ if (bindingPattern.parent.kind === 202 /* BindingElement */) {
return textSpan(bindingPattern.parent);
}
// Variable declaration is used as the span
return textSpanFromVariableDeclaration(bindingPattern.parent);
}
function spanInArrayLiteralOrObjectLiteralDestructuringPattern(node) {
- ts.Debug.assert(node.kind !== 200 /* ArrayBindingPattern */ && node.kind !== 199 /* ObjectBindingPattern */);
- var elements = node.kind === 202 /* ArrayLiteralExpression */ ? node.elements : node.properties;
- var firstBindingElement = ts.forEach(elements, function (element) { return element.kind !== 225 /* OmittedExpression */ ? element : undefined; });
+ ts.Debug.assert(node.kind !== 201 /* ArrayBindingPattern */ && node.kind !== 200 /* ObjectBindingPattern */);
+ var elements = node.kind === 203 /* ArrayLiteralExpression */ ? node.elements : node.properties;
+ var firstBindingElement = ts.forEach(elements, function (element) { return element.kind !== 226 /* OmittedExpression */ ? element : undefined; });
if (firstBindingElement) {
return spanInNode(firstBindingElement);
}
@@ -158849,18 +162109,18 @@ var ts;
// just nested element in another destructuring assignment
// set breakpoint on assignment when parent is destructuring assignment
// Otherwise set breakpoint for this element
- return textSpan(node.parent.kind === 219 /* BinaryExpression */ ? node.parent : node);
+ return textSpan(node.parent.kind === 220 /* BinaryExpression */ ? node.parent : node);
}
// Tokens:
function spanInOpenBraceToken(node) {
switch (node.parent.kind) {
- case 258 /* EnumDeclaration */:
+ case 259 /* EnumDeclaration */:
var enumDeclaration = node.parent;
return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile));
- case 255 /* ClassDeclaration */:
+ case 256 /* ClassDeclaration */:
var classDeclaration = node.parent;
return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile));
- case 261 /* CaseBlock */:
+ case 262 /* CaseBlock */:
return spanInNodeIfStartsOnSameLine(node.parent.parent, node.parent.clauses[0]);
}
// Default to parent node
@@ -158868,25 +162128,25 @@ var ts;
}
function spanInCloseBraceToken(node) {
switch (node.parent.kind) {
- case 260 /* ModuleBlock */:
+ case 261 /* ModuleBlock */:
// If this is not an instantiated module block, no bp span
if (ts.getModuleInstanceState(node.parent.parent) !== 1 /* Instantiated */) {
return undefined;
}
// falls through
- case 258 /* EnumDeclaration */:
- case 255 /* ClassDeclaration */:
+ case 259 /* EnumDeclaration */:
+ case 256 /* ClassDeclaration */:
// Span on close brace token
return textSpan(node);
- case 233 /* Block */:
+ case 234 /* Block */:
if (ts.isFunctionBlock(node.parent)) {
// Span on close brace token
return textSpan(node);
}
// falls through
- case 290 /* CatchClause */:
+ case 291 /* CatchClause */:
return spanInNode(ts.lastOrUndefined(node.parent.statements));
- case 261 /* CaseBlock */:
+ case 262 /* CaseBlock */:
// breakpoint in last statement of the last clause
var caseBlock = node.parent;
var lastClause = ts.lastOrUndefined(caseBlock.clauses);
@@ -158894,7 +162154,7 @@ var ts;
return spanInNode(ts.lastOrUndefined(lastClause.statements));
}
return undefined;
- case 199 /* ObjectBindingPattern */:
+ case 200 /* ObjectBindingPattern */:
// Breakpoint in last binding element or binding pattern if it contains no elements
var bindingPattern = node.parent;
return spanInNode(ts.lastOrUndefined(bindingPattern.elements) || bindingPattern);
@@ -158910,7 +162170,7 @@ var ts;
}
function spanInCloseBracketToken(node) {
switch (node.parent.kind) {
- case 200 /* ArrayBindingPattern */:
+ case 201 /* ArrayBindingPattern */:
// Breakpoint in last binding element or binding pattern if it contains no elements
var bindingPattern = node.parent;
return textSpan(ts.lastOrUndefined(bindingPattern.elements) || bindingPattern);
@@ -158925,12 +162185,12 @@ var ts;
}
}
function spanInOpenParenToken(node) {
- if (node.parent.kind === 238 /* DoStatement */ || // Go to while keyword and do action instead
- node.parent.kind === 206 /* CallExpression */ ||
- node.parent.kind === 207 /* NewExpression */) {
+ if (node.parent.kind === 239 /* DoStatement */ || // Go to while keyword and do action instead
+ node.parent.kind === 207 /* CallExpression */ ||
+ node.parent.kind === 208 /* NewExpression */) {
return spanInPreviousNode(node);
}
- if (node.parent.kind === 210 /* ParenthesizedExpression */) {
+ if (node.parent.kind === 211 /* ParenthesizedExpression */) {
return spanInNextNode(node);
}
// Default to parent node
@@ -158939,21 +162199,21 @@ var ts;
function spanInCloseParenToken(node) {
// Is this close paren token of parameter list, set span in previous token
switch (node.parent.kind) {
- case 211 /* FunctionExpression */:
- case 254 /* FunctionDeclaration */:
- case 212 /* ArrowFunction */:
- case 167 /* MethodDeclaration */:
- case 166 /* MethodSignature */:
- case 170 /* GetAccessor */:
- case 171 /* SetAccessor */:
- case 169 /* Constructor */:
- case 239 /* WhileStatement */:
- case 238 /* DoStatement */:
- case 240 /* ForStatement */:
- case 242 /* ForOfStatement */:
- case 206 /* CallExpression */:
- case 207 /* NewExpression */:
- case 210 /* ParenthesizedExpression */:
+ case 212 /* FunctionExpression */:
+ case 255 /* FunctionDeclaration */:
+ case 213 /* ArrowFunction */:
+ case 168 /* MethodDeclaration */:
+ case 167 /* MethodSignature */:
+ case 171 /* GetAccessor */:
+ case 172 /* SetAccessor */:
+ case 170 /* Constructor */:
+ case 240 /* WhileStatement */:
+ case 239 /* DoStatement */:
+ case 241 /* ForStatement */:
+ case 243 /* ForOfStatement */:
+ case 207 /* CallExpression */:
+ case 208 /* NewExpression */:
+ case 211 /* ParenthesizedExpression */:
return spanInPreviousNode(node);
// Default to parent node
default:
@@ -158963,20 +162223,20 @@ var ts;
function spanInColonToken(node) {
// Is this : specifying return annotation of the function declaration
if (ts.isFunctionLike(node.parent) ||
- node.parent.kind === 291 /* PropertyAssignment */ ||
- node.parent.kind === 162 /* Parameter */) {
+ node.parent.kind === 294 /* PropertyAssignment */ ||
+ node.parent.kind === 163 /* Parameter */) {
return spanInPreviousNode(node);
}
return spanInNode(node.parent);
}
function spanInGreaterThanOrLessThanToken(node) {
- if (node.parent.kind === 209 /* TypeAssertionExpression */) {
+ if (node.parent.kind === 210 /* TypeAssertionExpression */) {
return spanInNextNode(node);
}
return spanInNode(node.parent);
}
function spanInWhileKeyword(node) {
- if (node.parent.kind === 238 /* DoStatement */) {
+ if (node.parent.kind === 239 /* DoStatement */) {
// Set span on while expression
return textSpanEndingAtNextToken(node, node.parent.expression);
}
@@ -158984,7 +162244,7 @@ var ts;
return spanInNode(node.parent);
}
function spanInOfKeyword(node) {
- if (node.parent.kind === 242 /* ForOfStatement */) {
+ if (node.parent.kind === 243 /* ForOfStatement */) {
// Set using next token
return spanInNextNode(node);
}
@@ -159029,7 +162289,9 @@ var ts;
// limitations under the License.
//
/* @internal */
-var debugObjectHost = (function () { return this; })(); // eslint-disable-line prefer-const
+var debugObjectHost = (function () {
+ return this;
+})();
// We need to use 'null' to interface with the managed side.
/* eslint-disable no-in-operator */
/* @internal */
@@ -160571,7 +163833,7 @@ var ts;
}
else {
type = operatorOrType;
- operator = 139 /* KeyOfKeyword */;
+ operator = 140 /* KeyOfKeyword */;
}
return ts.factory.createTypeOperatorNode(operator, type);
}, factoryDeprecation);
@@ -160695,7 +163957,7 @@ var ts;
}, factoryDeprecation);
/** @deprecated Use `factory.updateExportDeclaration` or the factory supplied by your transformation context instead. */
ts.updateExportDeclaration = ts.Debug.deprecate(function updateExportDeclaration(node, decorators, modifiers, exportClause, moduleSpecifier, isTypeOnly) {
- return ts.factory.updateExportDeclaration(node, decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier);
+ return ts.factory.updateExportDeclaration(node, decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier, node.assertClause);
}, factoryDeprecation);
/** @deprecated Use `factory.createJSDocParameterTag` or the factory supplied by your transformation context instead. */
ts.createJSDocParamTag = ts.Debug.deprecate(function createJSDocParamTag(name, isBracketed, typeExpression, comment) {
@@ -160749,7 +164011,7 @@ var ts;
ts.createNode = ts.Debug.deprecate(function createNode(kind, pos, end) {
if (pos === void 0) { pos = 0; }
if (end === void 0) { end = 0; }
- return ts.setTextRangePosEnd(kind === 300 /* SourceFile */ ? ts.parseBaseNodeFactory.createBaseSourceFileNode(kind) :
+ return ts.setTextRangePosEnd(kind === 303 /* SourceFile */ ? ts.parseBaseNodeFactory.createBaseSourceFileNode(kind) :
kind === 79 /* Identifier */ ? ts.parseBaseNodeFactory.createBaseIdentifierNode(kind) :
kind === 80 /* PrivateIdentifier */ ? ts.parseBaseNodeFactory.createBasePrivateIdentifierNode(kind) :
!ts.isNodeKind(kind) ? ts.parseBaseNodeFactory.createBaseTokenNode(kind) :
@@ -160778,7 +164040,7 @@ var ts;
// #region Renamed node Tests
/** @deprecated Use `isTypeAssertionExpression` instead. */
ts.isTypeAssertion = ts.Debug.deprecate(function isTypeAssertion(node) {
- return node.kind === 209 /* TypeAssertionExpression */;
+ return node.kind === 210 /* TypeAssertionExpression */;
}, {
since: "4.0",
warnAfter: "4.1",
diff --git a/scripts/build-bazel.ts b/scripts/build-bazel.ts
new file mode 100644
index 000000000000..8a62137bdad1
--- /dev/null
+++ b/scripts/build-bazel.ts
@@ -0,0 +1,180 @@
+/**
+ * @license
+ * Copyright Google LLC All Rights Reserved.
+ *
+ * Use of this source code is governed by an MIT-style license that can be
+ * found in the LICENSE file at https://angular.io/license
+ */
+
+import { logging } from '@angular-devkit/core';
+import { spawn } from 'child_process';
+import fs from 'fs';
+import { dirname, join, relative, resolve } from 'path';
+
+const baseDir = resolve(`${__dirname}/..`);
+const bazelCmd = process.env.BAZEL ?? `yarn --cwd "${baseDir}" --silent bazel`;
+const distRoot = join(baseDir, '/dist');
+
+type BuildMode = 'local' | 'snapshot' | 'release';
+
+function _copy(from: string, to: string) {
+ // Create parent folder if necessary.
+ if (!fs.existsSync(dirname(to))) {
+ fs.mkdirSync(dirname(to), { recursive: true });
+ }
+
+ // Error out if destination already exists.
+ if (fs.existsSync(to)) {
+ throw new Error(`Path ${to} already exist...`);
+ }
+
+ from = relative(process.cwd(), from);
+ to = relative(process.cwd(), to);
+
+ const buffer = fs.readFileSync(from);
+ fs.writeFileSync(to, buffer);
+}
+
+function _recursiveCopy(from: string, to: string, logger: logging.Logger) {
+ if (!fs.existsSync(from)) {
+ logger.error(`File "${from}" does not exist.`);
+ process.exit(4);
+ }
+ if (fs.statSync(from).isDirectory()) {
+ fs.readdirSync(from).forEach((fileName) => {
+ _recursiveCopy(join(from, fileName), join(to, fileName), logger);
+ });
+ } else {
+ _copy(from, to);
+ }
+}
+
+function rimraf(location: string) {
+ // The below should be removed and replace with just `rmSync` when support for Node.Js 12 is removed.
+ const { rmSync, rmdirSync } = fs as typeof fs & {
+ rmSync?: (
+ path: fs.PathLike,
+ options?: {
+ force?: boolean;
+ maxRetries?: number;
+ recursive?: boolean;
+ retryDelay?: number;
+ },
+ ) => void;
+ };
+
+ if (rmSync) {
+ rmSync(location, { force: true, recursive: true, maxRetries: 3 });
+ } else {
+ rmdirSync(location, { recursive: true, maxRetries: 3 });
+ }
+}
+
+function _clean(logger: logging.Logger) {
+ logger.info('Cleaning...');
+ logger.info(' Removing dist/...');
+ rimraf(join(__dirname, '../dist'));
+}
+
+function _exec(cmd: string, captureStdout: boolean, logger: logging.Logger): Promise {
+ return new Promise((resolve, reject) => {
+ const proc = spawn(cmd, {
+ stdio: 'pipe',
+ shell: true,
+ });
+
+ let output = '';
+ proc.stdout.on('data', (data) => {
+ logger.info(data.toString().trim());
+ if (captureStdout) {
+ output += data.toString().trim();
+ }
+ });
+ proc.stderr.on('data', (data) => logger.info(data.toString().trim()));
+
+ proc.on('error', (error) => {
+ logger.error(error.message);
+ });
+
+ proc.on('exit', (status) => {
+ if (status !== 0) {
+ reject(`Command failed: ${cmd}`);
+ } else {
+ resolve(output);
+ }
+ });
+ });
+}
+
+async function _build(logger: logging.Logger, mode: BuildMode): Promise {
+ logger.info(`Building (mode=${mode})...`);
+
+ const queryLogger = logger.createChild('query');
+ const queryTargetsCmd = `${bazelCmd} query --output=label "attr(name, npm_package_archive, //packages/...)"`;
+ const targets = (await _exec(queryTargetsCmd, true, queryLogger)).split(/\r?\n/);
+
+ let configArg = '';
+ if (mode === 'snapshot') {
+ configArg = '--config=snapshot';
+ } else if (mode === 'release') {
+ configArg = '--config=release';
+ }
+
+ const buildLogger = logger.createChild('build');
+
+ // If we are in release mode, run `bazel clean` to ensure the execroot and action cache
+ // are not populated. This is necessary because targets using `npm_package` rely on
+ // workspace status variables for the package version. Such NPM package targets are not
+ // rebuilt if only the workspace status variables change. This could result in accidental
+ // re-use of previously built package output with a different `version` in the `package.json`.
+ if (mode == 'release') {
+ buildLogger.info('Building in release mode. Resetting the Bazel execroot and action cache..');
+ await _exec(`${bazelCmd} clean`, false, buildLogger);
+ }
+
+ await _exec(`${bazelCmd} build ${configArg} ${targets.join(' ')}`, false, buildLogger);
+
+ return targets;
+}
+
+export default async function (
+ argv: { local?: boolean; snapshot?: boolean } = {},
+ logger: logging.Logger = new logging.Logger('build-logger'),
+): Promise<{ name: string; outputPath: string }[]> {
+ const bazelBin = await _exec(`${bazelCmd} info bazel-bin`, true, logger);
+
+ _clean(logger);
+
+ let buildMode: BuildMode;
+ if (argv.local) {
+ buildMode = 'local';
+ } else if (argv.snapshot) {
+ buildMode = 'snapshot';
+ } else {
+ buildMode = 'release';
+ }
+
+ const targets = await _build(logger, buildMode);
+ const output: { name: string; outputPath: string }[] = [];
+
+ logger.info('Moving packages and tars to dist/');
+ const packageLogger = logger.createChild('packages');
+
+ for (const target of targets) {
+ const packageDir = target.replace(/\/\/packages\/(.*):npm_package_archive/, '$1');
+ const bazelOutDir = join(bazelBin, 'packages', packageDir, 'npm_package');
+ const tarPath = `${bazelBin}/packages/${packageDir}/npm_package_archive.tar.gz`;
+ const packageJsonPath = `${bazelOutDir}/package.json`;
+ const packageName = require(packageJsonPath).name;
+ const destDir = `${distRoot}/${packageName}`;
+
+ packageLogger.info(packageName);
+
+ _recursiveCopy(bazelOutDir, destDir, logger);
+ _copy(tarPath, `${distRoot}/${packageName.replace('@', '_').replace('/', '_')}.tgz`);
+
+ output.push({ name: packageDir, outputPath: destDir });
+ }
+
+ return output;
+}
diff --git a/tests/legacy-cli/e2e/setup/500-create-project.ts b/tests/legacy-cli/e2e/setup/500-create-project.ts
index 7b0649a66548..b8cb4b058fb4 100644
--- a/tests/legacy-cli/e2e/setup/500-create-project.ts
+++ b/tests/legacy-cli/e2e/setup/500-create-project.ts
@@ -6,7 +6,7 @@ import { setRegistry as setNPMConfigRegistry } from '../utils/packages';
import { ng, npm } from '../utils/process';
import { prepareProjectForE2e, updateJsonFile } from '../utils/project';
-export default async function() {
+export default async function () {
const argv = getGlobalVariable('argv');
if (argv.noproject) {
@@ -28,15 +28,6 @@ export default async function() {
await expectFileToExist(join(process.cwd(), 'test-project'));
process.chdir('./test-project');
- // Disable the TS version check to make TS updates easier.
- // Only VE does it, but on Ivy the i18n extraction uses VE.
- await updateJsonFile('tsconfig.json', config => {
- if (!config.angularCompilerOptions) {
- config.angularCompilerOptions = {};
- }
- config.angularCompilerOptions.disableTypeScriptVersionCheck = true;
- });
-
// If on CI, the user configuration set above will handle project usage
if (!isCI) {
// Ensure local test registry is used inside a project
diff --git a/tests/legacy-cli/e2e/tests/build/styles/tailwind.ts b/tests/legacy-cli/e2e/tests/build/styles/tailwind-v2.ts
similarity index 94%
rename from tests/legacy-cli/e2e/tests/build/styles/tailwind.ts
rename to tests/legacy-cli/e2e/tests/build/styles/tailwind-v2.ts
index 51f317533384..663ccc1b900c 100644
--- a/tests/legacy-cli/e2e/tests/build/styles/tailwind.ts
+++ b/tests/legacy-cli/e2e/tests/build/styles/tailwind-v2.ts
@@ -4,13 +4,8 @@ import { ng, silentExec } from '../../../utils/process';
import { expectToFail } from '../../../utils/utils';
export default async function () {
- // Tailwind is not supported in Node.js 10
- if (process.version.startsWith('v10')) {
- return;
- }
-
// Install Tailwind
- await installPackage('tailwindcss');
+ await installPackage('tailwindcss@2');
// Create configuration file
await silentExec('npx', 'tailwindcss', 'init');
diff --git a/tests/legacy-cli/e2e/tests/build/styles/tailwind-v3.ts b/tests/legacy-cli/e2e/tests/build/styles/tailwind-v3.ts
new file mode 100644
index 000000000000..032c45ceee05
--- /dev/null
+++ b/tests/legacy-cli/e2e/tests/build/styles/tailwind-v3.ts
@@ -0,0 +1,55 @@
+import { deleteFile, expectFileToMatch, writeFile } from '../../../utils/fs';
+import { installPackage, uninstallPackage } from '../../../utils/packages';
+import { ng, silentExec } from '../../../utils/process';
+import { expectToFail } from '../../../utils/utils';
+
+export default async function () {
+ // Install Tailwind
+ await installPackage('tailwindcss@3');
+
+ // Create configuration file
+ await silentExec('npx', 'tailwindcss', 'init');
+
+ // Add Tailwind directives to a component style
+ await writeFile('src/app/app.component.css', '@tailwind base; @tailwind components;');
+
+ // Add Tailwind directives to a global style
+ await writeFile('src/styles.css', '@tailwind base; @tailwind components;');
+
+ // Build should succeed and process Tailwind directives
+ await ng('build', '--configuration=development');
+
+ // Check for Tailwind output
+ await expectFileToMatch('dist/test-project/styles.css', /::placeholder/);
+ await expectFileToMatch('dist/test-project/main.js', /::placeholder/);
+ await expectToFail(() =>
+ expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;'),
+ );
+ await expectToFail(() =>
+ expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;'),
+ );
+
+ // Remove configuration file
+ await deleteFile('tailwind.config.js');
+
+ // Ensure Tailwind is disabled when no configuration file is present
+ await ng('build', '--configuration=development');
+ await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;');
+ await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;');
+
+ // Recreate configuration file
+ await silentExec('npx', 'tailwindcss', 'init');
+
+ // Uninstall Tailwind
+ await uninstallPackage('tailwindcss');
+
+ // Ensure installation warning is present
+ const { stderr } = await ng('build', '--configuration=development');
+ if (!stderr.includes("To enable Tailwind CSS, please install the 'tailwindcss' package.")) {
+ throw new Error('Expected tailwind installation warning');
+ }
+
+ // Tailwind directives should be unprocessed with missing package
+ await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;');
+ await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;');
+}
diff --git a/tests/legacy-cli/e2e/tests/i18n/ivy-localize-es2015.ts b/tests/legacy-cli/e2e/tests/i18n/ivy-localize-es2015.ts
index bbad96799cfb..0c9171dc743c 100644
--- a/tests/legacy-cli/e2e/tests/i18n/ivy-localize-es2015.ts
+++ b/tests/legacy-cli/e2e/tests/i18n/ivy-localize-es2015.ts
@@ -4,18 +4,14 @@ import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';
import { externalServer, langTranslations, setupI18nConfig } from './setup';
-export default async function() {
+export default async function () {
// Setup i18n tests and config.
await setupI18nConfig();
// Ensure a es2017 build is used.
await writeFile('.browserslistrc', 'Chrome 65');
- await updateJsonFile('tsconfig.json', config => {
+ await updateJsonFile('tsconfig.json', (config) => {
config.compilerOptions.target = 'es2017';
- if (!config.angularCompilerOptions) {
- config.angularCompilerOptions = {};
- }
- config.angularCompilerOptions.disableTypeScriptVersionCheck = true;
});
await ng('build', '--source-map');
diff --git a/yarn.lock b/yarn.lock
index 843398ca22aa..3b08ea88b06f 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -211,10 +211,9 @@
dependencies:
tslib "^2.0.0"
-"@angular/dev-infra-private@https://github.com/angular/dev-infra-private-builds.git#d206b030f3dc60a85777604a8f3d1bc8156454f2":
- version "0.0.0-a480a99a0d757e3b6fe9dec8ce6d3a60149efc13"
- uid d206b030f3dc60a85777604a8f3d1bc8156454f2
- resolved "https://github.com/angular/dev-infra-private-builds.git#d206b030f3dc60a85777604a8f3d1bc8156454f2"
+"@angular/dev-infra-private@https://github.com/angular/dev-infra-private-builds.git#2156ef860d69f7001c01e1fcb2c7087f8cbf8e5d":
+ version "0.0.0-0b4cae4acd9d42f33af92951947a30d6aa165070"
+ resolved "https://github.com/angular/dev-infra-private-builds.git#2156ef860d69f7001c01e1fcb2c7087f8cbf8e5d"
dependencies:
"@actions/core" "^1.4.0"
"@actions/github" "^5.0.0"
@@ -267,6 +266,7 @@
typed-graphqlify "^3.1.1"
typescript "~4.5.0"
uuid "^8.3.2"
+ which "^2.0.2"
yaml "^1.10.0"
yargs "^17.0.0"
@@ -9662,7 +9662,6 @@ sass@1.44.0, sass@^1.32.8:
"sauce-connect-proxy@https://saucelabs.com/downloads/sc-4.6.4-linux.tar.gz":
version "0.0.0"
- uid "992e2cb0d91e54b27a4f5bbd2049f3b774718115"
resolved "https://saucelabs.com/downloads/sc-4.6.4-linux.tar.gz#992e2cb0d91e54b27a4f5bbd2049f3b774718115"
saucelabs@^1.5.0:
@@ -10798,12 +10797,7 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
-typescript@4.5.3:
- version "4.5.3"
- resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.3.tgz#afaa858e68c7103317d89eb90c5d8906268d353c"
- integrity sha512-eVYaEHALSt+s9LbvgEv4Ef+Tdq7hBiIZgii12xXJnukryt3pMgJf6aKhoCZ3FWQsu6sydEnkg11fYXLzhLBjeQ==
-
-typescript@~4.5.2:
+typescript@4.5.3, typescript@~4.5.2:
version "4.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.3.tgz#afaa858e68c7103317d89eb90c5d8906268d353c"
integrity sha512-eVYaEHALSt+s9LbvgEv4Ef+Tdq7hBiIZgii12xXJnukryt3pMgJf6aKhoCZ3FWQsu6sydEnkg11fYXLzhLBjeQ==