typescript 4.6.0-dev.20220105 → 4.6.0-dev.20220109

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.20220105";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220109";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -14456,7 +14456,8 @@ var ts;
14456
14456
  Float64Array: ["at"],
14457
14457
  BigInt64Array: ["at"],
14458
14458
  BigUint64Array: ["at"],
14459
- ObjectConstructor: ["hasOwn"]
14459
+ ObjectConstructor: ["hasOwn"],
14460
+ Error: ["cause"]
14460
14461
  }
14461
14462
  };
14462
14463
  }
@@ -20767,9 +20768,40 @@ var ts;
20767
20768
  }
20768
20769
  ts.isFunctionExpressionOrArrowFunction = isFunctionExpressionOrArrowFunction;
20769
20770
  function escapeSnippetText(text) {
20770
- return text.replace(/\$/gm, "\\$");
20771
+ return text.replace(/\$/gm, function () { return "\\$"; });
20771
20772
  }
20772
20773
  ts.escapeSnippetText = escapeSnippetText;
20774
+ function isNumericLiteralName(name) {
20775
+ // The intent of numeric names is that
20776
+ // - they are names with text in a numeric form, and that
20777
+ // - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit',
20778
+ // acquired by applying the abstract 'ToNumber' operation on the name's text.
20779
+ //
20780
+ // The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name.
20781
+ // In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold.
20782
+ //
20783
+ // Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)'
20784
+ // according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'.
20785
+ // Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names
20786
+ // because their 'ToString' representation is not equal to their original text.
20787
+ // This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1.
20788
+ //
20789
+ // Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'.
20790
+ // The '+' prefix operator is equivalent here to applying the abstract ToNumber operation.
20791
+ // Applying the 'toString()' method on a number gives us the abstract ToString operation on a number.
20792
+ //
20793
+ // Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional.
20794
+ // This is desired behavior, because when indexing with them as numeric entities, you are indexing
20795
+ // with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively.
20796
+ return (+name).toString() === name;
20797
+ }
20798
+ ts.isNumericLiteralName = isNumericLiteralName;
20799
+ function createPropertyNameNodeForIdentifierOrLiteral(name, target, singleQuote, stringNamed) {
20800
+ return ts.isIdentifierText(name, target) ? ts.factory.createIdentifier(name) :
20801
+ !stringNamed && isNumericLiteralName(name) && +name >= 0 ? ts.factory.createNumericLiteral(+name) :
20802
+ ts.factory.createStringLiteral(name, !!singleQuote);
20803
+ }
20804
+ ts.createPropertyNameNodeForIdentifierOrLiteral = createPropertyNameNodeForIdentifierOrLiteral;
20773
20805
  function isThisTypeParameter(type) {
20774
20806
  return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
20775
20807
  }
@@ -46842,6 +46874,7 @@ var ts;
46842
46874
  var location = ts.getParseTreeNode(locationIn);
46843
46875
  return location ? getTypeOfSymbolAtLocation(symbol, location) : errorType;
46844
46876
  },
46877
+ getTypeOfSymbol: getTypeOfSymbol,
46845
46878
  getSymbolsOfParameterPropertyDeclaration: function (parameterIn, parameterName) {
46846
46879
  var parameter = ts.getParseTreeNode(parameterIn, ts.isParameter);
46847
46880
  if (parameter === undefined)
@@ -52197,7 +52230,7 @@ var ts;
52197
52230
  }
52198
52231
  var rawName = ts.unescapeLeadingUnderscores(symbol.escapedName);
52199
52232
  var stringNamed = !!ts.length(symbol.declarations) && ts.every(symbol.declarations, isStringNamed);
52200
- return createPropertyNameNodeForIdentifierOrLiteral(rawName, stringNamed, singleQuote);
52233
+ return ts.createPropertyNameNodeForIdentifierOrLiteral(rawName, ts.getEmitScriptTarget(compilerOptions), singleQuote, stringNamed);
52201
52234
  }
52202
52235
  // See getNameForSymbolFromNameType for a stringy equivalent
52203
52236
  function getPropertyNameNodeForSymbolFromNameType(symbol, context, singleQuote) {
@@ -52205,24 +52238,19 @@ var ts;
52205
52238
  if (nameType) {
52206
52239
  if (nameType.flags & 384 /* StringOrNumberLiteral */) {
52207
52240
  var name = "" + nameType.value;
52208
- if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !isNumericLiteralName(name)) {
52241
+ if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !ts.isNumericLiteralName(name)) {
52209
52242
  return ts.factory.createStringLiteral(name, !!singleQuote);
52210
52243
  }
52211
- if (isNumericLiteralName(name) && ts.startsWith(name, "-")) {
52244
+ if (ts.isNumericLiteralName(name) && ts.startsWith(name, "-")) {
52212
52245
  return ts.factory.createComputedPropertyName(ts.factory.createNumericLiteral(+name));
52213
52246
  }
52214
- return createPropertyNameNodeForIdentifierOrLiteral(name);
52247
+ return ts.createPropertyNameNodeForIdentifierOrLiteral(name, ts.getEmitScriptTarget(compilerOptions));
52215
52248
  }
52216
52249
  if (nameType.flags & 8192 /* UniqueESSymbol */) {
52217
52250
  return ts.factory.createComputedPropertyName(symbolToExpression(nameType.symbol, context, 111551 /* Value */));
52218
52251
  }
52219
52252
  }
52220
52253
  }
