typescript 4.6.0-dev.20220104 → 4.6.0-dev.20220108
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/lib.es2022.error.d.ts +50 -3
- package/lib/tsc.js +112 -80
- package/lib/tsserver.js +376 -228
- package/lib/tsserverlibrary.d.ts +5 -3
- package/lib/tsserverlibrary.js +347 -227
- package/lib/typescript.d.ts +4 -3
- package/lib/typescript.js +343 -226
- package/lib/typescriptServices.d.ts +4 -3
- package/lib/typescriptServices.js +343 -226
- package/lib/typingsInstaller.js +273 -190
- package/package.json +1 -1
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.
|
|
103
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220108";
|
|
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
|
}
|
|
@@ -22242,7 +22274,7 @@ var ts;
|
|
|
22242
22274
|
result.push(createModifier(144 /* ReadonlyKeyword */));
|
|
22243
22275
|
if (flags & 256 /* Async */)
|
|
22244
22276
|
result.push(createModifier(131 /* AsyncKeyword */));
|
|
22245
|
-
return result;
|
|
22277
|
+
return result.length ? result : undefined;
|
|
22246
22278
|
}
|
|
22247
22279
|
//
|
|
22248
22280
|
// Names
|
|
@@ -26199,32 +26231,36 @@ var ts;
|
|
|
26199
26231
|
}
|
|
26200
26232
|
function updateModifiers(node, modifiers) {
|
|
26201
26233
|
var _a;
|
|
26234
|
+
var modifierArray;
|
|
26202
26235
|
if (typeof modifiers === "number") {
|
|
26203
|
-
|
|
26204
|
-
}
|
|
26205
|
-
|
|
26206
|
-
|
|
26207
|
-
|
|
26208
|
-
|
|
26209
|
-
|
|
26210
|
-
|
|
26211
|
-
|
|
26212
|
-
|
|
26213
|
-
|
|
26214
|
-
|
|
26215
|
-
|
|
26216
|
-
|
|
26217
|
-
|
|
26218
|
-
|
|
26219
|
-
|
|
26220
|
-
|
|
26221
|
-
|
|
26222
|
-
|
|
26223
|
-
|
|
26224
|
-
|
|
26225
|
-
|
|
26226
|
-
|
|
26227
|
-
|
|
26236
|
+
modifierArray = createModifiersFromModifierFlags(modifiers);
|
|
26237
|
+
}
|
|
26238
|
+
else {
|
|
26239
|
+
modifierArray = modifiers;
|
|
26240
|
+
}
|
|
26241
|
+
return ts.isParameter(node) ? updateParameterDeclaration(node, node.decorators, modifierArray, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) :
|
|
26242
|
+
ts.isPropertySignature(node) ? updatePropertySignature(node, modifierArray, node.name, node.questionToken, node.type) :
|
|
26243
|
+
ts.isPropertyDeclaration(node) ? updatePropertyDeclaration(node, node.decorators, modifierArray, node.name, (_a = node.questionToken) !== null && _a !== void 0 ? _a : node.exclamationToken, node.type, node.initializer) :
|
|
26244
|
+
ts.isMethodSignature(node) ? updateMethodSignature(node, modifierArray, node.name, node.questionToken, node.typeParameters, node.parameters, node.type) :
|
|
26245
|
+
ts.isMethodDeclaration(node) ? updateMethodDeclaration(node, node.decorators, modifierArray, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body) :
|
|
26246
|
+
ts.isConstructorDeclaration(node) ? updateConstructorDeclaration(node, node.decorators, modifierArray, node.parameters, node.body) :
|
|
26247
|
+
ts.isGetAccessorDeclaration(node) ? updateGetAccessorDeclaration(node, node.decorators, modifierArray, node.name, node.parameters, node.type, node.body) :
|
|
26248
|
+
ts.isSetAccessorDeclaration(node) ? updateSetAccessorDeclaration(node, node.decorators, modifierArray, node.name, node.parameters, node.body) :
|
|
26249
|
+
ts.isIndexSignatureDeclaration(node) ? updateIndexSignature(node, node.decorators, modifierArray, node.parameters, node.type) :
|
|
26250
|
+
ts.isFunctionExpression(node) ? updateFunctionExpression(node, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
|
|
26251
|
+
ts.isArrowFunction(node) ? updateArrowFunction(node, modifierArray, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, node.body) :
|
|
26252
|
+
ts.isClassExpression(node) ? updateClassExpression(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
|
|
26253
|
+
ts.isVariableStatement(node) ? updateVariableStatement(node, modifierArray, node.declarationList) :
|
|
26254
|
+
ts.isFunctionDeclaration(node) ? updateFunctionDeclaration(node, node.decorators, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
|
|
26255
|
+
ts.isClassDeclaration(node) ? updateClassDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
|
|
26256
|
+
ts.isInterfaceDeclaration(node) ? updateInterfaceDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
|
|
26257
|
+
ts.isTypeAliasDeclaration(node) ? updateTypeAliasDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.type) :
|
|
26258
|
+
ts.isEnumDeclaration(node) ? updateEnumDeclaration(node, node.decorators, modifierArray, node.name, node.members) :
|
|
26259
|
+
ts.isModuleDeclaration(node) ? updateModuleDeclaration(node, node.decorators, modifierArray, node.name, node.body) :
|
|
26260
|
+
ts.isImportEqualsDeclaration(node) ? updateImportEqualsDeclaration(node, node.decorators, modifierArray, node.isTypeOnly, node.name, node.moduleReference) :
|
|
26261
|
+
ts.isImportDeclaration(node) ? updateImportDeclaration(node, node.decorators, modifierArray, node.importClause, node.moduleSpecifier, node.assertClause) :
|
|
26262
|
+
ts.isExportAssignment(node) ? updateExportAssignment(node, node.decorators, modifierArray, node.expression) :
|
|
26263
|
+
ts.isExportDeclaration(node) ? updateExportDeclaration(node, node.decorators, modifierArray, node.isTypeOnly, node.exportClause, node.moduleSpecifier, node.assertClause) :
|
|
26228
26264
|
ts.Debug.assertNever(node);
|
|
26229
26265
|
}
|
|
26230
26266
|
function asNodeArray(array) {
|
|
@@ -46838,6 +46874,7 @@ var ts;
|
|
|
46838
46874
|
var location = ts.getParseTreeNode(locationIn);
|
|
46839
46875
|
return location ? getTypeOfSymbolAtLocation(symbol, location) : errorType;
|
|
46840
46876
|
},
|
|
46877
|
+
getTypeOfSymbol: getTypeOfSymbol,
|
|
46841
46878
|
getSymbolsOfParameterPropertyDeclaration: function (parameterIn, parameterName) {
|
|
46842
46879
|
var parameter = ts.getParseTreeNode(parameterIn, ts.isParameter);
|
|
46843
46880
|
if (parameter === undefined)
|
|
@@ -52193,7 +52230,7 @@ var ts;
|
|
|
52193
52230
|
}
|
|
52194
52231
|
var rawName = ts.unescapeLeadingUnderscores(symbol.escapedName);
|
|
52195
52232
|
var stringNamed = !!ts.length(symbol.declarations) && ts.every(symbol.declarations, isStringNamed);
|
|
52196
|
-
return createPropertyNameNodeForIdentifierOrLiteral(rawName,
|
|
52233
|
+
return ts.createPropertyNameNodeForIdentifierOrLiteral(rawName, ts.getEmitScriptTarget(compilerOptions), singleQuote, stringNamed);
|
|
52197
52234
|
}
|
|
52198
52235
|
// See getNameForSymbolFromNameType for a stringy equivalent
|
|
52199
52236
|
function getPropertyNameNodeForSymbolFromNameType(symbol, context, singleQuote) {
|
|
@@ -52201,24 +52238,19 @@ var ts;
|
|
|
52201
52238
|
if (nameType) {
|
|
52202
52239
|
if (nameType.flags & 384 /* StringOrNumberLiteral */) {
|
|
52203
52240
|
var name = "" + nameType.value;
|
|
52204
|
-
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !isNumericLiteralName(name)) {
|
|
52241
|
+
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !ts.isNumericLiteralName(name)) {
|
|
52205
52242
|
return ts.factory.createStringLiteral(name, !!singleQuote);
|
|
52206
52243
|
}
|
|
52207
|
-
if (isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
52244
|
+
if (ts.isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
52208
52245
|
return ts.factory.createComputedPropertyName(ts.factory.createNumericLiteral(+name));
|
|
52209
52246
|
}
|
|
52210
|
-
return createPropertyNameNodeForIdentifierOrLiteral(name);
|
|
52247
|
+
return ts.createPropertyNameNodeForIdentifierOrLiteral(name, ts.getEmitScriptTarget(compilerOptions));
|
|
52211
52248
|
}
|
|
52212
52249
|
if (nameType.flags & 8192 /* UniqueESSymbol */) {
|
|
52213
52250
|
return ts.factory.createComputedPropertyName(symbolToExpression(nameType.symbol, context, 111551 /* Value */));
|
|
52214
52251
|
}
|
|
52215
52252
|
}
|
|
52216
52253
|
}
|
|
52217
|
-
function createPropertyNameNodeForIdentifierOrLiteral(name, stringNamed, singleQuote) {
|
|
52218
|
-
return ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) ? ts.factory.createIdentifier(name) :
|
|
52219
|
-
!stringNamed && isNumericLiteralName(name) && +name >= 0 ? ts.factory.createNumericLiteral(+name) :
|
|
52220
|
-
ts.factory.createStringLiteral(name, !!singleQuote);
|
|
52221
|
-
}
|
|
52222
52254
|
function cloneNodeBuilderContext(context) {
|
|
52223
52255
|
var initial = __assign({}, context);
|
|
52224
52256
|
// Make type parameters created within this context not consume the name outside this context
|
|
@@ -53734,10 +53766,10 @@ var ts;
|
|
|
53734
53766
|
if (nameType) {
|
|
53735
53767
|
if (nameType.flags & 384 /* StringOrNumberLiteral */) {
|
|
53736
53768
|
var name = "" + nameType.value;
|
|
53737
|
-
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !isNumericLiteralName(name)) {
|
|
53769
|
+
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !ts.isNumericLiteralName(name)) {
|
|
53738
53770
|
return "\"" + ts.escapeString(name, 34 /* doubleQuote */) + "\"";
|
|
53739
53771
|
}
|
|
53740
|
-
if (isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
53772
|
+
if (ts.isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
53741
53773
|
return "[" + name + "]";
|
|
53742
53774
|
}
|
|
53743
53775
|
return name;
|
|
@@ -57780,7 +57812,7 @@ var ts;
|
|
|
57780
57812
|
// signature applies to types assignable to 'number' and numeric string literal types.
|
|
57781
57813
|
return isTypeAssignableTo(source, target) ||
|
|
57782
57814
|
target === stringType && isTypeAssignableTo(source, numberType) ||
|
|
57783
|
-
target === numberType && !!(source.flags & 128 /* StringLiteral */) && isNumericLiteralName(source.value);
|
|
57815
|
+
target === numberType && !!(source.flags & 128 /* StringLiteral */) && ts.isNumericLiteralName(source.value);
|
|
57784
57816
|
}
|
|
57785
57817
|
function getIndexInfosOfStructuredType(type) {
|
|
57786
57818
|
if (type.flags & 3670016 /* StructuredType */) {
|
|
@@ -60346,7 +60378,7 @@ var ts;
|
|
|
60346
60378
|
getFlowTypeOfReference(accessExpression, propType) :
|
|
60347
60379
|
propType;
|
|
60348
60380
|
}
|
|
60349
|
-
if (everyType(objectType, isTupleType) && isNumericLiteralName(propName) && +propName >= 0) {
|
|
60381
|
+
if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName) && +propName >= 0) {
|
|
60350
60382
|
if (accessNode && everyType(objectType, function (t) { return !t.target.hasRestElement; }) && !(accessFlags & 16 /* NoTupleBoundsCheck */)) {
|
|
60351
60383
|
var indexNode = getIndexNodeForAccessExpression(accessNode);
|
|
60352
60384
|
if (isTupleType(objectType)) {
|
|
@@ -60631,7 +60663,7 @@ var ts;
|
|
|
60631
60663
|
return everyType(indexType, function (t) {
|
|
60632
60664
|
if (t.flags & 384 /* StringOrNumberLiteral */) {
|
|
60633
60665
|
var propName = getPropertyNameFromType(t);
|
|
60634
|
-
if (isNumericLiteralName(propName)) {
|
|
60666
|
+
if (ts.isNumericLiteralName(propName)) {
|
|
60635
60667
|
var index = +propName;
|
|
60636
60668
|
return index >= 0 && index < limit;
|
|
60637
60669
|
}
|
|
@@ -64173,7 +64205,7 @@ var ts;
|
|
|
64173
64205
|
else {
|
|
64174
64206
|
// conditionals aren't related to one another via distributive constraint as it is much too inaccurate and allows way
|
|
64175
64207
|
// more assignments than are desirable (since it maps the source check type to its constraint, it loses information)
|
|
64176
|
-
var distributiveConstraint = getConstraintOfDistributiveConditionalType(source);
|
|
64208
|
+
var distributiveConstraint = hasNonCircularBaseConstraint(source) ? getConstraintOfDistributiveConditionalType(source) : undefined;
|
|
64177
64209
|
if (distributiveConstraint) {
|
|
64178
64210
|
if (result = isRelatedTo(distributiveConstraint, target, 1 /* Source */, reportErrors)) {
|
|
64179
64211
|
resetErrorInfo(saveErrorInfo);
|
|
@@ -64719,7 +64751,7 @@ var ts;
|
|
|
64719
64751
|
for (var _b = 0, _c = excludeProperties(properties, excludedProperties); _b < _c.length; _b++) {
|
|
64720
64752
|
var targetProp = _c[_b];
|
|
64721
64753
|
var name = targetProp.escapedName;
|
|
64722
|
-
if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
|
|
64754
|
+
if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || ts.isNumericLiteralName(name) || name === "length")) {
|
|
64723
64755
|
var sourceProp = getPropertyOfType(source, name);
|
|
64724
64756
|
if (sourceProp && sourceProp !== targetProp) {
|
|
64725
64757
|
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getNonMissingTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation);
|
|
@@ -64792,7 +64824,8 @@ var ts;
|
|
|
64792
64824
|
var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
|
|
64793
64825
|
var sourceObjectFlags = ts.getObjectFlags(source);
|
|
64794
64826
|
var targetObjectFlags = ts.getObjectFlags(target);
|
|
64795
|
-
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) {
|
|
64796
64829
|
// We have instantiations of the same anonymous type (which typically will be the type of a
|
|
64797
64830
|
// method). Simply do a pairwise comparison of the signatures in the two signature lists instead
|
|
64798
64831
|
// of the much more expensive N * M comparison matrix we explore below. We erase type parameters
|
|
@@ -65827,9 +65860,12 @@ var ts;
|
|
|
65827
65860
|
* with no call or construct signatures.
|
|
65828
65861
|
*/
|
|
65829
65862
|
function isObjectTypeWithInferableIndex(type) {
|
|
65830
|
-
return type.flags & 2097152 /* Intersection */
|
|
65831
|
-
|
|
65832
|
-
|
|
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));
|
|
65833
65869
|
}
|
|
65834
65870
|
function createSymbolWithType(source, type) {
|
|
65835
65871
|
var symbol = createSymbol(source.flags, source.escapedName, ts.getCheckFlags(source) & 8 /* Readonly */);
|
|
@@ -67437,7 +67473,8 @@ var ts;
|
|
|
67437
67473
|
return access.kind === 205 /* PropertyAccessExpression */ ? access.name.escapedText :
|
|
67438
67474
|
access.kind === 206 /* ElementAccessExpression */ && ts.isStringOrNumericLiteralLike(access.argumentExpression) ? ts.escapeLeadingUnderscores(access.argumentExpression.text) :
|
|
67439
67475
|
access.kind === 202 /* BindingElement */ && (propertyName = getDestructuringPropertyName(access)) ? ts.escapeLeadingUnderscores(propertyName) :
|
|
67440
|
-
|
|
67476
|
+
access.kind === 163 /* Parameter */ ? ("" + access.parent.parameters.indexOf(access)) :
|
|
67477
|
+
undefined;
|
|
67441
67478
|
}
|
|
67442
67479
|
function containsMatchingReference(source, target) {
|
|
67443
67480
|
while (ts.isAccessExpression(source)) {
|
|
@@ -68777,13 +68814,14 @@ var ts;
|
|
|
68777
68814
|
return result;
|
|
68778
68815
|
}
|
|
68779
68816
|
function getCandidateDiscriminantPropertyAccess(expr) {
|
|
68780
|
-
if (ts.isBindingPattern(reference)) {
|
|
68781
|
-
// When the reference is a binding pattern, we are narrowing a pesudo-reference in
|
|
68782
|
-
// An identifier for a destructuring variable declared in the same binding pattern
|
|
68817
|
+
if (ts.isBindingPattern(reference) || ts.isFunctionExpressionOrArrowFunction(reference)) {
|
|
68818
|
+
// When the reference is a binding pattern or function or arrow expression, we are narrowing a pesudo-reference in
|
|
68819
|
+
// getNarrowedTypeOfSymbol. An identifier for a destructuring variable declared in the same binding pattern or
|
|
68820
|
+
// parameter declared in the same parameter list is a candidate.
|
|
68783
68821
|
if (ts.isIdentifier(expr)) {
|
|
68784
68822
|
var symbol = getResolvedSymbol(expr);
|
|
68785
68823
|
var declaration = symbol.valueDeclaration;
|
|
68786
|
-
if (declaration && ts.isBindingElement(declaration) &&
|
|
68824
|
+
if (declaration && (ts.isBindingElement(declaration) || ts.isParameter(declaration)) && reference === declaration.parent && !declaration.initializer && !declaration.dotDotDotToken) {
|
|
68787
68825
|
return declaration;
|
|
68788
68826
|
}
|
|
68789
68827
|
}
|
|
@@ -69585,42 +69623,78 @@ var ts;
|
|
|
69585
69623
|
}
|
|
69586
69624
|
}
|
|
69587
69625
|
function getNarrowedTypeOfSymbol(symbol, location) {
|
|
69588
|
-
// If we have a non-rest binding element with no initializer declared as a const variable or a const-like
|
|
69589
|
-
// parameter (a parameter for which there are no assignments in the function body), and if the parent type
|
|
69590
|
-
// for the destructuring is a union type, one or more of the binding elements may represent discriminant
|
|
69591
|
-
// properties, and we want the effects of conditional checks on such discriminants to affect the types of
|
|
69592
|
-
// other binding elements from the same destructuring. Consider:
|
|
69593
|
-
//
|
|
69594
|
-
// type Action =
|
|
69595
|
-
// | { kind: 'A', payload: number }
|
|
69596
|
-
// | { kind: 'B', payload: string };
|
|
69597
|
-
//
|
|
69598
|
-
// function f1({ kind, payload }: Action) {
|
|
69599
|
-
// if (kind === 'A') {
|
|
69600
|
-
// payload.toFixed();
|
|
69601
|
-
// }
|
|
69602
|
-
// if (kind === 'B') {
|
|
69603
|
-
// payload.toUpperCase();
|
|
69604
|
-
// }
|
|
69605
|
-
// }
|
|
69606
|
-
//
|
|
69607
|
-
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
|
|
69608
|
-
// the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
|
|
69609
|
-
// as if it occurred in the specified location. We then recompute the narrowed binding element type by
|
|
69610
|
-
// destructuring from the narrowed parent type.
|
|
69611
69626
|
var declaration = symbol.valueDeclaration;
|
|
69612
|
-
if (declaration
|
|
69613
|
-
|
|
69614
|
-
|
|
69615
|
-
|
|
69616
|
-
|
|
69617
|
-
|
|
69618
|
-
|
|
69619
|
-
|
|
69620
|
-
|
|
69621
|
-
|
|
69622
|
-
|
|
69623
|
-
|
|
69627
|
+
if (declaration) {
|
|
69628
|
+
// If we have a non-rest binding element with no initializer declared as a const variable or a const-like
|
|
69629
|
+
// parameter (a parameter for which there are no assignments in the function body), and if the parent type
|
|
69630
|
+
// for the destructuring is a union type, one or more of the binding elements may represent discriminant
|
|
69631
|
+
// properties, and we want the effects of conditional checks on such discriminants to affect the types of
|
|
69632
|
+
// other binding elements from the same destructuring. Consider:
|
|
69633
|
+
//
|
|
69634
|
+
// type Action =
|
|
69635
|
+
// | { kind: 'A', payload: number }
|
|
69636
|
+
// | { kind: 'B', payload: string };
|
|
69637
|
+
//
|
|
69638
|
+
// function f({ kind, payload }: Action) {
|
|
69639
|
+
// if (kind === 'A') {
|
|
69640
|
+
// payload.toFixed();
|
|
69641
|
+
// }
|
|
69642
|
+
// if (kind === 'B') {
|
|
69643
|
+
// payload.toUpperCase();
|
|
69644
|
+
// }
|
|
69645
|
+
// }
|
|
69646
|
+
//
|
|
69647
|
+
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
|
|
69648
|
+
// the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
|
|
69649
|
+
// as if it occurred in the specified location. We then recompute the narrowed binding element type by
|
|
69650
|
+
// destructuring from the narrowed parent type.
|
|
69651
|
+
if (ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) {
|
|
69652
|
+
var parent = declaration.parent.parent;
|
|
69653
|
+
if (parent.kind === 253 /* VariableDeclaration */ && ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || parent.kind === 163 /* Parameter */) {
|
|
69654
|
+
var links = getNodeLinks(location);
|
|
69655
|
+
if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
|
|
69656
|
+
links.flags |= 268435456 /* InCheckIdentifier */;
|
|
69657
|
+
var parentType = getTypeForBindingElementParent(parent);
|
|
69658
|
+
links.flags &= ~268435456 /* InCheckIdentifier */;
|
|
69659
|
+
if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
|
|
69660
|
+
var pattern = declaration.parent;
|
|
69661
|
+
var narrowedType = getFlowTypeOfReference(pattern, parentType, parentType, /*flowContainer*/ undefined, location.flowNode);
|
|
69662
|
+
return getBindingElementTypeFromParentType(declaration, narrowedType);
|
|
69663
|
+
}
|
|
69664
|
+
}
|
|
69665
|
+
}
|
|
69666
|
+
}
|
|
69667
|
+
// If we have a const-like parameter with no type annotation or initializer, and if the parameter is contextually
|
|
69668
|
+
// typed by a signature with a single rest parameter of a union of tuple types, one or more of the parameters may
|
|
69669
|
+
// represent discriminant tuple elements, and we want the effects of conditional checks on such discriminants to
|
|
69670
|
+
// affect the types of other parameters in the same parameter list. Consider:
|
|
69671
|
+
//
|
|
69672
|
+
// type Action = [kind: 'A', payload: number] | [kind: 'B', payload: string];
|
|
69673
|
+
//
|
|
69674
|
+
// const f: (...args: Action) => void = (kind, payload) => {
|
|
69675
|
+
// if (kind === 'A') {
|
|
69676
|
+
// payload.toFixed();
|
|
69677
|
+
// }
|
|
69678
|
+
// if (kind === 'B') {
|
|
69679
|
+
// payload.toUpperCase();
|
|
69680
|
+
// }
|
|
69681
|
+
// }
|
|
69682
|
+
//
|
|
69683
|
+
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
|
|
69684
|
+
// the arrow function AST node for '(kind, payload) => ...' as a pseudo-reference and narrow this reference as
|
|
69685
|
+
// if it occurred in the specified location. We then recompute the narrowed parameter type by indexing into the
|
|
69686
|
+
// narrowed tuple type.
|
|
69687
|
+
if (ts.isParameter(declaration) && !declaration.type && !declaration.initializer && !declaration.dotDotDotToken) {
|
|
69688
|
+
var func = declaration.parent;
|
|
69689
|
+
if (func.parameters.length >= 2 && isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
|
|
69690
|
+
var contextualSignature = getContextualSignature(func);
|
|
69691
|
+
if (contextualSignature && contextualSignature.parameters.length === 1 && signatureHasRestParameter(contextualSignature)) {
|
|
69692
|
+
var restType = getTypeOfSymbol(contextualSignature.parameters[0]);
|
|
69693
|
+
if (restType.flags & 1048576 /* Union */ && everyType(restType, isTupleType) && !isSymbolAssigned(symbol)) {
|
|
69694
|
+
var narrowedType = getFlowTypeOfReference(func, restType, restType, /*flowContainer*/ undefined, location.flowNode);
|
|
69695
|
+
var index = func.parameters.indexOf(declaration) - (ts.getThisParameter(func) ? 1 : 0);
|
|
69696
|
+
return getIndexedAccessType(narrowedType, getNumberLiteralType(index));
|
|
69697
|
+
}
|
|
69624
69698
|
}
|
|
69625
69699
|
}
|
|
69626
69700
|
}
|
|
@@ -70761,7 +70835,7 @@ var ts;
|
|
|
70761
70835
|
}
|
|
70762
70836
|
if (isTupleType(t)) {
|
|
70763
70837
|
var restType = getRestTypeOfTupleType(t);
|
|
70764
|
-
if (restType && isNumericLiteralName(name) && +name >= 0) {
|
|
70838
|
+
if (restType && ts.isNumericLiteralName(name) && +name >= 0) {
|
|
70765
70839
|
return restType;
|
|
70766
70840
|
}
|
|
70767
70841
|
}
|
|
@@ -71402,10 +71476,10 @@ var ts;
|
|
|
71402
71476
|
case 161 /* ComputedPropertyName */:
|
|
71403
71477
|
return isNumericComputedName(name);
|
|
71404
71478
|
case 79 /* Identifier */:
|
|
71405
|
-
return isNumericLiteralName(name.escapedText);
|
|
71479
|
+
return ts.isNumericLiteralName(name.escapedText);
|
|
71406
71480
|
case 8 /* NumericLiteral */:
|
|
71407
71481
|
case 10 /* StringLiteral */:
|
|
71408
|
-
return isNumericLiteralName(name.text);
|
|
71482
|
+
return ts.isNumericLiteralName(name.text);
|
|
71409
71483
|
default:
|
|
71410
71484
|
return false;
|
|
71411
71485
|
}
|
|
@@ -71415,30 +71489,6 @@ var ts;
|
|
|
71415
71489
|
// but this behavior is consistent with checkIndexedAccess
|
|
71416
71490
|
return isTypeAssignableToKind(checkComputedPropertyName(name), 296 /* NumberLike */);
|
|
71417
71491
|
}
|
|
71418
|
-
function isNumericLiteralName(name) {
|
|
71419
|
-
// The intent of numeric names is that
|
|
71420
|
-
// - they are names with text in a numeric form, and that
|
|
71421
|
-
// - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit',
|
|
71422
|
-
// acquired by applying the abstract 'ToNumber' operation on the name's text.
|
|
71423
|
-
//
|
|
71424
|
-
// The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name.
|
|
71425
|
-
// In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold.
|
|
71426
|
-
//
|
|
71427
|
-
// Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)'
|
|
71428
|
-
// according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'.
|
|
71429
|
-
// Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names
|
|
71430
|
-
// because their 'ToString' representation is not equal to their original text.
|
|
71431
|
-
// This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1.
|
|
71432
|
-
//
|
|
71433
|
-
// Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'.
|
|
71434
|
-
// The '+' prefix operator is equivalent here to applying the abstract ToNumber operation.
|
|
71435
|
-
// Applying the 'toString()' method on a number gives us the abstract ToString operation on a number.
|
|
71436
|
-
//
|
|
71437
|
-
// Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional.
|
|
71438
|
-
// This is desired behavior, because when indexing with them as numeric entities, you are indexing
|
|
71439
|
-
// with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively.
|
|
71440
|
-
return (+name).toString() === name;
|
|
71441
|
-
}
|
|
71442
71492
|
function checkComputedPropertyName(node) {
|
|
71443
71493
|
var links = getNodeLinks(node.expression);
|
|
71444
71494
|
if (!links.resolvedType) {
|
|
@@ -71474,7 +71524,7 @@ var ts;
|
|
|
71474
71524
|
function isSymbolWithNumericName(symbol) {
|
|
71475
71525
|
var _a;
|
|
71476
71526
|
var firstDecl = (_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a[0];
|
|
71477
|
-
return isNumericLiteralName(symbol.escapedName) || (firstDecl && ts.isNamedDeclaration(firstDecl) && isNumericName(firstDecl.name));
|
|
71527
|
+
return ts.isNumericLiteralName(symbol.escapedName) || (firstDecl && ts.isNamedDeclaration(firstDecl) && isNumericName(firstDecl.name));
|
|
71478
71528
|
}
|
|
71479
71529
|
function isSymbolWithSymbolName(symbol) {
|
|
71480
71530
|
var _a;
|
|
@@ -82412,7 +82462,7 @@ var ts;
|
|
|
82412
82462
|
}
|
|
82413
82463
|
else {
|
|
82414
82464
|
var text = ts.getTextOfPropertyName(member.name);
|
|
82415
|
-
if (isNumericLiteralName(text) && !ts.isInfinityOrNaNString(text)) {
|
|
82465
|
+
if (ts.isNumericLiteralName(text) && !ts.isInfinityOrNaNString(text)) {
|
|
82416
82466
|
error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name);
|
|
82417
82467
|
}
|
|
82418
82468
|
}
|
|
@@ -109018,7 +109068,7 @@ var ts;
|
|
|
109018
109068
|
emitPlaceholder(hint, node, snippet);
|
|
109019
109069
|
break;
|
|
109020
109070
|
case 0 /* TabStop */:
|
|
109021
|
-
emitTabStop(snippet);
|
|
109071
|
+
emitTabStop(hint, node, snippet);
|
|
109022
109072
|
break;
|
|
109023
109073
|
}
|
|
109024
109074
|
}
|
|
@@ -109028,7 +109078,10 @@ var ts;
|
|
|
109028
109078
|
nonEscapingWrite("}"); // `}`
|
|
109029
109079
|
// `${2:...}`
|
|
109030
109080
|
}
|
|
109031
|
-
function emitTabStop(snippet) {
|
|
109081
|
+
function emitTabStop(hint, node, snippet) {
|
|
109082
|
+
// A tab stop should only be attached to an empty node, i.e. a node that doesn't emit any text.
|
|
109083
|
+
ts.Debug.assert(node.kind === 235 /* EmptyStatement */, "A tab stop cannot be attached to a node of kind " + ts.Debug.formatSyntaxKind(node.kind) + ".");
|
|
109084
|
+
ts.Debug.assert(hint !== 5 /* EmbeddedStatement */, "A tab stop cannot be attached to an embedded statement.");
|
|
109032
109085
|
nonEscapingWrite("$" + snippet.order);
|
|
109033
109086
|
}
|
|
109034
109087
|
//
|
|
@@ -119874,7 +119927,7 @@ var ts;
|
|
|
119874
119927
|
}
|
|
119875
119928
|
ts.getLocaleTimeString = getLocaleTimeString;
|
|
119876
119929
|
/**
|
|
119877
|
-
* Create a function that reports watch status by writing to the system and handles the
|
|
119930
|
+
* Create a function that reports watch status by writing to the system and handles the formatting of the diagnostic
|
|
119878
119931
|
*/
|
|
119879
119932
|
function createWatchStatusReporter(system, pretty) {
|
|
119880
119933
|
return pretty ?
|
|
@@ -119935,7 +119988,7 @@ var ts;
|
|
|
119935
119988
|
ts.Diagnostics.Found_0_errors_Watching_for_file_changes;
|
|
119936
119989
|
}
|
|
119937
119990
|
ts.getWatchErrorSummaryDiagnosticMessage = getWatchErrorSummaryDiagnosticMessage;
|
|
119938
|
-
function getErrorSummaryText(errorCount, filesInError, newLine) {
|
|
119991
|
+
function getErrorSummaryText(errorCount, filesInError, newLine, host) {
|
|
119939
119992
|
if (errorCount === 0)
|
|
119940
119993
|
return "";
|
|
119941
119994
|
var nonNilFiles = filesInError.filter(function (fileInError) { return fileInError !== undefined; });
|
|
@@ -119950,10 +120003,10 @@ var ts;
|
|
|
119950
120003
|
distinctFileNamesWithLines.length === 1 ?
|
|
119951
120004
|
ts.Diagnostics.Found_0_errors_in_1_file :
|
|
119952
120005
|
ts.Diagnostics.Found_0_errors_in_1_files, errorCount, distinctFileNamesWithLines.length);
|
|
119953
|
-
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) : "");
|
|
119954
120007
|
}
|
|
119955
120008
|
ts.getErrorSummaryText = getErrorSummaryText;
|
|
119956
|
-
function createTabularErrorsDisplay(filesInError) {
|
|
120009
|
+
function createTabularErrorsDisplay(filesInError, host) {
|
|
119957
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); }); });
|
|
119958
120011
|
if (distinctFiles.length === 0)
|
|
119959
120012
|
return "";
|
|
@@ -119972,7 +120025,8 @@ var ts;
|
|
|
119972
120025
|
var leftPadding = errorCountDigitsLength < leftPaddingGoal ?
|
|
119973
120026
|
" ".repeat(leftPaddingGoal - errorCountDigitsLength)
|
|
119974
120027
|
: "";
|
|
119975
|
-
|
|
120028
|
+
var relativePath = ts.getRelativePathFromDirectory(host.getCurrentDirectory(), file.fileName, /* ignoreCase */ false);
|
|
120029
|
+
tabularData += "" + leftPadding + errorCount + " " + relativePath + ":" + file.line + "\n";
|
|
119976
120030
|
});
|
|
119977
120031
|
return tabularData;
|
|
119978
120032
|
}
|
|
@@ -120390,7 +120444,7 @@ var ts;
|
|
|
120390
120444
|
var system = input.system || ts.sys;
|
|
120391
120445
|
var host = input.host || (input.host = ts.createIncrementalCompilerHost(input.options, system));
|
|
120392
120446
|
var builderProgram = ts.createIncrementalProgram(input);
|
|
120393
|
-
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);
|
|
120394
120448
|
if (input.afterProgramEmitAndDiagnostics)
|
|
120395
120449
|
input.afterProgramEmitAndDiagnostics(builderProgram);
|
|
120396
120450
|
return exitStatus;
|
|
@@ -126166,6 +126220,16 @@ var ts;
|
|
|
126166
126220
|
: ts.getLocaleSpecificMessage(diag);
|
|
126167
126221
|
}
|
|
126168
126222
|
ts.diagnosticToString = diagnosticToString;
|
|
126223
|
+
/**
|
|
126224
|
+
* Get format code settings for a code writing context (e.g. when formatting text changes or completions code).
|
|
126225
|
+
*/
|
|
126226
|
+
function getFormatCodeSettingsForWriting(_a, sourceFile) {
|
|
126227
|
+
var options = _a.options;
|
|
126228
|
+
var shouldAutoDetectSemicolonPreference = !options.semicolons || options.semicolons === ts.SemicolonPreference.Ignore;
|
|
126229
|
+
var shouldRemoveSemicolons = options.semicolons === ts.SemicolonPreference.Remove || shouldAutoDetectSemicolonPreference && !probablyUsesSemicolons(sourceFile);
|
|
126230
|
+
return __assign(__assign({}, options), { semicolons: shouldRemoveSemicolons ? ts.SemicolonPreference.Remove : ts.SemicolonPreference.Ignore });
|
|
126231
|
+
}
|
|
126232
|
+
ts.getFormatCodeSettingsForWriting = getFormatCodeSettingsForWriting;
|
|
126169
126233
|
// #endregion
|
|
126170
126234
|
})(ts || (ts = {}));
|
|
126171
126235
|
/*@internal*/
|
|
@@ -127789,7 +127853,8 @@ var ts;
|
|
|
127789
127853
|
return convertPathCompletions(completion.paths);
|
|
127790
127854
|
case 1 /* Properties */: {
|
|
127791
127855
|
var entries = ts.createSortedArray();
|
|
127792
|
-
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, contextToken, sourceFile, sourceFile, host, program, 99 /* ESNext */, log, 4 /* String */, preferences, options
|
|
127856
|
+
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, contextToken, sourceFile, sourceFile, host, program, 99 /* ESNext */, log, 4 /* String */, preferences, options,
|
|
127857
|
+
/*formatContext*/ undefined); // Target will not be used, so arbitrary
|
|
127793
127858
|
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: completion.hasIndexSignature, optionalReplacementSpan: optionalReplacementSpan, entries: entries };
|
|
127794
127859
|
}
|
|
127795
127860
|
case 2 /* Types */: {
|
|
@@ -128610,7 +128675,7 @@ var ts;
|
|
|
128610
128675
|
return result;
|
|
128611
128676
|
}
|
|
128612
128677
|
}
|
|
128613
|
-
function getCompletionsAtPosition(host, program, log, sourceFile, position, preferences, triggerCharacter, completionKind, cancellationToken) {
|
|
128678
|
+
function getCompletionsAtPosition(host, program, log, sourceFile, position, preferences, triggerCharacter, completionKind, cancellationToken, formatContext) {
|
|
128614
128679
|
var _a;
|
|
128615
128680
|
var previousToken = getRelevantTokens(position, sourceFile).previousToken;
|
|
128616
128681
|
if (triggerCharacter && !ts.isInString(sourceFile, position, previousToken) && !isValidTrigger(sourceFile, triggerCharacter, previousToken, position)) {
|
|
@@ -128650,7 +128715,7 @@ var ts;
|
|
|
128650
128715
|
}
|
|
128651
128716
|
switch (completionData.kind) {
|
|
128652
128717
|
case 0 /* Data */:
|
|
128653
|
-
var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences);
|
|
128718
|
+
var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext);
|
|
128654
128719
|
if (response === null || response === void 0 ? void 0 : response.isIncomplete) {
|
|
128655
128720
|
incompleteCompletionsCache === null || incompleteCompletionsCache === void 0 ? void 0 : incompleteCompletionsCache.set(response);
|
|
128656
128721
|
}
|
|
@@ -128770,7 +128835,7 @@ var ts;
|
|
|
128770
128835
|
// StringLiteralLike locations are handled separately in stringCompletions.ts
|
|
128771
128836
|
return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
|
|
128772
128837
|
}
|
|
128773
|
-
function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences) {
|
|
128838
|
+
function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext) {
|
|
128774
128839
|
var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
|
|
128775
128840
|
// Verify if the file is JSX language variant
|
|
128776
128841
|
if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
|
|
@@ -128782,7 +128847,7 @@ var ts;
|
|
|
128782
128847
|
var entries = ts.createSortedArray();
|
|
128783
128848
|
if (isUncheckedFile(sourceFile, compilerOptions)) {
|
|
128784
128849
|
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
|
|
128785
|
-
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
128850
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
128786
128851
|
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
|
|
128787
128852
|
}
|
|
128788
128853
|
else {
|
|
@@ -128790,7 +128855,7 @@ var ts;
|
|
|
128790
128855
|
return undefined;
|
|
128791
128856
|
}
|
|
128792
128857
|
getCompletionEntriesFromSymbols(symbols, entries,
|
|
128793
|
-
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
128858
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
128794
128859
|
}
|
|
128795
128860
|
if (keywordFilters !== 0 /* None */) {
|
|
128796
128861
|
var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
|
|
@@ -128896,7 +128961,7 @@ var ts;
|
|
|
128896
128961
|
function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
|
|
128897
128962
|
return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
|
|
128898
128963
|
}
|
|
128899
|
-
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind) {
|
|
128964
|
+
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext) {
|
|
128900
128965
|
var _a, _b;
|
|
128901
128966
|
var insertText;
|
|
128902
128967
|
var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
|
|
@@ -128961,7 +129026,7 @@ var ts;
|
|
|
128961
129026
|
completionKind === 3 /* MemberLike */ &&
|
|
128962
129027
|
isClassLikeMemberCompletion(symbol, location)) {
|
|
128963
129028
|
var importAdder = void 0;
|
|
128964
|
-
(_b = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken), insertText = _b.insertText, isSnippet = _b.isSnippet, importAdder = _b.importAdder);
|
|
129029
|
+
(_b = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken, formatContext), insertText = _b.insertText, isSnippet = _b.isSnippet, importAdder = _b.importAdder);
|
|
128965
129030
|
if (importAdder === null || importAdder === void 0 ? void 0 : importAdder.hasFixes()) {
|
|
128966
129031
|
hasAction = true;
|
|
128967
129032
|
source = CompletionSource.ClassMemberSnippet;
|
|
@@ -129060,7 +129125,7 @@ var ts;
|
|
|
129060
129125
|
ts.isSyntaxList(location) &&
|
|
129061
129126
|
ts.isClassLike(location.parent)));
|
|
129062
129127
|
}
|
|
129063
|
-
function getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken) {
|
|
129128
|
+
function getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken, formatContext) {
|
|
129064
129129
|
var classLikeDeclaration = ts.findAncestor(location, ts.isClassLike);
|
|
129065
129130
|
if (!classLikeDeclaration) {
|
|
129066
129131
|
return { insertText: name };
|
|
@@ -129077,15 +129142,16 @@ var ts;
|
|
|
129077
129142
|
newLine: ts.getNewLineKind(ts.getNewLineCharacter(options, ts.maybeBind(host, host.getNewLine))),
|
|
129078
129143
|
});
|
|
129079
129144
|
var importAdder = ts.codefix.createImportAdder(sourceFile, program, preferences, host);
|
|
129145
|
+
// Create empty body for possible method implementation.
|
|
129080
129146
|
var body;
|
|
129081
129147
|
if (preferences.includeCompletionsWithSnippetText) {
|
|
129082
129148
|
isSnippet = true;
|
|
129083
129149
|
// We are adding a tabstop (i.e. `$0`) in the body of the suggested member,
|
|
129084
129150
|
// if it has one, so that the cursor ends up in the body once the completion is inserted.
|
|
129085
129151
|
// Note: this assumes we won't have more than one body in the completion nodes, which should be the case.
|
|
129086
|
-
var
|
|
129087
|
-
ts.
|
|
129088
|
-
|
|
129152
|
+
var emptyStmt = ts.factory.createEmptyStatement();
|
|
129153
|
+
body = ts.factory.createBlock([emptyStmt], /* multiline */ true);
|
|
129154
|
+
ts.setSnippetElement(emptyStmt, { kind: 0 /* TabStop */, order: 0 });
|
|
129089
129155
|
}
|
|
129090
129156
|
else {
|
|
129091
129157
|
body = ts.factory.createBlock([], /* multiline */ true);
|
|
@@ -129131,7 +129197,27 @@ var ts;
|
|
|
129131
129197
|
completionNodes.push(node);
|
|
129132
129198
|
}, body, 2 /* Property */, isAbstract);
|
|
129133
129199
|
if (completionNodes.length) {
|
|
129134
|
-
|
|
129200
|
+
// If we have access to formatting settings, we print the nodes using the emitter,
|
|
129201
|
+
// and then format the printed text.
|
|
129202
|
+
if (formatContext) {
|
|
129203
|
+
var syntheticFile_1 = {
|
|
129204
|
+
text: printer.printSnippetList(1 /* MultiLine */ | 131072 /* NoTrailingNewLine */, ts.factory.createNodeArray(completionNodes), sourceFile),
|
|
129205
|
+
getLineAndCharacterOfPosition: function (pos) {
|
|
129206
|
+
return ts.getLineAndCharacterOfPosition(this, pos);
|
|
129207
|
+
},
|
|
129208
|
+
};
|
|
129209
|
+
var formatOptions_1 = ts.getFormatCodeSettingsForWriting(formatContext, sourceFile);
|
|
129210
|
+
var changes = ts.flatMap(completionNodes, function (node) {
|
|
129211
|
+
var nodeWithPos = ts.textChanges.assignPositionsToNode(node);
|
|
129212
|
+
return ts.formatting.formatNodeGivenIndentation(nodeWithPos, syntheticFile_1, sourceFile.languageVariant,
|
|
129213
|
+
/* indentation */ 0,
|
|
129214
|
+
/* delta */ 0, __assign(__assign({}, formatContext), { options: formatOptions_1 }));
|
|
129215
|
+
});
|
|
129216
|
+
insertText = ts.textChanges.applyChanges(syntheticFile_1.text, changes);
|
|
129217
|
+
}
|
|
129218
|
+
else { // Otherwise, just use emitter to print the new nodes.
|
|
129219
|
+
insertText = printer.printSnippetList(1 /* MultiLine */ | 131072 /* NoTrailingNewLine */, ts.factory.createNodeArray(completionNodes), sourceFile);
|
|
129220
|
+
}
|
|
129135
129221
|
}
|
|
129136
129222
|
return { insertText: insertText, isSnippet: isSnippet, importAdder: importAdder };
|
|
129137
129223
|
}
|
|
@@ -129175,8 +129261,8 @@ var ts;
|
|
|
129175
129261
|
return undefined;
|
|
129176
129262
|
}
|
|
129177
129263
|
function createSnippetPrinter(printerOptions) {
|
|
129178
|
-
var
|
|
129179
|
-
var
|
|
129264
|
+
var baseWriter = ts.textChanges.createWriter(ts.getNewLineCharacter(printerOptions));
|
|
129265
|
+
var printer = ts.createPrinter(printerOptions, baseWriter);
|
|
129180
129266
|
var writer = __assign(__assign({}, baseWriter), { write: function (s) { return baseWriter.write(ts.escapeSnippetText(s)); }, nonEscapingWrite: baseWriter.write, writeLiteral: function (s) { return baseWriter.writeLiteral(ts.escapeSnippetText(s)); }, writeStringLiteral: function (s) { return baseWriter.writeStringLiteral(ts.escapeSnippetText(s)); }, writeSymbol: function (s, symbol) { return baseWriter.writeSymbol(ts.escapeSnippetText(s), symbol); }, writeParameter: function (s) { return baseWriter.writeParameter(ts.escapeSnippetText(s)); }, writeComment: function (s) { return baseWriter.writeComment(ts.escapeSnippetText(s)); }, writeProperty: function (s) { return baseWriter.writeProperty(ts.escapeSnippetText(s)); } });
|
|
129181
129267
|
return {
|
|
129182
129268
|
printSnippetList: printSnippetList,
|
|
@@ -129281,7 +129367,7 @@ var ts;
|
|
|
129281
129367
|
return CompletionSource.ThisProperty;
|
|
129282
129368
|
}
|
|
129283
129369
|
}
|
|
129284
|
-
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
129370
|
+
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
129285
129371
|
var _a;
|
|
129286
129372
|
var start = ts.timestamp();
|
|
129287
129373
|
var variableDeclaration = getVariableDeclaration(location);
|
|
@@ -129302,7 +129388,7 @@ var ts;
|
|
|
129302
129388
|
var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
|
|
129303
129389
|
var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
|
|
129304
129390
|
var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
|
|
129305
|
-
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind);
|
|
129391
|
+
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, formatContext);
|
|
129306
129392
|
if (!entry) {
|
|
129307
129393
|
continue;
|
|
129308
129394
|
}
|
|
@@ -129498,7 +129584,7 @@ var ts;
|
|
|
129498
129584
|
}
|
|
129499
129585
|
}
|
|
129500
129586
|
if (source === CompletionSource.ClassMemberSnippet) {
|
|
129501
|
-
var importAdder = getEntryForMemberCompletion(host, program, compilerOptions, preferences, name, symbol, location, contextToken).importAdder;
|
|
129587
|
+
var importAdder = getEntryForMemberCompletion(host, program, compilerOptions, preferences, name, symbol, location, contextToken, formatContext).importAdder;
|
|
129502
129588
|
if (importAdder) {
|
|
129503
129589
|
var changes = ts.textChanges.ChangeTracker.with({ host: host, formatContext: formatContext, preferences: preferences }, importAdder.writeFixes);
|
|
129504
129590
|
return {
|
|
@@ -145382,19 +145468,13 @@ var ts;
|
|
|
145382
145468
|
+ ((!options.suffix || ts.endsWith(noIndent, options.suffix))
|
|
145383
145469
|
? "" : options.suffix);
|
|
145384
145470
|
}
|
|
145385
|
-
function getFormatCodeSettingsForWriting(_a, sourceFile) {
|
|
145386
|
-
var options = _a.options;
|
|
145387
|
-
var shouldAutoDetectSemicolonPreference = !options.semicolons || options.semicolons === ts.SemicolonPreference.Ignore;
|
|
145388
|
-
var shouldRemoveSemicolons = options.semicolons === ts.SemicolonPreference.Remove || shouldAutoDetectSemicolonPreference && !ts.probablyUsesSemicolons(sourceFile);
|
|
145389
|
-
return __assign(__assign({}, options), { semicolons: shouldRemoveSemicolons ? ts.SemicolonPreference.Remove : ts.SemicolonPreference.Ignore });
|
|
145390
|
-
}
|
|
145391
145471
|
/** Note: this may mutate `nodeIn`. */
|
|
145392
145472
|
function getFormattedTextOfNode(nodeIn, sourceFile, pos, _a, newLineCharacter, formatContext, validate) {
|
|
145393
145473
|
var indentation = _a.indentation, prefix = _a.prefix, delta = _a.delta;
|
|
145394
145474
|
var _b = getNonformattedText(nodeIn, sourceFile, newLineCharacter), node = _b.node, text = _b.text;
|
|
145395
145475
|
if (validate)
|
|
145396
145476
|
validate(node, text);
|
|
145397
|
-
var formatOptions = getFormatCodeSettingsForWriting(formatContext, sourceFile);
|
|
145477
|
+
var formatOptions = ts.getFormatCodeSettingsForWriting(formatContext, sourceFile);
|
|
145398
145478
|
var initialIndentation = indentation !== undefined
|
|
145399
145479
|
? indentation
|
|
145400
145480
|
: ts.formatting.SmartIndenter.getIndentation(pos, sourceFile, formatOptions, prefix === newLineCharacter || ts.getLineStartPositionForPosition(pos, sourceFile) === pos);
|
|
@@ -145442,6 +145522,7 @@ var ts;
|
|
|
145442
145522
|
ts.setTextRangePosEnd(newNode, getPos(node), getEnd(node));
|
|
145443
145523
|
return newNode;
|
|
145444
145524
|
}
|
|
145525
|
+
textChanges_3.assignPositionsToNode = assignPositionsToNode;
|
|
145445
145526
|
function assignPositionsToNodeArray(nodes, visitor, test, start, count) {
|
|
145446
145527
|
var visited = ts.visitNodes(nodes, visitor, test, start, count);
|
|
145447
145528
|
if (!visited) {
|
|
@@ -145612,6 +145693,7 @@ var ts;
|
|
|
145612
145693
|
clear: clear
|
|
145613
145694
|
};
|
|
145614
145695
|
}
|
|
145696
|
+
textChanges_3.createWriter = createWriter;
|
|
145615
145697
|
function getInsertionPositionAtSourceFileTop(sourceFile) {
|
|
145616
145698
|
var lastPrologue;
|
|
145617
145699
|
for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
|
|
@@ -150347,7 +150429,8 @@ var ts;
|
|
|
150347
150429
|
return { kind: 3 /* ObjectLiteral */, token: token, properties: properties, indentation: undefined, parentDeclaration: parent.initializer };
|
|
150348
150430
|
}
|
|
150349
150431
|
if (ts.isIdentifier(token) && ts.isJsxOpeningLikeElement(token.parent)) {
|
|
150350
|
-
var
|
|
150432
|
+
var target = ts.getEmitScriptTarget(program.getCompilerOptions());
|
|
150433
|
+
var attributes = getUnmatchedAttributes(checker, target, token.parent);
|
|
150351
150434
|
if (!ts.length(attributes))
|
|
150352
150435
|
return undefined;
|
|
150353
150436
|
return { kind: 4 /* JsxAttributes */, token: token, attributes: attributes, parentDeclaration: token.parent };
|
|
@@ -150582,8 +150665,12 @@ var ts;
|
|
|
150582
150665
|
var jsxAttributesNode = info.parentDeclaration.attributes;
|
|
150583
150666
|
var hasSpreadAttribute = ts.some(jsxAttributesNode.properties, ts.isJsxSpreadAttribute);
|
|
150584
150667
|
var attrs = ts.map(info.attributes, function (attr) {
|
|
150585
|
-
var value =
|
|
150586
|
-
|
|
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;
|
|
150587
150674
|
});
|
|
150588
150675
|
var jsxAttributes = ts.factory.createJsxAttributes(hasSpreadAttribute ? __spreadArray(__spreadArray([], attrs, true), jsxAttributesNode.properties, true) : __spreadArray(__spreadArray([], jsxAttributesNode.properties, true), attrs, true));
|
|
150589
150676
|
var options = { prefix: jsxAttributesNode.pos === jsxAttributesNode.end ? " " : undefined };
|
|
@@ -150592,10 +150679,11 @@ var ts;
|
|
|
150592
150679
|
function addObjectLiteralProperties(changes, context, info) {
|
|
150593
150680
|
var importAdder = codefix.createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
|
|
150594
150681
|
var quotePreference = ts.getQuotePreference(context.sourceFile, context.preferences);
|
|
150682
|
+
var target = ts.getEmitScriptTarget(context.program.getCompilerOptions());
|
|
150595
150683
|
var checker = context.program.getTypeChecker();
|
|
150596
150684
|
var props = ts.map(info.properties, function (prop) {
|
|
150597
|
-
var initializer =
|
|
150598
|
-
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);
|
|
150599
150687
|
});
|
|
150600
150688
|
var options = {
|
|
150601
150689
|
leadingTriviaOption: ts.textChanges.LeadingTriviaOption.Exclude,
|
|
@@ -150682,7 +150770,7 @@ var ts;
|
|
|
150682
150770
|
return (type.flags & 524288 /* Object */) &&
|
|
150683
150771
|
((ts.getObjectFlags(type) & 128 /* ObjectLiteral */) || (type.symbol && ts.tryCast(ts.singleOrUndefined(type.symbol.declarations), ts.isTypeLiteralNode)));
|
|
150684
150772
|
}
|
|
150685
|
-
function getUnmatchedAttributes(checker, source) {
|
|
150773
|
+
function getUnmatchedAttributes(checker, target, source) {
|
|
150686
150774
|
var attrsType = checker.getContextualType(source.attributes);
|
|
150687
150775
|
if (attrsType === undefined)
|
|
150688
150776
|
return ts.emptyArray;
|
|
@@ -150704,7 +150792,7 @@ var ts;
|
|
|
150704
150792
|
}
|
|
150705
150793
|
}
|
|
150706
150794
|
return ts.filter(targetProps, function (targetProp) {
|
|
150707
|
-
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));
|
|
150708
150796
|
});
|
|
150709
150797
|
}
|
|
150710
150798
|
})(codefix = ts.codefix || (ts.codefix = {}));
|
|
@@ -160509,12 +160597,12 @@ var ts;
|
|
|
160509
160597
|
synchronizeHostData();
|
|
160510
160598
|
return __spreadArray(__spreadArray([], program.getOptionsDiagnostics(cancellationToken), true), program.getGlobalDiagnostics(cancellationToken), true);
|
|
160511
160599
|
}
|
|
160512
|
-
function getCompletionsAtPosition(fileName, position, options) {
|
|
160600
|
+
function getCompletionsAtPosition(fileName, position, options, formattingSettings) {
|
|
160513
160601
|
if (options === void 0) { options = ts.emptyOptions; }
|
|
160514
160602
|
// Convert from deprecated options names to new names
|
|
160515
160603
|
var fullPreferences = __assign(__assign({}, ts.identity(options)), { includeCompletionsForModuleExports: options.includeCompletionsForModuleExports || options.includeExternalModuleExports, includeCompletionsWithInsertText: options.includeCompletionsWithInsertText || options.includeInsertTextCompletions });
|
|
160516
160604
|
synchronizeHostData();
|
|
160517
|
-
return ts.Completions.getCompletionsAtPosition(host, program, log, getValidSourceFile(fileName), position, fullPreferences, options.triggerCharacter, options.triggerKind, cancellationToken);
|
|
160605
|
+
return ts.Completions.getCompletionsAtPosition(host, program, log, getValidSourceFile(fileName), position, fullPreferences, options.triggerCharacter, options.triggerKind, cancellationToken, formattingSettings && ts.formatting.getFormatContext(formattingSettings, host));
|
|
160518
160606
|
}
|
|
160519
160607
|
function getCompletionEntryDetails(fileName, position, name, formattingOptions, source, preferences, data) {
|
|
160520
160608
|
if (preferences === void 0) { preferences = ts.emptyOptions; }
|
|
@@ -162677,9 +162765,9 @@ var ts;
|
|
|
162677
162765
|
* to provide at the given source position and providing a member completion
|
|
162678
162766
|
* list if requested.
|
|
162679
162767
|
*/
|
|
162680
|
-
LanguageServiceShimObject.prototype.getCompletionsAtPosition = function (fileName, position, preferences) {
|
|
162768
|
+
LanguageServiceShimObject.prototype.getCompletionsAtPosition = function (fileName, position, preferences, formattingSettings) {
|
|
162681
162769
|
var _this = this;
|
|
162682
|
-
return this.forwardJSONCall("getCompletionsAtPosition('" + fileName + "', " + position + ", " + preferences + ")", function () { return _this.languageService.getCompletionsAtPosition(fileName, position, preferences); });
|
|
162770
|
+
return this.forwardJSONCall("getCompletionsAtPosition('" + fileName + "', " + position + ", " + preferences + ", " + formattingSettings + ")", function () { return _this.languageService.getCompletionsAtPosition(fileName, position, preferences, formattingSettings); });
|
|
162683
162771
|
};
|
|
162684
162772
|
/** Get a string based representation of a completion list entry details */
|
|
162685
162773
|
LanguageServiceShimObject.prototype.getCompletionEntryDetails = function (fileName, position, entryName, formatOptions, source, preferences, data) {
|
|
@@ -163208,14 +163296,8 @@ var ts;
|
|
|
163208
163296
|
var possibleSearchDirs = new ts.Set(fileNames.map(ts.getDirectoryPath));
|
|
163209
163297
|
possibleSearchDirs.add(projectRootPath);
|
|
163210
163298
|
possibleSearchDirs.forEach(function (searchDir) {
|
|
163211
|
-
|
|
163212
|
-
|
|
163213
|
-
var bowerJsonPath = ts.combinePaths(searchDir, "bower.json");
|
|
163214
|
-
getTypingNamesFromJson(bowerJsonPath, filesToWatch);
|
|
163215
|
-
var bowerComponentsPath = ts.combinePaths(searchDir, "bower_components");
|
|
163216
|
-
getTypingNamesFromPackagesFolder(bowerComponentsPath, filesToWatch);
|
|
163217
|
-
var nodeModulesPath = ts.combinePaths(searchDir, "node_modules");
|
|
163218
|
-
getTypingNamesFromPackagesFolder(nodeModulesPath, filesToWatch);
|
|
163299
|
+
getTypingNames(searchDir, "bower.json", "bower_components", filesToWatch);
|
|
163300
|
+
getTypingNames(searchDir, "package.json", "node_modules", filesToWatch);
|
|
163219
163301
|
});
|
|
163220
163302
|
if (!typeAcquisition.disableFilenameBasedTypeAcquisition) {
|
|
163221
163303
|
getTypingNamesFromSourceFileNames(fileNames);
|
|
@@ -163264,16 +163346,100 @@ var ts;
|
|
|
163264
163346
|
ts.forEach(typingNames, addInferredTyping);
|
|
163265
163347
|
}
|
|
163266
163348
|
/**
|
|
163267
|
-
*
|
|
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.
|
|
163268
163355
|
*/
|
|
163269
|
-
function
|
|
163270
|
-
|
|
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)) {
|
|
163271
163376
|
return;
|
|
163272
163377
|
}
|
|
163273
|
-
|
|
163274
|
-
|
|
163275
|
-
|
|
163276
|
-
|
|
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");
|
|
163277
163443
|
}
|
|
163278
163444
|
/**
|
|
163279
163445
|
* Infer typing names from given file names. For example, the file name "jquery-min.2.3.4.js"
|
|
@@ -163299,55 +163465,6 @@ var ts;
|
|
|
163299
163465
|
addInferredTyping("react");
|
|
163300
163466
|
}
|
|
163301
163467
|
}
|
|
163302
|
-
/**
|
|
163303
|
-
* Infer typing names from packages folder (ex: node_module, bower_components)
|
|
163304
|
-
* @param packagesFolderPath is the path to the packages folder
|
|
163305
|
-
*/
|
|
163306
|
-
function getTypingNamesFromPackagesFolder(packagesFolderPath, filesToWatch) {
|
|
163307
|
-
filesToWatch.push(packagesFolderPath);
|
|
163308
|
-
// Todo: add support for ModuleResolutionHost too
|
|
163309
|
-
if (!host.directoryExists(packagesFolderPath)) {
|
|
163310
|
-
return;
|
|
163311
|
-
}
|
|
163312
|
-
// depth of 2, so we access `node_modules/foo` but not `node_modules/foo/bar`
|
|
163313
|
-
var fileNames = host.readDirectory(packagesFolderPath, [".json" /* Json */], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2);
|
|
163314
|
-
if (log)
|
|
163315
|
-
log("Searching for typing names in " + packagesFolderPath + "; all files: " + JSON.stringify(fileNames));
|
|
163316
|
-
var packageNames = [];
|
|
163317
|
-
for (var _i = 0, fileNames_1 = fileNames; _i < fileNames_1.length; _i++) {
|
|
163318
|
-
var fileName = fileNames_1[_i];
|
|
163319
|
-
var normalizedFileName = ts.normalizePath(fileName);
|
|
163320
|
-
var baseFileName = ts.getBaseFileName(normalizedFileName);
|
|
163321
|
-
if (baseFileName !== "package.json" && baseFileName !== "bower.json") {
|
|
163322
|
-
continue;
|
|
163323
|
-
}
|
|
163324
|
-
var result_1 = ts.readConfigFile(normalizedFileName, function (path) { return host.readFile(path); });
|
|
163325
|
-
var packageJson = result_1.config;
|
|
163326
|
-
// npm 3's package.json contains a "_requiredBy" field
|
|
163327
|
-
// we should include all the top level module names for npm 2, and only module names whose
|
|
163328
|
-
// "_requiredBy" field starts with "#" or equals "/" for npm 3.
|
|
163329
|
-
if (baseFileName === "package.json" && packageJson._requiredBy &&
|
|
163330
|
-
ts.filter(packageJson._requiredBy, function (r) { return r[0] === "#" || r === "/"; }).length === 0) {
|
|
163331
|
-
continue;
|
|
163332
|
-
}
|
|
163333
|
-
// If the package has its own d.ts typings, those will take precedence. Otherwise the package name will be used
|
|
163334
|
-
// to download d.ts files from DefinitelyTyped
|
|
163335
|
-
if (!packageJson.name) {
|
|
163336
|
-
continue;
|
|
163337
|
-
}
|
|
163338
|
-
var ownTypes = packageJson.types || packageJson.typings;
|
|
163339
|
-
if (ownTypes) {
|
|
163340
|
-
var absolutePath = ts.getNormalizedAbsolutePath(ownTypes, ts.getDirectoryPath(normalizedFileName));
|
|
163341
|
-
if (log)
|
|
163342
|
-
log(" Package '" + packageJson.name + "' provides its own types.");
|
|
163343
|
-
inferredTypings.set(packageJson.name, absolutePath);
|
|
163344
|
-
}
|
|
163345
|
-
else {
|
|
163346
|
-
packageNames.push(packageJson.name);
|
|
163347
|
-
}
|
|
163348
|
-
}
|
|
163349
|
-
addInferredTypings(packageNames, " Found package names");
|
|
163350
|
-
}
|
|
163351
163468
|
}
|
|
163352
163469
|
JsTyping.discoverTypings = discoverTypings;
|
|
163353
163470
|
var NameValidationResult;
|
|
@@ -171233,6 +171350,9 @@ var ts;
|
|
|
171233
171350
|
}
|
|
171234
171351
|
return;
|
|
171235
171352
|
}
|
|
171353
|
+
this.writeMessage(msg);
|
|
171354
|
+
};
|
|
171355
|
+
Session.prototype.writeMessage = function (msg) {
|
|
171236
171356
|
var msgText = formatMessage(msg, this.logger, this.byteLength, this.host.newLine);
|
|
171237
171357
|
ts.perfLogger.logEvent("Response message size: " + msgText.length);
|
|
171238
171358
|
this.host.write(msgText);
|
|
@@ -171984,7 +172104,7 @@ var ts;
|
|
|
171984
172104
|
var _a = this.getFileAndProject(args), file = _a.file, project = _a.project;
|
|
171985
172105
|
var scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file);
|
|
171986
172106
|
var position = this.getPosition(args, scriptInfo);
|
|
171987
|
-
var completions = project.getLanguageService().getCompletionsAtPosition(file, position, __assign(__assign({}, server.convertUserPreferences(this.getPreferences(file))), { triggerCharacter: args.triggerCharacter, triggerKind: args.triggerKind, includeExternalModuleExports: args.includeExternalModuleExports, includeInsertTextCompletions: args.includeInsertTextCompletions }));
|
|
172107
|
+
var completions = project.getLanguageService().getCompletionsAtPosition(file, position, __assign(__assign({}, server.convertUserPreferences(this.getPreferences(file))), { triggerCharacter: args.triggerCharacter, triggerKind: args.triggerKind, includeExternalModuleExports: args.includeExternalModuleExports, includeInsertTextCompletions: args.includeInsertTextCompletions }), project.projectService.getFormatCodeOptions(file));
|
|
171988
172108
|
if (completions === undefined)
|
|
171989
172109
|
return undefined;
|
|
171990
172110
|
if (kind === "completions-full" /* CompletionsFull */)
|
|
@@ -175272,12 +175392,40 @@ var ts;
|
|
|
175272
175392
|
};
|
|
175273
175393
|
return IOSession;
|
|
175274
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));
|
|
175275
175422
|
var eventPort = parseEventPort(server.findArgument("--eventPort"));
|
|
175276
175423
|
var typingSafeListLocation = server.findArgument(server.Arguments.TypingSafeListLocation); // TODO: GH#18217
|
|
175277
175424
|
var typesMapLocation = server.findArgument(server.Arguments.TypesMapLocation) || ts.combinePaths(ts.getDirectoryPath(ts.sys.getExecutingFilePath()), "typesMap.json");
|
|
175278
175425
|
var npmLocation = server.findArgument(server.Arguments.NpmLocation);
|
|
175279
175426
|
var validateDefaultNpmLocation = server.hasArgument(server.Arguments.ValidateDefaultNpmLocation);
|
|
175280
175427
|
var disableAutomaticTypingAcquisition = server.hasArgument("--disableAutomaticTypingAcquisition");
|
|
175428
|
+
var useNodeIpc = server.hasArgument("--useNodeIpc");
|
|
175281
175429
|
var telemetryEnabled = server.hasArgument(server.Arguments.EnableTelemetry);
|
|
175282
175430
|
var commandLineTraceDir = server.findArgument("--traceDirectory");
|
|
175283
175431
|
var traceDir = commandLineTraceDir
|
|
@@ -175286,7 +175434,7 @@ var ts;
|
|
|
175286
175434
|
if (traceDir) {
|
|
175287
175435
|
ts.startTracing("server", traceDir);
|
|
175288
175436
|
}
|
|
175289
|
-
var ioSession = new IOSession();
|
|
175437
|
+
var ioSession = useNodeIpc ? new IpcIOSession() : new IOSession();
|
|
175290
175438
|
process.on("uncaughtException", function (err) {
|
|
175291
175439
|
ioSession.logError(err, "unknown");
|
|
175292
175440
|
});
|