typescript 4.6.0-dev.20220115 → 4.6.0-dev.20220119

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/tsserver.js CHANGED
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-dev.20220115";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220119";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -44497,7 +44497,7 @@ var ts;
44497
44497
  maybeBindExpressionFlowIfCall(node.expression);
44498
44498
  }
44499
44499
  function maybeBindExpressionFlowIfCall(node) {
44500
- // A top level or LHS of comma expression call expression with a dotted function name and at least one argument
44500
+ // A top level or comma expression call expression with a dotted function name and at least one argument
44501
44501
  // is potentially an assertion and is therefore included in the control flow.
44502
44502
  if (node.kind === 207 /* CallExpression */) {
44503
44503
  var call = node;
@@ -44665,22 +44665,27 @@ var ts;
44665
44665
  }
44666
44666
  return state;
44667
44667
  }
44668
- function onLeft(left, state, _node) {
44668
+ function onLeft(left, state, node) {
44669
44669
  if (!state.skip) {
44670
- return maybeBind(left);
44670
+ var maybeBound = maybeBind(left);
44671
+ if (node.operatorToken.kind === 27 /* CommaToken */) {
44672
+ maybeBindExpressionFlowIfCall(left);
44673
+ }
44674
+ return maybeBound;
44671
44675
  }
44672
44676
  }
44673
- function onOperator(operatorToken, state, node) {
44677
+ function onOperator(operatorToken, state, _node) {
44674
44678
  if (!state.skip) {
44675
- if (operatorToken.kind === 27 /* CommaToken */) {
44676
- maybeBindExpressionFlowIfCall(node.left);
44677
- }
44678
44679
  bind(operatorToken);
44679
44680
  }
44680
44681
  }
44681
- function onRight(right, state, _node) {
44682
+ function onRight(right, state, node) {
44682
44683
  if (!state.skip) {
44683
- return maybeBind(right);
44684
+ var maybeBound = maybeBind(right);
44685
+ if (node.operatorToken.kind === 27 /* CommaToken */) {
44686
+ maybeBindExpressionFlowIfCall(right);
44687
+ }
44688
+ return maybeBound;
44684
44689
  }
44685
44690
  }
44686
44691
  function onExit(node, state) {
@@ -50957,6 +50962,7 @@ var ts;
50957
50962
  getCommonSourceDirectory: !!host.getCommonSourceDirectory ? function () { return host.getCommonSourceDirectory(); } : function () { return ""; },
50958
50963
  getCurrentDirectory: function () { return host.getCurrentDirectory(); },
50959
50964
  getSymlinkCache: ts.maybeBind(host, host.getSymlinkCache),
50965
+ getPackageJsonInfoCache: function () { var _a; return (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host); },
50960
50966
  useCaseSensitiveFileNames: ts.maybeBind(host, host.useCaseSensitiveFileNames),
50961
50967
  redirectTargetsMap: host.redirectTargetsMap,
50962
50968
  getProjectReferenceRedirect: function (fileName) { return host.getProjectReferenceRedirect(fileName); },
@@ -95529,10 +95535,19 @@ var ts;
95529
95535
  var _a;
95530
95536
  var nonWhitespaceChildren = ts.getSemanticJsxChildren(children);
95531
95537
  var isStaticChildren = ts.length(nonWhitespaceChildren) > 1 || !!((_a = nonWhitespaceChildren[0]) === null || _a === void 0 ? void 0 : _a.dotDotDotToken);
95532
- var args = [tagName, objectProperties, !keyAttr ? factory.createVoidZero() : transformJsxAttributeInitializer(keyAttr.initializer)];
95538
+ var args = [tagName, objectProperties];
95539
+ // function jsx(type, config, maybeKey) {}
95540
+ // "maybeKey" is optional. It is acceptable to use "_jsx" without a third argument
95541
+ if (keyAttr) {
95542
+ args.push(transformJsxAttributeInitializer(keyAttr.initializer));
95543
+ }
95533
95544
  if (compilerOptions.jsx === 5 /* ReactJSXDev */) {
95534
95545
  var originalFile = ts.getOriginalNode(currentSourceFile);
95535
95546
  if (originalFile && ts.isSourceFile(originalFile)) {
95547
+ // "maybeKey" has to be replaced with "void 0" to not break the jsxDEV signature
95548
+ if (keyAttr === undefined) {
95549
+ args.push(factory.createVoidZero());
95550
+ }
95536
95551
  // isStaticChildren development flag
95537
95552
  args.push(isStaticChildren ? factory.createTrue() : factory.createFalse());
95538
95553
  // __source development flag
@@ -119397,11 +119412,12 @@ var ts;
119397
119412
  };
119398
119413
  }
119399
119414
  function isFormatRequiringExtensions(compilerOptions, importingSourceFileName, host) {
119415
+ var _a;
119400
119416
  if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node12
119401
119417
  && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) {
119402
119418
  return false;
119403
119419
  }
119404
- return ts.getImpliedNodeFormatForFile(importingSourceFileName, /*packageJsonInfoCache*/ undefined, getModuleResolutionHost(host), compilerOptions) !== ts.ModuleKind.CommonJS;
119420
+ return ts.getImpliedNodeFormatForFile(importingSourceFileName, (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host), getModuleResolutionHost(host), compilerOptions) !== ts.ModuleKind.CommonJS;
119405
119421
  }
119406
119422
  function getModuleResolutionHost(host) {
119407
119423
  var _a;
@@ -119961,11 +119977,13 @@ var ts;
119961
119977
  // For classic resolution, only allow importing from node_modules/@types, not other node_modules
119962
119978
  return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Classic && packageName === nodeModulesDirectoryName ? undefined : packageName;
119963
119979
  function tryDirectoryWithPackageJson(packageRootIndex) {
119980
+ var _a, _b;
119964
119981
  var packageRootPath = path.substring(0, packageRootIndex);
119965
119982
  var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
119966
119983
  var moduleFileToTry = path;
119967
- if (host.fileExists(packageJsonPath)) {
119968
- var packageJsonContent = JSON.parse(host.readFile(packageJsonPath));
119984
+ var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
119985
+ if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
119986
+ var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath));
119969
119987
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
119970
119988
  // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
119971
119989
  // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
@@ -120804,6 +120822,7 @@ var ts;
120804
120822
  var sharedExtendedConfigFileWatchers; // Map of file watchers for extended files, shared between different referenced projects
120805
120823
  var extendedConfigCache = host.extendedConfigCache; // Cache for extended config evaluation
120806
120824
  var changesAffectResolution = false; // Flag for indicating non-config changes affect module resolution
120825
+ var reportFileChangeDetectedOnCreateProgram = false; // True if synchronizeProgram should report "File change detected..." when a new program is created
120807
120826
  var sourceFilesCache = new ts.Map(); // Cache that stores the source file and version info
120808
120827
  var missingFilePathsRequestedForRelease; // These paths are held temporarily so that we can remove the entry from source file cache if the file is not tracked by missing files
120809
120828
  var hasChangedCompilerOptions = false; // True if the compiler options have changed between compilations
@@ -120966,14 +120985,21 @@ var ts;
120966
120985
  var hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution || changesAffectResolution);
120967
120986
  if (ts.isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
120968
120987
  if (hasChangedConfigFileParsingErrors) {
120988
+ if (reportFileChangeDetectedOnCreateProgram) {
120989
+ reportWatchDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation);
120990
+ }
120969
120991
  builderProgram = createProgram(/*rootNames*/ undefined, /*options*/ undefined, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
120970
120992
  hasChangedConfigFileParsingErrors = false;
120971
120993
  }
120972
120994
  }
120973
120995
  else {
120996
+ if (reportFileChangeDetectedOnCreateProgram) {
120997
+ reportWatchDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation);
120998
+ }
120974
120999
  createNewProgram(hasInvalidatedResolution);
120975
121000
  }
120976
121001
  changesAffectResolution = false; // reset for next sync
121002
+ reportFileChangeDetectedOnCreateProgram = false;
120977
121003
  if (host.afterProgramCreate && program !== builderProgram) {
120978
121004
  host.afterProgramCreate(builderProgram);
120979
121005
  }
@@ -121175,7 +121201,7 @@ var ts;
121175
121201
  }
121176
121202
  function updateProgramWithWatchStatus() {
121177
121203
  timerToUpdateProgram = undefined;
121178
- reportWatchDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation);
121204
+ reportFileChangeDetectedOnCreateProgram = true;
121179
121205
  updateProgram();
121180
121206
  }
