typescript 4.6.0-dev.20220101 → 4.6.0-dev.20220105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/typescript.js CHANGED
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220101";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220105";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -22436,7 +22436,7 @@ var ts;
22436
22436
  result.push(createModifier(144 /* ReadonlyKeyword */));
22437
22437
  if (flags & 256 /* Async */)
22438
22438
  result.push(createModifier(131 /* AsyncKeyword */));
22439
- return result;
22439
+ return result.length ? result : undefined;
22440
22440
  }
22441
22441
  //
22442
22442
  // Names
@@ -26393,32 +26393,36 @@ var ts;
26393
26393
  }
26394
26394
  function updateModifiers(node, modifiers) {
26395
26395
  var _a;
26396
+ var modifierArray;
26396
26397
  if (typeof modifiers === "number") {
26397
- modifiers = createModifiersFromModifierFlags(modifiers);
26398
- }
26399
- return ts.isParameter(node) ? updateParameterDeclaration(node, node.decorators, modifiers, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) :
26400
- ts.isPropertySignature(node) ? updatePropertySignature(node, modifiers, node.name, node.questionToken, node.type) :
26401
- ts.isPropertyDeclaration(node) ? updatePropertyDeclaration(node, node.decorators, modifiers, node.name, (_a = node.questionToken) !== null && _a !== void 0 ? _a : node.exclamationToken, node.type, node.initializer) :
26402
- ts.isMethodSignature(node) ? updateMethodSignature(node, modifiers, node.name, node.questionToken, node.typeParameters, node.parameters, node.type) :
26403
- ts.isMethodDeclaration(node) ? updateMethodDeclaration(node, node.decorators, modifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body) :
26404
- ts.isConstructorDeclaration(node) ? updateConstructorDeclaration(node, node.decorators, modifiers, node.parameters, node.body) :
26405
- ts.isGetAccessorDeclaration(node) ? updateGetAccessorDeclaration(node, node.decorators, modifiers, node.name, node.parameters, node.type, node.body) :
26406
- ts.isSetAccessorDeclaration(node) ? updateSetAccessorDeclaration(node, node.decorators, modifiers, node.name, node.parameters, node.body) :
26407
- ts.isIndexSignatureDeclaration(node) ? updateIndexSignature(node, node.decorators, modifiers, node.parameters, node.type) :
26408
- ts.isFunctionExpression(node) ? updateFunctionExpression(node, modifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
26409
- ts.isArrowFunction(node) ? updateArrowFunction(node, modifiers, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, node.body) :
26410
- ts.isClassExpression(node) ? updateClassExpression(node, node.decorators, modifiers, node.name, node.typeParameters, node.heritageClauses, node.members) :
26411
- ts.isVariableStatement(node) ? updateVariableStatement(node, modifiers, node.declarationList) :
26412
- ts.isFunctionDeclaration(node) ? updateFunctionDeclaration(node, node.decorators, modifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
26413
- ts.isClassDeclaration(node) ? updateClassDeclaration(node, node.decorators, modifiers, node.name, node.typeParameters, node.heritageClauses, node.members) :
26414
- ts.isInterfaceDeclaration(node) ? updateInterfaceDeclaration(node, node.decorators, modifiers, node.name, node.typeParameters, node.heritageClauses, node.members) :
26415
- ts.isTypeAliasDeclaration(node) ? updateTypeAliasDeclaration(node, node.decorators, modifiers, node.name, node.typeParameters, node.type) :
26416
- ts.isEnumDeclaration(node) ? updateEnumDeclaration(node, node.decorators, modifiers, node.name, node.members) :
26417
- ts.isModuleDeclaration(node) ? updateModuleDeclaration(node, node.decorators, modifiers, node.name, node.body) :
26418
- ts.isImportEqualsDeclaration(node) ? updateImportEqualsDeclaration(node, node.decorators, modifiers, node.isTypeOnly, node.name, node.moduleReference) :
26419
- ts.isImportDeclaration(node) ? updateImportDeclaration(node, node.decorators, modifiers, node.importClause, node.moduleSpecifier, node.assertClause) :
26420
- ts.isExportAssignment(node) ? updateExportAssignment(node, node.decorators, modifiers, node.expression) :
26421
- ts.isExportDeclaration(node) ? updateExportDeclaration(node, node.decorators, modifiers, node.isTypeOnly, node.exportClause, node.moduleSpecifier, node.assertClause) :
26398
+ modifierArray = createModifiersFromModifierFlags(modifiers);
26399
+ }
26400
+ else {
26401
+ modifierArray = modifiers;
26402
+ }
26403
+ return ts.isParameter(node) ? updateParameterDeclaration(node, node.decorators, modifierArray, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) :
26404
+ ts.isPropertySignature(node) ? updatePropertySignature(node, modifierArray, node.name, node.questionToken, node.type) :
26405
+ ts.isPropertyDeclaration(node) ? updatePropertyDeclaration(node, node.decorators, modifierArray, node.name, (_a = node.questionToken) !== null && _a !== void 0 ? _a : node.exclamationToken, node.type, node.initializer) :
26406
+ ts.isMethodSignature(node) ? updateMethodSignature(node, modifierArray, node.name, node.questionToken, node.typeParameters, node.parameters, node.type) :
26407
+ ts.isMethodDeclaration(node) ? updateMethodDeclaration(node, node.decorators, modifierArray, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body) :
26408
+ ts.isConstructorDeclaration(node) ? updateConstructorDeclaration(node, node.decorators, modifierArray, node.parameters, node.body) :
26409
+ ts.isGetAccessorDeclaration(node) ? updateGetAccessorDeclaration(node, node.decorators, modifierArray, node.name, node.parameters, node.type, node.body) :
26410
+ ts.isSetAccessorDeclaration(node) ? updateSetAccessorDeclaration(node, node.decorators, modifierArray, node.name, node.parameters, node.body) :
26411
+ ts.isIndexSignatureDeclaration(node) ? updateIndexSignature(node, node.decorators, modifierArray, node.parameters, node.type) :
26412
+ ts.isFunctionExpression(node) ? updateFunctionExpression(node, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
26413
+ ts.isArrowFunction(node) ? updateArrowFunction(node, modifierArray, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, node.body) :
26414
+ ts.isClassExpression(node) ? updateClassExpression(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
26415
+ ts.isVariableStatement(node) ? updateVariableStatement(node, modifierArray, node.declarationList) :
26416
+ ts.isFunctionDeclaration(node) ? updateFunctionDeclaration(node, node.decorators, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
26417
+ ts.isClassDeclaration(node) ? updateClassDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
26418
+ ts.isInterfaceDeclaration(node) ? updateInterfaceDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
26419
+ ts.isTypeAliasDeclaration(node) ? updateTypeAliasDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.type) :
26420
+ ts.isEnumDeclaration(node) ? updateEnumDeclaration(node, node.decorators, modifierArray, node.name, node.members) :
26421
+ ts.isModuleDeclaration(node) ? updateModuleDeclaration(node, node.decorators, modifierArray, node.name, node.body) :
26422
+ ts.isImportEqualsDeclaration(node) ? updateImportEqualsDeclaration(node, node.decorators, modifierArray, node.isTypeOnly, node.name, node.moduleReference) :
26423
+ ts.isImportDeclaration(node) ? updateImportDeclaration(node, node.decorators, modifierArray, node.importClause, node.moduleSpecifier, node.assertClause) :
26424
+ ts.isExportAssignment(node) ? updateExportAssignment(node, node.decorators, modifierArray, node.expression) :
26425
+ ts.isExportDeclaration(node) ? updateExportDeclaration(node, node.decorators, modifierArray, node.isTypeOnly, node.exportClause, node.moduleSpecifier, node.assertClause) :
26422
26426
  ts.Debug.assertNever(node);
26423
26427
  }
26424
26428
  function asNodeArray(array) {
@@ -67631,7 +67635,8 @@ var ts;
67631
67635
  return access.kind === 205 /* PropertyAccessExpression */ ? access.name.escapedText :
67632
67636
  access.kind === 206 /* ElementAccessExpression */ && ts.isStringOrNumericLiteralLike(access.argumentExpression) ? ts.escapeLeadingUnderscores(access.argumentExpression.text) :
67633
67637
  access.kind === 202 /* BindingElement */ && (propertyName = getDestructuringPropertyName(access)) ? ts.escapeLeadingUnderscores(propertyName) :
67634
- undefined;
67638
+ access.kind === 163 /* Parameter */ ? ("" + access.parent.parameters.indexOf(access)) :
67639
+ undefined;
67635
67640
  }
67636
67641
  function containsMatchingReference(source, target) {
67637
67642
  while (ts.isAccessExpression(source)) {
@@ -68971,13 +68976,14 @@ var ts;
68971
68976
  return result;
68972
68977
  }
68973
68978
  function getCandidateDiscriminantPropertyAccess(expr) {
68974
- if (ts.isBindingPattern(reference)) {
68975
- // When the reference is a binding pattern, we are narrowing a pesudo-reference in getNarrowedTypeOfSymbol.
68976
- // An identifier for a destructuring variable declared in the same binding pattern is a candidate.
68979
+ if (ts.isBindingPattern(reference) || ts.isFunctionExpressionOrArrowFunction(reference)) {
68980
+ // When the reference is a binding pattern or function or arrow expression, we are narrowing a pesudo-reference in
68981
+ // getNarrowedTypeOfSymbol. An identifier for a destructuring variable declared in the same binding pattern or
68982
+ // parameter declared in the same parameter list is a candidate.
68977
68983
  if (ts.isIdentifier(expr)) {
68978
68984
  var symbol = getResolvedSymbol(expr);
68979
68985
  var declaration = symbol.valueDeclaration;
68980
- if (declaration && ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && reference === declaration.parent) {
68986
+ if (declaration && (ts.isBindingElement(declaration) || ts.isParameter(declaration)) && reference === declaration.parent && !declaration.initializer && !declaration.dotDotDotToken) {
68981
68987
  return declaration;
68982
68988
  }
68983
68989
  }
@@ -69779,42 +69785,78 @@ var ts;
69779
69785
  }
69780
69786
  }
69781
69787
  function getNarrowedTypeOfSymbol(symbol, location) {
69782
- // If we have a non-rest binding element with no initializer declared as a const variable or a const-like
69783
- // parameter (a parameter for which there are no assignments in the function body), and if the parent type
69784
- // for the destructuring is a union type, one or more of the binding elements may represent discriminant
69785
- // properties, and we want the effects of conditional checks on such discriminants to affect the types of
69786
- // other binding elements from the same destructuring. Consider:
69787
- //
69788
- // type Action =
69789
- // | { kind: 'A', payload: number }
69790
- // | { kind: 'B', payload: string };
69791
- //
69792
- // function f1({ kind, payload }: Action) {
69793
- // if (kind === 'A') {
69794
- // payload.toFixed();
69795
- // }
69796
- // if (kind === 'B') {
69797
- // payload.toUpperCase();
69798
- // }
69799
- // }
69800
- //
69801
- // Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
69802
- // the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
69803
- // as if it occurred in the specified location. We then recompute the narrowed binding element type by
69804
- // destructuring from the narrowed parent type.
69805
69788
  var declaration = symbol.valueDeclaration;
69806
- if (declaration && ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) {
69807
- var parent = declaration.parent.parent;
69808
- if (parent.kind === 253 /* VariableDeclaration */ && ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || parent.kind === 163 /* Parameter */) {
69809
- var links = getNodeLinks(location);
69810
- if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
69811
- links.flags |= 268435456 /* InCheckIdentifier */;
69812
- var parentType = getTypeForBindingElementParent(parent);
69813
- links.flags &= ~268435456 /* InCheckIdentifier */;
69814
- if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
69815
- var pattern = declaration.parent;
69816
- var narrowedType = getFlowTypeOfReference(pattern, parentType, parentType, /*flowContainer*/ undefined, location.flowNode);
69817
- return getBindingElementTypeFromParentType(declaration, narrowedType);
69789
+ if (declaration) {
69790
+ // If we have a non-rest binding element with no initializer declared as a const variable or a const-like
69791
+ // parameter (a parameter for which there are no assignments in the function body), and if the parent type
69792
+ // for the destructuring is a union type, one or more of the binding elements may represent discriminant
69793
+ // properties, and we want the effects of conditional checks on such discriminants to affect the types of
69794
+ // other binding elements from the same destructuring. Consider:
69795
+ //
69796
+ // type Action =
69797
+ // | { kind: 'A', payload: number }
69798
+ // | { kind: 'B', payload: string };
69799
+ //
69800
+ // function f({ kind, payload }: Action) {
69801
+ // if (kind === 'A') {
69802
+ // payload.toFixed();
69803
+ // }
69804
+ // if (kind === 'B') {
69805
+ // payload.toUpperCase();
69806
+ // }
69807
+ // }
69808
+ //
69809
+ // Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
69810
+ // the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
69811
+ // as if it occurred in the specified location. We then recompute the narrowed binding element type by
69812
+ // destructuring from the narrowed parent type.
69813
+ if (ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) {
69814
+ var parent = declaration.parent.parent;
69815
+ if (parent.kind === 253 /* VariableDeclaration */ && ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || parent.kind === 163 /* Parameter */) {
69816
+ var links = getNodeLinks(location);
69817
+ if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
69818
+ links.flags |= 268435456 /* InCheckIdentifier */;
69819
+ var parentType = getTypeForBindingElementParent(parent);
69820
+ links.flags &= ~268435456 /* InCheckIdentifier */;
69821
+ if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
69822
+ var pattern = declaration.parent;
69823
+ var narrowedType = getFlowTypeOfReference(pattern, parentType, parentType, /*flowContainer*/ undefined, location.flowNode);
69824
+ return getBindingElementTypeFromParentType(declaration, narrowedType);
69825
+ }
69826
+ }
69827
+ }
69828
+ }
69829
+ // If we have a const-like parameter with no type annotation or initializer, and if the parameter is contextually
69830
+ // typed by a signature with a single rest parameter of a union of tuple types, one or more of the parameters may
69831
+ // represent discriminant tuple elements, and we want the effects of conditional checks on such discriminants to
69832
+ // affect the types of other parameters in the same parameter list. Consider:
69833
+ //
69834
+ // type Action = [kind: 'A', payload: number] | [kind: 'B', payload: string];
69835
+ //
69836
+ // const f: (...args: Action) => void = (kind, payload) => {
69837
+ // if (kind === 'A') {
69838
+ // payload.toFixed();
69839
+ // }
69840
+ // if (kind === 'B') {
69841
+ // payload.toUpperCase();
69842
+ // }
69843
+ // }
69844
+ //
69845
+ // Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
69846
+ // the arrow function AST node for '(kind, payload) => ...' as a pseudo-reference and narrow this reference as
69847
+ // if it occurred in the specified location. We then recompute the narrowed parameter type by indexing into the
69848
+ // narrowed tuple type.
69849
+ if (ts.isParameter(declaration) && !declaration.type && !declaration.initializer && !declaration.dotDotDotToken) {
69850
+ var func = declaration.parent;
69851
+ if (func.parameters.length >= 2 && isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
69852
+ var contextualSignature = getContextualSignature(func);
69853
+ if (contextualSignature && contextualSignature.parameters.length === 1 && signatureHasRestParameter(contextualSignature)) {
69854
+ var restType = getTypeOfSymbol(contextualSignature.parameters[0]);
69855
+ if (restType.flags & 1048576 /* Union */ && everyType(restType, isTupleType) && !isSymbolAssigned(symbol)) {
69856
+ var narrowedType = getFlowTypeOfReference(func, restType, restType, /*flowContainer*/ undefined, location.flowNode);
69857
+ var index = func.parameters.indexOf(declaration) - (ts.getThisParameter(func) ? 1 : 0);
69858
+ return getIndexedAccessType(narrowedType, getNumberLiteralType(index));
69859
+ }
69818
69860
  }
69819
69861
  }
69820
69862
  }
@@ -109212,7 +109254,7 @@ var ts;
109212
109254
  emitPlaceholder(hint, node, snippet);
109213
109255
  break;
109214
109256
  case 0 /* TabStop */:
109215
- emitTabStop(snippet);
109257
+ emitTabStop(hint, node, snippet);
109216
109258
  break;
109217
109259
  }
109218
109260
  }
@@ -109222,7 +109264,10 @@ var ts;
109222
109264
  nonEscapingWrite("}"); // `}`
109223
109265
  // `${2:...}`
109224
109266
  }
109225
- function emitTabStop(snippet) {
109267
+ function emitTabStop(hint, node, snippet) {
109268
+ // A tab stop should only be attached to an empty node, i.e. a node that doesn't emit any text.
109269
+ ts.Debug.assert(node.kind === 235 /* EmptyStatement */, "A tab stop cannot be attached to a node of kind " + ts.Debug.formatSyntaxKind(node.kind) + ".");
109270
+ ts.Debug.assert(hint !== 5 /* EmbeddedStatement */, "A tab stop cannot be attached to an embedded statement.");
109226
109271
  nonEscapingWrite("$" + snippet.order);
109227
109272
  }
109228
109273
  //
@@ -126748,6 +126793,16 @@ var ts;
126748
126793
  : ts.getLocaleSpecificMessage(diag);
126749
126794
  }
126750
126795
  ts.diagnosticToString = diagnosticToString;
126796
+ /**
126797
+ * Get format code settings for a code writing context (e.g. when formatting text changes or completions code).
126798
+ */
126799
+ function getFormatCodeSettingsForWriting(_a, sourceFile) {
126800
+ var options = _a.options;
126801
+ var shouldAutoDetectSemicolonPreference = !options.semicolons || options.semicolons === ts.SemicolonPreference.Ignore;
126802
+ var shouldRemoveSemicolons = options.semicolons === ts.SemicolonPreference.Remove || shouldAutoDetectSemicolonPreference && !probablyUsesSemicolons(sourceFile);
126803
+ return __assign(__assign({}, options), { semicolons: shouldRemoveSemicolons ? ts.SemicolonPreference.Remove : ts.SemicolonPreference.Ignore });
126804
+ }
126805
+ ts.getFormatCodeSettingsForWriting = getFormatCodeSettingsForWriting;
126751
126806
  // #endregion
126752
126807
  })(ts || (ts = {}));
126753
126808
  /*@internal*/
@@ -128371,7 +128426,8 @@ var ts;
128371
128426
  return convertPathCompletions(completion.paths);
128372
128427
  case 1 /* Properties */: {
128373
128428
  var entries = ts.createSortedArray();
128374
- 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
128429
+ Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, contextToken, sourceFile, sourceFile, host, program, 99 /* ESNext */, log, 4 /* String */, preferences, options,
128430
+ /*formatContext*/ undefined); // Target will not be used, so arbitrary
128375
128431
  return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: completion.hasIndexSignature, optionalReplacementSpan: optionalReplacementSpan, entries: entries };
128376
128432
  }
128377
128433
  case 2 /* Types */: {
@@ -129192,7 +129248,7 @@ var ts;
129192
129248
  return result;
129193
129249
  }
129194
129250
  }
