typescript 4.8.0-dev.20220809 → 4.9.0-dev.20220811

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
@@ -105,11 +105,11 @@ var ts;
105
105
  (function (ts) {
106
106
  // WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
107
107
  // If changing the text in this section, be sure to test `configurePrerelease` too.
108
- ts.versionMajorMinor = "4.8";
108
+ ts.versionMajorMinor = "4.9";
109
109
  // The following is baselined as a literal template type without intervention
110
110
  /** The version of the TypeScript compiler release */
111
111
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
112
- ts.version = ts.versionMajorMinor + ".0-dev.20220809";
112
+ ts.version = ts.versionMajorMinor + ".0-dev.20220811";
113
113
  /* @internal */
114
114
  var Comparison;
115
115
  (function (Comparison) {
@@ -131,7 +131,11 @@ var ts;
131
131
  // Internet Explorer's Map doesn't support iteration, so don't use it.
132
132
  var gMap = globals === null || globals === void 0 ? void 0 : globals.Map;
133
133
  // eslint-disable-next-line no-in-operator
134
- return typeof gMap !== "undefined" && "entries" in gMap.prototype && new gMap([[0, 0]]).size === 1 ? gMap : undefined;
134
+ var constructor = typeof gMap !== "undefined" && "entries" in gMap.prototype && new gMap([[0, 0]]).size === 1 ? gMap : undefined;
135
+ if (!constructor) {
136
+ throw new Error("No compatible Map implementation found.");
137
+ }
138
+ return constructor;
135
139
  }
136
140
  NativeCollections.tryGetNativeMap = tryGetNativeMap;
137
141
  /**
@@ -141,23 +145,18 @@ var ts;
141
145
  // Internet Explorer's Set doesn't support iteration, so don't use it.
142
146
  var gSet = globals === null || globals === void 0 ? void 0 : globals.Set;
143
147
  // eslint-disable-next-line no-in-operator
144
- return typeof gSet !== "undefined" && "entries" in gSet.prototype && new gSet([0]).size === 1 ? gSet : undefined;
148
+ var constructor = typeof gSet !== "undefined" && "entries" in gSet.prototype && new gSet([0]).size === 1 ? gSet : undefined;
149
+ if (!constructor) {
150
+ throw new Error("No compatible Set implementation found.");
151
+ }
152
+ return constructor;
145
153
  }
146
154
  NativeCollections.tryGetNativeSet = tryGetNativeSet;
147
155
  })(NativeCollections || (NativeCollections = {}));
148
156
  /* @internal */
149
- ts.Map = getCollectionImplementation("Map", "tryGetNativeMap", "createMapShim");
157
+ ts.Map = NativeCollections.tryGetNativeMap();
150
158
  /* @internal */
151
- ts.Set = getCollectionImplementation("Set", "tryGetNativeSet", "createSetShim");
152
- /* @internal */
153
- function getCollectionImplementation(name, nativeFactory, shimFactory) {
154
- var _a;
155
- // NOTE: ts.ShimCollections will be defined for typescriptServices.js but not for tsc.js, so we must test for it.
156
- var constructor = (_a = NativeCollections[nativeFactory]()) !== null && _a !== void 0 ? _a : ts.ShimCollections === null || ts.ShimCollections === void 0 ? void 0 : ts.ShimCollections[shimFactory](ts.getIterator);
157
- if (constructor)
158
- return constructor;
159
- throw new Error("TypeScript requires an environment that provides a compatible native " + name + " implementation.");
160
- }
159
+ ts.Set = NativeCollections.tryGetNativeSet();
161
160
  })(ts || (ts = {}));
162
161
  /* @internal */
163
162
  var ts;
@@ -873,15 +872,18 @@ var ts;
873
872
  function insertSorted(array, insert, compare, allowDuplicates) {
874
873
  if (array.length === 0) {
875
874
  array.push(insert);
876
- return;
875
+ return true;
877
876
  }
878
877
  var insertIndex = binarySearch(array, insert, identity, compare);
879
878
  if (insertIndex < 0) {
880
879
  array.splice(~insertIndex, 0, insert);
880
+ return true;
881
881
  }
882
- else if (allowDuplicates) {
882
+ if (allowDuplicates) {
883
883
  array.splice(insertIndex, 0, insert);
884
+ return true;
884
885
  }
886
+ return false;
885
887
  }
886
888
  ts.insertSorted = insertSorted;
887
889
  function sortAndDeduplicate(array, comparer, equalityComparer) {
@@ -7842,12 +7844,9 @@ var ts;
7842
7844
  * Normalize path separators, converting `\` into `/`.
7843
7845
  */
7844
7846
  function normalizeSlashes(path) {
7845
- var index = path.indexOf("\\");
7846
- if (index === -1) {
7847
- return path;
7848
- }
7849
- backslashRegExp.lastIndex = index; // prime regex with known position
7850
- return path.replace(backslashRegExp, ts.directorySeparator);
7847
+ return path.indexOf("\\") !== -1
7848
+ ? path.replace(backslashRegExp, ts.directorySeparator)
7849
+ : path;
7851
7850
  }
7852
7851
  ts.normalizeSlashes = normalizeSlashes;
7853
7852
  /**
@@ -9548,6 +9547,7 @@ var ts;
9548
9547
  Reusing_resolution_of_type_reference_directive_0_from_1_found_in_cache_from_location_2_it_was_not_resolved: diag(6398, ts.DiagnosticCategory.Message, "Reusing_resolution_of_type_reference_directive_0_from_1_found_in_cache_from_location_2_it_was_not_re_6398", "Reusing resolution of type reference directive '{0}' from '{1}' found in cache from location '{2}', it was not resolved."),
9549
9548
  Project_0_is_out_of_date_because_buildinfo_file_1_indicates_that_some_of_the_changes_were_not_emitted: diag(6399, ts.DiagnosticCategory.Message, "Project_0_is_out_of_date_because_buildinfo_file_1_indicates_that_some_of_the_changes_were_not_emitte_6399", "Project '{0}' is out of date because buildinfo file '{1}' indicates that some of the changes were not emitted"),
9550
9549
  Project_0_is_up_to_date_but_needs_to_update_timestamps_of_output_files_that_are_older_than_input_files: diag(6400, ts.DiagnosticCategory.Message, "Project_0_is_up_to_date_but_needs_to_update_timestamps_of_output_files_that_are_older_than_input_fil_6400", "Project '{0}' is up to date but needs to update timestamps of output files that are older than input files"),
9550
+ Project_0_is_out_of_date_because_there_was_error_reading_file_1: diag(6401, ts.DiagnosticCategory.Message, "Project_0_is_out_of_date_because_there_was_error_reading_file_1_6401", "Project '{0}' is out of date because there was error reading file '{1}'"),
9551
9551
  The_expected_type_comes_from_property_0_which_is_declared_here_on_type_1: diag(6500, ts.DiagnosticCategory.Message, "The_expected_type_comes_from_property_0_which_is_declared_here_on_type_1_6500", "The expected type comes from property '{0}' which is declared here on type '{1}'"),
9552
9552
  The_expected_type_comes_from_this_index_signature: diag(6501, ts.DiagnosticCategory.Message, "The_expected_type_comes_from_this_index_signature_6501", "The expected type comes from this index signature."),
9553
9553
  The_expected_type_comes_from_the_return_type_of_this_signature: diag(6502, ts.DiagnosticCategory.Message, "The_expected_type_comes_from_the_return_type_of_this_signature_6502", "The expected type comes from the return type of this signature."),
@@ -19391,21 +19391,17 @@ var ts;
19391
19391
  return getStringFromExpandedCharCodes(expandedCharCodes);
19392
19392
  }
19393
19393
  ts.base64decode = base64decode;
19394
+ function readJsonOrUndefined(path, hostOrText) {
19395
+ var jsonText = ts.isString(hostOrText) ? hostOrText : hostOrText.readFile(path);
19396
+ if (!jsonText)
19397
+ return undefined;
19398
+ // gracefully handle if readFile fails or returns not JSON
19399
+ var result = ts.parseConfigFileTextToJson(path, jsonText);
19400
+ return !result.error ? result.config : undefined;
19401
+ }
19402
+ ts.readJsonOrUndefined = readJsonOrUndefined;
19394
19403
  function readJson(path, host) {
19395
- try {
19396
- var jsonText = host.readFile(path);
19397
- if (!jsonText)
19398
- return {};
19399
- var result = ts.parseConfigFileTextToJson(path, jsonText);
19400
- if (result.error) {
19401
- return {};
19402
- }
19403
- return result.config;
19404
- }
19405
- catch (e) {
19406
- // gracefully handle if readFile fails or returns not JSON
19407
- return {};
19408
- }
19404
+ return readJsonOrUndefined(path, host) || {};
19409
19405
  }
19410
19406
  ts.readJson = readJson;
19411
19407
  function directoryProbablyExists(directoryName, host) {
@@ -27756,9 +27752,10 @@ var ts;
27756
27752
  };
27757
27753
  var buildInfo_1;
27758
27754
  var getAndCacheBuildInfo_1 = function (getText) {
27755
+ var _a;
27759
27756
  if (buildInfo_1 === undefined) {
27760
27757
  var result = getText();
27761
- buildInfo_1 = result !== undefined ? ts.getBuildInfo(result) : false;
27758
+ buildInfo_1 = result !== undefined ? (_a = ts.getBuildInfo(node.buildInfoPath, result)) !== null && _a !== void 0 ? _a : false : false;
27762
27759
  }
27763
27760
  return buildInfo_1 || undefined;
27764
27761
  };
@@ -45818,6 +45815,9 @@ var ts;
45818
45815
  case 203 /* BindingElement */:
45819
45816
  bindBindingElementFlow(node);
45820
45817
  break;
45818
+ case 164 /* Parameter */:
45819
+ bindParameterFlow(node);
45820
+ break;
45821
45821
  case 205 /* ObjectLiteralExpression */:
45822
45822
  case 204 /* ArrayLiteralExpression */:
45823
45823
  case 296 /* PropertyAssignment */:
@@ -46558,20 +46558,38 @@ var ts;
46558
46558
  }
46559
46559
  }
46560
46560
  function bindBindingElementFlow(node) {
46561
- if (ts.isBindingPattern(node.name)) {
46562
- // When evaluating a binding pattern, the initializer is evaluated before the binding pattern, per:
46563
- // - https://tc39.es/ecma262/#sec-destructuring-binding-patterns-runtime-semantics-iteratorbindinginitialization
46564
- // - `BindingElement: BindingPattern Initializer?`
46565
- // - https://tc39.es/ecma262/#sec-runtime-semantics-keyedbindinginitialization
46566
- // - `BindingElement: BindingPattern Initializer?`
46567
- bind(node.dotDotDotToken);
46568
- bind(node.propertyName);
46569
- bind(node.initializer);
46570
- bind(node.name);
46561
+ // When evaluating a binding pattern, the initializer is evaluated before the binding pattern, per:
46562
+ // - https://tc39.es/ecma262/#sec-destructuring-binding-patterns-runtime-semantics-iteratorbindinginitialization
46563
+ // - `BindingElement: BindingPattern Initializer?`
46564
+ // - https://tc39.es/ecma262/#sec-runtime-semantics-keyedbindinginitialization
46565
+ // - `BindingElement: BindingPattern Initializer?`
46566
+ bind(node.dotDotDotToken);
46567
+ bind(node.propertyName);
46568
+ bindInitializer(node.initializer);
46569
+ bind(node.name);
46570
+ }
46571
+ function bindParameterFlow(node) {
46572
+ bindEach(node.modifiers);
46573
+ bind(node.dotDotDotToken);
46574
+ bind(node.questionToken);
46575
+ bind(node.type);
46576
+ bindInitializer(node.initializer);
46577
+ bind(node.name);
46578
+ }
46579
+ // a BindingElement/Parameter does not have side effects if initializers are not evaluated and used. (see GH#49759)
46580
+ function bindInitializer(node) {
46581
+ if (!node) {
46582
+ return;
46571
46583
  }
46572
- else {
46573
- bindEachChild(node);
46584
+ var entryFlow = currentFlow;
46585
+ bind(node);
46586
+ if (entryFlow === unreachableFlow || entryFlow === currentFlow) {
46587
+ return;
46574
46588
  }
46589
+ var exitFlow = createBranchLabel();
46590
+ addAntecedent(exitFlow, entryFlow);
46591
+ addAntecedent(exitFlow, currentFlow);
46592
+ currentFlow = finishFlowLabel(exitFlow);
46575
46593
  }
46576
46594
  function bindJSDocTypeAlias(node) {
46577
46595
  bind(node.tagName);
@@ -49742,7 +49760,7 @@ var ts;
49742
49760
  if (unidirectional === void 0) { unidirectional = false; }
49743
49761
  source.forEach(function (sourceSymbol, id) {
49744
49762
  var targetSymbol = target.get(id);
49745
- target.set(id, targetSymbol ? mergeSymbol(targetSymbol, sourceSymbol, unidirectional) : sourceSymbol);
49763
+ target.set(id, targetSymbol ? mergeSymbol(targetSymbol, sourceSymbol, unidirectional) : getMergedSymbol(sourceSymbol));
49746
49764
  });
49747
49765
  }
49748
49766
  function mergeModuleAugmentation(moduleName) {
@@ -56533,11 +56551,9 @@ var ts;
56533
56551
  return getReturnTypeOfSignature(getterSignature);
56534
56552
  }
56535
56553
  }
56536
- if (ts.isInJSFile(declaration)) {
56537
- var type_1 = getParameterTypeOfTypeTag(func, declaration);
56538
- if (type_1)
56539
- return type_1;
56540
- }
56554
+ var parameterTypeOfTypeTag = getParameterTypeOfTypeTag(func, declaration);
56555
+ if (parameterTypeOfTypeTag)
56556
+ return parameterTypeOfTypeTag;
56541
56557
  // Use contextual parameter type if one is available
56542
56558
  var type = declaration.symbol.escapedName === "this" /* This */ ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration);
56543
56559
  if (type) {
@@ -57113,9 +57129,9 @@ var ts;
57113
57129
  if (typeNode === undefined) {
57114
57130
  return useUnknownInCatchVariables ? unknownType : anyType;
57115
57131
  }
57116
- var type_2 = getTypeOfNode(typeNode);
57132
+ var type_1 = getTypeOfNode(typeNode);
57117
57133
  // an errorType will make `checkTryStatement` issue an error
57118
- return isTypeAny(type_2) || type_2 === unknownType ? type_2 : errorType;
57134
+ return isTypeAny(type_1) || type_1 === unknownType ? type_1 : errorType;
57119
57135
  }
57120
57136
  // Handle export default expressions
57121
57137
  if (ts.isSourceFile(declaration) && ts.isJsonSourceFile(declaration)) {
@@ -57325,11 +57341,11 @@ var ts;
57325
57341
  return errorType;
57326
57342
  }
57327
57343
  var exportEquals = getMergedSymbol(symbol.exports.get("export=" /* ExportEquals */));
57328
- var type_3 = getWidenedTypeForAssignmentDeclaration(exportEquals, exportEquals === resolvedModule ? undefined : resolvedModule);
57344
+ var type_2 = getWidenedTypeForAssignmentDeclaration(exportEquals, exportEquals === resolvedModule ? undefined : resolvedModule);
57329
57345
  if (!popTypeResolution()) {
57330
57346
  return reportCircularityError(symbol);
57331
57347
  }
57332
- return type_3;
57348
+ return type_2;
57333
57349
  }
57334
57350
  }
57335
57351
  var type = createObjectType(16 /* Anonymous */, symbol);
@@ -59552,10 +59568,10 @@ var ts;
59552
59568
  var baseTypes = [];
59553
59569
  var different = false;
59554
59570
  for (var _i = 0, types_7 = types; _i < types_7.length; _i++) {
59555
- var type_4 = types_7[_i];
59556
- var baseType = getBaseConstraint(type_4);
59571
+ var type_3 = types_7[_i];
59572
+ var baseType = getBaseConstraint(type_3);
59557
59573
  if (baseType) {
59558
- if (baseType !== type_4) {
59574
+ if (baseType !== type_3) {
59559
59575
  different = true;
59560
59576
  }
59561
59577
  baseTypes.push(baseType);
@@ -60346,7 +60362,12 @@ var ts;
60346
60362
  continue;
60347
60363
  }
60348
60364
  }
60349
- result.push(getSignatureFromDeclaration(decl));
60365
+ // If this is a function or method declaration, get the signature from the @type tag for the sake of optional parameters.
60366
+ // Exclude contextually-typed kinds because we already apply the @type tag to the context, plus applying it here to the initializer would supress checks that the two are compatible.
60367
+ result.push((!ts.isFunctionExpressionOrArrowFunction(decl) &&
60368
+ !ts.isObjectLiteralMethod(decl) &&
60369
+ getSignatureOfTypeTag(decl)) ||
60370
+ getSignatureFromDeclaration(decl));
60350
60371
  }
60351
60372
  return result;
60352
60373
  }
@@ -60377,7 +60398,7 @@ var ts;
60377
60398
  else {
60378
60399
  var type = signature.declaration && ts.getEffectiveReturnTypeNode(signature.declaration);
60379
60400
  var jsdocPredicate = void 0;
60380
- if (!type && ts.isInJSFile(signature.declaration)) {
60401
+ if (!type) {
60381
60402
  var jsdocSignature = getSignatureOfTypeTag(signature.declaration);
60382
60403
  if (jsdocSignature && signature !== jsdocSignature) {
60383
60404
  jsdocPredicate = getTypePredicateOfSignature(jsdocSignature);
@@ -64403,15 +64424,14 @@ var ts;
64403
64424
  return false;
64404
64425
  }
64405
64426
  function isContextSensitiveFunctionLikeDeclaration(node) {
64406
- return (!ts.isFunctionDeclaration(node) || ts.isInJSFile(node) && !!getTypeForDeclarationFromJSDocComment(node)) &&
64407
- (ts.hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node));
64427
+ return ts.hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node);
64408
64428
  }
64409
64429
  function hasContextSensitiveReturnExpression(node) {
64410
64430
  // TODO(anhans): A block should be context-sensitive if it has a context-sensitive return value.
64411
64431
  return !node.typeParameters && !ts.getEffectiveReturnTypeNode(node) && !!node.body && node.body.kind !== 235 /* Block */ && isContextSensitive(node.body);
64412
64432
  }
64413
64433
  function isContextSensitiveFunctionOrObjectLiteralMethod(func) {
64414
- return (ts.isInJSFile(func) && ts.isFunctionDeclaration(func) || ts.isFunctionExpressionOrArrowFunction(func) || ts.isObjectLiteralMethod(func)) &&
64434
+ return (ts.isFunctionExpressionOrArrowFunction(func) || ts.isObjectLiteralMethod(func)) &&
64415
64435
  isContextSensitiveFunctionLikeDeclaration(func);
64416
64436
  }
64417
64437
  function getTypeWithoutSignatures(type) {
@@ -73469,9 +73489,11 @@ var ts;
73469
73489
  case 1 /* ExportsProperty */:
73470
73490
  case 6 /* Prototype */:
73471
73491
  case 3 /* PrototypeProperty */:
73472
- var valueDeclaration = (_a = binaryExpression.left.symbol) === null || _a === void 0 ? void 0 : _a.valueDeclaration;
73473
- // falls through
73474
73492
  case 2 /* ModuleExports */:
73493
+ var valueDeclaration = void 0;
73494
+ if (kind !== 2 /* ModuleExports */) {
73495
+ valueDeclaration = (_a = binaryExpression.left.symbol) === null || _a === void 0 ? void 0 : _a.valueDeclaration;
73496
+ }
73475
73497
  valueDeclaration || (valueDeclaration = (_b = binaryExpression.symbol) === null || _b === void 0 ? void 0 : _b.valueDeclaration);
73476
73498
  var annotated = valueDeclaration && ts.getEffectiveTypeAnnotationNode(valueDeclaration);
73477
73499
  return annotated ? getTypeFromTypeNode(annotated) : undefined;
@@ -73949,9 +73971,18 @@ var ts;
73949
73971
  if (!isErrorType(intrinsicClassAttribs)) {
73950
73972
  var typeParams = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(intrinsicClassAttribs.symbol);
73951
73973
  var hostClassType = getReturnTypeOfSignature(sig);
73952
- apparentAttributesType = intersectTypes(typeParams
73953
- ? createTypeReference(intrinsicClassAttribs, fillMissingTypeArguments([hostClassType], typeParams, getMinTypeArgumentCount(typeParams), ts.isInJSFile(context)))
73954
- : intrinsicClassAttribs, apparentAttributesType);
73974
+ var libraryManagedAttributeType = void 0;
73975
+ if (typeParams && typeParams.length === 1) {
73976
+ var inferredArgs = fillMissingTypeArguments([hostClassType], typeParams, getMinTypeArgumentCount(typeParams), ts.isInJSFile(context));
73977
+ libraryManagedAttributeType = instantiateType(intrinsicClassAttribs, createTypeMapper(typeParams, inferredArgs));
73978
+ }
73979
+ else if (typeParams)
73980
+ libraryManagedAttributeType = undefined;
73981
+ else
73982
+ libraryManagedAttributeType = intrinsicClassAttribs;
73983
+ if (libraryManagedAttributeType) {
73984
+ apparentAttributesType = intersectTypes(libraryManagedAttributeType, apparentAttributesType);
73985
+ }
73955
73986
  }
73956
73987
  var intrinsicAttribs = getJsxType(JsxNames.IntrinsicAttributes, context);
73957
73988
  if (!isErrorType(intrinsicAttribs)) {
@@ -77778,12 +77809,15 @@ var ts;
77778
77809
  return false;
77779
77810
  }
77780
77811
  var func = ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) ? node :
77781
- ts.isVariableDeclaration(node) && node.initializer && ts.isFunctionExpression(node.initializer) ? node.initializer :
77812
+ (ts.isVariableDeclaration(node) || ts.isPropertyAssignment(node)) && node.initializer && ts.isFunctionExpression(node.initializer) ? node.initializer :
77782
77813
  undefined;
77783
77814
  if (func) {
77784
- // If the node has a @class tag, treat it like a constructor.
77815
+ // If the node has a @class or @constructor tag, treat it like a constructor.
77785
77816
  if (ts.getJSDocClassTag(node))
77786
77817
  return true;
77818
+ // If the node is a property of an object literal.
77819
+ if (ts.isPropertyAssignment(ts.walkUpParenthesizedExpressions(func.parent)))
77820
+ return false;
77787
77821
  // If the symbol of the node has members, treat it like a constructor.
77788
77822
  var symbol = getSymbolOfNode(func);
77789
77823
  return !!((_a = symbol === null || symbol === void 0 ? void 0 : symbol.members) === null || _a === void 0 ? void 0 : _a.size);
@@ -78031,8 +78065,8 @@ var ts;
78031
78065
  if (hasDefaultOnly && type && !isErrorType(type)) {
78032
78066
  var synthType = type;
78033
78067
  if (!synthType.defaultOnlyType) {
78034
- var type_5 = createDefaultPropertyWrapperForModule(symbol, originalSymbol);
78035
- synthType.defaultOnlyType = type_5;
78068
+ var type_4 = createDefaultPropertyWrapperForModule(symbol, originalSymbol);
78069
+ synthType.defaultOnlyType = type_4;
78036
78070
  }
78037
78071
  return synthType.defaultOnlyType;
78038
78072
  }
@@ -87369,6 +87403,12 @@ var ts;
87369
87403
  return resolveJSDocMemberName(name, /*ignoreErrors*/ false, getSymbolOfNode(container));
87370
87404
  }
87371
87405
  }
87406
+ if (result && isJSDoc_1) {
87407
+ var container = ts.getJSDocHost(name);
87408
+ if (container && ts.isEnumMember(container) && container === result.valueDeclaration) {
87409
+ return resolveEntityName(name, meaning, /*ignoreErrors*/ true, /* dontResolveAlias */ true, ts.getSourceFileOfNode(container)) || result;
87410
+ }
87411
+ }
87372
87412
  return result;
87373
87413
  }
87374
87414
  else if (ts.isPrivateIdentifier(name)) {
@@ -107530,6 +107570,13 @@ var ts;
107530
107570
  ts.Debug.assert(importVariableName !== undefined);
107531
107571
  // save import into the local
107532
107572
  statements.push(factory.createExpressionStatement(factory.createAssignment(importVariableName, parameterName)));
107573
+ if (ts.hasSyntacticModifier(entry, 1 /* Export */)) {
107574
+ statements.push(factory.createExpressionStatement(factory.createCallExpression(exportFunction,
107575
+ /*typeArguments*/ undefined, [
107576
+ factory.createStringLiteral(ts.idText(importVariableName)),
107577
+ parameterName,
107578
+ ])));
107579
+ }
107533
107580
  break;
107534
107581
  case 272 /* ExportDeclaration */:
107535
107582
  ts.Debug.assert(importVariableName !== undefined);
@@ -110372,8 +110419,12 @@ var ts;
110372
110419
  }
110373
110420
  var previousNeedsDeclare = needsDeclare;
110374
110421
  switch (input.kind) {
110375
- case 259 /* TypeAliasDeclaration */: // Type aliases get `declare`d if need be (for legacy support), but that's all
110376
- return cleanup(factory.updateTypeAliasDeclaration(input, ensureModifiers(input), input.name, ts.visitNodes(input.typeParameters, visitDeclarationSubtree, ts.isTypeParameterDeclaration), ts.visitNode(input.type, visitDeclarationSubtree, ts.isTypeNode)));
110422
+ case 259 /* TypeAliasDeclaration */: {
110423
+ needsDeclare = false;
110424
+ var clean = cleanup(factory.updateTypeAliasDeclaration(input, ensureModifiers(input), input.name, ts.visitNodes(input.typeParameters, visitDeclarationSubtree, ts.isTypeParameterDeclaration), ts.visitNode(input.type, visitDeclarationSubtree, ts.isTypeNode)));
110425
+ needsDeclare = previousNeedsDeclare;
110426
+ return clean;
110427
+ }
110377
110428
  case 258 /* InterfaceDeclaration */: {
110378
110429
  return cleanup(factory.updateInterfaceDeclaration(input, ensureModifiers(input), input.name, ensureTypeParams(input, input.typeParameters), transformHeritageClauses(input.heritageClauses), ts.visitNodes(input.members, visitDeclarationSubtree)));
110379
110430
  }
@@ -111877,8 +111928,8 @@ var ts;
111877
111928
  }
111878
111929
  ts.getBuildInfoText = getBuildInfoText;
111879
111930
  /*@internal*/
111880
- function getBuildInfo(buildInfoText) {
111881
- return JSON.parse(buildInfoText);
111931
+ function getBuildInfo(buildInfoFile, buildInfoText) {
111932
+ return ts.readJsonOrUndefined(buildInfoFile, buildInfoText);
111882
111933
  }
111883
111934
  ts.getBuildInfo = getBuildInfo;
111884
111935
  /*@internal*/
@@ -111956,17 +112007,16 @@ var ts;
111956
112007
  var buildInfo;
111957
112008
  if (host.getBuildInfo) {
111958
112009
  // If host directly provides buildinfo we can get it directly. This allows host to cache the buildinfo
111959
- var hostBuildInfo = host.getBuildInfo(buildInfoPath, config.options.configFilePath);
111960
- if (!hostBuildInfo)
111961
- return buildInfoPath;
111962
- buildInfo = hostBuildInfo;
112010
+ buildInfo = host.getBuildInfo(buildInfoPath, config.options.configFilePath);
111963
112011
  }
111964
112012
  else {
111965
112013
  var buildInfoText = host.readFile(buildInfoPath);
111966
112014
  if (!buildInfoText)
111967
112015
  return buildInfoPath;
111968
- buildInfo = getBuildInfo(buildInfoText);
112016
+ buildInfo = getBuildInfo(buildInfoPath, buildInfoText);
111969
112017
  }
112018
+ if (!buildInfo)
112019
+ return buildInfoPath;
111970
112020
  if (!buildInfo.bundle || !buildInfo.bundle.js || (declarationFilePath && !buildInfo.bundle.dts))
111971
112021
  return buildInfoPath;
111972
112022
  var jsFileText = host.readFile(ts.Debug.checkDefined(jsFilePath));
@@ -116624,7 +116674,16 @@ var ts;
116624
116674
  return cachedReadDirectoryResult.get(ts.ensureTrailingDirectorySeparator(rootDirPath));
116625
116675
  }
116626
116676
  function getCachedFileSystemEntriesForBaseDir(path) {
116627
- return getCachedFileSystemEntries(ts.getDirectoryPath(path));
116677
+ var entries = getCachedFileSystemEntries(ts.getDirectoryPath(path));
116678
+ if (!entries) {
116679
+ return entries;
116680
+ }
116681
+ // If we're looking for the base directory, we're definitely going to search the entries
116682
+ if (!entries.sortedAndCanonicalizedFiles) {
116683
+ entries.sortedAndCanonicalizedFiles = entries.files.map(getCanonicalFileName).sort();
116684
+ entries.sortedAndCanonicalizedDirectories = entries.directories.map(getCanonicalFileName).sort();
116685
+ }
116686
+ return entries;
116628
116687
  }
116629
116688
  function getBaseNameOfFileName(fileName) {
116630
116689
  return ts.getBaseFileName(ts.normalizePath(fileName));
@@ -116667,21 +116726,10 @@ var ts;
116667
116726
  return undefined;
116668
116727
  }
116669
116728
  }
116670
- function fileNameEqual(name1, name2) {
116671
- return getCanonicalFileName(name1) === getCanonicalFileName(name2);
116672
- }
116673
116729
  function hasEntry(entries, name) {
116674
- return ts.some(entries, function (file) { return fileNameEqual(file, name); });
116675
- }
116676
- function updateFileSystemEntry(entries, baseName, isValid) {
116677
- if (hasEntry(entries, baseName)) {
116678
- if (!isValid) {
116679
- return ts.filterMutate(entries, function (entry) { return !fileNameEqual(entry, baseName); });
116680
- }
116681
- }
116682
- else if (isValid) {
116683
- return entries.push(baseName);
116684
- }
116730
+ // Case-sensitive comparison since already canonicalized
116731
+ var index = ts.binarySearch(entries, name, ts.identity, ts.compareStringsCaseSensitive);
116732
+ return index >= 0;
116685
116733
  }
116686
116734
  function writeFile(fileName, data, writeByteOrderMark) {
116687
116735
  var path = toPath(fileName);
@@ -116694,7 +116742,7 @@ var ts;
116694
116742
  function fileExists(fileName) {
116695
116743
  var path = toPath(fileName);
116696
116744
  var result = getCachedFileSystemEntriesForBaseDir(path);
116697
- return result && hasEntry(result.files, getBaseNameOfFileName(fileName)) ||
116745
+ return result && hasEntry(result.sortedAndCanonicalizedFiles, getCanonicalFileName(getBaseNameOfFileName(fileName))) ||
116698
116746
  host.fileExists(fileName);
116699
116747
  }
116700
116748
  function directoryExists(dirPath) {
@@ -116704,9 +116752,14 @@ var ts;
116704
116752
  function createDirectory(dirPath) {
116705
116753
  var path = toPath(dirPath);
116706
116754
  var result = getCachedFileSystemEntriesForBaseDir(path);
116707
- var baseFileName = getBaseNameOfFileName(dirPath);
116708
116755
  if (result) {
116709
- updateFileSystemEntry(result.directories, baseFileName, /*isValid*/ true);
116756
+ var baseName = getBaseNameOfFileName(dirPath);
116757
+ var canonicalizedBaseName = getCanonicalFileName(baseName);
116758
+ var canonicalizedDirectories = result.sortedAndCanonicalizedDirectories;
116759
+ // Case-sensitive comparison since already canonicalized
116760
+ if (ts.insertSorted(canonicalizedDirectories, canonicalizedBaseName, ts.compareStringsCaseSensitive)) {
116761
+ result.directories.push(baseName);
116762
+ }
116710
116763
  }
116711
116764
  host.createDirectory(dirPath);
116712
116765
  }
@@ -116775,7 +116828,7 @@ var ts;
116775
116828
  fileExists: host.fileExists(fileOrDirectoryPath),
116776
116829
  directoryExists: host.directoryExists(fileOrDirectoryPath)
116777
116830
  };
116778
- if (fsQueryResult.directoryExists || hasEntry(parentResult.directories, baseName)) {
116831
+ if (fsQueryResult.directoryExists || hasEntry(parentResult.sortedAndCanonicalizedDirectories, getCanonicalFileName(baseName))) {
116779
116832
  // Folder added or removed, clear the cache instead of updating the folder and its structure
116780
116833
  clearCache();
116781
116834
  }
@@ -116795,7 +116848,23 @@ var ts;
116795
116848
  }
116796
116849
  }
116797
116850
  function updateFilesOfFileSystemEntry(parentResult, baseName, fileExists) {
116798
- updateFileSystemEntry(parentResult.files, baseName, fileExists);
116851
+ var canonicalizedFiles = parentResult.sortedAndCanonicalizedFiles;
116852
+ var canonicalizedBaseName = getCanonicalFileName(baseName);
116853
+ if (fileExists) {
116854
+ // Case-sensitive comparison since already canonicalized
116855
+ if (ts.insertSorted(canonicalizedFiles, canonicalizedBaseName, ts.compareStringsCaseSensitive)) {
116856
+ parentResult.files.push(baseName);
116857
+ }
116858
+ }
116859
+ else {
116860
+ // Case-sensitive comparison since already canonicalized
116861
+ var sortedIndex = ts.binarySearch(canonicalizedFiles, canonicalizedBaseName, ts.identity, ts.compareStringsCaseSensitive);
116862
+ if (sortedIndex >= 0) {
116863
+ canonicalizedFiles.splice(sortedIndex, 1);
116864
+ var unsortedIndex = parentResult.files.findIndex(function (entry) { return getCanonicalFileName(entry) === canonicalizedBaseName; });
116865
+ parentResult.files.splice(unsortedIndex, 1);
116866
+ }
116867
+ }
116799
116868
  }
116800
116869
  function clearCache() {
116801
116870
  cachedReadDirectoryResult.clear();
@@ -125033,18 +125102,14 @@ var ts;
125033
125102
  if (host.getBuildInfo) {
125034
125103
  // host provides buildinfo, get it from there. This allows host to cache it
125035
125104
  buildInfo = host.getBuildInfo(buildInfoPath, compilerOptions.configFilePath);
125036
- if (!buildInfo)
125037
- return undefined;
125038
125105
  }
125039
125106
  else {
125040
125107
  var content = host.readFile(buildInfoPath);
125041
125108
  if (!content)
125042
125109
  return undefined;
125043
- buildInfo = ts.getBuildInfo(content);
125110
+ buildInfo = ts.getBuildInfo(buildInfoPath, content);
125044
125111
  }
125045
- if (buildInfo.version !== ts.version)
125046
- return undefined;
125047
- if (!buildInfo.program)
125112
+ if (!buildInfo || buildInfo.version !== ts.version || !buildInfo.program)
125048
125113
  return undefined;
125049
125114
  return ts.createBuilderProgramUsingProgramBuildInfo(buildInfo.program, buildInfoPath, host);
125050
125115
  }
@@ -125266,7 +125331,8 @@ var ts;
125266
125331
  }
125267
125332
  // All resolutions are invalid if user provided resolutions
125268
125333
  var hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution);
125269
- if (ts.isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
125334
+ var _a = ts.changeCompilerHostLikeToUseCache(compilerHost, toPath), originalReadFile = _a.originalReadFile, originalFileExists = _a.originalFileExists, originalDirectoryExists = _a.originalDirectoryExists, originalCreateDirectory = _a.originalCreateDirectory, originalWriteFile = _a.originalWriteFile;
125335
+ if (ts.isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, function (fileName) { return compilerHost.fileExists(fileName); }, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
125270
125336
  if (hasChangedConfigFileParsingErrors) {
125271
125337
  if (reportFileChangeDetectedOnCreateProgram) {
125272
125338
  reportWatchDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation);
@@ -125285,6 +125351,11 @@ var ts;
125285
125351
  if (host.afterProgramCreate && program !== builderProgram) {
125286
125352
  host.afterProgramCreate(builderProgram);
125287
125353
  }
125354
+ compilerHost.readFile = originalReadFile;
125355
+ compilerHost.fileExists = originalFileExists;
125356
+ compilerHost.directoryExists = originalDirectoryExists;
125357
+ compilerHost.createDirectory = originalCreateDirectory;
125358
+ compilerHost.writeFile = originalWriteFile;
125288
125359
  return builderProgram;
125289
125360
  }
125290
125361
  function createNewProgram(hasInvalidatedResolution) {
@@ -125762,19 +125833,20 @@ var ts;
125762
125833
  */
125763
125834
  UpToDateStatusType[UpToDateStatusType["OutOfDateWithPrepend"] = 3] = "OutOfDateWithPrepend";
125764
125835
  UpToDateStatusType[UpToDateStatusType["OutputMissing"] = 4] = "OutputMissing";
125765
- UpToDateStatusType[UpToDateStatusType["OutOfDateWithSelf"] = 5] = "OutOfDateWithSelf";
125766
- UpToDateStatusType[UpToDateStatusType["OutOfDateWithUpstream"] = 6] = "OutOfDateWithUpstream";
125767
- UpToDateStatusType[UpToDateStatusType["OutOfDateBuildInfo"] = 7] = "OutOfDateBuildInfo";
125768
- UpToDateStatusType[UpToDateStatusType["UpstreamOutOfDate"] = 8] = "UpstreamOutOfDate";
125769
- UpToDateStatusType[UpToDateStatusType["UpstreamBlocked"] = 9] = "UpstreamBlocked";
125770
- UpToDateStatusType[UpToDateStatusType["ComputingUpstream"] = 10] = "ComputingUpstream";
125771
- UpToDateStatusType[UpToDateStatusType["TsVersionOutputOfDate"] = 11] = "TsVersionOutputOfDate";
125772
- UpToDateStatusType[UpToDateStatusType["UpToDateWithInputFileText"] = 12] = "UpToDateWithInputFileText";
125836
+ UpToDateStatusType[UpToDateStatusType["ErrorReadingFile"] = 5] = "ErrorReadingFile";
125837
+ UpToDateStatusType[UpToDateStatusType["OutOfDateWithSelf"] = 6] = "OutOfDateWithSelf";
125838
+ UpToDateStatusType[UpToDateStatusType["OutOfDateWithUpstream"] = 7] = "OutOfDateWithUpstream";
125839
+ UpToDateStatusType[UpToDateStatusType["OutOfDateBuildInfo"] = 8] = "OutOfDateBuildInfo";
125840
+ UpToDateStatusType[UpToDateStatusType["UpstreamOutOfDate"] = 9] = "UpstreamOutOfDate";
125841
+ UpToDateStatusType[UpToDateStatusType["UpstreamBlocked"] = 10] = "UpstreamBlocked";
125842
+ UpToDateStatusType[UpToDateStatusType["ComputingUpstream"] = 11] = "ComputingUpstream";
125843
+ UpToDateStatusType[UpToDateStatusType["TsVersionOutputOfDate"] = 12] = "TsVersionOutputOfDate";
125844
+ UpToDateStatusType[UpToDateStatusType["UpToDateWithInputFileText"] = 13] = "UpToDateWithInputFileText";
125773
125845
  /**
125774
125846
  * Projects with no outputs (i.e. "solution" files)
125775
125847
  */
125776
- UpToDateStatusType[UpToDateStatusType["ContainerOnly"] = 13] = "ContainerOnly";
125777
- UpToDateStatusType[UpToDateStatusType["ForceBuild"] = 14] = "ForceBuild";
125848
+ UpToDateStatusType[UpToDateStatusType["ContainerOnly"] = 14] = "ContainerOnly";
125849
+ UpToDateStatusType[UpToDateStatusType["ForceBuild"] = 15] = "ForceBuild";
125778
125850
  })(UpToDateStatusType = ts.UpToDateStatusType || (ts.UpToDateStatusType = {}));
125779
125851
  function resolveConfigFileProjectName(project) {
125780
125852
  if (ts.fileExtensionIs(project, ".json" /* Json */)) {
@@ -126476,13 +126548,13 @@ var ts;
126476
126548
  var emitterDiagnostics = ts.createDiagnosticCollection();
126477
126549
  var emittedOutputs = new ts.Map();
126478
126550
  var resultFlags = BuildResultFlags.DeclarationOutputUnchanged;
126479
- var existingBuildInfo = state.buildInfoCache.get(projectPath).buildInfo;
126551
+ var existingBuildInfo = state.buildInfoCache.get(projectPath).buildInfo || undefined;
126480
126552
  outputFiles.forEach(function (_a) {
126481
126553
  var _b, _c;
126482
126554
  var name = _a.name, text = _a.text, writeByteOrderMark = _a.writeByteOrderMark, buildInfo = _a.buildInfo;
126483
126555
  emittedOutputs.set(toPath(state, name), name);
126484
126556
  if (buildInfo) {
126485
- if (((_b = buildInfo.program) === null || _b === void 0 ? void 0 : _b.outSignature) !== ((_c = existingBuildInfo.program) === null || _c === void 0 ? void 0 : _c.outSignature)) {
126557
+ if (((_b = buildInfo.program) === null || _b === void 0 ? void 0 : _b.outSignature) !== ((_c = existingBuildInfo === null || existingBuildInfo === void 0 ? void 0 : existingBuildInfo.program) === null || _c === void 0 ? void 0 : _c.outSignature)) {
126486
126558
  resultFlags &= ~BuildResultFlags.DeclarationOutputUnchanged;
126487
126559
  }
126488
126560
  setBuildInfo(state, buildInfo, projectPath, config.options, resultFlags);
@@ -126775,8 +126847,7 @@ var ts;
126775
126847
  return existing.buildInfo || undefined;
126776
126848
  }
126777
126849
  var value = state.readFileWithCache(buildInfoPath);
126778
- var buildInfo = value ? ts.getBuildInfo(value) : undefined;
126779
- ts.Debug.assert(modifiedTime || !buildInfo);
126850
+ var buildInfo = value ? ts.getBuildInfo(buildInfoPath, value) : undefined;
126780
126851
  state.buildInfoCache.set(resolvedConfigPath, { path: path, buildInfo: buildInfo || false, modifiedTime: modifiedTime || ts.missingFileModifiedTime });
126781
126852
  return buildInfo;
126782
126853
  }
@@ -126861,7 +126932,14 @@ var ts;
126861
126932
  missingOutputFileName: buildInfoPath
126862
126933
  };
126863
126934
  }
126864
- var buildInfo = ts.Debug.checkDefined(getBuildInfo(state, buildInfoPath, resolvedPath, buildInfoTime));
126935
+ var buildInfo = getBuildInfo(state, buildInfoPath, resolvedPath, buildInfoTime);
126936
+ if (!buildInfo) {
126937
+ // Error reading buildInfo
126938
+ return {
126939
+ type: ts.UpToDateStatusType.ErrorReadingFile,
126940
+ fileName: buildInfoPath
126941
+ };
126942
+ }
126865
126943
  if ((buildInfo.bundle || buildInfo.program) && buildInfo.version !== ts.version) {
126866
126944
  return {
126867
126945
  type: ts.UpToDateStatusType.TsVersionOutputOfDate,
@@ -127519,6 +127597,8 @@ var ts;
127519
127597
  return reportStatus(state, ts.Diagnostics.Project_0_is_out_of_date_because_output_1_is_older_than_input_2, relName(state, configFileName), relName(state, status.outOfDateOutputFileName), relName(state, status.newerProjectName));
127520
127598
  case ts.UpToDateStatusType.OutputMissing:
127521
127599
  return reportStatus(state, ts.Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, relName(state, configFileName), relName(state, status.missingOutputFileName));
127600
+ case ts.UpToDateStatusType.ErrorReadingFile:
127601
+ return reportStatus(state, ts.Diagnostics.Project_0_is_out_of_date_because_there_was_error_reading_file_1, relName(state, configFileName), relName(state, status.fileName));
127522
127602
  case ts.UpToDateStatusType.OutOfDateBuildInfo:
127523
127603
  return reportStatus(state, ts.Diagnostics.Project_0_is_out_of_date_because_buildinfo_file_1_indicates_that_some_of_the_changes_were_not_emitted, relName(state, configFileName), relName(state, status.buildInfoFile));
127524
127604
  case ts.UpToDateStatusType.UpToDate:
@@ -156553,6 +156633,15 @@ var ts;
156553
156633
  ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code,
156554
156634
  ts.Diagnostics.Cannot_find_name_0.code
156555
156635
  ];
156636
+ var InfoKind;
156637
+ (function (InfoKind) {
156638
+ InfoKind[InfoKind["TypeLikeDeclaration"] = 0] = "TypeLikeDeclaration";
156639
+ InfoKind[InfoKind["Enum"] = 1] = "Enum";
156640
+ InfoKind[InfoKind["Function"] = 2] = "Function";
156641
+ InfoKind[InfoKind["ObjectLiteral"] = 3] = "ObjectLiteral";
156642
+ InfoKind[InfoKind["JsxAttributes"] = 4] = "JsxAttributes";
156643
+ InfoKind[InfoKind["Signature"] = 5] = "Signature";
156644
+ })(InfoKind || (InfoKind = {}));
156556
156645
  codefix.registerCodeFix({
156557
156646
  errorCodes: errorCodes,
156558
156647
  getCodeActions: function (context) {
@@ -156561,19 +156650,19 @@ var ts;
156561
156650
  if (!info) {
156562
156651
  return undefined;
156563
156652
  }
156564
- if (info.kind === 3 /* ObjectLiteral */) {
156653
+ if (info.kind === InfoKind.ObjectLiteral) {
156565
156654
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addObjectLiteralProperties(t, context, info); });
156566
156655
  return [codefix.createCodeFixAction(fixMissingProperties, changes, ts.Diagnostics.Add_missing_properties, fixMissingProperties, ts.Diagnostics.Add_all_missing_properties)];
156567
156656
  }
156568
- if (info.kind === 4 /* JsxAttributes */) {
156657
+ if (info.kind === InfoKind.JsxAttributes) {
156569
156658
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addJsxAttributes(t, context, info); });
156570
156659
  return [codefix.createCodeFixAction(fixMissingAttributes, changes, ts.Diagnostics.Add_missing_attributes, fixMissingAttributes, ts.Diagnostics.Add_all_missing_attributes)];
156571
156660
  }
156572
- if (info.kind === 2 /* Function */) {
156661
+ if (info.kind === InfoKind.Function || info.kind === InfoKind.Signature) {
156573
156662
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addFunctionDeclaration(t, context, info); });
156574
156663
  return [codefix.createCodeFixAction(fixMissingFunctionDeclaration, changes, [ts.Diagnostics.Add_missing_function_declaration_0, info.token.text], fixMissingFunctionDeclaration, ts.Diagnostics.Add_all_missing_function_declarations)];
156575
156664
  }
156576
- if (info.kind === 1 /* Enum */) {
156665
+ if (info.kind === InfoKind.Enum) {
156577
156666
  var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addEnumMemberDeclaration(t, context.program.getTypeChecker(), info); });
156578
156667
  return [codefix.createCodeFixAction(fixMissingMember, changes, [ts.Diagnostics.Add_missing_enum_member_0, info.token.text], fixMissingMember, ts.Diagnostics.Add_all_missing_members)];
156579
156668
  }
@@ -156591,20 +156680,20 @@ var ts;
156591
156680
  if (!info || !ts.addToSeen(seen, ts.getNodeId(info.parentDeclaration) + "#" + info.token.text)) {
156592
156681
  return;
156593
156682
  }
156594
- if (fixId === fixMissingFunctionDeclaration && info.kind === 2 /* Function */) {
156683
+ if (fixId === fixMissingFunctionDeclaration && (info.kind === InfoKind.Function || info.kind === InfoKind.Signature)) {
156595
156684
  addFunctionDeclaration(changes, context, info);
156596
156685
  }
156597
- else if (fixId === fixMissingProperties && info.kind === 3 /* ObjectLiteral */) {
156686
+ else if (fixId === fixMissingProperties && info.kind === InfoKind.ObjectLiteral) {
156598
156687
  addObjectLiteralProperties(changes, context, info);
156599
156688
  }
156600
- else if (fixId === fixMissingAttributes && info.kind === 4 /* JsxAttributes */) {
156689
+ else if (fixId === fixMissingAttributes && info.kind === InfoKind.JsxAttributes) {
156601
156690
  addJsxAttributes(changes, context, info);
156602
156691
  }
156603
156692
  else {
156604
- if (info.kind === 1 /* Enum */) {
156693
+ if (info.kind === InfoKind.Enum) {
156605
156694
  addEnumMemberDeclaration(changes, checker, info);
156606
156695
  }
156607
- if (info.kind === 0 /* TypeLikeDeclaration */) {
156696
+ if (info.kind === InfoKind.TypeLikeDeclaration) {
156608
156697
  var parentDeclaration = info.parentDeclaration, token_1 = info.token;
156609
156698
  var infos = ts.getOrUpdate(typeDeclToMembers, parentDeclaration, function () { return []; });
156610
156699
  if (!infos.some(function (i) { return i.token.text === token_1.text; })) {
@@ -156648,14 +156737,6 @@ var ts;
156648
156737
  }));
156649
156738
  },
156650
156739
  });
156651
- var InfoKind;
156652
- (function (InfoKind) {
156653
- InfoKind[InfoKind["TypeLikeDeclaration"] = 0] = "TypeLikeDeclaration";
156654
- InfoKind[InfoKind["Enum"] = 1] = "Enum";
156655
- InfoKind[InfoKind["Function"] = 2] = "Function";
156656
- InfoKind[InfoKind["ObjectLiteral"] = 3] = "ObjectLiteral";
156657
- InfoKind[InfoKind["JsxAttributes"] = 4] = "JsxAttributes";
156658
- })(InfoKind || (InfoKind = {}));
156659
156740
  function getInfo(sourceFile, tokenPos, errorCode, checker, program) {
156660
156741
  // The identifier of the missing property. eg:
156661
156742
  // this.missing = 1;
@@ -156677,7 +156758,7 @@ var ts;
156677
156758
  var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent), checker.getParameterType(signature, argIndex), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
156678
156759
  if (!ts.length(properties))
156679
156760
  return undefined;
156680
- return { kind: 3 /* ObjectLiteral */, token: param.name, properties: properties, parentDeclaration: parent };
156761
+ return { kind: InfoKind.ObjectLiteral, token: param.name, properties: properties, parentDeclaration: parent };
156681
156762
  }
156682
156763
  if (!ts.isMemberName(token))
156683
156764
  return undefined;
@@ -156685,17 +156766,26 @@ var ts;
156685
156766
  var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent.initializer), checker.getTypeAtLocation(token), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
156686
156767
  if (!ts.length(properties))
156687
156768
  return undefined;
156688
- return { kind: 3 /* ObjectLiteral */, token: token, properties: properties, parentDeclaration: parent.initializer };
156769
+ return { kind: InfoKind.ObjectLiteral, token: token, properties: properties, parentDeclaration: parent.initializer };
156689
156770
  }
156690
156771
  if (ts.isIdentifier(token) && ts.isJsxOpeningLikeElement(token.parent)) {
156691
156772
  var target = ts.getEmitScriptTarget(program.getCompilerOptions());
156692
156773
  var attributes = getUnmatchedAttributes(checker, target, token.parent);
156693
156774
  if (!ts.length(attributes))
156694
156775
  return undefined;
156695
- return { kind: 4 /* JsxAttributes */, token: token, attributes: attributes, parentDeclaration: token.parent };
156776
+ return { kind: InfoKind.JsxAttributes, token: token, attributes: attributes, parentDeclaration: token.parent };
156696
156777
  }
156697
- if (ts.isIdentifier(token) && ts.isCallExpression(parent) && parent.expression === token) {
156698
- return { kind: 2 /* Function */, token: token, call: parent, sourceFile: sourceFile, modifierFlags: 0 /* None */, parentDeclaration: sourceFile };
156778
+ if (ts.isIdentifier(token)) {
156779
+ var type = checker.getContextualType(token);
156780
+ if (type && ts.getObjectFlags(type) & 16 /* Anonymous */) {
156781
+ var signature = ts.firstOrUndefined(checker.getSignaturesOfType(type, 0 /* Call */));
156782
+ if (signature === undefined)
156783
+ return undefined;
156784
+ return { kind: InfoKind.Signature, token: token, signature: signature, sourceFile: sourceFile, parentDeclaration: findScope(token) };
156785
+ }
156786
+ if (ts.isCallExpression(parent) && parent.expression === token) {
156787
+ return { kind: InfoKind.Function, token: token, call: parent, sourceFile: sourceFile, modifierFlags: 0 /* None */, parentDeclaration: findScope(token) };
156788
+ }
156699
156789
  }
156700
156790
  if (!ts.isPropertyAccessExpression(parent))
156701
156791
  return undefined;
@@ -156707,13 +156797,13 @@ var ts;
156707
156797
  var moduleDeclaration = ts.find(symbol.declarations, ts.isModuleDeclaration);
156708
156798
  var moduleDeclarationSourceFile = moduleDeclaration === null || moduleDeclaration === void 0 ? void 0 : moduleDeclaration.getSourceFile();
156709
156799
  if (moduleDeclaration && moduleDeclarationSourceFile && !isSourceFileFromLibrary(program, moduleDeclarationSourceFile)) {
156710
- return { kind: 2 /* Function */, token: token, call: parent.parent, sourceFile: sourceFile, modifierFlags: 1 /* Export */, parentDeclaration: moduleDeclaration };
156800
+ return { kind: InfoKind.Function, token: token, call: parent.parent, sourceFile: sourceFile, modifierFlags: 1 /* Export */, parentDeclaration: moduleDeclaration };
156711
156801
  }
156712
156802
  var moduleSourceFile = ts.find(symbol.declarations, ts.isSourceFile);
156713
156803
  if (sourceFile.commonJsModuleIndicator)
156714
156804
  return undefined;
156715
156805
  if (moduleSourceFile && !isSourceFileFromLibrary(program, moduleSourceFile)) {
156716
- return { kind: 2 /* Function */, token: token, call: parent.parent, sourceFile: moduleSourceFile, modifierFlags: 1 /* Export */, parentDeclaration: moduleSourceFile };
156806
+ return { kind: InfoKind.Function, token: token, call: parent.parent, sourceFile: moduleSourceFile, modifierFlags: 1 /* Export */, parentDeclaration: moduleSourceFile };
156717
156807
  }
156718
156808
  }
156719
156809
  var classDeclaration = ts.find(symbol.declarations, ts.isClassLike);
@@ -156731,11 +156821,11 @@ var ts;
156731
156821
  (makeStatic ? 32 /* Static */ : 0 /* None */) | (ts.startsWithUnderscore(token.text) ? 8 /* Private */ : 0 /* None */);
156732
156822
  var isJSFile = ts.isSourceFileJS(declSourceFile);
156733
156823
  var call = ts.tryCast(parent.parent, ts.isCallExpression);
156734
- return { kind: 0 /* TypeLikeDeclaration */, token: token, call: call, modifierFlags: modifierFlags, parentDeclaration: declaration, declSourceFile: declSourceFile, isJSFile: isJSFile };
156824
+ return { kind: InfoKind.TypeLikeDeclaration, token: token, call: call, modifierFlags: modifierFlags, parentDeclaration: declaration, declSourceFile: declSourceFile, isJSFile: isJSFile };
156735
156825
  }
156736
156826
  var enumDeclaration = ts.find(symbol.declarations, ts.isEnumDeclaration);
156737
156827
  if (enumDeclaration && !ts.isPrivateIdentifier(token) && !isSourceFileFromLibrary(program, enumDeclaration.getSourceFile())) {
156738
- return { kind: 1 /* Enum */, token: token, parentDeclaration: enumDeclaration };
156828
+ return { kind: InfoKind.Enum, token: token, parentDeclaration: enumDeclaration };
156739
156829
  }
156740
156830
  return undefined;
156741
156831
  }
@@ -156911,9 +157001,17 @@ var ts;
156911
157001
  });
156912
157002
  }
156913
157003
  function addFunctionDeclaration(changes, context, info) {
157004
+ var quotePreference = ts.getQuotePreference(context.sourceFile, context.preferences);
156914
157005
  var importAdder = codefix.createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
156915
- var functionDeclaration = codefix.createSignatureDeclarationFromCallExpression(256 /* FunctionDeclaration */, context, importAdder, info.call, ts.idText(info.token), info.modifierFlags, info.parentDeclaration);
156916
- changes.insertNodeAtEndOfScope(info.sourceFile, info.parentDeclaration, functionDeclaration);
157006
+ var functionDeclaration = info.kind === InfoKind.Function
157007
+ ? codefix.createSignatureDeclarationFromCallExpression(256 /* FunctionDeclaration */, context, importAdder, info.call, ts.idText(info.token), info.modifierFlags, info.parentDeclaration)
157008
+ : codefix.createSignatureDeclarationFromSignature(256 /* FunctionDeclaration */, context, quotePreference, info.signature, codefix.createStubbedBody(ts.Diagnostics.Function_not_implemented.message, quotePreference), info.token, /*modifiers*/ undefined, /*optional*/ undefined, /*enclosingDeclaration*/ undefined, importAdder);
157009
+ if (functionDeclaration === undefined) {
157010
+ ts.Debug.fail("fixMissingFunctionDeclaration codefix got unexpected error.");
157011
+ }
157012
+ ts.isReturnStatement(info.parentDeclaration)
157013
+ ? changes.insertNodeBefore(info.sourceFile, info.parentDeclaration, functionDeclaration, /*blankLineBetween*/ true)
157014
+ : changes.insertNodeAtEndOfScope(info.sourceFile, info.parentDeclaration, functionDeclaration);
156917
157015
  importAdder.writeFixes(changes);
156918
157016
  }
156919
157017
  function addJsxAttributes(changes, context, info) {
@@ -157071,6 +157169,14 @@ var ts;
157071
157169
  }
157072
157170
  return ts.createPropertyNameNodeForIdentifierOrLiteral(symbol.name, target, quotePreference === 0 /* Single */);
157073
157171
  }
157172
+ function findScope(node) {
157173
+ if (ts.findAncestor(node, ts.isJsxExpression)) {
157174
+ var returnStatement = ts.findAncestor(node.parent, ts.isReturnStatement);
157175
+ if (returnStatement)
157176
+ return returnStatement;
157177
+ }
157178
+ return ts.getSourceFileOfNode(node);
157179
+ }
157074
157180
  })(codefix = ts.codefix || (ts.codefix = {}));
157075
157181
  })(ts || (ts = {}));
157076
157182
  /* @internal */
@@ -159760,6 +159866,9 @@ var ts;
159760
159866
  if (ts.isMethodDeclaration(signatureDeclaration)) {
159761
159867
  return ts.factory.updateMethodDeclaration(signatureDeclaration, modifiers, asteriskToken, name !== null && name !== void 0 ? name : ts.factory.createIdentifier(""), questionToken, typeParameters, parameters, type, body);
159762
159868
  }
159869
+ if (ts.isFunctionDeclaration(signatureDeclaration)) {
159870
+ return ts.factory.updateFunctionDeclaration(signatureDeclaration, modifiers, signatureDeclaration.asteriskToken, ts.tryCast(name, ts.isIdentifier), typeParameters, parameters, type, body !== null && body !== void 0 ? body : signatureDeclaration.body);
159871
+ }
159763
159872
  return undefined;
159764
159873
  }
159765
159874
  codefix.createSignatureDeclarationFromSignature = createSignatureDeclarationFromSignature;
@@ -167062,6 +167171,10 @@ var ts;
167062
167171
  getCurrentDirectory: compilerHost.getCurrentDirectory,
167063
167172
  onUnRecoverableConfigFileDiagnostic: ts.noop,
167064
167173
  };
167174
+ // The call to isProgramUptoDate below may refer back to documentRegistryBucketKey;
167175
+ // calculate this early so it's not undefined if downleveled to a var (or, if emitted
167176
+ // as a const variable without downleveling, doesn't crash).
167177
+ var documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings);
167065
167178
  // If the program is already up-to-date, we can reuse it
167066
167179
  if (ts.isProgramUptoDate(program, rootFileNames, newSettings, function (_path, fileName) { return host.getScriptVersion(fileName); }, function (fileName) { return compilerHost.fileExists(fileName); }, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
167067
167180
  return;
@@ -167071,7 +167184,6 @@ var ts;
167071
167184
  // instance. If we cancel midway through, we may end up in an inconsistent state where
167072
167185
  // the program points to old source files that have been invalidated because of
167073
167186
  // incremental parsing.
167074
- var documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings);
167075
167187
  var options = {
167076
167188
  rootNames: rootFileNames,
167077
167189
  options: newSettings,