121181
121207
  function updateProgram() {
@@ -123282,6 +123308,7 @@ var ts;
123282
123308
  ScriptElementKind["externalModuleName"] = "external module name";
123283
123309
  /**
123284
123310
  * <JsxTagName attribute1 attribute2={0} />
123311
+ * @deprecated
123285
123312
  */
123286
123313
  ScriptElementKind["jsxAttribute"] = "JSX attribute";
123287
123314
  /** String literal */
@@ -125173,6 +125200,7 @@ var ts;
125173
125200
  useCaseSensitiveFileNames: ts.maybeBind(host, host.useCaseSensitiveFileNames),
125174
125201
  getSymlinkCache: ts.maybeBind(host, host.getSymlinkCache) || program.getSymlinkCache,
125175
125202
  getModuleSpecifierCache: ts.maybeBind(host, host.getModuleSpecifierCache),
125203
+ getPackageJsonInfoCache: function () { var _a; return (_a = program.getModuleResolutionCache()) === null || _a === void 0 ? void 0 : _a.getPackageJsonInfoCache(); },
125176
125204
  getGlobalTypingsCacheLocation: ts.maybeBind(host, host.getGlobalTypingsCacheLocation),
125177
125205
  redirectTargetsMap: program.redirectTargetsMap,
125178
125206
  getProjectReferenceRedirect: function (fileName) { return program.getProjectReferenceRedirect(fileName); },
@@ -128917,6 +128945,7 @@ var ts;
128917
128945
  function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, preferences, isForImportStatementCompletion, cb) {
128918
128946
  var _a, _b, _c;
128919
128947
  var start = ts.timestamp();
128948
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
128920
128949
  var resolutionLimitExceeded = false;
128921
128950
  var ambientCount = 0;
128922
128951
  var resolvedCount = 0;
@@ -128939,7 +128968,7 @@ var ts;
128939
128968
  var shouldResolveModuleSpecifier = isForImportStatementCompletion || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
128940
128969
  var shouldGetModuleSpecifierFromCache = !shouldResolveModuleSpecifier && preferences.allowIncompleteCompletions && cacheAttemptCount < Completions.moduleSpecifierResolutionCacheAttemptLimit;
128941
128970
  var result = (shouldResolveModuleSpecifier || shouldGetModuleSpecifierFromCache)
128942
- ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences, shouldGetModuleSpecifierFromCache)
128971
+ ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
128943
128972
  : undefined;