129195
- function getCompletionsAtPosition(host, program, log, sourceFile, position, preferences, triggerCharacter, completionKind, cancellationToken) {
129251
+ function getCompletionsAtPosition(host, program, log, sourceFile, position, preferences, triggerCharacter, completionKind, cancellationToken, formatContext) {
129196
129252
  var _a;
129197
129253
  var previousToken = getRelevantTokens(position, sourceFile).previousToken;
129198
129254
  if (triggerCharacter && !ts.isInString(sourceFile, position, previousToken) && !isValidTrigger(sourceFile, triggerCharacter, previousToken, position)) {
@@ -129232,7 +129288,7 @@ var ts;
129232
129288
  }
129233
129289
  switch (completionData.kind) {
129234
129290
  case 0 /* Data */:
129235
- var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences);
129291
+ var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext);
129236
129292
  if (response === null || response === void 0 ? void 0 : response.isIncomplete) {
129237
129293
  incompleteCompletionsCache === null || incompleteCompletionsCache === void 0 ? void 0 : incompleteCompletionsCache.set(response);
129238
129294
  }
@@ -129352,7 +129408,7 @@ var ts;
129352
129408
  // StringLiteralLike locations are handled separately in stringCompletions.ts
129353
129409
  return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
129354
129410
  }
