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/tsserverlibrary.js
CHANGED
|
@@ -294,7 +294,7 @@ var ts;
|
|
|
294
294
|
// The following is baselined as a literal template type without intervention
|
|
295
295
|
/** The version of the TypeScript compiler release */
|
|
296
296
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
297
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
297
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220108";
|
|
298
298
|
/* @internal */
|
|
299
299
|
var Comparison;
|
|
300
300
|
(function (Comparison) {
|
|
@@ -14650,7 +14650,8 @@ var ts;
|
|
|
14650
14650
|
Float64Array: ["at"],
|
|
14651
14651
|
BigInt64Array: ["at"],
|
|
14652
14652
|
BigUint64Array: ["at"],
|
|
14653
|
-
ObjectConstructor: ["hasOwn"]
|
|
14653
|
+
ObjectConstructor: ["hasOwn"],
|
|
14654
|
+
Error: ["cause"]
|
|
14654
14655
|
}
|
|
14655
14656
|
};
|
|
14656
14657
|
}
|
|
@@ -20961,9 +20962,40 @@ var ts;
|
|
|
20961
20962
|
}
|
|
20962
20963
|
ts.isFunctionExpressionOrArrowFunction = isFunctionExpressionOrArrowFunction;
|
|
20963
20964
|
function escapeSnippetText(text) {
|
|
20964
|
-
return text.replace(/\$/gm, "\\$");
|
|
20965
|
+
return text.replace(/\$/gm, function () { return "\\$"; });
|
|
20965
20966
|
}
|
|
20966
20967
|
ts.escapeSnippetText = escapeSnippetText;
|
|
20968
|
+
function isNumericLiteralName(name) {
|
|
20969
|
+
// The intent of numeric names is that
|
|
20970
|
+
// - they are names with text in a numeric form, and that
|
|
20971
|
+
// - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit',
|
|
20972
|
+
// acquired by applying the abstract 'ToNumber' operation on the name's text.
|
|
20973
|
+
//
|
|
20974
|
+
// The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name.
|
|
20975
|
+
// In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold.
|
|
20976
|
+
//
|
|
20977
|
+
// Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)'
|
|
20978
|
+
// according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'.
|
|
20979
|
+
// Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names
|
|
20980
|
+
// because their 'ToString' representation is not equal to their original text.
|
|
20981
|
+
// This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1.
|
|
20982
|
+
//
|
|
20983
|
+
// Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'.
|
|
20984
|
+
// The '+' prefix operator is equivalent here to applying the abstract ToNumber operation.
|
|
20985
|
+
// Applying the 'toString()' method on a number gives us the abstract ToString operation on a number.
|
|
20986
|
+
//
|
|
20987
|
+
// Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional.
|
|
20988
|
+
// This is desired behavior, because when indexing with them as numeric entities, you are indexing
|
|
20989
|
+
// with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively.
|
|
20990
|
+
return (+name).toString() === name;
|
|
20991
|
+
}
|
|
20992
|
+
ts.isNumericLiteralName = isNumericLiteralName;
|
|
20993
|
+
function createPropertyNameNodeForIdentifierOrLiteral(name, target, singleQuote, stringNamed) {
|
|
20994
|
+
return ts.isIdentifierText(name, target) ? ts.factory.createIdentifier(name) :
|
|
20995
|
+
!stringNamed && isNumericLiteralName(name) && +name >= 0 ? ts.factory.createNumericLiteral(+name) :
|
|
20996
|
+
ts.factory.createStringLiteral(name, !!singleQuote);
|
|
20997
|
+
}
|
|
20998
|
+
ts.createPropertyNameNodeForIdentifierOrLiteral = createPropertyNameNodeForIdentifierOrLiteral;
|
|
20967
20999
|
function isThisTypeParameter(type) {
|
|
20968
21000
|
return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
|
|
20969
21001
|
}
|
|
@@ -22436,7 +22468,7 @@ var ts;
|
|
|
22436
22468
|
result.push(createModifier(144 /* ReadonlyKeyword */));
|
|
22437
22469
|
if (flags & 256 /* Async */)
|
|
22438
22470
|
result.push(createModifier(131 /* AsyncKeyword */));
|
|
22439
|
-
return result;
|
|
22471
|
+
return result.length ? result : undefined;
|
|
22440
22472
|
}
|
|
22441
22473
|
//
|
|
22442
22474
|
// Names
|
|
@@ -26393,32 +26425,36 @@ var ts;
|
|
|
26393
26425
|
}
|
|
26394
26426
|
function updateModifiers(node, modifiers) {
|
|
26395
26427
|
var _a;
|
|
26428
|
+
var modifierArray;
|
|
26396
26429
|
if (typeof modifiers === "number") {
|
|
26397
|
-
|
|
26398
|
-
}
|
|
26399
|
-
|
|
26400
|
-
|
|
26401
|
-
|
|
26402
|
-
|
|
26403
|
-
|
|
26404
|
-
|
|
26405
|
-
|
|
26406
|
-
|
|
26407
|
-
|
|
26408
|
-
|
|
26409
|
-
|
|
26410
|
-
|
|
26411
|
-
|
|
26412
|
-
|
|
26413
|
-
|
|
26414
|
-
|
|
26415
|
-
|
|
26416
|
-
|
|
26417
|
-
|
|
26418
|
-
|
|
26419
|
-
|
|
26420
|
-
|
|
26421
|
-
|
|
26430
|
+
modifierArray = createModifiersFromModifierFlags(modifiers);
|
|
26431
|
+
}
|
|
26432
|
+
else {
|
|
26433
|
+
modifierArray = modifiers;
|
|
26434
|
+
}
|
|
26435
|
+
return ts.isParameter(node) ? updateParameterDeclaration(node, node.decorators, modifierArray, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) :
|
|
26436
|
+
ts.isPropertySignature(node) ? updatePropertySignature(node, modifierArray, node.name, node.questionToken, node.type) :
|
|
26437
|
+
ts.isPropertyDeclaration(node) ? updatePropertyDeclaration(node, node.decorators, modifierArray, node.name, (_a = node.questionToken) !== null && _a !== void 0 ? _a : node.exclamationToken, node.type, node.initializer) :
|
|
26438
|
+
ts.isMethodSignature(node) ? updateMethodSignature(node, modifierArray, node.name, node.questionToken, node.typeParameters, node.parameters, node.type) :
|
|
26439
|
+
ts.isMethodDeclaration(node) ? updateMethodDeclaration(node, node.decorators, modifierArray, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body) :
|
|
26440
|
+
ts.isConstructorDeclaration(node) ? updateConstructorDeclaration(node, node.decorators, modifierArray, node.parameters, node.body) :
|
|
26441
|
+
ts.isGetAccessorDeclaration(node) ? updateGetAccessorDeclaration(node, node.decorators, modifierArray, node.name, node.parameters, node.type, node.body) :
|
|
26442
|
+
ts.isSetAccessorDeclaration(node) ? updateSetAccessorDeclaration(node, node.decorators, modifierArray, node.name, node.parameters, node.body) :
|
|
26443
|
+
ts.isIndexSignatureDeclaration(node) ? updateIndexSignature(node, node.decorators, modifierArray, node.parameters, node.type) :
|
|
26444
|
+
ts.isFunctionExpression(node) ? updateFunctionExpression(node, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
|
|
26445
|
+
ts.isArrowFunction(node) ? updateArrowFunction(node, modifierArray, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, node.body) :
|
|
26446
|
+
ts.isClassExpression(node) ? updateClassExpression(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
|
|
26447
|
+
ts.isVariableStatement(node) ? updateVariableStatement(node, modifierArray, node.declarationList) :
|
|
26448
|
+
ts.isFunctionDeclaration(node) ? updateFunctionDeclaration(node, node.decorators, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
|
|
26449
|
+
ts.isClassDeclaration(node) ? updateClassDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
|
|
26450
|
+
ts.isInterfaceDeclaration(node) ? updateInterfaceDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
|
|
26451
|
+
ts.isTypeAliasDeclaration(node) ? updateTypeAliasDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.type) :
|
|
26452
|
+
ts.isEnumDeclaration(node) ? updateEnumDeclaration(node, node.decorators, modifierArray, node.name, node.members) :
|
|
26453
|
+
ts.isModuleDeclaration(node) ? updateModuleDeclaration(node, node.decorators, modifierArray, node.name, node.body) :
|
|
26454
|
+
ts.isImportEqualsDeclaration(node) ? updateImportEqualsDeclaration(node, node.decorators, modifierArray, node.isTypeOnly, node.name, node.moduleReference) :
|
|
26455
|
+
ts.isImportDeclaration(node) ? updateImportDeclaration(node, node.decorators, modifierArray, node.importClause, node.moduleSpecifier, node.assertClause) :
|
|
26456
|
+
ts.isExportAssignment(node) ? updateExportAssignment(node, node.decorators, modifierArray, node.expression) :
|
|
26457
|
+
ts.isExportDeclaration(node) ? updateExportDeclaration(node, node.decorators, modifierArray, node.isTypeOnly, node.exportClause, node.moduleSpecifier, node.assertClause) :
|
|
26422
26458
|
ts.Debug.assertNever(node);
|
|
26423
26459
|
}
|
|
26424
26460
|
function asNodeArray(array) {
|
|
@@ -47032,6 +47068,7 @@ var ts;
|
|
|
47032
47068
|
var location = ts.getParseTreeNode(locationIn);
|
|
47033
47069
|
return location ? getTypeOfSymbolAtLocation(symbol, location) : errorType;
|
|
47034
47070
|
},
|
|
47071
|
+
getTypeOfSymbol: getTypeOfSymbol,
|
|
47035
47072
|
getSymbolsOfParameterPropertyDeclaration: function (parameterIn, parameterName) {
|
|
47036
47073
|
var parameter = ts.getParseTreeNode(parameterIn, ts.isParameter);
|
|
47037
47074
|
if (parameter === undefined)
|
|
@@ -52387,7 +52424,7 @@ var ts;
|
|
|
52387
52424
|
}
|
|
52388
52425
|
var rawName = ts.unescapeLeadingUnderscores(symbol.escapedName);
|
|
52389
52426
|
var stringNamed = !!ts.length(symbol.declarations) && ts.every(symbol.declarations, isStringNamed);
|
|
52390
|
-
return createPropertyNameNodeForIdentifierOrLiteral(rawName,
|
|
52427
|
+
return ts.createPropertyNameNodeForIdentifierOrLiteral(rawName, ts.getEmitScriptTarget(compilerOptions), singleQuote, stringNamed);
|
|
52391
52428
|
}
|
|
52392
52429
|
// See getNameForSymbolFromNameType for a stringy equivalent
|
|
52393
52430
|
function getPropertyNameNodeForSymbolFromNameType(symbol, context, singleQuote) {
|
|
@@ -52395,24 +52432,19 @@ var ts;
|
|
|
52395
52432
|
if (nameType) {
|
|
52396
52433
|
if (nameType.flags & 384 /* StringOrNumberLiteral */) {
|
|
52397
52434
|
var name = "" + nameType.value;
|
|
52398
|
-
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !isNumericLiteralName(name)) {
|
|
52435
|
+
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !ts.isNumericLiteralName(name)) {
|
|
52399
52436
|
return ts.factory.createStringLiteral(name, !!singleQuote);
|
|
52400
52437
|
}
|
|
52401
|
-
if (isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
52438
|
+
if (ts.isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
52402
52439
|
return ts.factory.createComputedPropertyName(ts.factory.createNumericLiteral(+name));
|
|
52403
52440
|
}
|
|
52404
|
-
return createPropertyNameNodeForIdentifierOrLiteral(name);
|
|
52441
|
+
return ts.createPropertyNameNodeForIdentifierOrLiteral(name, ts.getEmitScriptTarget(compilerOptions));
|
|
52405
52442
|
}
|
|
52406
52443
|
if (nameType.flags & 8192 /* UniqueESSymbol */) {
|
|
52407
52444
|
return ts.factory.createComputedPropertyName(symbolToExpression(nameType.symbol, context, 111551 /* Value */));
|
|
52408
52445
|
}
|
|
52409
52446
|
}
|
|
52410
52447
|
}
|
|
52411
|
-
function createPropertyNameNodeForIdentifierOrLiteral(name, stringNamed, singleQuote) {
|
|
52412
|
-
return ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) ? ts.factory.createIdentifier(name) :
|
|
52413
|
-
!stringNamed && isNumericLiteralName(name) && +name >= 0 ? ts.factory.createNumericLiteral(+name) :
|
|
52414
|
-
ts.factory.createStringLiteral(name, !!singleQuote);
|
|
52415
|
-
}
|
|
52416
52448
|
function cloneNodeBuilderContext(context) {
|
|
52417
52449
|
var initial = __assign({}, context);
|
|
52418
52450
|
// Make type parameters created within this context not consume the name outside this context
|
|
@@ -53928,10 +53960,10 @@ var ts;
|
|
|
53928
53960
|
if (nameType) {
|
|
53929
53961
|
if (nameType.flags & 384 /* StringOrNumberLiteral */) {
|
|
53930
53962
|
var name = "" + nameType.value;
|
|
53931
|
-
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !isNumericLiteralName(name)) {
|
|
53963
|
+
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !ts.isNumericLiteralName(name)) {
|
|
53932
53964
|
return "\"" + ts.escapeString(name, 34 /* doubleQuote */) + "\"";
|
|
53933
53965
|
}
|
|
53934
|
-
if (isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
53966
|
+
if (ts.isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
53935
53967
|
return "[" + name + "]";
|
|
53936
53968
|
}
|
|
53937
53969
|
return name;
|
|
@@ -57974,7 +58006,7 @@ var ts;
|
|
|
57974
58006
|
// signature applies to types assignable to 'number' and numeric string literal types.
|
|
57975
58007
|
return isTypeAssignableTo(source, target) ||
|
|
57976
58008
|
target === stringType && isTypeAssignableTo(source, numberType) ||
|
|
57977
|
-
target === numberType && !!(source.flags & 128 /* StringLiteral */) && isNumericLiteralName(source.value);
|
|
58009
|
+
target === numberType && !!(source.flags & 128 /* StringLiteral */) && ts.isNumericLiteralName(source.value);
|
|
57978
58010
|
}
|
|
57979
58011
|
function getIndexInfosOfStructuredType(type) {
|
|
57980
58012
|
if (type.flags & 3670016 /* StructuredType */) {
|
|
@@ -60540,7 +60572,7 @@ var ts;
|
|
|
60540
60572
|
getFlowTypeOfReference(accessExpression, propType) :
|
|
60541
60573
|
propType;
|
|
60542
60574
|
}
|
|
60543
|
-
if (everyType(objectType, isTupleType) && isNumericLiteralName(propName) && +propName >= 0) {
|
|
60575
|
+
if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName) && +propName >= 0) {
|
|
60544
60576
|
if (accessNode && everyType(objectType, function (t) { return !t.target.hasRestElement; }) && !(accessFlags & 16 /* NoTupleBoundsCheck */)) {
|
|
60545
60577
|
var indexNode = getIndexNodeForAccessExpression(accessNode);
|
|
60546
60578
|
if (isTupleType(objectType)) {
|
|
@@ -60825,7 +60857,7 @@ var ts;
|
|
|
60825
60857
|
return everyType(indexType, function (t) {
|
|
60826
60858
|
if (t.flags & 384 /* StringOrNumberLiteral */) {
|
|
60827
60859
|
var propName = getPropertyNameFromType(t);
|
|
60828
|
-
if (isNumericLiteralName(propName)) {
|
|
60860
|
+
if (ts.isNumericLiteralName(propName)) {
|
|
60829
60861
|
var index = +propName;
|
|
60830
60862
|
return index >= 0 && index < limit;
|
|
60831
60863
|
}
|
|
@@ -64367,7 +64399,7 @@ var ts;
|
|
|
64367
64399
|
else {
|
|
64368
64400
|
// conditionals aren't related to one another via distributive constraint as it is much too inaccurate and allows way
|
|
64369
64401
|
// more assignments than are desirable (since it maps the source check type to its constraint, it loses information)
|
|
64370
|
-
var distributiveConstraint = getConstraintOfDistributiveConditionalType(source);
|
|
64402
|
+
var distributiveConstraint = hasNonCircularBaseConstraint(source) ? getConstraintOfDistributiveConditionalType(source) : undefined;
|
|
64371
64403
|
if (distributiveConstraint) {
|
|
64372
64404
|
if (result = isRelatedTo(distributiveConstraint, target, 1 /* Source */, reportErrors)) {
|
|
64373
64405
|
resetErrorInfo(saveErrorInfo);
|
|
@@ -64913,7 +64945,7 @@ var ts;
|
|
|
64913
64945
|
for (var _b = 0, _c = excludeProperties(properties, excludedProperties); _b < _c.length; _b++) {
|
|
64914
64946
|
var targetProp = _c[_b];
|
|
64915
64947
|
var name = targetProp.escapedName;
|
|
64916
|
-
if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
|
|
64948
|
+
if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || ts.isNumericLiteralName(name) || name === "length")) {
|
|
64917
64949
|
var sourceProp = getPropertyOfType(source, name);
|
|
64918
64950
|
if (sourceProp && sourceProp !== targetProp) {
|
|
64919
64951
|
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getNonMissingTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation);
|
|
@@ -64986,7 +65018,8 @@ var ts;
|
|
|
64986
65018
|
var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
|
|
64987
65019
|
var sourceObjectFlags = ts.getObjectFlags(source);
|
|
64988
65020
|
var targetObjectFlags = ts.getObjectFlags(target);
|
|
64989
|
-
if (sourceObjectFlags & 64 /* Instantiated */ && targetObjectFlags & 64 /* Instantiated */ && source.symbol === target.symbol
|
|
65021
|
+
if (sourceObjectFlags & 64 /* Instantiated */ && targetObjectFlags & 64 /* Instantiated */ && source.symbol === target.symbol ||
|
|
65022
|
+
sourceObjectFlags & 4 /* Reference */ && targetObjectFlags & 4 /* Reference */ && source.target === target.target) {
|
|
64990
65023
|
// We have instantiations of the same anonymous type (which typically will be the type of a
|
|
64991
65024
|
// method). Simply do a pairwise comparison of the signatures in the two signature lists instead
|
|
64992
65025
|
// of the much more expensive N * M comparison matrix we explore below. We erase type parameters
|
|
@@ -66021,9 +66054,12 @@ var ts;
|
|
|
66021
66054
|
* with no call or construct signatures.
|
|
66022
66055
|
*/
|
|
66023
66056
|
function isObjectTypeWithInferableIndex(type) {
|
|
66024
|
-
return type.flags & 2097152 /* Intersection */
|
|
66025
|
-
|
|
66026
|
-
|
|
66057
|
+
return type.flags & 2097152 /* Intersection */
|
|
66058
|
+
? ts.every(type.types, isObjectTypeWithInferableIndex)
|
|
66059
|
+
: !!(type.symbol
|
|
66060
|
+
&& (type.symbol.flags & (4096 /* ObjectLiteral */ | 2048 /* TypeLiteral */ | 384 /* Enum */ | 512 /* ValueModule */)) !== 0
|
|
66061
|
+
&& !(type.symbol.flags & 32 /* Class */)
|
|
66062
|
+
&& !typeHasCallOrConstructSignatures(type)) || !!(ts.getObjectFlags(type) & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
|
|
66027
66063
|
}
|
|
66028
66064
|
function createSymbolWithType(source, type) {
|
|
66029
66065
|
var symbol = createSymbol(source.flags, source.escapedName, ts.getCheckFlags(source) & 8 /* Readonly */);
|
|
@@ -67631,7 +67667,8 @@ var ts;
|
|
|
67631
67667
|
return access.kind === 205 /* PropertyAccessExpression */ ? access.name.escapedText :
|
|
67632
67668
|
access.kind === 206 /* ElementAccessExpression */ && ts.isStringOrNumericLiteralLike(access.argumentExpression) ? ts.escapeLeadingUnderscores(access.argumentExpression.text) :
|
|
67633
67669
|
access.kind === 202 /* BindingElement */ && (propertyName = getDestructuringPropertyName(access)) ? ts.escapeLeadingUnderscores(propertyName) :
|
|
67634
|
-
|
|
67670
|
+
access.kind === 163 /* Parameter */ ? ("" + access.parent.parameters.indexOf(access)) :
|
|
67671
|
+
undefined;
|
|
67635
67672
|
}
|
|
67636
67673
|
function containsMatchingReference(source, target) {
|
|
67637
67674
|
while (ts.isAccessExpression(source)) {
|
|
@@ -68971,13 +69008,14 @@ var ts;
|
|
|
68971
69008
|
return result;
|
|
68972
69009
|
}
|
|
68973
69010
|
function getCandidateDiscriminantPropertyAccess(expr) {
|
|
68974
|
-
if (ts.isBindingPattern(reference)) {
|
|
68975
|
-
// When the reference is a binding pattern, we are narrowing a pesudo-reference in
|
|
68976
|
-
// An identifier for a destructuring variable declared in the same binding pattern
|
|
69011
|
+
if (ts.isBindingPattern(reference) || ts.isFunctionExpressionOrArrowFunction(reference)) {
|
|
69012
|
+
// When the reference is a binding pattern or function or arrow expression, we are narrowing a pesudo-reference in
|
|
69013
|
+
// getNarrowedTypeOfSymbol. An identifier for a destructuring variable declared in the same binding pattern or
|
|
69014
|
+
// parameter declared in the same parameter list is a candidate.
|
|
68977
69015
|
if (ts.isIdentifier(expr)) {
|
|
68978
69016
|
var symbol = getResolvedSymbol(expr);
|
|
68979
69017
|
var declaration = symbol.valueDeclaration;
|
|
68980
|
-
if (declaration && ts.isBindingElement(declaration) &&
|
|
69018
|
+
if (declaration && (ts.isBindingElement(declaration) || ts.isParameter(declaration)) && reference === declaration.parent && !declaration.initializer && !declaration.dotDotDotToken) {
|
|
68981
69019
|
return declaration;
|
|
68982
69020
|
}
|
|
68983
69021
|
}
|
|
@@ -69779,42 +69817,78 @@ var ts;
|
|
|
69779
69817
|
}
|
|
69780
69818
|
}
|
|
69781
69819
|
function getNarrowedTypeOfSymbol(symbol, location) {
|
|
69782
|
-
// If we have a non-rest binding element with no initializer declared as a const variable or a const-like
|
|
69783
|
-
// parameter (a parameter for which there are no assignments in the function body), and if the parent type
|
|
69784
|
-
// for the destructuring is a union type, one or more of the binding elements may represent discriminant
|
|
69785
|
-
// properties, and we want the effects of conditional checks on such discriminants to affect the types of
|
|
69786
|
-
// other binding elements from the same destructuring. Consider:
|
|
69787
|
-
//
|
|
69788
|
-
// type Action =
|
|
69789
|
-
// | { kind: 'A', payload: number }
|
|
69790
|
-
// | { kind: 'B', payload: string };
|
|
69791
|
-
//
|
|
69792
|
-
// function f1({ kind, payload }: Action) {
|
|
69793
|
-
// if (kind === 'A') {
|
|
69794
|
-
// payload.toFixed();
|
|
69795
|
-
// }
|
|
69796
|
-
// if (kind === 'B') {
|
|
69797
|
-
// payload.toUpperCase();
|
|
69798
|
-
// }
|
|
69799
|
-
// }
|
|
69800
|
-
//
|
|
69801
|
-
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
|
|
69802
|
-
// the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
|
|
69803
|
-
// as if it occurred in the specified location. We then recompute the narrowed binding element type by
|
|
69804
|
-
// destructuring from the narrowed parent type.
|
|
69805
69820
|
var declaration = symbol.valueDeclaration;
|
|
69806
|
-
if (declaration
|
|
69807
|
-
|
|
69808
|
-
|
|
69809
|
-
|
|
69810
|
-
|
|
69811
|
-
|
|
69812
|
-
|
|
69813
|
-
|
|
69814
|
-
|
|
69815
|
-
|
|
69816
|
-
|
|
69817
|
-
|
|
69821
|
+
if (declaration) {
|
|
69822
|
+
// If we have a non-rest binding element with no initializer declared as a const variable or a const-like
|
|
69823
|
+
// parameter (a parameter for which there are no assignments in the function body), and if the parent type
|
|
69824
|
+
// for the destructuring is a union type, one or more of the binding elements may represent discriminant
|
|
69825
|
+
// properties, and we want the effects of conditional checks on such discriminants to affect the types of
|
|
69826
|
+
// other binding elements from the same destructuring. Consider:
|
|
69827
|
+
//
|
|
69828
|
+
// type Action =
|
|
69829
|
+
// | { kind: 'A', payload: number }
|
|
69830
|
+
// | { kind: 'B', payload: string };
|
|
69831
|
+
//
|
|
69832
|
+
// function f({ kind, payload }: Action) {
|
|
69833
|
+
// if (kind === 'A') {
|
|
69834
|
+
// payload.toFixed();
|
|
69835
|
+
// }
|
|
69836
|
+
// if (kind === 'B') {
|
|
69837
|
+
// payload.toUpperCase();
|
|
69838
|
+
// }
|
|
69839
|
+
// }
|
|
69840
|
+
//
|
|
69841
|
+
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
|
|
69842
|
+
// the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
|
|
69843
|
+
// as if it occurred in the specified location. We then recompute the narrowed binding element type by
|
|
69844
|
+
// destructuring from the narrowed parent type.
|
|
69845
|
+
if (ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) {
|
|
69846
|
+
var parent = declaration.parent.parent;
|
|
69847
|
+
if (parent.kind === 253 /* VariableDeclaration */ && ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || parent.kind === 163 /* Parameter */) {
|
|
69848
|
+
var links = getNodeLinks(location);
|
|
69849
|
+
if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
|
|
69850
|
+
links.flags |= 268435456 /* InCheckIdentifier */;
|
|
69851
|
+
var parentType = getTypeForBindingElementParent(parent);
|
|
69852
|
+
links.flags &= ~268435456 /* InCheckIdentifier */;
|
|
69853
|
+
if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
|
|
69854
|
+
var pattern = declaration.parent;
|
|
69855
|
+
var narrowedType = getFlowTypeOfReference(pattern, parentType, parentType, /*flowContainer*/ undefined, location.flowNode);
|
|
69856
|
+
return getBindingElementTypeFromParentType(declaration, narrowedType);
|
|
69857
|
+
}
|
|
69858
|
+
}
|
|
69859
|
+
}
|
|
69860
|
+
}
|
|
69861
|
+
// If we have a const-like parameter with no type annotation or initializer, and if the parameter is contextually
|
|
69862
|
+
// typed by a signature with a single rest parameter of a union of tuple types, one or more of the parameters may
|
|
69863
|
+
// represent discriminant tuple elements, and we want the effects of conditional checks on such discriminants to
|
|
69864
|
+
// affect the types of other parameters in the same parameter list. Consider:
|
|
69865
|
+
//
|
|
69866
|
+
// type Action = [kind: 'A', payload: number] | [kind: 'B', payload: string];
|
|
69867
|
+
//
|
|
69868
|
+
// const f: (...args: Action) => void = (kind, payload) => {
|
|
69869
|
+
// if (kind === 'A') {
|
|
69870
|
+
// payload.toFixed();
|
|
69871
|
+
// }
|
|
69872
|
+
// if (kind === 'B') {
|
|
69873
|
+
// payload.toUpperCase();
|
|
69874
|
+
// }
|
|
69875
|
+
// }
|
|
69876
|
+
//
|
|
69877
|
+
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
|
|
69878
|
+
// the arrow function AST node for '(kind, payload) => ...' as a pseudo-reference and narrow this reference as
|
|
69879
|
+
// if it occurred in the specified location. We then recompute the narrowed parameter type by indexing into the
|
|
69880
|
+
// narrowed tuple type.
|
|
69881
|
+
if (ts.isParameter(declaration) && !declaration.type && !declaration.initializer && !declaration.dotDotDotToken) {
|
|
69882
|
+
var func = declaration.parent;
|
|
69883
|
+
if (func.parameters.length >= 2 && isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
|
|
69884
|
+
var contextualSignature = getContextualSignature(func);
|
|
69885
|
+
if (contextualSignature && contextualSignature.parameters.length === 1 && signatureHasRestParameter(contextualSignature)) {
|
|
69886
|
+
var restType = getTypeOfSymbol(contextualSignature.parameters[0]);
|
|
69887
|
+
if (restType.flags & 1048576 /* Union */ && everyType(restType, isTupleType) && !isSymbolAssigned(symbol)) {
|
|
69888
|
+
var narrowedType = getFlowTypeOfReference(func, restType, restType, /*flowContainer*/ undefined, location.flowNode);
|
|
69889
|
+
var index = func.parameters.indexOf(declaration) - (ts.getThisParameter(func) ? 1 : 0);
|
|
69890
|
+
return getIndexedAccessType(narrowedType, getNumberLiteralType(index));
|
|
69891
|
+
}
|
|
69818
69892
|
}
|
|
69819
69893
|
}
|
|
69820
69894
|
}
|
|
@@ -70955,7 +71029,7 @@ var ts;
|
|
|
70955
71029
|
}
|
|
70956
71030
|
if (isTupleType(t)) {
|
|
70957
71031
|
var restType = getRestTypeOfTupleType(t);
|
|
70958
|
-
if (restType && isNumericLiteralName(name) && +name >= 0) {
|
|
71032
|
+
if (restType && ts.isNumericLiteralName(name) && +name >= 0) {
|
|
70959
71033
|
return restType;
|
|
70960
71034
|
}
|
|
70961
71035
|
}
|
|
@@ -71596,10 +71670,10 @@ var ts;
|
|
|
71596
71670
|
case 161 /* ComputedPropertyName */:
|
|
71597
71671
|
return isNumericComputedName(name);
|
|
71598
71672
|
case 79 /* Identifier */:
|
|
71599
|
-
return isNumericLiteralName(name.escapedText);
|
|
71673
|
+
return ts.isNumericLiteralName(name.escapedText);
|
|
71600
71674
|
case 8 /* NumericLiteral */:
|
|
71601
71675
|
case 10 /* StringLiteral */:
|
|
71602
|
-
return isNumericLiteralName(name.text);
|
|
71676
|
+
return ts.isNumericLiteralName(name.text);
|
|
71603
71677
|
default:
|
|
71604
71678
|
return false;
|
|
71605
71679
|
}
|
|
@@ -71609,30 +71683,6 @@ var ts;
|
|
|
71609
71683
|
// but this behavior is consistent with checkIndexedAccess
|
|
71610
71684
|
return isTypeAssignableToKind(checkComputedPropertyName(name), 296 /* NumberLike */);
|
|
71611
71685
|
}
|
|
71612
|
-
function isNumericLiteralName(name) {
|
|
71613
|
-
// The intent of numeric names is that
|
|
71614
|
-
// - they are names with text in a numeric form, and that
|
|
71615
|
-
// - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit',
|
|
71616
|
-
// acquired by applying the abstract 'ToNumber' operation on the name's text.
|
|
71617
|
-
//
|
|
71618
|
-
// The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name.
|
|
71619
|
-
// In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold.
|
|
71620
|
-
//
|
|
71621
|
-
// Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)'
|
|
71622
|
-
// according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'.
|
|
71623
|
-
// Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names
|
|
71624
|
-
// because their 'ToString' representation is not equal to their original text.
|
|
71625
|
-
// This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1.
|
|
71626
|
-
//
|
|
71627
|
-
// Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'.
|
|
71628
|
-
// The '+' prefix operator is equivalent here to applying the abstract ToNumber operation.
|
|
71629
|
-
// Applying the 'toString()' method on a number gives us the abstract ToString operation on a number.
|
|
71630
|
-
//
|
|
71631
|
-
// Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional.
|
|
71632
|
-
// This is desired behavior, because when indexing with them as numeric entities, you are indexing
|
|
71633
|
-
// with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively.
|
|
71634
|
-
return (+name).toString() === name;
|
|
71635
|
-
}
|
|
71636
71686
|
function checkComputedPropertyName(node) {
|
|
71637
71687
|
var links = getNodeLinks(node.expression);
|
|
71638
71688
|
if (!links.resolvedType) {
|
|
@@ -71668,7 +71718,7 @@ var ts;
|
|
|
71668
71718
|
function isSymbolWithNumericName(symbol) {
|
|
71669
71719
|
var _a;
|
|
71670
71720
|
var firstDecl = (_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a[0];
|
|
71671
|
-
return isNumericLiteralName(symbol.escapedName) || (firstDecl && ts.isNamedDeclaration(firstDecl) && isNumericName(firstDecl.name));
|
|
71721
|
+
return ts.isNumericLiteralName(symbol.escapedName) || (firstDecl && ts.isNamedDeclaration(firstDecl) && isNumericName(firstDecl.name));
|
|
71672
71722
|
}
|
|
71673
71723
|
function isSymbolWithSymbolName(symbol) {
|
|
71674
71724
|
var _a;
|
|
@@ -82606,7 +82656,7 @@ var ts;
|
|
|
82606
82656
|
}
|
|
82607
82657
|
else {
|
|
82608
82658
|
var text = ts.getTextOfPropertyName(member.name);
|
|
82609
|
-
if (isNumericLiteralName(text) && !ts.isInfinityOrNaNString(text)) {
|
|
82659
|
+
if (ts.isNumericLiteralName(text) && !ts.isInfinityOrNaNString(text)) {
|
|
82610
82660
|
error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name);
|
|
82611
82661
|
}
|
|
82612
82662
|
}
|
|
@@ -109212,7 +109262,7 @@ var ts;
|
|
|
109212
109262
|
emitPlaceholder(hint, node, snippet);
|
|
109213
109263
|
break;
|
|
109214
109264
|
case 0 /* TabStop */:
|
|
109215
|
-
emitTabStop(snippet);
|
|
109265
|
+
emitTabStop(hint, node, snippet);
|
|
109216
109266
|
break;
|
|
109217
109267
|
}
|
|
109218
109268
|
}
|
|
@@ -109222,7 +109272,10 @@ var ts;
|
|
|
109222
109272
|
nonEscapingWrite("}"); // `}`
|
|
109223
109273
|
// `${2:...}`
|
|
109224
109274
|
}
|
|
109225
|
-
function emitTabStop(snippet) {
|
|
109275
|
+
function emitTabStop(hint, node, snippet) {
|
|
109276
|
+
// A tab stop should only be attached to an empty node, i.e. a node that doesn't emit any text.
|
|
109277
|
+
ts.Debug.assert(node.kind === 235 /* EmptyStatement */, "A tab stop cannot be attached to a node of kind " + ts.Debug.formatSyntaxKind(node.kind) + ".");
|
|
109278
|
+
ts.Debug.assert(hint !== 5 /* EmbeddedStatement */, "A tab stop cannot be attached to an embedded statement.");
|
|
109226
109279
|
nonEscapingWrite("$" + snippet.order);
|
|
109227
109280
|
}
|
|
109228
109281
|
//
|
|
@@ -120068,7 +120121,7 @@ var ts;
|
|
|
120068
120121
|
}
|
|
120069
120122
|
ts.getLocaleTimeString = getLocaleTimeString;
|
|
120070
120123
|
/**
|
|
120071
|
-
* Create a function that reports watch status by writing to the system and handles the
|
|
120124
|
+
* Create a function that reports watch status by writing to the system and handles the formatting of the diagnostic
|
|
120072
120125
|
*/
|
|
120073
120126
|
function createWatchStatusReporter(system, pretty) {
|
|
120074
120127
|
return pretty ?
|
|
@@ -120129,7 +120182,7 @@ var ts;
|
|
|
120129
120182
|
ts.Diagnostics.Found_0_errors_Watching_for_file_changes;
|
|
120130
120183
|
}
|
|
120131
120184
|
ts.getWatchErrorSummaryDiagnosticMessage = getWatchErrorSummaryDiagnosticMessage;
|
|
120132
|
-
function getErrorSummaryText(errorCount, filesInError, newLine) {
|
|
120185
|
+
function getErrorSummaryText(errorCount, filesInError, newLine, host) {
|
|
120133
120186
|
if (errorCount === 0)
|
|
120134
120187
|
return "";
|
|
120135
120188
|
var nonNilFiles = filesInError.filter(function (fileInError) { return fileInError !== undefined; });
|
|
@@ -120144,10 +120197,10 @@ var ts;
|
|
|
120144
120197
|
distinctFileNamesWithLines.length === 1 ?
|
|
120145
120198
|
ts.Diagnostics.Found_0_errors_in_1_file :
|
|
120146
120199
|
ts.Diagnostics.Found_0_errors_in_1_files, errorCount, distinctFileNamesWithLines.length);
|
|
120147
|
-
return "" + newLine + ts.flattenDiagnosticMessageText(d.messageText, newLine) + newLine + newLine + (errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles) : "");
|
|
120200
|
+
return "" + newLine + ts.flattenDiagnosticMessageText(d.messageText, newLine) + newLine + newLine + (errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles, host) : "");
|
|
120148
120201
|
}
|
|
120149
120202
|
ts.getErrorSummaryText = getErrorSummaryText;
|
|
120150
|
-
function createTabularErrorsDisplay(filesInError) {
|
|
120203
|
+
function createTabularErrorsDisplay(filesInError, host) {
|
|
120151
120204
|
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); }); });
|
|
120152
120205
|
if (distinctFiles.length === 0)
|
|
120153
120206
|
return "";
|
|
@@ -120166,7 +120219,8 @@ var ts;
|
|
|
120166
120219
|
var leftPadding = errorCountDigitsLength < leftPaddingGoal ?
|
|
120167
120220
|
" ".repeat(leftPaddingGoal - errorCountDigitsLength)
|
|
120168
120221
|
: "";
|
|
120169
|
-
|
|
120222
|
+
var relativePath = ts.getRelativePathFromDirectory(host.getCurrentDirectory(), file.fileName, /* ignoreCase */ false);
|
|
120223
|
+
tabularData += "" + leftPadding + errorCount + " " + relativePath + ":" + file.line + "\n";
|
|
120170
120224
|
});
|
|
120171
120225
|
return tabularData;
|
|
120172
120226
|
}
|
|
@@ -120584,7 +120638,7 @@ var ts;
|
|
|
120584
120638
|
var system = input.system || ts.sys;
|
|
120585
120639
|
var host = input.host || (input.host = ts.createIncrementalCompilerHost(input.options, system));
|
|
120586
120640
|
var builderProgram = ts.createIncrementalProgram(input);
|
|
120587
|
-
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);
|
|
120641
|
+
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);
|
|
120588
120642
|
if (input.afterProgramEmitAndDiagnostics)
|
|
120589
120643
|
input.afterProgramEmitAndDiagnostics(builderProgram);
|
|
120590
120644
|
return exitStatus;
|
|
@@ -123058,14 +123112,8 @@ var ts;
|
|
|
123058
123112
|
var possibleSearchDirs = new ts.Set(fileNames.map(ts.getDirectoryPath));
|
|
123059
123113
|
possibleSearchDirs.add(projectRootPath);
|
|
123060
123114
|
possibleSearchDirs.forEach(function (searchDir) {
|
|
123061
|
-
|
|
123062
|
-
|
|
123063
|
-
var bowerJsonPath = ts.combinePaths(searchDir, "bower.json");
|
|
123064
|
-
getTypingNamesFromJson(bowerJsonPath, filesToWatch);
|
|
123065
|
-
var bowerComponentsPath = ts.combinePaths(searchDir, "bower_components");
|
|
123066
|
-
getTypingNamesFromPackagesFolder(bowerComponentsPath, filesToWatch);
|
|
123067
|
-
var nodeModulesPath = ts.combinePaths(searchDir, "node_modules");
|
|
123068
|
-
getTypingNamesFromPackagesFolder(nodeModulesPath, filesToWatch);
|
|
123115
|
+
getTypingNames(searchDir, "bower.json", "bower_components", filesToWatch);
|
|
123116
|
+
getTypingNames(searchDir, "package.json", "node_modules", filesToWatch);
|
|
123069
123117
|
});
|
|
123070
123118
|
if (!typeAcquisition.disableFilenameBasedTypeAcquisition) {
|
|
123071
123119
|
getTypingNamesFromSourceFileNames(fileNames);
|
|
@@ -123114,16 +123162,100 @@ var ts;
|
|
|
123114
123162
|
ts.forEach(typingNames, addInferredTyping);
|
|
123115
123163
|
}
|
|
123116
123164
|
/**
|
|
123117
|
-
*
|
|
123165
|
+
* Adds inferred typings from manifest/module pairs (think package.json + node_modules)
|
|
123166
|
+
*
|
|
123167
|
+
* @param projectRootPath is the path to the directory where to look for package.json, bower.json and other typing information
|
|
123168
|
+
* @param manifestName is the name of the manifest (package.json or bower.json)
|
|
123169
|
+
* @param modulesDirName is the directory name for modules (node_modules or bower_components). Should be lowercase!
|
|
123170
|
+
* @param filesToWatch are the files to watch for changes. We will push things into this array.
|
|
123118
123171
|
*/
|
|
123119
|
-
function
|
|
123120
|
-
|
|
123172
|
+
function getTypingNames(projectRootPath, manifestName, modulesDirName, filesToWatch) {
|
|
123173
|
+
// First, we check the manifests themselves. They're not
|
|
123174
|
+
// _required_, but they allow us to do some filtering when dealing
|
|
123175
|
+
// with big flat dep directories.
|
|
123176
|
+
var manifestPath = ts.combinePaths(projectRootPath, manifestName);
|
|
123177
|
+
var manifest;
|
|
123178
|
+
var manifestTypingNames;
|
|
123179
|
+
if (host.fileExists(manifestPath)) {
|
|
123180
|
+
filesToWatch.push(manifestPath);
|
|
123181
|
+
manifest = ts.readConfigFile(manifestPath, function (path) { return host.readFile(path); }).config;
|
|
123182
|
+
manifestTypingNames = ts.flatMap([manifest.dependencies, manifest.devDependencies, manifest.optionalDependencies, manifest.peerDependencies], ts.getOwnKeys);
|
|
123183
|
+
addInferredTypings(manifestTypingNames, "Typing names in '" + manifestPath + "' dependencies");
|
|
123184
|
+
}
|
|
123185
|
+
// Now we scan the directories for typing information in
|
|
123186
|
+
// already-installed dependencies (if present). Note that this
|
|
123187
|
+
// step happens regardless of whether a manifest was present,
|
|
123188
|
+
// which is certainly a valid configuration, if an unusual one.
|
|
123189
|
+
var packagesFolderPath = ts.combinePaths(projectRootPath, modulesDirName);
|
|
123190
|
+
filesToWatch.push(packagesFolderPath);
|
|
123191
|
+
if (!host.directoryExists(packagesFolderPath)) {
|
|
123121
123192
|
return;
|
|
123122
123193
|
}
|
|
123123
|
-
|
|
123124
|
-
|
|
123125
|
-
|
|
123126
|
-
|
|
123194
|
+
// There's two cases we have to take into account here:
|
|
123195
|
+
// 1. If manifest is undefined, then we're not using a manifest.
|
|
123196
|
+
// That means that we should scan _all_ dependencies at the top
|
|
123197
|
+
// level of the modulesDir.
|
|
123198
|
+
// 2. If manifest is defined, then we can do some special
|
|
123199
|
+
// filtering to reduce the amount of scanning we need to do.
|
|
123200
|
+
//
|
|
123201
|
+
// Previous versions of this algorithm checked for a `_requiredBy`
|
|
123202
|
+
// field in the package.json, but that field is only present in
|
|
123203
|
+
// `npm@>=3 <7`.
|
|
123204
|
+
// Package names that do **not** provide their own typings, so
|
|
123205
|
+
// we'll look them up.
|
|
123206
|
+
var packageNames = [];
|
|
123207
|
+
var dependencyManifestNames = manifestTypingNames
|
|
123208
|
+
// This is #1 described above.
|
|
123209
|
+
? manifestTypingNames.map(function (typingName) { return ts.combinePaths(packagesFolderPath, typingName, manifestName); })
|
|
123210
|
+
// And #2. Depth = 3 because scoped packages look like `node_modules/@foo/bar/package.json`
|
|
123211
|
+
: host.readDirectory(packagesFolderPath, [".json" /* Json */], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 3)
|
|
123212
|
+
.filter(function (manifestPath) {
|
|
123213
|
+
if (ts.getBaseFileName(manifestPath) !== manifestName) {
|
|
123214
|
+
return false;
|
|
123215
|
+
}
|
|
123216
|
+
// It's ok to treat
|
|
123217
|
+
// `node_modules/@foo/bar/package.json` as a manifest,
|
|
123218
|
+
// but not `node_modules/jquery/nested/package.json`.
|
|
123219
|
+
// We only assume depth 3 is ok for formally scoped
|
|
123220
|
+
// packages. So that needs this dance here.
|
|
123221
|
+
var pathComponents = ts.getPathComponents(ts.normalizePath(manifestPath));
|
|
123222
|
+
var isScoped = pathComponents[pathComponents.length - 3][0] === "@";
|
|
123223
|
+
return isScoped && pathComponents[pathComponents.length - 4].toLowerCase() === modulesDirName || // `node_modules/@foo/bar`
|
|
123224
|
+
!isScoped && pathComponents[pathComponents.length - 3].toLowerCase() === modulesDirName; // `node_modules/foo`
|
|
123225
|
+
});
|
|
123226
|
+
if (log)
|
|
123227
|
+
log("Searching for typing names in " + packagesFolderPath + "; all files: " + JSON.stringify(dependencyManifestNames));
|
|
123228
|
+
// Once we have the names of things to look up, we iterate over
|
|
123229
|
+
// and either collect their included typings, or add them to the
|
|
123230
|
+
// list of typings we need to look up separately.
|
|
123231
|
+
for (var _i = 0, dependencyManifestNames_1 = dependencyManifestNames; _i < dependencyManifestNames_1.length; _i++) {
|
|
123232
|
+
var manifestPath_1 = dependencyManifestNames_1[_i];
|
|
123233
|
+
var normalizedFileName = ts.normalizePath(manifestPath_1);
|
|
123234
|
+
var result_1 = ts.readConfigFile(normalizedFileName, function (path) { return host.readFile(path); });
|
|
123235
|
+
var manifest_1 = result_1.config;
|
|
123236
|
+
// If the package has its own d.ts typings, those will take precedence. Otherwise the package name will be used
|
|
123237
|
+
// to download d.ts files from DefinitelyTyped
|
|
123238
|
+
if (!manifest_1.name) {
|
|
123239
|
+
continue;
|
|
123240
|
+
}
|
|
123241
|
+
var ownTypes = manifest_1.types || manifest_1.typings;
|
|
123242
|
+
if (ownTypes) {
|
|
123243
|
+
var absolutePath = ts.getNormalizedAbsolutePath(ownTypes, ts.getDirectoryPath(normalizedFileName));
|
|
123244
|
+
if (host.fileExists(absolutePath)) {
|
|
123245
|
+
if (log)
|
|
123246
|
+
log(" Package '" + manifest_1.name + "' provides its own types.");
|
|
123247
|
+
inferredTypings.set(manifest_1.name, absolutePath);
|
|
123248
|
+
}
|
|
123249
|
+
else {
|
|
123250
|
+
if (log)
|
|
123251
|
+
log(" Package '" + manifest_1.name + "' provides its own types but they are missing.");
|
|
123252
|
+
}
|
|
123253
|
+
}
|
|
123254
|
+
else {
|
|
123255
|
+
packageNames.push(manifest_1.name);
|
|
123256
|
+
}
|
|
123257
|
+
}
|
|
123258
|
+
addInferredTypings(packageNames, " Found package names");
|
|
123127
123259
|
}
|
|
123128
123260
|
/**
|
|
123129
123261
|
* Infer typing names from given file names. For example, the file name "jquery-min.2.3.4.js"
|
|
@@ -123149,55 +123281,6 @@ var ts;
|
|
|
123149
123281
|
addInferredTyping("react");
|
|
123150
123282
|
}
|
|
123151
123283
|
}
|
|
123152
|
-
/**
|
|
123153
|
-
* Infer typing names from packages folder (ex: node_module, bower_components)
|
|
123154
|
-
* @param packagesFolderPath is the path to the packages folder
|
|
123155
|
-
*/
|
|
123156
|
-
function getTypingNamesFromPackagesFolder(packagesFolderPath, filesToWatch) {
|
|
123157
|
-
filesToWatch.push(packagesFolderPath);
|
|
123158
|
-
// Todo: add support for ModuleResolutionHost too
|
|
123159
|
-
if (!host.directoryExists(packagesFolderPath)) {
|
|
123160
|
-
return;
|
|
123161
|
-
}
|
|
123162
|
-
// depth of 2, so we access `node_modules/foo` but not `node_modules/foo/bar`
|
|
123163
|
-
var fileNames = host.readDirectory(packagesFolderPath, [".json" /* Json */], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2);
|
|
123164
|
-
if (log)
|
|
123165
|
-
log("Searching for typing names in " + packagesFolderPath + "; all files: " + JSON.stringify(fileNames));
|
|
123166
|
-
var packageNames = [];
|
|
123167
|
-
for (var _i = 0, fileNames_1 = fileNames; _i < fileNames_1.length; _i++) {
|
|
123168
|
-
var fileName = fileNames_1[_i];
|
|
123169
|
-
var normalizedFileName = ts.normalizePath(fileName);
|
|
123170
|
-
var baseFileName = ts.getBaseFileName(normalizedFileName);
|
|
123171
|
-
if (baseFileName !== "package.json" && baseFileName !== "bower.json") {
|
|
123172
|
-
continue;
|
|
123173
|
-
}
|
|
123174
|
-
var result_1 = ts.readConfigFile(normalizedFileName, function (path) { return host.readFile(path); });
|
|
123175
|
-
var packageJson = result_1.config;
|
|
123176
|
-
// npm 3's package.json contains a "_requiredBy" field
|
|
123177
|
-
// we should include all the top level module names for npm 2, and only module names whose
|
|
123178
|
-
// "_requiredBy" field starts with "#" or equals "/" for npm 3.
|
|
123179
|
-
if (baseFileName === "package.json" && packageJson._requiredBy &&
|
|
123180
|
-
ts.filter(packageJson._requiredBy, function (r) { return r[0] === "#" || r === "/"; }).length === 0) {
|
|
123181
|
-
continue;
|
|
123182
|
-
}
|
|
123183
|
-
// If the package has its own d.ts typings, those will take precedence. Otherwise the package name will be used
|
|
123184
|
-
// to download d.ts files from DefinitelyTyped
|
|
123185
|
-
if (!packageJson.name) {
|
|
123186
|
-
continue;
|
|
123187
|
-
}
|
|
123188
|
-
var ownTypes = packageJson.types || packageJson.typings;
|
|
123189
|
-
if (ownTypes) {
|
|
123190
|
-
var absolutePath = ts.getNormalizedAbsolutePath(ownTypes, ts.getDirectoryPath(normalizedFileName));
|
|
123191
|
-
if (log)
|
|
123192
|
-
log(" Package '" + packageJson.name + "' provides its own types.");
|
|
123193
|
-
inferredTypings.set(packageJson.name, absolutePath);
|
|
123194
|
-
}
|
|
123195
|
-
else {
|
|
123196
|
-
packageNames.push(packageJson.name);
|
|
123197
|
-
}
|
|
123198
|
-
}
|
|
123199
|
-
addInferredTypings(packageNames, " Found package names");
|
|
123200
|
-
}
|
|
123201
123284
|
}
|
|
123202
123285
|
JsTyping.discoverTypings = discoverTypings;
|
|
123203
123286
|
var NameValidationResult;
|
|
@@ -126748,6 +126831,16 @@ var ts;
|
|
|
126748
126831
|
: ts.getLocaleSpecificMessage(diag);
|
|
126749
126832
|
}
|
|
126750
126833
|
ts.diagnosticToString = diagnosticToString;
|
|
126834
|
+
/**
|
|
126835
|
+
* Get format code settings for a code writing context (e.g. when formatting text changes or completions code).
|
|
126836
|
+
*/
|
|
126837
|
+
function getFormatCodeSettingsForWriting(_a, sourceFile) {
|
|
126838
|
+
var options = _a.options;
|
|
126839
|
+
var shouldAutoDetectSemicolonPreference = !options.semicolons || options.semicolons === ts.SemicolonPreference.Ignore;
|
|
126840
|
+
var shouldRemoveSemicolons = options.semicolons === ts.SemicolonPreference.Remove || shouldAutoDetectSemicolonPreference && !probablyUsesSemicolons(sourceFile);
|
|
126841
|
+
return __assign(__assign({}, options), { semicolons: shouldRemoveSemicolons ? ts.SemicolonPreference.Remove : ts.SemicolonPreference.Ignore });
|
|
126842
|
+
}
|
|
126843
|
+
ts.getFormatCodeSettingsForWriting = getFormatCodeSettingsForWriting;
|
|
126751
126844
|
// #endregion
|
|
126752
126845
|
})(ts || (ts = {}));
|
|
126753
126846
|
/*@internal*/
|
|
@@ -128371,7 +128464,8 @@ var ts;
|
|
|
128371
128464
|
return convertPathCompletions(completion.paths);
|
|
128372
128465
|
case 1 /* Properties */: {
|
|
128373
128466
|
var entries = ts.createSortedArray();
|
|
128374
|
-
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, contextToken, sourceFile, sourceFile, host, program, 99 /* ESNext */, log, 4 /* String */, preferences, options
|
|
128467
|
+
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, contextToken, sourceFile, sourceFile, host, program, 99 /* ESNext */, log, 4 /* String */, preferences, options,
|
|
128468
|
+
/*formatContext*/ undefined); // Target will not be used, so arbitrary
|
|
128375
128469
|
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: completion.hasIndexSignature, optionalReplacementSpan: optionalReplacementSpan, entries: entries };
|
|
128376
128470
|
}
|
|
128377
128471
|
case 2 /* Types */: {
|
|
@@ -129192,7 +129286,7 @@ var ts;
|
|
|
129192
129286
|
return result;
|
|
129193
129287
|
}
|
|
129194
129288
|
}
|
|
129195
|
-
function getCompletionsAtPosition(host, program, log, sourceFile, position, preferences, triggerCharacter, completionKind, cancellationToken) {
|
|
129289
|
+
function getCompletionsAtPosition(host, program, log, sourceFile, position, preferences, triggerCharacter, completionKind, cancellationToken, formatContext) {
|
|
129196
129290
|
var _a;
|
|
129197
129291
|
var previousToken = getRelevantTokens(position, sourceFile).previousToken;
|
|
129198
129292
|
if (triggerCharacter && !ts.isInString(sourceFile, position, previousToken) && !isValidTrigger(sourceFile, triggerCharacter, previousToken, position)) {
|
|
@@ -129232,7 +129326,7 @@ var ts;
|
|
|
129232
129326
|
}
|
|
129233
129327
|
switch (completionData.kind) {
|
|
129234
129328
|
case 0 /* Data */:
|
|
129235
|
-
var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences);
|
|
129329
|
+
var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext);
|
|
129236
129330
|
if (response === null || response === void 0 ? void 0 : response.isIncomplete) {
|
|
129237
129331
|
incompleteCompletionsCache === null || incompleteCompletionsCache === void 0 ? void 0 : incompleteCompletionsCache.set(response);
|
|
129238
129332
|
}
|
|
@@ -129352,7 +129446,7 @@ var ts;
|
|
|
129352
129446
|
// StringLiteralLike locations are handled separately in stringCompletions.ts
|
|
129353
129447
|
return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
|
|
129354
129448
|
}
|
|
129355
|
-
function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences) {
|
|
129449
|
+
function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext) {
|
|
129356
129450
|
var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
|
|
129357
129451
|
// Verify if the file is JSX language variant
|
|
129358
129452
|
if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
|
|
@@ -129364,7 +129458,7 @@ var ts;
|
|
|
129364
129458
|
var entries = ts.createSortedArray();
|
|
129365
129459
|
if (isUncheckedFile(sourceFile, compilerOptions)) {
|
|
129366
129460
|
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
|
|
129367
|
-
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
129461
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
129368
129462
|
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
|
|
129369
129463
|
}
|
|
129370
129464
|
else {
|
|
@@ -129372,7 +129466,7 @@ var ts;
|
|
|
129372
129466
|
return undefined;
|
|
129373
129467
|
}
|
|
129374
129468
|
getCompletionEntriesFromSymbols(symbols, entries,
|
|
129375
|
-
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
129469
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
129376
129470
|
}
|
|
129377
129471
|
if (keywordFilters !== 0 /* None */) {
|
|
129378
129472
|
var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
|
|
@@ -129478,7 +129572,7 @@ var ts;
|
|
|
129478
129572
|
function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
|
|
129479
129573
|
return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
|
|
129480
129574
|
}
|
|
129481
|
-
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind) {
|
|
129575
|
+
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext) {
|
|
129482
129576
|
var _a, _b;
|
|
129483
129577
|
var insertText;
|
|
129484
129578
|
var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
|
|
@@ -129543,7 +129637,7 @@ var ts;
|
|
|
129543
129637
|
completionKind === 3 /* MemberLike */ &&
|
|
129544
129638
|
isClassLikeMemberCompletion(symbol, location)) {
|
|
129545
129639
|
var importAdder = void 0;
|
|
129546
|
-
(_b = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken), insertText = _b.insertText, isSnippet = _b.isSnippet, importAdder = _b.importAdder);
|
|
129640
|
+
(_b = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken, formatContext), insertText = _b.insertText, isSnippet = _b.isSnippet, importAdder = _b.importAdder);
|
|
129547
129641
|
if (importAdder === null || importAdder === void 0 ? void 0 : importAdder.hasFixes()) {
|
|
129548
129642
|
hasAction = true;
|
|
129549
129643
|
source = CompletionSource.ClassMemberSnippet;
|
|
@@ -129642,7 +129736,7 @@ var ts;
|
|
|
129642
129736
|
ts.isSyntaxList(location) &&
|
|
129643
129737
|
ts.isClassLike(location.parent)));
|
|
129644
129738
|
}
|
|
129645
|
-
function getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken) {
|
|
129739
|
+
function getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken, formatContext) {
|
|
129646
129740
|
var classLikeDeclaration = ts.findAncestor(location, ts.isClassLike);
|
|
129647
129741
|
if (!classLikeDeclaration) {
|
|
129648
129742
|
return { insertText: name };
|
|
@@ -129659,15 +129753,16 @@ var ts;
|
|
|
129659
129753
|
newLine: ts.getNewLineKind(ts.getNewLineCharacter(options, ts.maybeBind(host, host.getNewLine))),
|
|
129660
129754
|
});
|
|
129661
129755
|
var importAdder = ts.codefix.createImportAdder(sourceFile, program, preferences, host);
|
|
129756
|
+
// Create empty body for possible method implementation.
|
|
129662
129757
|
var body;
|
|
129663
129758
|
if (preferences.includeCompletionsWithSnippetText) {
|
|
129664
129759
|
isSnippet = true;
|
|
129665
129760
|
// We are adding a tabstop (i.e. `$0`) in the body of the suggested member,
|
|
129666
129761
|
// if it has one, so that the cursor ends up in the body once the completion is inserted.
|
|
129667
129762
|
// Note: this assumes we won't have more than one body in the completion nodes, which should be the case.
|
|
129668
|
-
var
|
|
129669
|
-
ts.
|
|
129670
|
-
|
|
129763
|
+
var emptyStmt = ts.factory.createEmptyStatement();
|
|
129764
|
+
body = ts.factory.createBlock([emptyStmt], /* multiline */ true);
|
|
129765
|
+
ts.setSnippetElement(emptyStmt, { kind: 0 /* TabStop */, order: 0 });
|
|
129671
129766
|
}
|
|
129672
129767
|
else {
|
|
129673
129768
|
body = ts.factory.createBlock([], /* multiline */ true);
|
|
@@ -129713,7 +129808,27 @@ var ts;
|
|
|
129713
129808
|
completionNodes.push(node);
|
|
129714
129809
|
}, body, 2 /* Property */, isAbstract);
|
|
129715
129810
|
if (completionNodes.length) {
|
|
129716
|
-
|
|
129811
|
+
// If we have access to formatting settings, we print the nodes using the emitter,
|
|
129812
|
+
// and then format the printed text.
|
|
129813
|
+
if (formatContext) {
|
|
129814
|
+
var syntheticFile_1 = {
|
|
129815
|
+
text: printer.printSnippetList(1 /* MultiLine */ | 131072 /* NoTrailingNewLine */, ts.factory.createNodeArray(completionNodes), sourceFile),
|
|
129816
|
+
getLineAndCharacterOfPosition: function (pos) {
|
|
129817
|
+
return ts.getLineAndCharacterOfPosition(this, pos);
|
|
129818
|
+
},
|
|
129819
|
+
};
|
|
129820
|
+
var formatOptions_1 = ts.getFormatCodeSettingsForWriting(formatContext, sourceFile);
|
|
129821
|
+
var changes = ts.flatMap(completionNodes, function (node) {
|
|
129822
|
+
var nodeWithPos = ts.textChanges.assignPositionsToNode(node);
|
|
129823
|
+
return ts.formatting.formatNodeGivenIndentation(nodeWithPos, syntheticFile_1, sourceFile.languageVariant,
|
|
129824
|
+
/* indentation */ 0,
|
|
129825
|
+
/* delta */ 0, __assign(__assign({}, formatContext), { options: formatOptions_1 }));
|
|
129826
|
+
});
|
|
129827
|
+
insertText = ts.textChanges.applyChanges(syntheticFile_1.text, changes);
|
|
129828
|
+
}
|
|
129829
|
+
else { // Otherwise, just use emitter to print the new nodes.
|
|
129830
|
+
insertText = printer.printSnippetList(1 /* MultiLine */ | 131072 /* NoTrailingNewLine */, ts.factory.createNodeArray(completionNodes), sourceFile);
|
|
129831
|
+
}
|
|
129717
129832
|
}
|
|
129718
129833
|
return { insertText: insertText, isSnippet: isSnippet, importAdder: importAdder };
|
|
129719
129834
|
}
|
|
@@ -129757,8 +129872,8 @@ var ts;
|
|
|
129757
129872
|
return undefined;
|
|
129758
129873
|
}
|
|
129759
129874
|
function createSnippetPrinter(printerOptions) {
|
|
129760
|
-
var
|
|
129761
|
-
var
|
|
129875
|
+
var baseWriter = ts.textChanges.createWriter(ts.getNewLineCharacter(printerOptions));
|
|
129876
|
+
var printer = ts.createPrinter(printerOptions, baseWriter);
|
|
129762
129877
|
var writer = __assign(__assign({}, baseWriter), { write: function (s) { return baseWriter.write(ts.escapeSnippetText(s)); }, nonEscapingWrite: baseWriter.write, writeLiteral: function (s) { return baseWriter.writeLiteral(ts.escapeSnippetText(s)); }, writeStringLiteral: function (s) { return baseWriter.writeStringLiteral(ts.escapeSnippetText(s)); }, writeSymbol: function (s, symbol) { return baseWriter.writeSymbol(ts.escapeSnippetText(s), symbol); }, writeParameter: function (s) { return baseWriter.writeParameter(ts.escapeSnippetText(s)); }, writeComment: function (s) { return baseWriter.writeComment(ts.escapeSnippetText(s)); }, writeProperty: function (s) { return baseWriter.writeProperty(ts.escapeSnippetText(s)); } });
|
|
129763
129878
|
return {
|
|
129764
129879
|
printSnippetList: printSnippetList,
|
|
@@ -129863,7 +129978,7 @@ var ts;
|
|
|
129863
129978
|
return CompletionSource.ThisProperty;
|
|
129864
129979
|
}
|
|
129865
129980
|
}
|
|
129866
|
-
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
129981
|
+
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
129867
129982
|
var _a;
|
|
129868
129983
|
var start = ts.timestamp();
|
|
129869
129984
|
var variableDeclaration = getVariableDeclaration(location);
|
|
@@ -129884,7 +129999,7 @@ var ts;
|
|
|
129884
129999
|
var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
|
|
129885
130000
|
var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
|
|
129886
130001
|
var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
|
|
129887
|
-
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind);
|
|
130002
|
+
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, formatContext);
|
|
129888
130003
|
if (!entry) {
|
|
129889
130004
|
continue;
|
|
129890
130005
|
}
|
|
@@ -130080,7 +130195,7 @@ var ts;
|
|
|
130080
130195
|
}
|
|
130081
130196
|
}
|
|
130082
130197
|
if (source === CompletionSource.ClassMemberSnippet) {
|
|
130083
|
-
var importAdder = getEntryForMemberCompletion(host, program, compilerOptions, preferences, name, symbol, location, contextToken).importAdder;
|
|
130198
|
+
var importAdder = getEntryForMemberCompletion(host, program, compilerOptions, preferences, name, symbol, location, contextToken, formatContext).importAdder;
|
|
130084
130199
|
if (importAdder) {
|
|
130085
130200
|
var changes = ts.textChanges.ChangeTracker.with({ host: host, formatContext: formatContext, preferences: preferences }, importAdder.writeFixes);
|
|
130086
130201
|
return {
|
|
@@ -145964,19 +146079,13 @@ var ts;
|
|
|
145964
146079
|
+ ((!options.suffix || ts.endsWith(noIndent, options.suffix))
|
|
145965
146080
|
? "" : options.suffix);
|
|
145966
146081
|
}
|
|
145967
|
-
function getFormatCodeSettingsForWriting(_a, sourceFile) {
|
|
145968
|
-
var options = _a.options;
|
|
145969
|
-
var shouldAutoDetectSemicolonPreference = !options.semicolons || options.semicolons === ts.SemicolonPreference.Ignore;
|
|
145970
|
-
var shouldRemoveSemicolons = options.semicolons === ts.SemicolonPreference.Remove || shouldAutoDetectSemicolonPreference && !ts.probablyUsesSemicolons(sourceFile);
|
|
145971
|
-
return __assign(__assign({}, options), { semicolons: shouldRemoveSemicolons ? ts.SemicolonPreference.Remove : ts.SemicolonPreference.Ignore });
|
|
145972
|
-
}
|
|
145973
146082
|
/** Note: this may mutate `nodeIn`. */
|
|
145974
146083
|
function getFormattedTextOfNode(nodeIn, sourceFile, pos, _a, newLineCharacter, formatContext, validate) {
|
|
145975
146084
|
var indentation = _a.indentation, prefix = _a.prefix, delta = _a.delta;
|
|
145976
146085
|
var _b = getNonformattedText(nodeIn, sourceFile, newLineCharacter), node = _b.node, text = _b.text;
|
|
145977
146086
|
if (validate)
|
|
145978
146087
|
validate(node, text);
|
|
145979
|
-
var formatOptions = getFormatCodeSettingsForWriting(formatContext, sourceFile);
|
|
146088
|
+
var formatOptions = ts.getFormatCodeSettingsForWriting(formatContext, sourceFile);
|
|
145980
146089
|
var initialIndentation = indentation !== undefined
|
|
145981
146090
|
? indentation
|
|
145982
146091
|
: ts.formatting.SmartIndenter.getIndentation(pos, sourceFile, formatOptions, prefix === newLineCharacter || ts.getLineStartPositionForPosition(pos, sourceFile) === pos);
|
|
@@ -146024,6 +146133,7 @@ var ts;
|
|
|
146024
146133
|
ts.setTextRangePosEnd(newNode, getPos(node), getEnd(node));
|
|
146025
146134
|
return newNode;
|
|
146026
146135
|
}
|
|
146136
|
+
textChanges_3.assignPositionsToNode = assignPositionsToNode;
|
|
146027
146137
|
function assignPositionsToNodeArray(nodes, visitor, test, start, count) {
|
|
146028
146138
|
var visited = ts.visitNodes(nodes, visitor, test, start, count);
|
|
146029
146139
|
if (!visited) {
|
|
@@ -146194,6 +146304,7 @@ var ts;
|
|
|
146194
146304
|
clear: clear
|
|
146195
146305
|
};
|
|
146196
146306
|
}
|
|
146307
|
+
textChanges_3.createWriter = createWriter;
|
|
146197
146308
|
function getInsertionPositionAtSourceFileTop(sourceFile) {
|
|
146198
146309
|
var lastPrologue;
|
|
146199
146310
|
for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
|
|
@@ -150929,7 +151040,8 @@ var ts;
|
|
|
150929
151040
|
return { kind: 3 /* ObjectLiteral */, token: token, properties: properties, indentation: undefined, parentDeclaration: parent.initializer };
|
|
150930
151041
|
}
|
|
150931
151042
|
if (ts.isIdentifier(token) && ts.isJsxOpeningLikeElement(token.parent)) {
|
|
150932
|
-
var
|
|
151043
|
+
var target = ts.getEmitScriptTarget(program.getCompilerOptions());
|
|
151044
|
+
var attributes = getUnmatchedAttributes(checker, target, token.parent);
|
|
150933
151045
|
if (!ts.length(attributes))
|
|
150934
151046
|
return undefined;
|
|
150935
151047
|
return { kind: 4 /* JsxAttributes */, token: token, attributes: attributes, parentDeclaration: token.parent };
|
|
@@ -151164,8 +151276,12 @@ var ts;
|
|
|
151164
151276
|
var jsxAttributesNode = info.parentDeclaration.attributes;
|
|
151165
151277
|
var hasSpreadAttribute = ts.some(jsxAttributesNode.properties, ts.isJsxSpreadAttribute);
|
|
151166
151278
|
var attrs = ts.map(info.attributes, function (attr) {
|
|
151167
|
-
var value =
|
|
151168
|
-
|
|
151279
|
+
var value = tryGetValueFromType(context, checker, importAdder, quotePreference, checker.getTypeOfSymbol(attr));
|
|
151280
|
+
var name = ts.factory.createIdentifier(attr.name);
|
|
151281
|
+
var jsxAttribute = ts.factory.createJsxAttribute(name, ts.factory.createJsxExpression(/*dotDotDotToken*/ undefined, value));
|
|
151282
|
+
// formattingScanner requires the Identifier to have a context for scanning attributes with "-" (data-foo).
|
|
151283
|
+
ts.setParent(name, jsxAttribute);
|
|
151284
|
+
return jsxAttribute;
|
|
151169
151285
|
});
|
|
151170
151286
|
var jsxAttributes = ts.factory.createJsxAttributes(hasSpreadAttribute ? __spreadArray(__spreadArray([], attrs, true), jsxAttributesNode.properties, true) : __spreadArray(__spreadArray([], jsxAttributesNode.properties, true), attrs, true));
|
|
151171
151287
|
var options = { prefix: jsxAttributesNode.pos === jsxAttributesNode.end ? " " : undefined };
|
|
@@ -151174,10 +151290,11 @@ var ts;
|
|
|
151174
151290
|
function addObjectLiteralProperties(changes, context, info) {
|
|
151175
151291
|
var importAdder = codefix.createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
|
|
151176
151292
|
var quotePreference = ts.getQuotePreference(context.sourceFile, context.preferences);
|
|
151293
|
+
var target = ts.getEmitScriptTarget(context.program.getCompilerOptions());
|
|
151177
151294
|
var checker = context.program.getTypeChecker();
|
|
151178
151295
|
var props = ts.map(info.properties, function (prop) {
|
|
151179
|
-
var initializer =
|
|
151180
|
-
return ts.factory.createPropertyAssignment(prop.name, initializer);
|
|
151296
|
+
var initializer = tryGetValueFromType(context, checker, importAdder, quotePreference, checker.getTypeOfSymbol(prop));
|
|
151297
|
+
return ts.factory.createPropertyAssignment(ts.createPropertyNameNodeForIdentifierOrLiteral(prop.name, target, quotePreference === 0 /* Single */), initializer);
|
|
151181
151298
|
});
|
|
151182
151299
|
var options = {
|
|
151183
151300
|
leadingTriviaOption: ts.textChanges.LeadingTriviaOption.Exclude,
|
|
@@ -151264,7 +151381,7 @@ var ts;
|
|
|
151264
151381
|
return (type.flags & 524288 /* Object */) &&
|
|
151265
151382
|
((ts.getObjectFlags(type) & 128 /* ObjectLiteral */) || (type.symbol && ts.tryCast(ts.singleOrUndefined(type.symbol.declarations), ts.isTypeLiteralNode)));
|
|
151266
151383
|
}
|
|
151267
|
-
function getUnmatchedAttributes(checker, source) {
|
|
151384
|
+
function getUnmatchedAttributes(checker, target, source) {
|
|
151268
151385
|
var attrsType = checker.getContextualType(source.attributes);
|
|
151269
151386
|
if (attrsType === undefined)
|
|
151270
151387
|
return ts.emptyArray;
|
|
@@ -151286,7 +151403,7 @@ var ts;
|
|
|
151286
151403
|
}
|
|
151287
151404
|
}
|
|
151288
151405
|
return ts.filter(targetProps, function (targetProp) {
|
|
151289
|
-
return !((targetProp.flags & 16777216 /* Optional */ || ts.getCheckFlags(targetProp) & 48 /* Partial */) || seenNames.has(targetProp.escapedName));
|
|
151406
|
+
return ts.isIdentifierText(targetProp.name, target, 1 /* JSX */) && !((targetProp.flags & 16777216 /* Optional */ || ts.getCheckFlags(targetProp) & 48 /* Partial */) || seenNames.has(targetProp.escapedName));
|
|
151290
151407
|
});
|
|
151291
151408
|
}
|
|
151292
151409
|
})(codefix = ts.codefix || (ts.codefix = {}));
|
|
@@ -161091,12 +161208,12 @@ var ts;
|
|
|
161091
161208
|
synchronizeHostData();
|
|
161092
161209
|
return __spreadArray(__spreadArray([], program.getOptionsDiagnostics(cancellationToken), true), program.getGlobalDiagnostics(cancellationToken), true);
|
|
161093
161210
|
}
|
|
161094
|
-
function getCompletionsAtPosition(fileName, position, options) {
|
|
161211
|
+
function getCompletionsAtPosition(fileName, position, options, formattingSettings) {
|
|
161095
161212
|
if (options === void 0) { options = ts.emptyOptions; }
|
|
161096
161213
|
// Convert from deprecated options names to new names
|
|
161097
161214
|
var fullPreferences = __assign(__assign({}, ts.identity(options)), { includeCompletionsForModuleExports: options.includeCompletionsForModuleExports || options.includeExternalModuleExports, includeCompletionsWithInsertText: options.includeCompletionsWithInsertText || options.includeInsertTextCompletions });
|
|
161098
161215
|
synchronizeHostData();
|
|
161099
|
-
return ts.Completions.getCompletionsAtPosition(host, program, log, getValidSourceFile(fileName), position, fullPreferences, options.triggerCharacter, options.triggerKind, cancellationToken);
|
|
161216
|
+
return ts.Completions.getCompletionsAtPosition(host, program, log, getValidSourceFile(fileName), position, fullPreferences, options.triggerCharacter, options.triggerKind, cancellationToken, formattingSettings && ts.formatting.getFormatContext(formattingSettings, host));
|
|
161100
161217
|
}
|
|
161101
161218
|
function getCompletionEntryDetails(fileName, position, name, formattingOptions, source, preferences, data) {
|
|
161102
161219
|
if (preferences === void 0) { preferences = ts.emptyOptions; }
|
|
@@ -163259,9 +163376,9 @@ var ts;
|
|
|
163259
163376
|
* to provide at the given source position and providing a member completion
|
|
163260
163377
|
* list if requested.
|
|
163261
163378
|
*/
|
|
163262
|
-
LanguageServiceShimObject.prototype.getCompletionsAtPosition = function (fileName, position, preferences) {
|
|
163379
|
+
LanguageServiceShimObject.prototype.getCompletionsAtPosition = function (fileName, position, preferences, formattingSettings) {
|
|
163263
163380
|
var _this = this;
|
|
163264
|
-
return this.forwardJSONCall("getCompletionsAtPosition('" + fileName + "', " + position + ", " + preferences + ")", function () { return _this.languageService.getCompletionsAtPosition(fileName, position, preferences); });
|
|
163381
|
+
return this.forwardJSONCall("getCompletionsAtPosition('" + fileName + "', " + position + ", " + preferences + ", " + formattingSettings + ")", function () { return _this.languageService.getCompletionsAtPosition(fileName, position, preferences, formattingSettings); });
|
|
163265
163382
|
};
|
|
163266
163383
|
/** Get a string based representation of a completion list entry details */
|
|
163267
163384
|
LanguageServiceShimObject.prototype.getCompletionEntryDetails = function (fileName, position, entryName, formatOptions, source, preferences, data) {
|
|
@@ -171427,6 +171544,9 @@ var ts;
|
|
|
171427
171544
|
}
|
|
171428
171545
|
return;
|
|
171429
171546
|
}
|
|
171547
|
+
this.writeMessage(msg);
|
|
171548
|
+
};
|
|
171549
|
+
Session.prototype.writeMessage = function (msg) {
|
|
171430
171550
|
var msgText = formatMessage(msg, this.logger, this.byteLength, this.host.newLine);
|
|
171431
171551
|
ts.perfLogger.logEvent("Response message size: " + msgText.length);
|
|
171432
171552
|
this.host.write(msgText);
|
|
@@ -172178,7 +172298,7 @@ var ts;
|
|
|
172178
172298
|
var _a = this.getFileAndProject(args), file = _a.file, project = _a.project;
|
|
172179
172299
|
var scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file);
|
|
172180
172300
|
var position = this.getPosition(args, scriptInfo);
|
|
172181
|
-
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 }));
|
|
172301
|
+
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));
|
|
172182
172302
|
if (completions === undefined)
|
|
172183
172303
|
return undefined;
|
|
172184
172304
|
if (kind === "completions-full" /* CompletionsFull */)
|