128944
128973
  if (!shouldResolveModuleSpecifier && !shouldGetModuleSpecifierFromCache || shouldGetModuleSpecifierFromCache && !result) {
128945
128974
  resolutionLimitExceeded = true;
@@ -130337,9 +130366,7 @@ var ts;
130337
130366
  // GH#39946. Pulling on the type of a node inside of a function with a contextual `this` parameter can result in a circularity
130338
130367
  // if the `node` is part of the exprssion of a `yield` or `return`. This circularity doesn't exist at compile time because
130339
130368
  // we will check (and cache) the type of `this` *before* checking the type of the node.
130340
- var container = ts.getThisContainer(node, /*includeArrowFunctions*/ false);
130341
- if (!ts.isSourceFile(container) && container.parent)
130342
- typeChecker.getTypeAtLocation(container);
130369
+ typeChecker.tryGetThisTypeAt(node, /*includeGlobalThis*/ false);
130343
130370
  var type = typeChecker.getTypeAtLocation(node).getNonOptionalType();
130344
130371
  var insertQuestionDot = false;
130345
130372
  if (type.isNullableType()) {
@@ -141209,18 +141236,7 @@ var ts;
141209
141236
  }
141210
141237
  return unionPropertyKind;
141211
141238
  }
141212
- // If we requested completions after `x.` at the top-level, we may be at a source file location.
141213
- switch (location.parent && location.parent.kind) {
141214
- // If we've typed a character of the attribute name, will be 'JsxAttribute', else will be 'JsxOpeningElement'.
141215
- case 279 /* JsxOpeningElement */:
141216
- case 277 /* JsxElement */:
141217
- case 278 /* JsxSelfClosingElement */:
141218
- return location.kind === 79 /* Identifier */ ? "property" /* memberVariableElement */ : "JSX attribute" /* jsxAttribute */;
141219
- case 284 /* JsxAttribute */:
141220
- return "JSX attribute" /* jsxAttribute */;
141221
- default:
141222
- return "property" /* memberVariableElement */;
141223
- }
141239
+ return "property" /* memberVariableElement */;
141224
141240
  }