129355
- function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences) {
129411
+ function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext) {
129356
129412
  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;
129357
129413
  // Verify if the file is JSX language variant
129358
129414
  if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
@@ -129364,7 +129420,7 @@ var ts;
129364
129420
  var entries = ts.createSortedArray();
129365
129421
  if (isUncheckedFile(sourceFile, compilerOptions)) {
129366
129422
  var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
129367
- /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
129423
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
129368
129424
  getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
129369
129425
  }
129370
129426
  else {
@@ -129372,7 +129428,7 @@ var ts;
129372
129428
  return undefined;
129373
129429
  }
129374
129430
  getCompletionEntriesFromSymbols(symbols, entries,
129375
- /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
129431
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
129376
129432
  }
129377
129433
  if (keywordFilters !== 0 /* None */) {
129378
129434
  var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
@@ -129478,7 +129534,7 @@ var ts;
129478
129534
  function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
129479
129535
  return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
129480
129536
  }
129481
- function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind) {
129537
+ function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext) {
129482
129538
  var _a, _b;
129483
129539
  var insertText;
129484
129540
  var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
@@ -129543,7 +129599,7 @@ var ts;
129543
129599
  completionKind === 3 /* MemberLike */ &&
129544
129600
  isClassLikeMemberCompletion(symbol, location)) {
129545
129601
  var importAdder = void 0;
129546
- (_b = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken), insertText = _b.insertText, isSnippet = _b.isSnippet, importAdder = _b.importAdder);
129602
+ (_b = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken, formatContext), insertText = _b.insertText, isSnippet = _b.isSnippet, importAdder = _b.importAdder);
129547
129603
  if (importAdder === null || importAdder === void 0 ? void 0 : importAdder.hasFixes()) {
129548
129604
  hasAction = true;
129549
129605
  source = CompletionSource.ClassMemberSnippet;
@@ -129642,7 +129698,7 @@ var ts;
129642
129698
  ts.isSyntaxList(location) &&
129643
129699
  ts.isClassLike(location.parent)));