52221
- function createPropertyNameNodeForIdentifierOrLiteral(name, stringNamed, singleQuote) {
52222
- return ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) ? ts.factory.createIdentifier(name) :
52223
- !stringNamed && isNumericLiteralName(name) && +name >= 0 ? ts.factory.createNumericLiteral(+name) :
52224
- ts.factory.createStringLiteral(name, !!singleQuote);
52225
- }
52226
52254
  function cloneNodeBuilderContext(context) {
52227
52255
  var initial = __assign({}, context);
52228
52256
  // Make type parameters created within this context not consume the name outside this context
@@ -53738,10 +53766,10 @@ var ts;
53738
53766
  if (nameType) {
53739
53767
  if (nameType.flags & 384 /* StringOrNumberLiteral */) {
53740
53768
  var name = "" + nameType.value;
53741
- if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !isNumericLiteralName(name)) {
53769
+ if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !ts.isNumericLiteralName(name)) {
53742
53770
  return "\"" + ts.escapeString(name, 34 /* doubleQuote */) + "\"";
53743
53771
  }
53744
- if (isNumericLiteralName(name) && ts.startsWith(name, "-")) {
53772
+ if (ts.isNumericLiteralName(name) && ts.startsWith(name, "-")) {
53745
53773
  return "[" + name + "]";
53746
53774
  }
53747
53775
  return name;
@@ -57784,7 +57812,7 @@ var ts;
57784
57812
  // signature applies to types assignable to 'number' and numeric string literal types.
57785
57813
  return isTypeAssignableTo(source, target) ||
57786
57814
  target === stringType && isTypeAssignableTo(source, numberType) ||
57787
- target === numberType && !!(source.flags & 128 /* StringLiteral */) && isNumericLiteralName(source.value);
57815
+ target === numberType && !!(source.flags & 128 /* StringLiteral */) && ts.isNumericLiteralName(source.value);
57788
57816
  }
57789
57817
  function getIndexInfosOfStructuredType(type) {
57790
57818
  if (type.flags & 3670016 /* StructuredType */) {
@@ -60350,7 +60378,7 @@ var ts;
60350
60378
  getFlowTypeOfReference(accessExpression, propType) :
60351
60379
  propType;
60352
60380
  }
60353
- if (everyType(objectType, isTupleType) && isNumericLiteralName(propName) && +propName >= 0) {
60381
+ if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName) && +propName >= 0) {
60354
60382
  if (accessNode && everyType(objectType, function (t) { return !t.target.hasRestElement; }) && !(accessFlags & 16 /* NoTupleBoundsCheck */)) {
60355
60383
  var indexNode = getIndexNodeForAccessExpression(accessNode);
60356
60384
  if (isTupleType(objectType)) {
@@ -60635,7 +60663,7 @@ var ts;
60635
60663
  return everyType(indexType, function (t) {
60636
60664
  if (t.flags & 384 /* StringOrNumberLiteral */) {
60637
60665
  var propName = getPropertyNameFromType(t);
60638
- if (isNumericLiteralName(propName)) {
60666
+ if (ts.isNumericLiteralName(propName)) {
60639
60667
  var index = +propName;
60640
60668
  return index >= 0 && index < limit;
60641
60669
  }
@@ -64177,7 +64205,7 @@ var ts;
64177
64205
  else {
64178
64206
  // conditionals aren't related to one another via distributive constraint as it is much too inaccurate and allows way
64179
64207
  // more assignments than are desirable (since it maps the source check type to its constraint, it loses information)
64180
- var distributiveConstraint = getConstraintOfDistributiveConditionalType(source);
64208
+ var distributiveConstraint = hasNonCircularBaseConstraint(source) ? getConstraintOfDistributiveConditionalType(source) : undefined;
64181
64209
  if (distributiveConstraint) {
64182
64210
  if (result = isRelatedTo(distributiveConstraint, target, 1 /* Source */, reportErrors)) {
64183
64211
  resetErrorInfo(saveErrorInfo);
@@ -64723,7 +64751,7 @@ var ts;
64723
64751
  for (var _b = 0, _c = excludeProperties(properties, excludedProperties); _b < _c.length; _b++) {
64724
64752
  var targetProp = _c[_b];
64725
64753
  var name = targetProp.escapedName;
64726
- if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
64754
+ if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || ts.isNumericLiteralName(name) || name === "length")) {
64727
64755
  var sourceProp = getPropertyOfType(source, name);
64728
64756
  if (sourceProp && sourceProp !== targetProp) {
64729
64757
  var related = propertyRelatedTo(source, target, sourceProp, targetProp, getNonMissingTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation);
@@ -64796,7 +64824,8 @@ var ts;
64796
64824
  var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
64797
64825
  var sourceObjectFlags = ts.getObjectFlags(source);
64798
64826
  var targetObjectFlags = ts.getObjectFlags(target);
64799
- if (sourceObjectFlags & 64 /* Instantiated */ && targetObjectFlags & 64 /* Instantiated */ && source.symbol === target.symbol) {
64827
+ if (sourceObjectFlags & 64 /* Instantiated */ && targetObjectFlags & 64 /* Instantiated */ && source.symbol === target.symbol ||
64828
+ sourceObjectFlags & 4 /* Reference */ && targetObjectFlags & 4 /* Reference */ && source.target === target.target) {
64800
64829
  // We have instantiations of the same anonymous type (which typically will be the type of a
64801
64830
  // method). Simply do a pairwise comparison of the signatures in the two signature lists instead
64802
64831
  // of the much more expensive N * M comparison matrix we explore below. We erase type parameters
@@ -65831,9 +65860,12 @@ var ts;
65831
65860
  * with no call or construct signatures.
65832
65861
  */
65833
65862
  function isObjectTypeWithInferableIndex(type) {
65834
- return type.flags & 2097152 /* Intersection */ ? ts.every(type.types, isObjectTypeWithInferableIndex) :
65835
- !!(type.symbol && (type.symbol.flags & (4096 /* ObjectLiteral */ | 2048 /* TypeLiteral */ | 384 /* Enum */ | 512 /* ValueModule */)) !== 0 &&
65836
- !typeHasCallOrConstructSignatures(type)) || !!(ts.getObjectFlags(type) & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
65863
+ return type.flags & 2097152 /* Intersection */
65864
+ ? ts.every(type.types, isObjectTypeWithInferableIndex)
65865
+ : !!(type.symbol
65866
+ && (type.symbol.flags & (4096 /* ObjectLiteral */ | 2048 /* TypeLiteral */ | 384 /* Enum */ | 512 /* ValueModule */)) !== 0
65867
+ && !(type.symbol.flags & 32 /* Class */)
65868
+ && !typeHasCallOrConstructSignatures(type)) || !!(ts.getObjectFlags(type) & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
65837
65869
  }
65838
65870
  function createSymbolWithType(source, type) {
65839
65871
  var symbol = createSymbol(source.flags, source.escapedName, ts.getCheckFlags(source) & 8 /* Readonly */);
@@ -70803,7 +70835,7 @@ var ts;
70803
70835
  }
70804
70836
  if (isTupleType(t)) {
70805
70837
  var restType = getRestTypeOfTupleType(t);
70806
- if (restType && isNumericLiteralName(name) && +name >= 0) {
70838
+ if (restType && ts.isNumericLiteralName(name) && +name >= 0) {
70807
70839
  return restType;
70808
70840
  }
70809
70841
  }
@@ -71444,10 +71476,10 @@ var ts;
71444
71476
  case 161 /* ComputedPropertyName */:
71445
71477
  return isNumericComputedName(name);
71446
71478
  case 79 /* Identifier */:
71447
- return isNumericLiteralName(name.escapedText);
71479
+ return ts.isNumericLiteralName(name.escapedText);
71448
71480
  case 8 /* NumericLiteral */:
71449
71481
  case 10 /* StringLiteral */:
71450
- return isNumericLiteralName(name.text);
71482
+ return ts.isNumericLiteralName(name.text);
71451
71483
  default:
71452
71484
  return false;
71453
71485
  }
@@ -71457,30 +71489,6 @@ var ts;
71457
71489
  // but this behavior is consistent with checkIndexedAccess
71458
71490
  return isTypeAssignableToKind(checkComputedPropertyName(name), 296 /* NumberLike */);
71459
71491
  }
71460
- function isNumericLiteralName(name) {
71461
- // The intent of numeric names is that
71462
- // - they are names with text in a numeric form, and that
71463
- // - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit',
71464
- // acquired by applying the abstract 'ToNumber' operation on the name's text.
71465
- //
71466
- // The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name.
71467
- // In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold.
71468
- //
71469
- // Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)'
71470
- // according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'.
71471
- // Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names
71472
- // because their 'ToString' representation is not equal to their original text.
71473
- // This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1.
71474
- //
71475
- // Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'.
71476
- // The '+' prefix operator is equivalent here to applying the abstract ToNumber operation.
71477
- // Applying the 'toString()' method on a number gives us the abstract ToString operation on a number.
71478
- //
71479
- // Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional.
71480
- // This is desired behavior, because when indexing with them as numeric entities, you are indexing
71481
- // with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively.
71482
- return (+name).toString() === name;
71483
- }
71484
71492
  function checkComputedPropertyName(node) {
71485
71493
  var links = getNodeLinks(node.expression);
71486
71494
  if (!links.resolvedType) {
@@ -71516,7 +71524,7 @@ var ts;
71516
71524
  function isSymbolWithNumericName(symbol) {
71517
71525
  var _a;
71518
71526
  var firstDecl = (_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a[0];
71519
- return isNumericLiteralName(symbol.escapedName) || (firstDecl && ts.isNamedDeclaration(firstDecl) && isNumericName(firstDecl.name));
71527
+ return ts.isNumericLiteralName(symbol.escapedName) || (firstDecl && ts.isNamedDeclaration(firstDecl) && isNumericName(firstDecl.name));
71520
71528
  }
71521
71529
  function isSymbolWithSymbolName(symbol) {
71522
71530
  var _a;
@@ -82454,7 +82462,7 @@ var ts;
82454
82462
  }
82455
82463
  else {
82456
82464
  var text = ts.getTextOfPropertyName(member.name);
82457
- if (isNumericLiteralName(text) && !ts.isInfinityOrNaNString(text)) {
82465
+ if (ts.isNumericLiteralName(text) && !ts.isInfinityOrNaNString(text)) {
82458
82466
  error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name);
82459
82467
  }
82460
82468
  }
@@ -119919,7 +119927,7 @@ var ts;
119919
119927
  }
119920
119928
  ts.getLocaleTimeString = getLocaleTimeString;
119921
119929
  /**
119922
- * Create a function that reports watch status by writing to the system and handles the formating of the diagnostic
119930
+ * Create a function that reports watch status by writing to the system and handles the formatting of the diagnostic
119923
119931
  */
119924
119932
  function createWatchStatusReporter(system, pretty) {
119925
119933
  return pretty ?
@@ -119980,7 +119988,7 @@ var ts;
119980
119988
  ts.Diagnostics.Found_0_errors_Watching_for_file_changes;
119981
119989
  }
119982
119990
  ts.getWatchErrorSummaryDiagnosticMessage = getWatchErrorSummaryDiagnosticMessage;
119983
- function getErrorSummaryText(errorCount, filesInError, newLine) {
119991
+ function getErrorSummaryText(errorCount, filesInError, newLine, host) {
119984
119992
  if (errorCount === 0)
119985
119993
  return "";
119986
119994
  var nonNilFiles = filesInError.filter(function (fileInError) { return fileInError !== undefined; });
@@ -119995,10 +120003,10 @@ var ts;
119995
120003
  distinctFileNamesWithLines.length === 1 ?
119996
120004
  ts.Diagnostics.Found_0_errors_in_1_file :
119997
120005
  ts.Diagnostics.Found_0_errors_in_1_files, errorCount, distinctFileNamesWithLines.length);
119998
- return "" + newLine + ts.flattenDiagnosticMessageText(d.messageText, newLine) + newLine + newLine + (errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles) : "");
120006
+ return "" + newLine + ts.flattenDiagnosticMessageText(d.messageText, newLine) + newLine + newLine + (errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles, host) : "");
119999
120007
  }
120000
120008
  ts.getErrorSummaryText = getErrorSummaryText;
120001
- function createTabularErrorsDisplay(filesInError) {
120009
+ function createTabularErrorsDisplay(filesInError, host) {
120002
120010
  var distinctFiles = filesInError.filter(function (value, index, self) { return index === self.findIndex(function (file) { return (file === null || file === void 0 ? void 0 : file.fileName) === (value === null || value === void 0 ? void 0 : value.fileName); }); });
120003
120011
  if (distinctFiles.length === 0)
120004
120012
  return "";
@@ -120017,7 +120025,8 @@ var ts;
120017
120025
  var leftPadding = errorCountDigitsLength < leftPaddingGoal ?
120018
120026
  " ".repeat(leftPaddingGoal - errorCountDigitsLength)
120019
120027
  : "";
120020
- tabularData += "" + leftPadding + errorCount + " " + file.fileName + ":" + file.line + "\n";
120028
+ var relativePath = ts.getRelativePathFromDirectory(host.getCurrentDirectory(), file.fileName, /* ignoreCase */ false);
120029
+ tabularData += "" + leftPadding + errorCount + " " + relativePath + ":" + file.line + "\n";
120021
120030
  });
120022
120031
  return tabularData;
120023
120032
  }
@@ -120435,7 +120444,7 @@ var ts;
120435
120444
  var system = input.system || ts.sys;
120436
120445
  var host = input.host || (input.host = ts.createIncrementalCompilerHost(input.options, system));
120437
120446
  var builderProgram = ts.createIncrementalProgram(input);
120438
- var exitStatus = emitFilesAndReportErrorsAndGetExitStatus(builderProgram, input.reportDiagnostic || createDiagnosticReporter(system), function (s) { return host.trace && host.trace(s); }, input.reportErrorSummary || input.options.pretty ? function (errorCount, filesInError) { return system.write(getErrorSummaryText(errorCount, filesInError, system.newLine)); } : undefined);
120447
+ var exitStatus = emitFilesAndReportErrorsAndGetExitStatus(builderProgram, input.reportDiagnostic || createDiagnosticReporter(system), function (s) { return host.trace && host.trace(s); }, input.reportErrorSummary || input.options.pretty ? function (errorCount, filesInError) { return system.write(getErrorSummaryText(errorCount, filesInError, system.newLine, host)); } : undefined);
120439
120448
  if (input.afterProgramEmitAndDiagnostics)
120440
120449
  input.afterProgramEmitAndDiagnostics(builderProgram);
120441
120450
  return exitStatus;
@@ -150420,7 +150429,8 @@ var ts;
150420
150429
  return { kind: 3 /* ObjectLiteral */, token: token, properties: properties, indentation: undefined, parentDeclaration: parent.initializer };
150421
150430
  }
150422
150431
  if (ts.isIdentifier(token) && ts.isJsxOpeningLikeElement(token.parent)) {
150423
- var attributes = getUnmatchedAttributes(checker, token.parent);
150432
+ var target = ts.getEmitScriptTarget(program.getCompilerOptions());
150433
+ var attributes = getUnmatchedAttributes(checker, target, token.parent);
150424
150434
  if (!ts.length(attributes))
150425
150435
  return undefined;
150426
150436
  return { kind: 4 /* JsxAttributes */, token: token, attributes: attributes, parentDeclaration: token.parent };
@@ -150655,8 +150665,12 @@ var ts;
150655
150665
  var jsxAttributesNode = info.parentDeclaration.attributes;
150656
150666
  var hasSpreadAttribute = ts.some(jsxAttributesNode.properties, ts.isJsxSpreadAttribute);
150657
150667
  var attrs = ts.map(info.attributes, function (attr) {
150658
- var value = attr.valueDeclaration ? tryGetValueFromType(context, checker, importAdder, quotePreference, checker.getTypeAtLocation(attr.valueDeclaration)) : createUndefined();
150659
- return ts.factory.createJsxAttribute(ts.factory.createIdentifier(attr.name), ts.factory.createJsxExpression(/*dotDotDotToken*/ undefined, value));
150668
+ var value = tryGetValueFromType(context, checker, importAdder, quotePreference, checker.getTypeOfSymbol(attr));
150669
+ var name = ts.factory.createIdentifier(attr.name);
150670
+ var jsxAttribute = ts.factory.createJsxAttribute(name, ts.factory.createJsxExpression(/*dotDotDotToken*/ undefined, value));
150671
+ // formattingScanner requires the Identifier to have a context for scanning attributes with "-" (data-foo).
150672
+ ts.setParent(name, jsxAttribute);
150673
+ return jsxAttribute;
150660
150674
  });
150661
150675
  var jsxAttributes = ts.factory.createJsxAttributes(hasSpreadAttribute ? __spreadArray(__spreadArray([], attrs, true), jsxAttributesNode.properties, true) : __spreadArray(__spreadArray([], jsxAttributesNode.properties, true), attrs, true));
150662
150676
  var options = { prefix: jsxAttributesNode.pos === jsxAttributesNode.end ? " " : undefined };
@@ -150665,10 +150679,11 @@ var ts;
150665
150679
  function addObjectLiteralProperties(changes, context, info) {
150666
150680
  var importAdder = codefix.createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
150667
150681
  var quotePreference = ts.getQuotePreference(context.sourceFile, context.preferences);
150682
+ var target = ts.getEmitScriptTarget(context.program.getCompilerOptions());
150668
150683
  var checker = context.program.getTypeChecker();
150669
150684
  var props = ts.map(info.properties, function (prop) {
150670
- var initializer = prop.valueDeclaration ? tryGetValueFromType(context, checker, importAdder, quotePreference, checker.getTypeAtLocation(prop.valueDeclaration)) : createUndefined();
150671
- return ts.factory.createPropertyAssignment(prop.name, initializer);
150685
+ var initializer = tryGetValueFromType(context, checker, importAdder, quotePreference, checker.getTypeOfSymbol(prop));
150686
+ return ts.factory.createPropertyAssignment(ts.createPropertyNameNodeForIdentifierOrLiteral(prop.name, target, quotePreference === 0 /* Single */), initializer);
150672
150687
  });
150673
150688
  var options = {
150674
150689
  leadingTriviaOption: ts.textChanges.LeadingTriviaOption.Exclude,
@@ -150755,7 +150770,7 @@ var ts;
150755
150770
  return (type.flags & 524288 /* Object */) &&
150756
150771
  ((ts.getObjectFlags(type) & 128 /* ObjectLiteral */) || (type.symbol && ts.tryCast(ts.singleOrUndefined(type.symbol.declarations), ts.isTypeLiteralNode)));
150757
150772
  }
150758
- function getUnmatchedAttributes(checker, source) {
150773
+ function getUnmatchedAttributes(checker, target, source) {
150759
150774
  var attrsType = checker.getContextualType(source.attributes);
150760
150775
  if (attrsType === undefined)
150761
150776
  return ts.emptyArray;
@@ -150777,7 +150792,7 @@ var ts;
150777
150792
  }
150778
150793
  }
150779
150794
  return ts.filter(targetProps, function (targetProp) {
150780
- return !((targetProp.flags & 16777216 /* Optional */ || ts.getCheckFlags(targetProp) & 48 /* Partial */) || seenNames.has(targetProp.escapedName));
150795
+ return ts.isIdentifierText(targetProp.name, target, 1 /* JSX */) && !((targetProp.flags & 16777216 /* Optional */ || ts.getCheckFlags(targetProp) & 48 /* Partial */) || seenNames.has(targetProp.escapedName));
150781
150796
  });
150782
150797
  }
150783
150798
  })(codefix = ts.codefix || (ts.codefix = {}));
@@ -163281,14 +163296,8 @@ var ts;
163281
163296
  var possibleSearchDirs = new ts.Set(fileNames.map(ts.getDirectoryPath));
163282
163297
  possibleSearchDirs.add(projectRootPath);
163283
163298
  possibleSearchDirs.forEach(function (searchDir) {
163284
- var packageJsonPath = ts.combinePaths(searchDir, "package.json");
163285
- getTypingNamesFromJson(packageJsonPath, filesToWatch);
163286
- var bowerJsonPath = ts.combinePaths(searchDir, "bower.json");
163287
- getTypingNamesFromJson(bowerJsonPath, filesToWatch);
163288
- var bowerComponentsPath = ts.combinePaths(searchDir, "bower_components");
163289
- getTypingNamesFromPackagesFolder(bowerComponentsPath, filesToWatch);
163290
- var nodeModulesPath = ts.combinePaths(searchDir, "node_modules");
163291
- getTypingNamesFromPackagesFolder(nodeModulesPath, filesToWatch);
163299
+ getTypingNames(searchDir, "bower.json", "bower_components", filesToWatch);
163300
+ getTypingNames(searchDir, "package.json", "node_modules", filesToWatch);
163292
163301
  });
163293
163302
  if (!typeAcquisition.disableFilenameBasedTypeAcquisition) {
163294
163303
  getTypingNamesFromSourceFileNames(fileNames);
@@ -163337,16 +163346,100 @@ var ts;
163337
163346
  ts.forEach(typingNames, addInferredTyping);
163338
163347
  }
163339
163348
  /**
163340
- * Get the typing info from common package manager json files like package.json or bower.json
163349
+ * Adds inferred typings from manifest/module pairs (think package.json + node_modules)
163350
+ *
163351
+ * @param projectRootPath is the path to the directory where to look for package.json, bower.json and other typing information
163352
+ * @param manifestName is the name of the manifest (package.json or bower.json)
163353
+ * @param modulesDirName is the directory name for modules (node_modules or bower_components). Should be lowercase!
163354
+ * @param filesToWatch are the files to watch for changes. We will push things into this array.
163341
163355
  */
163342
- function getTypingNamesFromJson(jsonPath, filesToWatch) {
163343
- if (!host.fileExists(jsonPath)) {
163356
+ function getTypingNames(projectRootPath, manifestName, modulesDirName, filesToWatch) {
163357
+ // First, we check the manifests themselves. They're not
163358
+ // _required_, but they allow us to do some filtering when dealing
163359
+ // with big flat dep directories.
163360
+ var manifestPath = ts.combinePaths(projectRootPath, manifestName);
163361
+ var manifest;
163362
+ var manifestTypingNames;
163363
+ if (host.fileExists(manifestPath)) {
163364
+ filesToWatch.push(manifestPath);
163365
+ manifest = ts.readConfigFile(manifestPath, function (path) { return host.readFile(path); }).config;
163366
+ manifestTypingNames = ts.flatMap([manifest.dependencies, manifest.devDependencies, manifest.optionalDependencies, manifest.peerDependencies], ts.getOwnKeys);
163367
+ addInferredTypings(manifestTypingNames, "Typing names in '" + manifestPath + "' dependencies");
163368
+ }
163369
+ // Now we scan the directories for typing information in
163370
+ // already-installed dependencies (if present). Note that this
163371
+ // step happens regardless of whether a manifest was present,
163372
+ // which is certainly a valid configuration, if an unusual one.
163373
+ var packagesFolderPath = ts.combinePaths(projectRootPath, modulesDirName);
163374
+ filesToWatch.push(packagesFolderPath);
163375
+ if (!host.directoryExists(packagesFolderPath)) {
163344
163376
  return;
163345
163377
  }
163346
- filesToWatch.push(jsonPath);
163347
- var jsonConfig = ts.readConfigFile(jsonPath, function (path) { return host.readFile(path); }).config;
163348
- var jsonTypingNames = ts.flatMap([jsonConfig.dependencies, jsonConfig.devDependencies, jsonConfig.optionalDependencies, jsonConfig.peerDependencies], ts.getOwnKeys);
163349
- addInferredTypings(jsonTypingNames, "Typing names in '" + jsonPath + "' dependencies");
163378
+ // There's two cases we have to take into account here:
163379
+ // 1. If manifest is undefined, then we're not using a manifest.
163380
+ // That means that we should scan _all_ dependencies at the top
163381
+ // level of the modulesDir.
163382
+ // 2. If manifest is defined, then we can do some special
163383
+ // filtering to reduce the amount of scanning we need to do.
163384
+ //
163385
+ // Previous versions of this algorithm checked for a `_requiredBy`
163386
+ // field in the package.json, but that field is only present in
163387
+ // `npm@>=3 <7`.
163388
+ // Package names that do **not** provide their own typings, so
163389
+ // we'll look them up.
163390
+ var packageNames = [];
163391
+ var dependencyManifestNames = manifestTypingNames
163392
+ // This is #1 described above.
163393
+ ? manifestTypingNames.map(function (typingName) { return ts.combinePaths(packagesFolderPath, typingName, manifestName); })
163394
+ // And #2. Depth = 3 because scoped packages look like `node_modules/@foo/bar/package.json`
163395
+ : host.readDirectory(packagesFolderPath, [".json" /* Json */], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 3)
163396
+ .filter(function (manifestPath) {
163397
+ if (ts.getBaseFileName(manifestPath) !== manifestName) {
163398
+ return false;
163399
+ }
163400
+ // It's ok to treat
163401
+ // `node_modules/@foo/bar/package.json` as a manifest,
163402
+ // but not `node_modules/jquery/nested/package.json`.
163403
+ // We only assume depth 3 is ok for formally scoped
163404
+ // packages. So that needs this dance here.
163405
+ var pathComponents = ts.getPathComponents(ts.normalizePath(manifestPath));
163406
+ var isScoped = pathComponents[pathComponents.length - 3][0] === "@";
163407
+ return isScoped && pathComponents[pathComponents.length - 4].toLowerCase() === modulesDirName || // `node_modules/@foo/bar`
163408
+ !isScoped && pathComponents[pathComponents.length - 3].toLowerCase() === modulesDirName; // `node_modules/foo`
163409
+ });
163410
+ if (log)
163411
+ log("Searching for typing names in " + packagesFolderPath + "; all files: " + JSON.stringify(dependencyManifestNames));
163412
+ // Once we have the names of things to look up, we iterate over
163413
+ // and either collect their included typings, or add them to the
163414
+ // list of typings we need to look up separately.
163415
+ for (var _i = 0, dependencyManifestNames_1 = dependencyManifestNames; _i < dependencyManifestNames_1.length; _i++) {
163416
+ var manifestPath_1 = dependencyManifestNames_1[_i];
163417
+ var normalizedFileName = ts.normalizePath(manifestPath_1);
163418
+ var result_1 = ts.readConfigFile(normalizedFileName, function (path) { return host.readFile(path); });
163419
+ var manifest_1 = result_1.config;
163420
+ // If the package has its own d.ts typings, those will take precedence. Otherwise the package name will be used
163421
+ // to download d.ts files from DefinitelyTyped
163422
+ if (!manifest_1.name) {
163423
+ continue;
163424
+ }
163425
+ var ownTypes = manifest_1.types || manifest_1.typings;
163426
+ if (ownTypes) {
163427
+ var absolutePath = ts.getNormalizedAbsolutePath(ownTypes, ts.getDirectoryPath(normalizedFileName));
163428
+ if (host.fileExists(absolutePath)) {
163429
+ if (log)
163430
+ log(" Package '" + manifest_1.name + "' provides its own types.");
163431
+ inferredTypings.set(manifest_1.name, absolutePath);
163432
+ }
163433
+ else {
163434
+ if (log)
163435
+ log(" Package '" + manifest_1.name + "' provides its own types but they are missing.");
163436
+ }
163437
+ }
163438
+ else {
163439
+ packageNames.push(manifest_1.name);
163440
+ }
163441
+ }
163442
+ addInferredTypings(packageNames, " Found package names");
163350
163443
  }
163351
163444
  /**
163352
163445
  * Infer typing names from given file names. For example, the file name "jquery-min.2.3.4.js"
@@ -163372,55 +163465,6 @@ var ts;
163372
163465
  addInferredTyping("react");
163373
163466
  }
163374
163467
  }
163375
- /**
163376
- * Infer typing names from packages folder (ex: node_module, bower_components)
163377
- * @param packagesFolderPath is the path to the packages folder
163378
- */
163379
- function getTypingNamesFromPackagesFolder(packagesFolderPath, filesToWatch) {
163380
- filesToWatch.push(packagesFolderPath);
163381
- // Todo: add support for ModuleResolutionHost too
163382
- if (!host.directoryExists(packagesFolderPath)) {
163383
- return;
163384
- }
163385
- // depth of 2, so we access `node_modules/foo` but not `node_modules/foo/bar`
163386
- var fileNames = host.readDirectory(packagesFolderPath, [".json" /* Json */], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2);
163387
- if (log)
163388
- log("Searching for typing names in " + packagesFolderPath + "; all files: " + JSON.stringify(fileNames));
163389
- var packageNames = [];
163390
- for (var _i = 0, fileNames_1 = fileNames; _i < fileNames_1.length; _i++) {
163391
- var fileName = fileNames_1[_i];
163392
- var normalizedFileName = ts.normalizePath(fileName);
163393
- var baseFileName = ts.getBaseFileName(normalizedFileName);
163394
- if (baseFileName !== "package.json" && baseFileName !== "bower.json") {
163395
- continue;
163396
- }
163397
- var result_1 = ts.readConfigFile(normalizedFileName, function (path) { return host.readFile(path); });
163398
- var packageJson = result_1.config;
163399
- // npm 3's package.json contains a "_requiredBy" field
163400
- // we should include all the top level module names for npm 2, and only module names whose
163401
- // "_requiredBy" field starts with "#" or equals "/" for npm 3.
163402
- if (baseFileName === "package.json" && packageJson._requiredBy &&
163403
- ts.filter(packageJson._requiredBy, function (r) { return r[0] === "#" || r === "/"; }).length === 0) {
163404
- continue;
163405
- }
163406
- // If the package has its own d.ts typings, those will take precedence. Otherwise the package name will be used
163407
- // to download d.ts files from DefinitelyTyped
163408
- if (!packageJson.name) {
163409
- continue;
163410
- }
163411
- var ownTypes = packageJson.types || packageJson.typings;
163412
- if (ownTypes) {
163413
- var absolutePath = ts.getNormalizedAbsolutePath(ownTypes, ts.getDirectoryPath(normalizedFileName));
163414
- if (log)
163415
- log(" Package '" + packageJson.name + "' provides its own types.");
163416
- inferredTypings.set(packageJson.name, absolutePath);
163417
- }
163418
- else {
163419
- packageNames.push(packageJson.name);
163420
- }
163421
- }
163422
- addInferredTypings(packageNames, " Found package names");
163423
- }
163424
163468
  }
163425
163469
  JsTyping.discoverTypings = discoverTypings;
163426
163470
  var NameValidationResult;
@@ -171306,6 +171350,9 @@ var ts;
171306
171350
  }
171307
171351
  return;
171308
171352
  }
171353
+ this.writeMessage(msg);
171354
+ };
171355
+ Session.prototype.writeMessage = function (msg) {
171309
171356
  var msgText = formatMessage(msg, this.logger, this.byteLength, this.host.newLine);
171310
171357
  ts.perfLogger.logEvent("Response message size: " + msgText.length);
171311
171358
  this.host.write(msgText);
@@ -175345,12 +175392,40 @@ var ts;
175345
175392
  };
175346
175393
  return IOSession;
175347
175394
  }(server.Session));
175395
+ var IpcIOSession = /** @class */ (function (_super) {
175396
+ __extends(IpcIOSession, _super);
175397
+ function IpcIOSession() {
175398
+ return _super !== null && _super.apply(this, arguments) || this;
175399
+ }
175400
+ IpcIOSession.prototype.writeMessage = function (msg) {
175401
+ var verboseLogging = logger.hasLevel(server.LogLevel.verbose);
175402
+ if (verboseLogging) {
175403
+ var json = JSON.stringify(msg);
175404
+ logger.info(msg.type + ":" + server.indent(json));
175405
+ }
175406
+ process.send(msg);
175407
+ };
175408
+ IpcIOSession.prototype.parseMessage = function (message) {
175409
+ return message;
175410
+ };
175411
+ IpcIOSession.prototype.toStringMessage = function (message) {
175412
+ return JSON.stringify(message, undefined, 2);
175413
+ };
175414
+ IpcIOSession.prototype.listen = function () {
175415
+ var _this = this;
175416
+ process.on("message", function (e) {
175417
+ _this.onMessage(e);
175418
+ });
175419
+ };
175420
+ return IpcIOSession;
175421
+ }(IOSession));
175348
175422
  var eventPort = parseEventPort(server.findArgument("--eventPort"));
175349
175423
  var typingSafeListLocation = server.findArgument(server.Arguments.TypingSafeListLocation); // TODO: GH#18217
175350
175424
  var typesMapLocation = server.findArgument(server.Arguments.TypesMapLocation) || ts.combinePaths(ts.getDirectoryPath(ts.sys.getExecutingFilePath()), "typesMap.json");
175351
175425
  var npmLocation = server.findArgument(server.Arguments.NpmLocation);
175352
175426
  var validateDefaultNpmLocation = server.hasArgument(server.Arguments.ValidateDefaultNpmLocation);
175353
175427
  var disableAutomaticTypingAcquisition = server.hasArgument("--disableAutomaticTypingAcquisition");
175428
+ var useNodeIpc = server.hasArgument("--useNodeIpc");
175354
175429
  var telemetryEnabled = server.hasArgument(server.Arguments.EnableTelemetry);
175355
175430
  var commandLineTraceDir = server.findArgument("--traceDirectory");
175356
175431
  var traceDir = commandLineTraceDir
@@ -175359,7 +175434,7 @@ var ts;
175359
175434
  if (traceDir) {
175360
175435
  ts.startTracing("server", traceDir);
175361
175436
  }
175362
- var ioSession = new IOSession();
175437
+ var ioSession = useNodeIpc ? new IpcIOSession() : new IOSession();
175363
175438
  process.on("uncaughtException", function (err) {
175364
175439
  ioSession.logError(err, "unknown");
175365
175440
  });
@@ -10487,6 +10487,7 @@ declare namespace ts.server {
10487
10487
  logError(err: Error, cmd: string): void;
10488
10488
  private logErrorWorker;
10489
10489
  send(msg: protocol.Message): void;
10490
+ protected writeMessage(msg: protocol.Message): void;
10490
10491
  event<T extends object>(body: T, eventName: string): void;
10491
10492
  /** @deprecated */
10492
10493
  output(info: any, cmdName: string, reqSeq?: number, errorMsg?: string): void;