141225
141241
  return "" /* unknown */;
141226
141242
  }
@@ -145238,7 +145254,11 @@ var ts;
145238
145254
  oldTags[i] = merged;
145239
145255
  return !!merged;
145240
145256
  }); });
145241
- var tag = ts.factory.createJSDocComment(ts.factory.createNodeArray(ts.intersperse(comments, ts.factory.createJSDocText("\n"))), ts.factory.createNodeArray(__spreadArray(__spreadArray([], oldTags, true), unmergedNewTags, true)));
145257
+ var tags = __spreadArray(__spreadArray([], oldTags, true), unmergedNewTags, true);
145258
+ var jsDoc = ts.singleOrUndefined(parent.jsDoc);
145259
+ var comment = jsDoc && ts.positionsAreOnSameLine(jsDoc.pos, jsDoc.end, sourceFile) && !ts.length(comments) ? undefined :
145260
+ ts.factory.createNodeArray(ts.intersperse(comments, ts.factory.createJSDocText("\n")));
145261
+ var tag = ts.factory.createJSDocComment(comment, ts.factory.createNodeArray(tags));
145242
145262
  var host = updateJSDocHost(parent);
145243
145263
  this.insertJsdocCommentBefore(sourceFile, host, tag);
145244
145264
  };
@@ -145668,6 +145688,8 @@ var ts;
145668
145688
  }
145669
145689
  case 339 /* JSDocReturnTag */:
145670
145690
  return ts.factory.createJSDocReturnTag(/*tagName*/ undefined, newTag.typeExpression, oldTag.comment);
145691
+ case 341 /* JSDocTypeTag */:
145692
+ return ts.factory.createJSDocTypeTag(/*tagName*/ undefined, newTag.typeExpression, oldTag.comment);
145671
145693
  }
145672
145694
  }
145673
145695
  // find first non-whitespace position in the leading trivia of the node
@@ -149206,7 +149228,8 @@ var ts;
149206
149228
  codefix.getImportCompletionAction = getImportCompletionAction;
149207
149229
  function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
149208
149230
  ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
149209
- return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, host, preferences);
149231
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
149232
+ return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, packageJsonImportFilter);
149210
149233
  }
149211
149234
  function codeFixActionToCodeAction(_a) {
149212
149235
  var description = _a.description, changes = _a.changes, commands = _a.commands;
@@ -149261,12 +149284,12 @@ var ts;
149261
149284
  return !moduleFile || ts.isImportableFile(program, importingFile, moduleFile, preferences, /*packageJsonFilter*/ undefined, getModuleSpecifierResolutionHost(isFromPackageJson), (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host));
149262
149285
  }
149263
149286
  }
149264
- function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, fromCacheOnly) {
149287
+ function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
149265
149288
  var _a = getNewImportFixes(program, importingFile,
149266
149289
  /*position*/ undefined,
149267
149290
  /*isValidTypeOnlyUseSite*/ false,
149268
149291
  /*useRequire*/ false, exportInfo, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
149269
- var result = getBestFix(fixes, importingFile, program, host, preferences);
149292
+ var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter || ts.createPackageJsonImportFilter(importingFile, preferences, host));
149270
149293
  return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
149271
149294
  }
149272
149295
  codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
@@ -149486,23 +149509,22 @@ var ts;
149486
149509
  var info = errorCode === ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code
149487
149510
  ? getFixesInfoForUMDImport(context, symbolToken)
149488
149511
  : ts.isIdentifier(symbolToken) ? getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider) : undefined;
149489
- return info && __assign(__assign({}, info), { fixes: sortFixes(info.fixes, context.sourceFile, context.program, context.host, context.preferences) });
149512
+ var packageJsonImportFilter = ts.createPackageJsonImportFilter(context.sourceFile, context.preferences, context.host);
149513
+ return info && __assign(__assign({}, info), { fixes: sortFixes(info.fixes, context.sourceFile, context.program, packageJsonImportFilter) });
149490
149514
  }