129644
129700
  }
129645
- function getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken) {
129701
+ function getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken, formatContext) {
129646
129702
  var classLikeDeclaration = ts.findAncestor(location, ts.isClassLike);
129647
129703
  if (!classLikeDeclaration) {
129648
129704
  return { insertText: name };
@@ -129659,15 +129715,16 @@ var ts;
129659
129715
  newLine: ts.getNewLineKind(ts.getNewLineCharacter(options, ts.maybeBind(host, host.getNewLine))),
129660
129716
  });
129661
129717
  var importAdder = ts.codefix.createImportAdder(sourceFile, program, preferences, host);
129718
+ // Create empty body for possible method implementation.
129662
129719
  var body;
129663
129720
  if (preferences.includeCompletionsWithSnippetText) {
129664
129721
  isSnippet = true;
129665
129722
  // We are adding a tabstop (i.e. `$0`) in the body of the suggested member,
129666
129723
  // if it has one, so that the cursor ends up in the body once the completion is inserted.
129667
129724
  // Note: this assumes we won't have more than one body in the completion nodes, which should be the case.
129668
- var emptyStatement = ts.factory.createExpressionStatement(ts.factory.createIdentifier(""));
129669
- ts.setSnippetElement(emptyStatement, { kind: 0 /* TabStop */, order: 0 });
129670
- body = ts.factory.createBlock([emptyStatement], /* multiline */ true);
129725
+ var emptyStmt = ts.factory.createEmptyStatement();
129726
+ body = ts.factory.createBlock([emptyStmt], /* multiline */ true);
129727
+ ts.setSnippetElement(emptyStmt, { kind: 0 /* TabStop */, order: 0 });
129671
129728
  }