149491
- function sortFixes(fixes, sourceFile, program, host, preferences) {
149492
- var allowsImportingSpecifier = ts.createPackageJsonImportFilter(sourceFile, preferences, host).allowsImportingSpecifier;
149493
- return ts.sort(fixes, function (a, b) { return ts.compareValues(a.kind, b.kind) || compareModuleSpecifiers(a, b, sourceFile, program, allowsImportingSpecifier); });
149515
+ function sortFixes(fixes, sourceFile, program, packageJsonImportFilter) {
149516
+ return ts.sort(fixes, function (a, b) { return ts.compareValues(a.kind, b.kind) || compareModuleSpecifiers(a, b, sourceFile, program, packageJsonImportFilter.allowsImportingSpecifier); });
149494
149517
  }
149495
- function getBestFix(fixes, sourceFile, program, host, preferences) {
149518
+ function getBestFix(fixes, sourceFile, program, packageJsonImportFilter) {
149496
149519
  if (!ts.some(fixes))
149497
149520
  return;
149498
149521
  // These will always be placed first if available, and are better than other kinds
149499
149522
  if (fixes[0].kind === 0 /* UseNamespace */ || fixes[0].kind === 2 /* AddToExisting */) {
149500
149523
  return fixes[0];
149501
149524
  }
149502
- var allowsImportingSpecifier = ts.createPackageJsonImportFilter(sourceFile, preferences, host).allowsImportingSpecifier;
149503
149525
  return fixes.reduce(function (best, fix) {
149504
149526
  // Takes true branch of conditional if `fix` is better than `best`
149505
- return compareModuleSpecifiers(fix, best, sourceFile, program, allowsImportingSpecifier) === -1 /* LessThan */ ? fix : best;
149527
+ return compareModuleSpecifiers(fix, best, sourceFile, program, packageJsonImportFilter.allowsImportingSpecifier) === -1 /* LessThan */ ? fix : best;
149506
149528
  });
149507
149529
  }
149508
149530
  /** @returns `Comparison.LessThan` if `a` is better than `b`. */
@@ -152354,7 +152376,7 @@ var ts;
152354
152376
  });
152355
152377
  var name = declaration && ts.getNameOfDeclaration(declaration);
152356
152378
  return !name || changes.length === 0 ? undefined
152357
- : [codefix.createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), name.getText(sourceFile)], fixId, ts.Diagnostics.Infer_all_types_from_usage)];
152379
+ : [codefix.createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), ts.getTextOfNode(name)], fixId, ts.Diagnostics.Infer_all_types_from_usage)];
152358
152380
  },
152359
152381
  fixIds: [fixId],
152360
152382
  getAllCodeActions: function (context) {
@@ -152432,7 +152454,7 @@ var ts;
152432
152454
  case ts.Diagnostics.Variable_0_implicitly_has_an_1_type.code: {
152433
152455
  var symbol = program.getTypeChecker().getSymbolAtLocation(token);
152434
152456
  if (symbol && symbol.valueDeclaration && ts.isVariableDeclaration(symbol.valueDeclaration) && markSeen(symbol.valueDeclaration)) {
152435
- annotateVariableDeclaration(changes, importAdder, sourceFile, symbol.valueDeclaration, program, host, cancellationToken);
152457
+ annotateVariableDeclaration(changes, importAdder, ts.getSourceFileOfNode(symbol.valueDeclaration), symbol.valueDeclaration, program, host, cancellationToken);
152436
152458
  importAdder.writeFixes(changes);
152437
152459
  return symbol.valueDeclaration;
152438
152460
  }
@@ -154131,35 +154153,34 @@ var ts;
154131
154153
  codefix.registerCodeFix({
154132
154154
  errorCodes: errorCodes,
154133
154155
  getCodeActions: function getCodeActionsForStrictClassInitializationErrors(context) {
154134
- var propertyDeclaration = getPropertyDeclaration(context.sourceFile, context.span.start);
154135
- if (!propertyDeclaration)
154156
+ var info = getInfo(context.sourceFile, context.span.start);
154157
+ if (!info)
154136
154158
  return;
154137
- var result = [
154138
- getActionForAddMissingUndefinedType(context, propertyDeclaration),
154139
- getActionForAddMissingDefiniteAssignmentAssertion(context, propertyDeclaration)
154140
- ];
154141
- ts.append(result, getActionForAddMissingInitializer(context, propertyDeclaration));
154159
+ var result = [];
154160
+ ts.append(result, getActionForAddMissingUndefinedType(context, info));
154161
+ ts.append(result, getActionForAddMissingDefiniteAssignmentAssertion(context, info));
154162
+ ts.append(result, getActionForAddMissingInitializer(context, info));
154142
154163
  return result;
154143
154164
  },
154144
154165
  fixIds: [fixIdAddDefiniteAssignmentAssertions, fixIdAddUndefinedType, fixIdAddInitializer],
154145
154166
  getAllCodeActions: function (context) {
154146
154167
  return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
154147
- var propertyDeclaration = getPropertyDeclaration(diag.file, diag.start);
154148
- if (!propertyDeclaration)
154168
+ var info = getInfo(diag.file, diag.start);
154169
+ if (!info)
154149
154170
  return;
154150
154171
  switch (context.fixId) {
154151
154172
  case fixIdAddDefiniteAssignmentAssertions:
154152
- addDefiniteAssignmentAssertion(changes, diag.file, propertyDeclaration);
154173
+ addDefiniteAssignmentAssertion(changes, diag.file, info.prop);
154153
154174
  break;
154154
154175
  case fixIdAddUndefinedType:
154155
- addUndefinedType(changes, diag.file, propertyDeclaration);
154176
+ addUndefinedType(changes, diag.file, info);
154156
154177
  break;
154157
154178
  case fixIdAddInitializer:
154158
154179
  var checker = context.program.getTypeChecker();
154159
- var initializer = getInitializer(checker, propertyDeclaration);
154180
+ var initializer = getInitializer(checker, info.prop);
154160
154181
  if (!initializer)
154161
154182
  return;
154162
- addInitializer(changes, diag.file, propertyDeclaration, initializer);
154183
+ addInitializer(changes, diag.file, info.prop, initializer);
154163
154184
  break;
154164
154185
  default:
154165
154186
  ts.Debug.fail(JSON.stringify(context.fixId));
@@ -154167,35 +154188,50 @@ var ts;
154167
154188
  });
154168
154189
  },
154169
154190
  });
154170
- function getPropertyDeclaration(sourceFile, pos) {
154191
+ function getInfo(sourceFile, pos) {
154171
154192
  var token = ts.getTokenAtPosition(sourceFile, pos);
154172
- return ts.isIdentifier(token) ? ts.cast(token.parent, ts.isPropertyDeclaration) : undefined;
154193
+ if (ts.isIdentifier(token) && ts.isPropertyDeclaration(token.parent)) {
154194
+ var type = ts.getEffectiveTypeAnnotationNode(token.parent);
154195
+ if (type) {
154196
+ return { type: type, prop: token.parent, isJs: ts.isInJSFile(token.parent) };
154197
+ }
154198
+ }
154199
+ return undefined;
154173
154200
  }
154174
- function getActionForAddMissingDefiniteAssignmentAssertion(context, propertyDeclaration) {
154175
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addDefiniteAssignmentAssertion(t, context.sourceFile, propertyDeclaration); });
154176
- return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_definite_assignment_assertion_to_property_0, propertyDeclaration.getText()], fixIdAddDefiniteAssignmentAssertions, ts.Diagnostics.Add_definite_assignment_assertions_to_all_uninitialized_properties);
154201
+ function getActionForAddMissingDefiniteAssignmentAssertion(context, info) {
154202
+ if (info.isJs)
154203
+ return undefined;
154204
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addDefiniteAssignmentAssertion(t, context.sourceFile, info.prop); });
154205
+ return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_definite_assignment_assertion_to_property_0, info.prop.getText()], fixIdAddDefiniteAssignmentAssertions, ts.Diagnostics.Add_definite_assignment_assertions_to_all_uninitialized_properties);
154177
154206
  }
154178
154207
  function addDefiniteAssignmentAssertion(changeTracker, propertyDeclarationSourceFile, propertyDeclaration) {
154179
154208
  var property = ts.factory.updatePropertyDeclaration(propertyDeclaration, propertyDeclaration.decorators, propertyDeclaration.modifiers, propertyDeclaration.name, ts.factory.createToken(53 /* ExclamationToken */), propertyDeclaration.type, propertyDeclaration.initializer);
154180
154209
  changeTracker.replaceNode(propertyDeclarationSourceFile, propertyDeclaration, property);
154181
154210
  }