129672
129729
  else {
129673
129730
  body = ts.factory.createBlock([], /* multiline */ true);
@@ -129713,7 +129770,27 @@ var ts;
129713
129770
  completionNodes.push(node);
129714
129771
  }, body, 2 /* Property */, isAbstract);
129715
129772
  if (completionNodes.length) {
129716
- insertText = printer.printSnippetList(1 /* MultiLine */ | 131072 /* NoTrailingNewLine */, ts.factory.createNodeArray(completionNodes), sourceFile);
129773
+ // If we have access to formatting settings, we print the nodes using the emitter,
129774
+ // and then format the printed text.
129775
+ if (formatContext) {
129776
+ var syntheticFile_1 = {
129777
+ text: printer.printSnippetList(1 /* MultiLine */ | 131072 /* NoTrailingNewLine */, ts.factory.createNodeArray(completionNodes), sourceFile),
129778
+ getLineAndCharacterOfPosition: function (pos) {
129779
+ return ts.getLineAndCharacterOfPosition(this, pos);
129780
+ },
129781
+ };
129782
+ var formatOptions_1 = ts.getFormatCodeSettingsForWriting(formatContext, sourceFile);
129783
+ var changes = ts.flatMap(completionNodes, function (node) {
129784
+ var nodeWithPos = ts.textChanges.assignPositionsToNode(node);
129785
+ return ts.formatting.formatNodeGivenIndentation(nodeWithPos, syntheticFile_1, sourceFile.languageVariant,
129786
+ /* indentation */ 0,
129787
+ /* delta */ 0, __assign(__assign({}, formatContext), { options: formatOptions_1 }));
129788
+ });
129789
+ insertText = ts.textChanges.applyChanges(syntheticFile_1.text, changes);
129790
+ }
129791
+ else { // Otherwise, just use emitter to print the new nodes.
129792
+ insertText = printer.printSnippetList(1 /* MultiLine */ | 131072 /* NoTrailingNewLine */, ts.factory.createNodeArray(completionNodes), sourceFile);
129793
+ }
129717
129794
  }
129718
129795
  return { insertText: insertText, isSnippet: isSnippet, importAdder: importAdder };
129719
129796
  }
@@ -129757,8 +129834,8 @@ var ts;
129757
129834
  return undefined;
129758
129835
  }
129759
129836
  function createSnippetPrinter(printerOptions) {
129760
- var printer = ts.createPrinter(printerOptions);
129761
- var baseWriter = ts.createTextWriter(ts.getNewLineCharacter(printerOptions));
129837
+ var baseWriter = ts.textChanges.createWriter(ts.getNewLineCharacter(printerOptions));
129838
+ var printer = ts.createPrinter(printerOptions, baseWriter);
129762
129839
  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)); } });
129763
129840
  return {
129764
129841
  printSnippetList: printSnippetList,
@@ -129863,7 +129940,7 @@ var ts;
129863
129940
  return CompletionSource.ThisProperty;
129864
129941
  }
129865
129942
  }
129866
- function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
129943
+ function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
129867
129944
  var _a;
129868
129945
  var start = ts.timestamp();
129869
129946
  var variableDeclaration = getVariableDeclaration(location);
@@ -129884,7 +129961,7 @@ var ts;
129884
129961
  var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
129885
129962
  var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
129886
129963
  var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
129887
- var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind);
129964
+ var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, formatContext);
129888
129965
  if (!entry) {
129889
129966
  continue;
129890
129967
  }