154182
- function getActionForAddMissingUndefinedType(context, propertyDeclaration) {
154183
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addUndefinedType(t, context.sourceFile, propertyDeclaration); });
154184
- 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);
154211
+ function getActionForAddMissingUndefinedType(context, info) {
154212
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addUndefinedType(t, context.sourceFile, info); });
154213
+ return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_undefined_type_to_property_0, info.prop.name.getText()], fixIdAddUndefinedType, ts.Diagnostics.Add_undefined_type_to_all_uninitialized_properties);
154185
154214
  }
154186
- function addUndefinedType(changeTracker, propertyDeclarationSourceFile, propertyDeclaration) {
154215
+ function addUndefinedType(changeTracker, sourceFile, info) {
154187
154216
  var undefinedTypeNode = ts.factory.createKeywordTypeNode(152 /* UndefinedKeyword */);
154188
- var type = propertyDeclaration.type; // TODO: GH#18217
154189
- var types = ts.isUnionTypeNode(type) ? type.types.concat(undefinedTypeNode) : [type, undefinedTypeNode];
154190
- changeTracker.replaceNode(propertyDeclarationSourceFile, type, ts.factory.createUnionTypeNode(types));
154217
+ var types = ts.isUnionTypeNode(info.type) ? info.type.types.concat(undefinedTypeNode) : [info.type, undefinedTypeNode];
154218
+ var unionTypeNode = ts.factory.createUnionTypeNode(types);
154219
+ if (info.isJs) {
154220
+ changeTracker.addJSDocTags(sourceFile, info.prop, [ts.factory.createJSDocTypeTag(/*tagName*/ undefined, ts.factory.createJSDocTypeExpression(unionTypeNode))]);
154221
+ }
154222
+ else {
154223
+ changeTracker.replaceNode(sourceFile, info.type, unionTypeNode);
154224
+ }
154191
154225
  }
154192
- function getActionForAddMissingInitializer(context, propertyDeclaration) {
154226
+ function getActionForAddMissingInitializer(context, info) {
154227
+ if (info.isJs)
154228
+ return undefined;
154193
154229
  var checker = context.program.getTypeChecker();
154194
- var initializer = getInitializer(checker, propertyDeclaration);
154230
+ var initializer = getInitializer(checker, info.prop);
154195
154231
  if (!initializer)
154196
154232
  return undefined;
154197
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addInitializer(t, context.sourceFile, propertyDeclaration, initializer); });
154198
- return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_initializer_to_property_0, propertyDeclaration.name.getText()], fixIdAddInitializer, ts.Diagnostics.Add_initializers_to_all_uninitialized_properties);
154233
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addInitializer(t, context.sourceFile, info.prop, initializer); });
154234
+ return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_initializer_to_property_0, info.prop.name.getText()], fixIdAddInitializer, ts.Diagnostics.Add_initializers_to_all_uninitialized_properties);
154199
154235
  }
154200
154236
  function addInitializer(changeTracker, propertyDeclarationSourceFile, propertyDeclaration, initializer) {
154201
154237
  var property = ts.factory.updatePropertyDeclaration(propertyDeclaration, propertyDeclaration.decorators, propertyDeclaration.modifiers, propertyDeclaration.name, propertyDeclaration.questionToken, propertyDeclaration.type, initializer);
@@ -160697,6 +160733,7 @@ var ts;
160697
160733
  hasChangedAutomaticTypeDirectiveNames: hasChangedAutomaticTypeDirectiveNames,
160698
160734
  trace: parseConfigHost.trace,
160699
160735
  resolveModuleNames: ts.maybeBind(host, host.resolveModuleNames),
160736
+ getModuleResolutionCache: ts.maybeBind(host, host.getModuleResolutionCache),
160700
160737
  resolveTypeReferenceDirectives: ts.maybeBind(host, host.resolveTypeReferenceDirectives),
160701
160738
  useSourceOfProjectReferenceRedirect: ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect),
160702
160739
  getParsedCommandLine: getParsedCommandLine,
@@ -165327,6 +165364,9 @@ var ts;
165327
165364
  Project.prototype.resolveModuleNames = function (moduleNames, containingFile, reusedNames, redirectedReference, _options, containingSourceFile) {
165328
165365
  return this.resolutionCache.resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, containingSourceFile);
165329
165366
  };
165367
+ Project.prototype.getModuleResolutionCache = function () {
165368
+ return this.resolutionCache.getModuleResolutionCache();
165369
+ };
165330
165370
  Project.prototype.getResolvedModuleWithFailedLookupLocationsFromCache = function (moduleName, containingFile, resolutionMode) {
165331
165371
  return this.resolutionCache.getResolvedModuleWithFailedLookupLocationsFromCache(moduleName, containingFile, resolutionMode);
165332
165372
  };
@@ -166589,6 +166629,7 @@ var ts;
166589
166629
  if (!program) {
166590
166630
  return ts.emptyArray;
166591
166631
  }
166632
+ var start = ts.timestamp();
166592
166633
  var dependencyNames;
166593
166634
  var rootNames;
166594
166635
  var rootFileName = ts.combinePaths(hostProject.currentDirectory, ts.inferredTypesContainingFile);
@@ -166598,14 +166639,14 @@ var ts;
166598
166639
  (_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a.forEach(function (_, dependenyName) { return addDependency(dependenyName); });
166599
166640
  (_b = packageJson.peerDependencies) === null || _b === void 0 ? void 0 : _b.forEach(function (_, dependencyName) { return addDependency(dependencyName); });
166600
166641
  }
166642
+ var dependenciesAdded = 0;
166601
166643
  if (dependencyNames) {
166602
- var dependenciesAdded = 0;
166603
166644
  var symlinkCache = hostProject.getSymlinkCache();
166604
166645
  for (var _c = 0, _d = ts.arrayFrom(dependencyNames.keys()); _c < _d.length; _c++) {
166605
166646
  var name = _d[_c];
166606
166647
  // Avoid creating a large project that would significantly slow down time to editor interactivity
166607
166648
  if (dependencySelection === 2 /* Auto */ && dependenciesAdded > this.maxDependencies) {
166608
- hostProject.log("Auto-import provider attempted to add more than " + this.maxDependencies + " dependencies.");
166649
+ hostProject.log("AutoImportProviderProject: attempted to add more than " + this.maxDependencies + " dependencies. Aborting.");
166609
166650
  return ts.emptyArray;
166610
166651
  }
166611
166652
  // 1. Try to load from the implementation package. For many dependencies, the
@@ -166639,6 +166680,9 @@ var ts;
166639
166680
  }
166640
166681
  }
166641
166682
  }
166683
+ if (rootNames === null || rootNames === void 0 ? void 0 : rootNames.length) {
166684
+ hostProject.log("AutoImportProviderProject: found " + rootNames.length + " root files in " + dependenciesAdded + " dependencies in " + (ts.timestamp() - start) + " ms");
166685
+ }
166642
166686
  return rootNames || ts.emptyArray;
166643
166687
  function addDependency(dependency) {
166644
166688
  if (!ts.startsWith(dependency, "@types/")) {
@@ -166739,6 +166783,11 @@ var ts;
166739
166783
  return this.hostProject.getSymlinkCache();
166740
166784
  };
166741
166785
  /*@internal*/
166786
+ AutoImportProviderProject.prototype.getModuleResolutionCache = function () {
166787
+ var _a;
166788
+ return (_a = this.hostProject.getCurrentProgram()) === null || _a === void 0 ? void 0 : _a.getModuleResolutionCache();
166789
+ };
166790
+ /*@internal*/
166742
166791
  AutoImportProviderProject.maxDependencies = 10;
166743
166792
  /*@internal*/
166744
166793
  AutoImportProviderProject.compilerOptionsOverrides = {
@@ -6594,6 +6594,7 @@ declare namespace ts {
6594
6594
  externalModuleName = "external module name",
6595
6595
  /**
6596
6596
  * <JsxTagName attribute1 attribute2={0} />
6597
+ * @deprecated
6597
6598
  */
6598
6599
  jsxAttribute = "JSX attribute",
6599
6600
  /** String literal */
@@ -9874,6 +9875,7 @@ declare namespace ts.server {
9874
9875
  writeFile(fileName: string, content: string): void;
9875
9876
  fileExists(file: string): boolean;
9876
9877
  resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference, _options?: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModuleFull | undefined)[];
9878
+ getModuleResolutionCache(): ModuleResolutionCache | undefined;
9877
9879
  getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
9878
9880
  resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string, redirectedReference?: ResolvedProjectReference): (ResolvedTypeReferenceDirective | undefined)[];
9879
9881
  directoryExists(path: string): boolean;