@@ -130080,7 +130157,7 @@ var ts;
130080
130157
  }
130081
130158
  }
130082
130159
  if (source === CompletionSource.ClassMemberSnippet) {
130083
- var importAdder = getEntryForMemberCompletion(host, program, compilerOptions, preferences, name, symbol, location, contextToken).importAdder;
130160
+ var importAdder = getEntryForMemberCompletion(host, program, compilerOptions, preferences, name, symbol, location, contextToken, formatContext).importAdder;
130084
130161
  if (importAdder) {
130085
130162
  var changes = ts.textChanges.ChangeTracker.with({ host: host, formatContext: formatContext, preferences: preferences }, importAdder.writeFixes);
130086
130163
  return {
@@ -145964,19 +146041,13 @@ var ts;
145964
146041
  + ((!options.suffix || ts.endsWith(noIndent, options.suffix))
145965
146042
  ? "" : options.suffix);
145966
146043
  }
145967
- function getFormatCodeSettingsForWriting(_a, sourceFile) {
145968
- var options = _a.options;
145969
- var shouldAutoDetectSemicolonPreference = !options.semicolons || options.semicolons === ts.SemicolonPreference.Ignore;
145970
- var shouldRemoveSemicolons = options.semicolons === ts.SemicolonPreference.Remove || shouldAutoDetectSemicolonPreference && !ts.probablyUsesSemicolons(sourceFile);
145971
- return __assign(__assign({}, options), { semicolons: shouldRemoveSemicolons ? ts.SemicolonPreference.Remove : ts.SemicolonPreference.Ignore });
145972
- }
145973
146044
  /** Note: this may mutate `nodeIn`. */
145974
146045
  function getFormattedTextOfNode(nodeIn, sourceFile, pos, _a, newLineCharacter, formatContext, validate) {
145975
146046
  var indentation = _a.indentation, prefix = _a.prefix, delta = _a.delta;
145976
146047
  var _b = getNonformattedText(nodeIn, sourceFile, newLineCharacter), node = _b.node, text = _b.text;
145977
146048
  if (validate)
145978
146049
  validate(node, text);
145979
- var formatOptions = getFormatCodeSettingsForWriting(formatContext, sourceFile);
146050
+ var formatOptions = ts.getFormatCodeSettingsForWriting(formatContext, sourceFile);
145980
146051
  var initialIndentation = indentation !== undefined
145981
146052
  ? indentation
145982
146053
  : ts.formatting.SmartIndenter.getIndentation(pos, sourceFile, formatOptions, prefix === newLineCharacter || ts.getLineStartPositionForPosition(pos, sourceFile) === pos);
@@ -146024,6 +146095,7 @@ var ts;
146024
146095
  ts.setTextRangePosEnd(newNode, getPos(node), getEnd(node));
146025
146096
  return newNode;
146026
146097
  }
146098
+ textChanges_3.assignPositionsToNode = assignPositionsToNode;
146027
146099
  function assignPositionsToNodeArray(nodes, visitor, test, start, count) {
146028
146100
  var visited = ts.visitNodes(nodes, visitor, test, start, count);
146029
146101
  if (!visited) {
@@ -146194,6 +146266,7 @@ var ts;
146194
146266
  clear: clear
146195
146267
  };
146196
146268
  }
146269
+ textChanges_3.createWriter = createWriter;
146197
146270
  function getInsertionPositionAtSourceFileTop(sourceFile) {
146198
146271
  var lastPrologue;
146199
146272
  for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
@@ -161091,12 +161164,12 @@ var ts;
161091
161164
  synchronizeHostData();
161092
161165
  return __spreadArray(__spreadArray([], program.getOptionsDiagnostics(cancellationToken), true), program.getGlobalDiagnostics(cancellationToken), true);
161093
161166
  }
161094
- function getCompletionsAtPosition(fileName, position, options) {
161167
+ function getCompletionsAtPosition(fileName, position, options, formattingSettings) {
161095
161168
  if (options === void 0) { options = ts.emptyOptions; }
161096
161169
  // Convert from deprecated options names to new names
161097
161170
  var fullPreferences = __assign(__assign({}, ts.identity(options)), { includeCompletionsForModuleExports: options.includeCompletionsForModuleExports || options.includeExternalModuleExports, includeCompletionsWithInsertText: options.includeCompletionsWithInsertText || options.includeInsertTextCompletions });
161098
161171
  synchronizeHostData();
161099
- return ts.Completions.getCompletionsAtPosition(host, program, log, getValidSourceFile(fileName), position, fullPreferences, options.triggerCharacter, options.triggerKind, cancellationToken);
161172
+ return ts.Completions.getCompletionsAtPosition(host, program, log, getValidSourceFile(fileName), position, fullPreferences, options.triggerCharacter, options.triggerKind, cancellationToken, formattingSettings && ts.formatting.getFormatContext(formattingSettings, host));
161100
161173
  }
161101
161174
  function getCompletionEntryDetails(fileName, position, name, formattingOptions, source, preferences, data) {
161102
161175
  if (preferences === void 0) { preferences = ts.emptyOptions; }
@@ -163259,9 +163332,9 @@ var ts;
163259
163332
  * to provide at the given source position and providing a member completion
163260
163333
  * list if requested.
163261
163334
  */
163262
- LanguageServiceShimObject.prototype.getCompletionsAtPosition = function (fileName, position, preferences) {
163335
+ LanguageServiceShimObject.prototype.getCompletionsAtPosition = function (fileName, position, preferences, formattingSettings) {
163263
163336
  var _this = this;
163264
- return this.forwardJSONCall("getCompletionsAtPosition('" + fileName + "', " + position + ", " + preferences + ")", function () { return _this.languageService.getCompletionsAtPosition(fileName, position, preferences); });
163337
+ return this.forwardJSONCall("getCompletionsAtPosition('" + fileName + "', " + position + ", " + preferences + ", " + formattingSettings + ")", function () { return _this.languageService.getCompletionsAtPosition(fileName, position, preferences, formattingSettings); });
163265
163338
  };
163266
163339
  /** Get a string based representation of a completion list entry details */
163267
163340
  LanguageServiceShimObject.prototype.getCompletionEntryDetails = function (fileName, position, entryName, formatOptions, source, preferences, data) {
@@ -3344,7 +3344,7 @@ declare namespace ts {
3344
3344
  createTrue(): TrueLiteral;
3345
3345
  createFalse(): FalseLiteral;
3346
3346
  createModifier<T extends ModifierSyntaxKind>(kind: T): ModifierToken<T>;
3347
- createModifiersFromModifierFlags(flags: ModifierFlags): Modifier[];
3347
+ createModifiersFromModifierFlags(flags: ModifierFlags): Modifier[] | undefined;
3348
3348
  createQualifiedName(left: EntityName, right: string | Identifier): QualifiedName;
3349
3349
  updateQualifiedName(node: QualifiedName, left: EntityName, right: Identifier): QualifiedName;
3350
3350
  createComputedPropertyName(expression: Expression): ComputedPropertyName;
@@ -5760,8 +5760,9 @@ declare namespace ts {
5760
5760
  * @param position A zero-based index of the character where you want the entries
5761
5761
  * @param options An object describing how the request was triggered and what kinds
5762
5762
  * of code actions can be returned with the completions.
5763
+ * @param formattingSettings settings needed for calling formatting functions.
5763
5764
  */
5764
- getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): WithMetadata<CompletionInfo> | undefined;
5765
+ getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined, formattingSettings?: FormatCodeSettings): WithMetadata<CompletionInfo> | undefined;
5765
5766
  /**
5766
5767
  * Gets the extended details for a completion entry retrieved from `getCompletionsAtPosition`.
5767
5768
  *
@@ -6862,7 +6863,7 @@ declare namespace ts {
6862
6863
  /** @deprecated Use `factory.createModifier` or the factory supplied by your transformation context instead. */
6863
6864
  const createModifier: <T extends ModifierSyntaxKind>(kind: T) => ModifierToken<T>;
6864
6865
  /** @deprecated Use `factory.createModifiersFromModifierFlags` or the factory supplied by your transformation context instead. */
6865
- const createModifiersFromModifierFlags: (flags: ModifierFlags) => Modifier[];
6866
+ const createModifiersFromModifierFlags: (flags: ModifierFlags) => Modifier[] | undefined;
6866
6867
  /** @deprecated Use `factory.createQualifiedName` or the factory supplied by your transformation context instead. */
6867
6868
  const createQualifiedName: (left: EntityName, right: string | Identifier) => QualifiedName;
6868
6869
  /** @deprecated Use `factory.updateQualifiedName` or the factory supplied by your transformation context instead. */