typescript 4.6.0-dev.20220113 → 4.6.0-dev.20220117
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/tsc.js +185 -76
- package/lib/tsserver.js +311 -138
- package/lib/tsserverlibrary.js +311 -138
- package/lib/typescript.js +311 -138
- package/lib/typescriptServices.js +311 -138
- package/lib/typingsInstaller.js +231 -94
- 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.20220117";
|
|
104
104
|
/* @internal */
|
|
105
105
|
var Comparison;
|
|
106
106
|
(function (Comparison) {
|
|
@@ -8288,7 +8288,7 @@ var ts;
|
|
|
8288
8288
|
Parameter_0_cannot_reference_identifier_1_declared_after_it: diag(2373, ts.DiagnosticCategory.Error, "Parameter_0_cannot_reference_identifier_1_declared_after_it_2373", "Parameter '{0}' cannot reference identifier '{1}' declared after it."),
|
|
8289
8289
|
Duplicate_index_signature_for_type_0: diag(2374, ts.DiagnosticCategory.Error, "Duplicate_index_signature_for_type_0_2374", "Duplicate index signature for type '{0}'."),
|
|
8290
8290
|
Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties: diag(2375, ts.DiagnosticCategory.Error, "Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefi_2375", "Type '{0}' is not assignable to type '{1}' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties."),
|
|
8291
|
-
|
|
8291
|
+
A_super_call_must_be_the_first_statement_in_the_constructor_to_refer_to_super_or_this_when_a_derived_class_contains_initialized_properties_parameter_properties_or_private_identifiers: diag(2376, ts.DiagnosticCategory.Error, "A_super_call_must_be_the_first_statement_in_the_constructor_to_refer_to_super_or_this_when_a_derived_2376", "A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers."),
|
|
8292
8292
|
Constructors_for_derived_classes_must_contain_a_super_call: diag(2377, ts.DiagnosticCategory.Error, "Constructors_for_derived_classes_must_contain_a_super_call_2377", "Constructors for derived classes must contain a 'super' call."),
|
|
8293
8293
|
A_get_accessor_must_return_a_value: diag(2378, ts.DiagnosticCategory.Error, "A_get_accessor_must_return_a_value_2378", "A 'get' accessor must return a value."),
|
|
8294
8294
|
Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties: diag(2379, ts.DiagnosticCategory.Error, "Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_tr_2379", "Argument of type '{0}' is not assignable to parameter of type '{1}' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties."),
|
|
@@ -8311,6 +8311,7 @@ var ts;
|
|
|
8311
8311
|
constructor_cannot_be_used_as_a_parameter_property_name: diag(2398, ts.DiagnosticCategory.Error, "constructor_cannot_be_used_as_a_parameter_property_name_2398", "'constructor' cannot be used as a parameter property name."),
|
|
8312
8312
|
Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: diag(2399, ts.DiagnosticCategory.Error, "Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference_2399", "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference."),
|
|
8313
8313
|
Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: diag(2400, ts.DiagnosticCategory.Error, "Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference_2400", "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference."),
|
|
8314
|
+
A_super_call_must_be_a_root_level_statement_within_a_constructor_of_a_derived_class_that_contains_initialized_properties_parameter_properties_or_private_identifiers: diag(2401, ts.DiagnosticCategory.Error, "A_super_call_must_be_a_root_level_statement_within_a_constructor_of_a_derived_class_that_contains_in_2401", "A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers."),
|
|
8314
8315
|
Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference: diag(2402, ts.DiagnosticCategory.Error, "Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference_2402", "Expression resolves to '_super' that compiler uses to capture base class reference."),
|
|
8315
8316
|
Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2: diag(2403, ts.DiagnosticCategory.Error, "Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_t_2403", "Subsequent variable declarations must have the same type. Variable '{0}' must be of type '{1}', but here has type '{2}'."),
|
|
8316
8317
|
The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation: diag(2404, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation_2404", "The left-hand side of a 'for...in' statement cannot use a type annotation."),
|
|
@@ -15471,6 +15472,34 @@ var ts;
|
|
|
15471
15472
|
}
|
|
15472
15473
|
}
|
|
15473
15474
|
ts.getThisContainer = getThisContainer;
|
|
15475
|
+
/**
|
|
15476
|
+
* @returns Whether the node creates a new 'this' scope for its children.
|
|
15477
|
+
*/
|
|
15478
|
+
function isThisContainerOrFunctionBlock(node) {
|
|
15479
|
+
switch (node.kind) {
|
|
15480
|
+
// Arrow functions use the same scope, but may do so in a "delayed" manner
|
|
15481
|
+
// For example, `const getThis = () => this` may be before a super() call in a derived constructor
|
|
15482
|
+
case 213 /* ArrowFunction */:
|
|
15483
|
+
case 255 /* FunctionDeclaration */:
|
|
15484
|
+
case 212 /* FunctionExpression */:
|
|
15485
|
+
case 166 /* PropertyDeclaration */:
|
|
15486
|
+
return true;
|
|
15487
|
+
case 234 /* Block */:
|
|
15488
|
+
switch (node.parent.kind) {
|
|
15489
|
+
case 170 /* Constructor */:
|
|
15490
|
+
case 168 /* MethodDeclaration */:
|
|
15491
|
+
case 171 /* GetAccessor */:
|
|
15492
|
+
case 172 /* SetAccessor */:
|
|
15493
|
+
// Object properties can have computed names; only method-like bodies start a new scope
|
|
15494
|
+
return true;
|
|
15495
|
+
default:
|
|
15496
|
+
return false;
|
|
15497
|
+
}
|
|
15498
|
+
default:
|
|
15499
|
+
return false;
|
|
15500
|
+
}
|
|
15501
|
+
}
|
|
15502
|
+
ts.isThisContainerOrFunctionBlock = isThisContainerOrFunctionBlock;
|
|
15474
15503
|
function isInTopLevelContext(node) {
|
|
15475
15504
|
// The name of a class or function declaration is a BindingIdentifier in its surrounding scope.
|
|
15476
15505
|
if (ts.isIdentifier(node) && (ts.isClassDeclaration(node.parent) || ts.isFunctionDeclaration(node.parent)) && node.parent.name === node) {
|
|
@@ -26057,7 +26086,7 @@ var ts;
|
|
|
26057
26086
|
* @param visitor Optional callback used to visit any custom prologue directives.
|
|
26058
26087
|
*/
|
|
26059
26088
|
function copyPrologue(source, target, ensureUseStrict, visitor) {
|
|
26060
|
-
var offset = copyStandardPrologue(source, target, ensureUseStrict);
|
|
26089
|
+
var offset = copyStandardPrologue(source, target, 0, ensureUseStrict);
|
|
26061
26090
|
return copyCustomPrologue(source, target, offset, visitor);
|
|
26062
26091
|
}
|
|
26063
26092
|
function isUseStrictPrologue(node) {
|
|
@@ -26070,12 +26099,14 @@ var ts;
|
|
|
26070
26099
|
* Copies only the standard (string-expression) prologue-directives into the target statement-array.
|
|
26071
26100
|
* @param source origin statements array
|
|
26072
26101
|
* @param target result statements array
|
|
26102
|
+
* @param statementOffset The offset at which to begin the copy.
|
|
26073
26103
|
* @param ensureUseStrict boolean determining whether the function need to add prologue-directives
|
|
26104
|
+
* @returns Count of how many directive statements were copied.
|
|
26074
26105
|
*/
|
|
26075
|
-
function copyStandardPrologue(source, target, ensureUseStrict) {
|
|
26106
|
+
function copyStandardPrologue(source, target, statementOffset, ensureUseStrict) {
|
|
26107
|
+
if (statementOffset === void 0) { statementOffset = 0; }
|
|
26076
26108
|
ts.Debug.assert(target.length === 0, "Prologue directives should be at the first statement in the target statements array");
|
|
26077
26109
|
var foundUseStrict = false;
|
|
26078
|
-
var statementOffset = 0;
|
|
26079
26110
|
var numStatements = source.length;
|
|
26080
26111
|
while (statementOffset < numStatements) {
|
|
26081
26112
|
var statement = source[statementOffset];
|
|
@@ -27498,7 +27529,7 @@ var ts;
|
|
|
27498
27529
|
importName: "__createBinding",
|
|
27499
27530
|
scoped: false,
|
|
27500
27531
|
priority: 1,
|
|
27501
|
-
text: "\n var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n Object.
|
|
27532
|
+
text: "\n var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n }) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n }));"
|
|
27502
27533
|
};
|
|
27503
27534
|
ts.setModuleDefaultHelper = {
|
|
27504
27535
|
name: "typescript:commonjscreatevalue",
|
|
@@ -41133,7 +41164,7 @@ var ts;
|
|
|
41133
41164
|
? 1 /* Recursive */ : 0 /* None */
|
|
41134
41165
|
};
|
|
41135
41166
|
}
|
|
41136
|
-
if (ts.isImplicitGlob(spec)) {
|
|
41167
|
+
if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) {
|
|
41137
41168
|
return {
|
|
41138
41169
|
key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec),
|
|
41139
41170
|
flags: 1 /* Recursive */
|
|
@@ -78518,32 +78549,38 @@ var ts;
|
|
|
78518
78549
|
if (classExtendsNull) {
|
|
78519
78550
|
error(superCall, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
|
|
78520
78551
|
}
|
|
78521
|
-
//
|
|
78522
|
-
// if both of the following are true:
|
|
78552
|
+
// A super call must be root-level in a constructor if both of the following are true:
|
|
78523
78553
|
// - The containing class is a derived class.
|
|
78524
78554
|
// - The constructor declares parameter properties
|
|
78525
78555
|
// or the containing class declares instance member variables with initializers.
|
|
78526
|
-
var
|
|
78556
|
+
var superCallShouldBeRootLevel = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
|
|
78527
78557
|
(ts.some(node.parent.members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
|
|
78528
78558
|
ts.some(node.parameters, function (p) { return ts.hasSyntacticModifier(p, 16476 /* ParameterPropertyModifier */); }));
|
|
78529
|
-
|
|
78530
|
-
|
|
78531
|
-
|
|
78532
|
-
|
|
78533
|
-
|
|
78534
|
-
|
|
78535
|
-
|
|
78536
|
-
|
|
78537
|
-
|
|
78538
|
-
|
|
78559
|
+
if (superCallShouldBeRootLevel) {
|
|
78560
|
+
// Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
|
|
78561
|
+
// See GH #8277
|
|
78562
|
+
if (!superCallIsRootLevelInConstructor(superCall, node.body)) {
|
|
78563
|
+
error(superCall, ts.Diagnostics.A_super_call_must_be_a_root_level_statement_within_a_constructor_of_a_derived_class_that_contains_initialized_properties_parameter_properties_or_private_identifiers);
|
|
78564
|
+
}
|
|
78565
|
+
// Skip past any prologue directives to check statements for referring to 'super' or 'this' before a super call
|
|
78566
|
+
else {
|
|
78567
|
+
var superCallStatement = void 0;
|
|
78568
|
+
for (var _i = 0, _a = node.body.statements; _i < _a.length; _i++) {
|
|
78569
|
+
var statement = _a[_i];
|
|
78570
|
+
if (ts.isExpressionStatement(statement) && ts.isSuperCall(ts.skipOuterExpressions(statement.expression))) {
|
|
78571
|
+
superCallStatement = statement;
|
|
78572
|
+
break;
|
|
78573
|
+
}
|
|
78574
|
+
if (!ts.isPrologueDirective(statement) && nodeImmediatelyReferencesSuperOrThis(statement)) {
|
|
78575
|
+
break;
|
|
78576
|
+
}
|
|
78539
78577
|
}
|
|
78540
|
-
|
|
78541
|
-
|
|
78578
|
+
// Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
|
|
78579
|
+
// See GH #8277
|
|
78580
|
+
if (superCallStatement === undefined) {
|
|
78581
|
+
error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_to_refer_to_super_or_this_when_a_derived_class_contains_initialized_properties_parameter_properties_or_private_identifiers);
|
|
78542
78582
|
}
|
|
78543
78583
|
}
|
|
78544
|
-
if (!superCallStatement) {
|
|
78545
|
-
error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_parameter_properties_or_private_identifiers);
|
|
78546
|
-
}
|
|
78547
78584
|
}
|
|
78548
78585
|
}
|
|
78549
78586
|
else if (!classExtendsNull) {
|
|
@@ -78551,6 +78588,19 @@ var ts;
|
|
|
78551
78588
|
}
|
|
78552
78589
|
}
|
|
78553
78590
|
}
|
|
78591
|
+
function superCallIsRootLevelInConstructor(superCall, body) {
|
|
78592
|
+
var superCallParent = ts.walkUpParenthesizedExpressions(superCall.parent);
|
|
78593
|
+
return ts.isExpressionStatement(superCallParent) && superCallParent.parent === body;
|
|
78594
|
+
}
|
|
78595
|
+
function nodeImmediatelyReferencesSuperOrThis(node) {
|
|
78596
|
+
if (node.kind === 106 /* SuperKeyword */ || node.kind === 108 /* ThisKeyword */) {
|
|
78597
|
+
return true;
|
|
78598
|
+
}
|
|
78599
|
+
if (ts.isThisContainerOrFunctionBlock(node)) {
|
|
78600
|
+
return false;
|
|
78601
|
+
}
|
|
78602
|
+
return !!ts.forEachChild(node, nodeImmediatelyReferencesSuperOrThis);
|
|
78603
|
+
}
|
|
78554
78604
|
function checkAccessorDeclaration(node) {
|
|
78555
78605
|
if (produceDiagnostics) {
|
|
78556
78606
|
// Grammar checking accessors
|
|
@@ -88673,34 +88723,31 @@ var ts;
|
|
|
88673
88723
|
}
|
|
88674
88724
|
ts.getNonAssignmentOperatorForCompoundAssignment = getNonAssignmentOperatorForCompoundAssignment;
|
|
88675
88725
|
/**
|
|
88676
|
-
*
|
|
88677
|
-
|
|
88678
|
-
|
|
88679
|
-
|
|
88680
|
-
|
|
88681
|
-
|
|
88726
|
+
* @returns Contained super() call from descending into the statement ignoring parentheses, if that call exists.
|
|
88727
|
+
*/
|
|
88728
|
+
function getSuperCallFromStatement(statement) {
|
|
88729
|
+
if (!ts.isExpressionStatement(statement)) {
|
|
88730
|
+
return undefined;
|
|
88731
|
+
}
|
|
88732
|
+
var expression = ts.skipParentheses(statement.expression);
|
|
88733
|
+
return ts.isSuperCall(expression)
|
|
88734
|
+
? expression
|
|
88735
|
+
: undefined;
|
|
88736
|
+
}
|
|
88737
|
+
ts.getSuperCallFromStatement = getSuperCallFromStatement;
|
|
88738
|
+
/**
|
|
88739
|
+
* @returns The index (after prologue statements) of a super call, or -1 if not found.
|
|
88682
88740
|
*/
|
|
88683
|
-
function
|
|
88684
|
-
|
|
88685
|
-
var
|
|
88686
|
-
|
|
88687
|
-
|
|
88688
|
-
if (index === statements.length) {
|
|
88689
|
-
// list contains nothing but prologue directives (or empty) - exit
|
|
88690
|
-
return index;
|
|
88691
|
-
}
|
|
88692
|
-
var superIndex = ts.findIndex(statements, function (s) { return ts.isExpressionStatement(s) && ts.isSuperCall(s.expression); }, index);
|
|
88693
|
-
if (superIndex > -1) {
|
|
88694
|
-
for (var i = index; i <= superIndex; i++) {
|
|
88695
|
-
result.push(ts.visitNode(statements[i], visitor, ts.isStatement));
|
|
88696
|
-
}
|
|
88697
|
-
return superIndex + 1;
|
|
88741
|
+
function findSuperStatementIndex(statements, indexAfterLastPrologueStatement) {
|
|
88742
|
+
for (var i = indexAfterLastPrologueStatement; i < statements.length; i += 1) {
|
|
88743
|
+
var statement = statements[i];
|
|
88744
|
+
if (getSuperCallFromStatement(statement)) {
|
|
88745
|
+
return i;
|
|
88698
88746
|
}
|
|
88699
|
-
return index;
|
|
88700
88747
|
}
|
|
88701
|
-
return
|
|
88748
|
+
return -1;
|
|
88702
88749
|
}
|
|
88703
|
-
ts.
|
|
88750
|
+
ts.findSuperStatementIndex = findSuperStatementIndex;
|
|
88704
88751
|
function getProperties(node, requireInitializer, isStatic) {
|
|
88705
88752
|
return ts.filter(node.members, function (m) { return isInitializedOrStaticProperty(m, requireInitializer, isStatic); });
|
|
88706
88753
|
}
|
|
@@ -90938,10 +90985,14 @@ var ts;
|
|
|
90938
90985
|
return ts.visitFunctionBody(body, visitor, context);
|
|
90939
90986
|
}
|
|
90940
90987
|
var statements = [];
|
|
90941
|
-
var indexOfFirstStatement = 0;
|
|
90942
90988
|
resumeLexicalEnvironment();
|
|
90943
|
-
|
|
90944
|
-
|
|
90989
|
+
var indexAfterLastPrologueStatement = factory.copyPrologue(body.statements, statements, /*ensureUseStrict*/ false, visitor);
|
|
90990
|
+
var superStatementIndex = ts.findSuperStatementIndex(body.statements, indexAfterLastPrologueStatement);
|
|
90991
|
+
// If there was a super call, visit existing statements up to and including it
|
|
90992
|
+
if (superStatementIndex >= 0) {
|
|
90993
|
+
ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, indexAfterLastPrologueStatement, superStatementIndex + 1 - indexAfterLastPrologueStatement));
|
|
90994
|
+
}
|
|
90995
|
+
// Transform parameters into property assignments. Transforms this:
|
|
90945
90996
|
//
|
|
90946
90997
|
// constructor (public x, public y) {
|
|
90947
90998
|
// }
|
|
@@ -90953,9 +91004,17 @@ var ts;
|
|
|
90953
91004
|
// this.y = y;
|
|
90954
91005
|
// }
|
|
90955
91006
|
//
|
|
90956
|
-
|
|
90957
|
-
//
|
|
90958
|
-
|
|
91007
|
+
var parameterPropertyAssignments = ts.mapDefined(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment);
|
|
91008
|
+
// If there is a super() call, the parameter properties go immediately after it
|
|
91009
|
+
if (superStatementIndex >= 0) {
|
|
91010
|
+
ts.addRange(statements, parameterPropertyAssignments);
|
|
91011
|
+
}
|
|
91012
|
+
// Since there was no super() call, parameter properties are the first statements in the constructor
|
|
91013
|
+
else {
|
|
91014
|
+
statements = ts.addRange(parameterPropertyAssignments, statements);
|
|
91015
|
+
}
|
|
91016
|
+
// Add remaining statements from the body, skipping the super() call if it was found
|
|
91017
|
+
ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, superStatementIndex + 1));
|
|
90959
91018
|
// End the lexical environment.
|
|
90960
91019
|
statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
|
|
90961
91020
|
var block = factory.createBlock(ts.setTextRange(factory.createNodeArray(statements), body.statements), /*multiLine*/ true);
|
|
@@ -92853,6 +92912,7 @@ var ts;
|
|
|
92853
92912
|
/*modifiers*/ undefined, parameters !== null && parameters !== void 0 ? parameters : [], body), constructor || node), constructor));
|
|
92854
92913
|
}
|
|
92855
92914
|
function transformConstructorBody(node, constructor, isDerivedClass) {
|
|
92915
|
+
var _a;
|
|
92856
92916
|
var properties = ts.getProperties(node, /*requireInitializer*/ false, /*isStatic*/ false);
|
|
92857
92917
|
if (!useDefineForClassFields) {
|
|
92858
92918
|
properties = ts.filter(properties, function (property) { return !!property.initializer || ts.isPrivateIdentifier(property.name); });
|
|
@@ -92864,9 +92924,21 @@ var ts;
|
|
|
92864
92924
|
return ts.visitFunctionBody(/*node*/ undefined, visitor, context);
|
|
92865
92925
|
}
|
|
92866
92926
|
resumeLexicalEnvironment();
|
|
92867
|
-
var
|
|
92927
|
+
var needsSyntheticConstructor = !constructor && isDerivedClass;
|
|
92928
|
+
var indexOfFirstStatementAfterSuper = 0;
|
|
92929
|
+
var prologueStatementCount = 0;
|
|
92930
|
+
var superStatementIndex = -1;
|
|
92868
92931
|
var statements = [];
|
|
92869
|
-
if (
|
|
92932
|
+
if ((_a = constructor === null || constructor === void 0 ? void 0 : constructor.body) === null || _a === void 0 ? void 0 : _a.statements) {
|
|
92933
|
+
prologueStatementCount = factory.copyPrologue(constructor.body.statements, statements, /*ensureUseStrict*/ false, visitor);
|
|
92934
|
+
superStatementIndex = ts.findSuperStatementIndex(constructor.body.statements, prologueStatementCount);
|
|
92935
|
+
// If there was a super call, visit existing statements up to and including it
|
|
92936
|
+
if (superStatementIndex >= 0) {
|
|
92937
|
+
indexOfFirstStatementAfterSuper = superStatementIndex + 1;
|
|
92938
|
+
statements = __spreadArray(__spreadArray(__spreadArray([], statements.slice(0, prologueStatementCount), true), ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, prologueStatementCount, indexOfFirstStatementAfterSuper - prologueStatementCount), true), statements.slice(prologueStatementCount), true);
|
|
92939
|
+
}
|
|
92940
|
+
}
|
|
92941
|
+
if (needsSyntheticConstructor) {
|
|
92870
92942
|
// Add a synthetic `super` call:
|
|
92871
92943
|
//
|
|
92872
92944
|
// super(...arguments);
|
|
@@ -92874,9 +92946,6 @@ var ts;
|
|
|
92874
92946
|
statements.push(factory.createExpressionStatement(factory.createCallExpression(factory.createSuper(),
|
|
92875
92947
|
/*typeArguments*/ undefined, [factory.createSpreadElement(factory.createIdentifier("arguments"))])));
|
|
92876
92948
|
}
|
|
92877
|
-
if (constructor) {
|
|
92878
|
-
indexOfFirstStatement = ts.addPrologueDirectivesAndInitialSuperCall(factory, constructor, statements, visitor);
|
|
92879
|
-
}
|
|
92880
92949
|
// Add the property initializers. Transforms this:
|
|
92881
92950
|
//
|
|
92882
92951
|
// public x = 1;
|
|
@@ -92887,31 +92956,59 @@ var ts;
|
|
|
92887
92956
|
// this.x = 1;
|
|
92888
92957
|
// }
|
|
92889
92958
|
//
|
|
92959
|
+
// If we do useDefineForClassFields, they'll be converted elsewhere.
|
|
92960
|
+
// We instead *remove* them from the transformed output at this stage.
|
|
92961
|
+
var parameterPropertyDeclarationCount = 0;
|
|
92890
92962
|
if (constructor === null || constructor === void 0 ? void 0 : constructor.body) {
|
|
92891
|
-
|
|
92892
|
-
|
|
92893
|
-
afterParameterProperties = constructor.body.statements.length;
|
|
92963
|
+
if (useDefineForClassFields) {
|
|
92964
|
+
statements = statements.filter(function (statement) { return !ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor); });
|
|
92894
92965
|
}
|
|
92895
|
-
|
|
92896
|
-
|
|
92897
|
-
|
|
92966
|
+
else {
|
|
92967
|
+
for (var _i = 0, _b = constructor.body.statements; _i < _b.length; _i++) {
|
|
92968
|
+
var statement = _b[_i];
|
|
92969
|
+
if (ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor)) {
|
|
92970
|
+
parameterPropertyDeclarationCount++;
|
|
92971
|
+
}
|
|
92972
|
+
}
|
|
92973
|
+
if (parameterPropertyDeclarationCount > 0) {
|
|
92974
|
+
var parameterProperties = ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, indexOfFirstStatementAfterSuper, parameterPropertyDeclarationCount);
|
|
92975
|
+
// If there was a super() call found, add parameter properties immediately after it
|
|
92976
|
+
if (superStatementIndex >= 0) {
|
|
92977
|
+
ts.addRange(statements, parameterProperties);
|
|
92978
|
+
}
|
|
92979
|
+
// If a synthetic super() call was added, add them just after it
|
|
92980
|
+
else if (needsSyntheticConstructor) {
|
|
92981
|
+
statements = __spreadArray(__spreadArray([
|
|
92982
|
+
statements[0]
|
|
92983
|
+
], parameterProperties, true), statements.slice(1), true);
|
|
92984
|
+
}
|
|
92985
|
+
// Since there wasn't a super() call, add them to the top of the constructor
|
|
92986
|
+
else {
|
|
92987
|
+
statements = __spreadArray(__spreadArray([], parameterProperties, true), statements, true);
|
|
92988
|
+
}
|
|
92989
|
+
indexOfFirstStatementAfterSuper += parameterPropertyDeclarationCount;
|
|
92898
92990
|
}
|
|
92899
|
-
indexOfFirstStatement = afterParameterProperties;
|
|
92900
92991
|
}
|
|
92901
92992
|
}
|
|
92902
92993
|
var receiver = factory.createThis();
|
|
92903
92994
|
// private methods can be called in property initializers, they should execute first.
|
|
92904
92995
|
addMethodStatements(statements, privateMethodsAndAccessors, receiver);
|
|
92905
92996
|
addPropertyOrClassStaticBlockStatements(statements, properties, receiver);
|
|
92906
|
-
// Add existing statements
|
|
92997
|
+
// Add existing statements after the initial prologues and super call
|
|
92907
92998
|
if (constructor) {
|
|
92908
|
-
ts.addRange(statements, ts.visitNodes(constructor.body.statements,
|
|
92999
|
+
ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitBodyStatement, ts.isStatement, indexOfFirstStatementAfterSuper + prologueStatementCount));
|
|
92909
93000
|
}
|
|
92910
93001
|
statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
|
|
92911
93002
|
return ts.setTextRange(factory.createBlock(ts.setTextRange(factory.createNodeArray(statements),
|
|
92912
93003
|
/*location*/ constructor ? constructor.body.statements : node.members),
|
|
92913
93004
|
/*multiLine*/ true),
|
|
92914
93005
|
/*location*/ constructor ? constructor.body : undefined);
|
|
93006
|
+
function visitBodyStatement(statement) {
|
|
93007
|
+
if (useDefineForClassFields && ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor)) {
|
|
93008
|
+
return undefined;
|
|
93009
|
+
}
|
|
93010
|
+
return visitor(statement);
|
|
93011
|
+
}
|
|
92915
93012
|
}
|
|
92916
93013
|
/**
|
|
92917
93014
|
* Generates assignment statements for property initializers.
|
|
@@ -96703,37 +96800,39 @@ var ts;
|
|
|
96703
96800
|
var prologue = [];
|
|
96704
96801
|
var statements = [];
|
|
96705
96802
|
resumeLexicalEnvironment();
|
|
96803
|
+
// In derived classes, there may be code before the necessary super() call
|
|
96804
|
+
// We'll remove pre-super statements to be tacked on after the rest of the body
|
|
96805
|
+
var existingPrologue = ts.takeWhile(constructor.body.statements, ts.isPrologueDirective);
|
|
96806
|
+
var _a = findSuperCallAndStatementIndex(constructor.body.statements, existingPrologue), superCall = _a.superCall, superStatementIndex = _a.superStatementIndex;
|
|
96807
|
+
var postSuperStatementsStart = superStatementIndex === -1 ? existingPrologue.length : superStatementIndex + 1;
|
|
96706
96808
|
// If a super call has already been synthesized,
|
|
96707
96809
|
// we're going to assume that we should just transform everything after that.
|
|
96708
96810
|
// The assumption is that no prior step in the pipeline has added any prologue directives.
|
|
96709
|
-
var statementOffset =
|
|
96811
|
+
var statementOffset = postSuperStatementsStart;
|
|
96710
96812
|
if (!hasSynthesizedSuper)
|
|
96711
|
-
statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, /*ensureUseStrict*/ false);
|
|
96712
|
-
addDefaultValueAssignmentsIfNeeded(statements, constructor);
|
|
96713
|
-
addRestParameterIfNeeded(statements, constructor, hasSynthesizedSuper);
|
|
96813
|
+
statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, statementOffset, /*ensureUseStrict*/ false);
|
|
96714
96814
|
if (!hasSynthesizedSuper)
|
|
96715
|
-
statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor);
|
|
96716
|
-
// If
|
|
96815
|
+
statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor, /*filter*/ undefined);
|
|
96816
|
+
// If there already exists a call to `super()`, visit the statement directly
|
|
96717
96817
|
var superCallExpression;
|
|
96718
96818
|
if (hasSynthesizedSuper) {
|
|
96719
96819
|
superCallExpression = createDefaultSuperCallOrThis();
|
|
96720
96820
|
}
|
|
96721
|
-
else if (
|
|
96722
|
-
|
|
96723
|
-
if (ts.isExpressionStatement(firstStatement) && ts.isSuperCall(firstStatement.expression)) {
|
|
96724
|
-
superCallExpression = visitImmediateSuperCallInBody(firstStatement.expression);
|
|
96725
|
-
}
|
|
96821
|
+
else if (superCall) {
|
|
96822
|
+
superCallExpression = visitSuperCallInBody(superCall);
|
|
96726
96823
|
}
|
|
96727
96824
|
if (superCallExpression) {
|
|
96728
96825
|
hierarchyFacts |= 8192 /* ConstructorWithCapturedSuper */;
|
|
96729
|
-
statementOffset++; // skip this statement, we will add it after visiting the rest of the body.
|
|
96730
96826
|
}
|
|
96827
|
+
// Add parameter defaults at the beginning of the output, with prologue statements
|
|
96828
|
+
addDefaultValueAssignmentsIfNeeded(prologue, constructor);
|
|
96829
|
+
addRestParameterIfNeeded(prologue, constructor, hasSynthesizedSuper);
|
|
96731
96830
|
// visit the remaining statements
|
|
96732
96831
|
ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, /*start*/ statementOffset));
|
|
96733
96832
|
factory.mergeLexicalEnvironment(prologue, endLexicalEnvironment());
|
|
96734
96833
|
insertCaptureNewTargetIfNeeded(prologue, constructor, /*copyOnWrite*/ false);
|
|
96735
|
-
if (isDerivedClass) {
|
|
96736
|
-
if (superCallExpression &&
|
|
96834
|
+
if (isDerivedClass || superCallExpression) {
|
|
96835
|
+
if (superCallExpression && postSuperStatementsStart === constructor.body.statements.length && !(constructor.body.transformFlags & 8192 /* ContainsLexicalThis */)) {
|
|
96737
96836
|
// If the subclass constructor does *not* contain `this` and *ends* with a `super()` call, we will use the
|
|
96738
96837
|
// following representation:
|
|
96739
96838
|
//
|
|
@@ -96753,10 +96852,10 @@ var ts;
|
|
|
96753
96852
|
// return C;
|
|
96754
96853
|
// })(Base);
|
|
96755
96854
|
// ```
|
|
96756
|
-
var
|
|
96855
|
+
var superCall_1 = ts.cast(ts.cast(superCallExpression, ts.isBinaryExpression).left, ts.isCallExpression);
|
|
96757
96856
|
var returnStatement = factory.createReturnStatement(superCallExpression);
|
|
96758
|
-
ts.setCommentRange(returnStatement, ts.getCommentRange(
|
|
96759
|
-
ts.setEmitFlags(
|
|
96857
|
+
ts.setCommentRange(returnStatement, ts.getCommentRange(superCall_1));
|
|
96858
|
+
ts.setEmitFlags(superCall_1, 1536 /* NoComments */);
|
|
96760
96859
|
statements.push(returnStatement);
|
|
96761
96860
|
}
|
|
96762
96861
|
else {
|
|
@@ -96781,9 +96880,19 @@ var ts;
|
|
|
96781
96880
|
// return C;
|
|
96782
96881
|
// })(Base);
|
|
96783
96882
|
// ```
|
|
96784
|
-
//
|
|
96785
|
-
|
|
96786
|
-
|
|
96883
|
+
// If the super() call is the first statement, we can directly create and assign its result to `_this`
|
|
96884
|
+
if (superStatementIndex <= existingPrologue.length) {
|
|
96885
|
+
insertCaptureThisForNode(statements, constructor, superCallExpression || createActualThis());
|
|
96886
|
+
}
|
|
96887
|
+
// Since the `super()` call isn't the first statement, it's split across 1-2 statements:
|
|
96888
|
+
// * A prologue `var _this = this;`, in case the constructor accesses this before super()
|
|
96889
|
+
// * If it exists, a reassignment to that `_this` of the super() call
|
|
96890
|
+
else {
|
|
96891
|
+
insertCaptureThisForNode(prologue, constructor, createActualThis());
|
|
96892
|
+
if (superCallExpression) {
|
|
96893
|
+
insertSuperThisCaptureThisForNode(statements, superCallExpression);
|
|
96894
|
+
}
|
|
96895
|
+
}
|
|
96787
96896
|
if (!isSufficientlyCoveredByReturnStatements(constructor.body)) {
|
|
96788
96897
|
statements.push(factory.createReturnStatement(factory.createUniqueName("_this", 16 /* Optimistic */ | 32 /* FileLevel */)));
|
|
96789
96898
|
}
|
|
@@ -96806,11 +96915,27 @@ var ts;
|
|
|
96806
96915
|
// ```
|
|
96807
96916
|
insertCaptureThisForNodeIfNeeded(prologue, constructor);
|
|
96808
96917
|
}
|
|
96809
|
-
var
|
|
96918
|
+
var body = factory.createBlock(ts.setTextRange(factory.createNodeArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], existingPrologue, true), prologue, true), (superStatementIndex <= existingPrologue.length ? ts.emptyArray : ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, existingPrologue.length, superStatementIndex)), true), statements, true)),
|
|
96810
96919
|
/*location*/ constructor.body.statements),
|
|
96811
96920
|
/*multiLine*/ true);
|
|
96812
|
-
ts.setTextRange(
|
|
96813
|
-
return
|
|
96921
|
+
ts.setTextRange(body, constructor.body);
|
|
96922
|
+
return body;
|
|
96923
|
+
}
|
|
96924
|
+
function findSuperCallAndStatementIndex(originalBodyStatements, existingPrologue) {
|
|
96925
|
+
for (var i = existingPrologue.length; i < originalBodyStatements.length; i += 1) {
|
|
96926
|
+
var superCall = ts.getSuperCallFromStatement(originalBodyStatements[i]);
|
|
96927
|
+
if (superCall) {
|
|
96928
|
+
// With a super() call, split the statements into pre-super() and 'body' (post-super())
|
|
96929
|
+
return {
|
|
96930
|
+
superCall: superCall,
|
|
96931
|
+
superStatementIndex: i,
|
|
96932
|
+
};
|
|
96933
|
+
}
|
|
96934
|
+
}
|
|
96935
|
+
// Since there was no super() call found, consider all statements to be in the main 'body' (post-super())
|
|
96936
|
+
return {
|
|
96937
|
+
superStatementIndex: -1,
|
|
96938
|
+
};
|
|
96814
96939
|
}
|
|
96815
96940
|
/**
|
|
96816
96941
|
* We want to try to avoid emitting a return statement in certain cases if a user already returned something.
|
|
@@ -97039,6 +97164,18 @@ var ts;
|
|
|
97039
97164
|
}
|
|
97040
97165
|
return false;
|
|
97041
97166
|
}
|
|
97167
|
+
/**
|
|
97168
|
+
* Assigns the `this` in a constructor to the result of its `super()` call.
|
|
97169
|
+
*
|
|
97170
|
+
* @param statements Statements in the constructor body.
|
|
97171
|
+
* @param superExpression Existing `super()` call for the constructor.
|
|
97172
|
+
*/
|
|
97173
|
+
function insertSuperThisCaptureThisForNode(statements, superExpression) {
|
|
97174
|
+
enableSubstitutionsForCapturedThis();
|
|
97175
|
+
var assignSuperExpression = factory.createExpressionStatement(factory.createBinaryExpression(factory.createThis(), 63 /* EqualsToken */, superExpression));
|
|
97176
|
+
ts.insertStatementAfterCustomPrologue(statements, assignSuperExpression);
|
|
97177
|
+
ts.setCommentRange(assignSuperExpression, ts.getOriginalNode(superExpression).parent);
|
|
97178
|
+
}
|
|
97042
97179
|
function insertCaptureThisForNode(statements, node, initializer) {
|
|
97043
97180
|
enableSubstitutionsForCapturedThis();
|
|
97044
97181
|
var captureThisStatement = factory.createVariableStatement(
|
|
@@ -97348,7 +97485,7 @@ var ts;
|
|
|
97348
97485
|
if (ts.isBlock(body)) {
|
|
97349
97486
|
// ensureUseStrict is false because no new prologue-directive should be added.
|
|
97350
97487
|
// addStandardPrologue will put already-existing directives at the beginning of the target statement-array
|
|
97351
|
-
statementOffset = factory.copyStandardPrologue(body.statements, prologue, /*ensureUseStrict*/ false);
|
|
97488
|
+
statementOffset = factory.copyStandardPrologue(body.statements, prologue, 0, /*ensureUseStrict*/ false);
|
|
97352
97489
|
statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedFunction);
|
|
97353
97490
|
statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedVariableStatement);
|
|
97354
97491
|
}
|
|
@@ -98719,7 +98856,7 @@ var ts;
|
|
|
98719
98856
|
/*type*/ undefined, factory.updateBlock(func.body, statements))),
|
|
98720
98857
|
/*typeArguments*/ undefined, call.arguments))));
|
|
98721
98858
|
}
|
|
98722
|
-
function
|
|
98859
|
+
function visitSuperCallInBody(node) {
|
|
98723
98860
|
return visitCallExpressionWithPotentialCapturedThisAssignment(node, /*assignToCapturedThis*/ false);
|
|
98724
98861
|
}
|
|
98725
98862
|
function visitCallExpressionWithPotentialCapturedThisAssignment(node, assignToCapturedThis) {
|
|
@@ -128976,7 +129113,7 @@ var ts;
|
|
|
128976
129113
|
return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
|
|
128977
129114
|
}
|
|
128978
129115
|
function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext) {
|
|
128979
|
-
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;
|
|
129116
|
+
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, isRightOfOpenTag = completionData.isRightOfOpenTag, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
|
|
128980
129117
|
// Verify if the file is JSX language variant
|
|
128981
129118
|
if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
|
|
128982
129119
|
var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
|
|
@@ -128987,7 +129124,7 @@ var ts;
|
|
|
128987
129124
|
var entries = ts.createSortedArray();
|
|
128988
129125
|
if (isUncheckedFile(sourceFile, compilerOptions)) {
|
|
128989
129126
|
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
|
|
128990
|
-
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
129127
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
|
|
128991
129128
|
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
|
|
128992
129129
|
}
|
|
128993
129130
|
else {
|
|
@@ -128995,7 +129132,7 @@ var ts;
|
|
|
128995
129132
|
return undefined;
|
|
128996
129133
|
}
|
|
128997
129134
|
getCompletionEntriesFromSymbols(symbols, entries,
|
|
128998
|
-
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
129135
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
|
|
128999
129136
|
}
|
|
129000
129137
|
if (keywordFilters !== 0 /* None */) {
|
|
129001
129138
|
var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
|
|
@@ -129101,7 +129238,7 @@ var ts;
|
|
|
129101
129238
|
function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
|
|
129102
129239
|
return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
|
|
129103
129240
|
}
|
|
129104
|
-
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext) {
|
|
129241
|
+
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag) {
|
|
129105
129242
|
var _a, _b;
|
|
129106
129243
|
var insertText;
|
|
129107
129244
|
var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
|
|
@@ -129172,8 +129309,7 @@ var ts;
|
|
|
129172
129309
|
source = CompletionSource.ClassMemberSnippet;
|
|
129173
129310
|
}
|
|
129174
129311
|
}
|
|
129175
|
-
|
|
129176
|
-
if (kind === "JSX attribute" /* jsxAttribute */ && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
|
|
129312
|
+
if (isJsxIdentifierExpected && !isRightOfOpenTag && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
|
|
129177
129313
|
var useBraces_1 = preferences.jsxAttributeCompletionStyle === "braces";
|
|
129178
129314
|
var type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
|
|
129179
129315
|
// If is boolean like or undefined, don't return a snippet we want just to return the completion.
|
|
@@ -129211,7 +129347,7 @@ var ts;
|
|
|
129211
129347
|
// entries (like JavaScript identifier entries).
|
|
129212
129348
|
return {
|
|
129213
129349
|
name: name,
|
|
129214
|
-
kind:
|
|
129350
|
+
kind: ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, location),
|
|
129215
129351
|
kindModifiers: ts.SymbolDisplay.getSymbolModifiers(typeChecker, symbol),
|
|
129216
129352
|
sortText: sortText,
|
|
129217
129353
|
source: source,
|
|
@@ -129507,7 +129643,7 @@ var ts;
|
|
|
129507
129643
|
return CompletionSource.ThisProperty;
|
|
129508
129644
|
}
|
|
129509
129645
|
}
|
|
129510
|
-
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
129646
|
+
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag) {
|
|
129511
129647
|
var _a;
|
|
129512
129648
|
var start = ts.timestamp();
|
|
129513
129649
|
var variableDeclaration = getVariableDeclaration(location);
|
|
@@ -129528,7 +129664,7 @@ var ts;
|
|
|
129528
129664
|
var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
|
|
129529
129665
|
var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
|
|
129530
129666
|
var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
|
|
129531
|
-
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, formatContext);
|
|
129667
|
+
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag);
|
|
129532
129668
|
if (!entry) {
|
|
129533
129669
|
continue;
|
|
129534
129670
|
}
|
|
@@ -130122,6 +130258,7 @@ var ts;
|
|
|
130122
130258
|
symbolToSortTextIdMap: symbolToSortTextIdMap,
|
|
130123
130259
|
isTypeOnlyLocation: isTypeOnlyLocation,
|
|
130124
130260
|
isJsxIdentifierExpected: isJsxIdentifierExpected,
|
|
130261
|
+
isRightOfOpenTag: isRightOfOpenTag,
|
|
130125
130262
|
importCompletionNode: importCompletionNode,
|
|
130126
130263
|
hasUnresolvedAutoImports: hasUnresolvedAutoImports,
|
|
130127
130264
|
};
|
|
@@ -145101,7 +145238,11 @@ var ts;
|
|
|
145101
145238
|
oldTags[i] = merged;
|
|
145102
145239
|
return !!merged;
|
|
145103
145240
|
}); });
|
|
145104
|
-
var
|
|
145241
|
+
var tags = __spreadArray(__spreadArray([], oldTags, true), unmergedNewTags, true);
|
|
145242
|
+
var jsDoc = ts.singleOrUndefined(parent.jsDoc);
|
|
145243
|
+
var comment = jsDoc && ts.positionsAreOnSameLine(jsDoc.pos, jsDoc.end, sourceFile) && !ts.length(comments) ? undefined :
|
|
145244
|
+
ts.factory.createNodeArray(ts.intersperse(comments, ts.factory.createJSDocText("\n")));
|
|
145245
|
+
var tag = ts.factory.createJSDocComment(comment, ts.factory.createNodeArray(tags));
|
|
145105
145246
|
var host = updateJSDocHost(parent);
|
|
145106
145247
|
this.insertJsdocCommentBefore(sourceFile, host, tag);
|
|
145107
145248
|
};
|
|
@@ -145531,6 +145672,8 @@ var ts;
|
|
|
145531
145672
|
}
|
|
145532
145673
|
case 339 /* JSDocReturnTag */:
|
|
145533
145674
|
return ts.factory.createJSDocReturnTag(/*tagName*/ undefined, newTag.typeExpression, oldTag.comment);
|
|
145675
|
+
case 341 /* JSDocTypeTag */:
|
|
145676
|
+
return ts.factory.createJSDocTypeTag(/*tagName*/ undefined, newTag.typeExpression, oldTag.comment);
|
|
145534
145677
|
}
|
|
145535
145678
|
}
|
|
145536
145679
|
// find first non-whitespace position in the leading trivia of the node
|
|
@@ -146231,20 +146374,31 @@ var ts;
|
|
|
146231
146374
|
codefix.registerCodeFix({
|
|
146232
146375
|
errorCodes: errorCodes,
|
|
146233
146376
|
getCodeActions: function getCodeActionsToAddConvertToUnknownForNonOverlappingTypes(context) {
|
|
146234
|
-
var
|
|
146377
|
+
var assertion = getAssertion(context.sourceFile, context.span.start);
|
|
146378
|
+
if (assertion === undefined)
|
|
146379
|
+
return undefined;
|
|
146380
|
+
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return makeChange(t, context.sourceFile, assertion); });
|
|
146235
146381
|
return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_unknown_conversion_for_non_overlapping_types, fixId, ts.Diagnostics.Add_unknown_to_all_conversions_of_non_overlapping_types)];
|
|
146236
146382
|
},
|
|
146237
146383
|
fixIds: [fixId],
|
|
146238
|
-
getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
|
|
146384
|
+
getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
|
|
146385
|
+
var assertion = getAssertion(diag.file, diag.start);
|
|
146386
|
+
if (assertion) {
|
|
146387
|
+
makeChange(changes, diag.file, assertion);
|
|
146388
|
+
}
|
|
146389
|
+
}); },
|
|
146239
146390
|
});
|
|
146240
|
-
function makeChange(changeTracker, sourceFile,
|
|
146241
|
-
var token = ts.getTokenAtPosition(sourceFile, pos);
|
|
146242
|
-
var assertion = ts.Debug.checkDefined(ts.findAncestor(token, function (n) { return ts.isAsExpression(n) || ts.isTypeAssertionExpression(n); }), "Expected to find an assertion expression");
|
|
146391
|
+
function makeChange(changeTracker, sourceFile, assertion) {
|
|
146243
146392
|
var replacement = ts.isAsExpression(assertion)
|
|
146244
146393
|
? ts.factory.createAsExpression(assertion.expression, ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */))
|
|
146245
146394
|
: ts.factory.createTypeAssertion(ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */), assertion.expression);
|
|
146246
146395
|
changeTracker.replaceNode(sourceFile, assertion.expression, replacement);
|
|
146247
146396
|
}
|
|
146397
|
+
function getAssertion(sourceFile, pos) {
|
|
146398
|
+
if (ts.isInJSFile(sourceFile))
|
|
146399
|
+
return undefined;
|
|
146400
|
+
return ts.findAncestor(ts.getTokenAtPosition(sourceFile, pos), function (n) { return ts.isAsExpression(n) || ts.isTypeAssertionExpression(n); });
|
|
146401
|
+
}
|
|
146248
146402
|
})(codefix = ts.codefix || (ts.codefix = {}));
|
|
146249
146403
|
})(ts || (ts = {}));
|
|
146250
146404
|
/* @internal */
|
|
@@ -149362,10 +149516,15 @@ var ts;
|
|
|
149362
149516
|
if (a.kind !== 0 /* UseNamespace */ && b.kind !== 0 /* UseNamespace */) {
|
|
149363
149517
|
return ts.compareBooleans(allowsImportingSpecifier(b.moduleSpecifier), allowsImportingSpecifier(a.moduleSpecifier))
|
|
149364
149518
|
|| compareNodeCoreModuleSpecifiers(a.moduleSpecifier, b.moduleSpecifier, importingFile, program)
|
|
149519
|
+
|| ts.compareBooleans(isOnlyDotsAndSlashes(a.moduleSpecifier), isOnlyDotsAndSlashes(b.moduleSpecifier))
|
|
149365
149520
|
|| ts.compareNumberOfDirectorySeparators(a.moduleSpecifier, b.moduleSpecifier);
|
|
149366
149521
|
}
|
|
149367
149522
|
return 0 /* EqualTo */;
|
|
149368
149523
|
}
|
|
149524
|
+
var notDotOrSlashPattern = /[^.\/]/;
|
|
149525
|
+
function isOnlyDotsAndSlashes(path) {
|
|
149526
|
+
return !notDotOrSlashPattern.test(path);
|
|
149527
|
+
}
|
|
149369
149528
|
function compareNodeCoreModuleSpecifiers(a, b, importingFile, program) {
|
|
149370
149529
|
if (ts.startsWith(a, "node:") && !ts.startsWith(b, "node:"))
|
|
149371
149530
|
return ts.shouldUseUriStyleNodeCoreModules(importingFile, program) ? -1 /* LessThan */ : 1 /* GreaterThan */;
|
|
@@ -153978,35 +154137,34 @@ var ts;
|
|
|
153978
154137
|
codefix.registerCodeFix({
|
|
153979
154138
|
errorCodes: errorCodes,
|
|
153980
154139
|
getCodeActions: function getCodeActionsForStrictClassInitializationErrors(context) {
|
|
153981
|
-
var
|
|
153982
|
-
if (!
|
|
154140
|
+
var info = getInfo(context.sourceFile, context.span.start);
|
|
154141
|
+
if (!info)
|
|
153983
154142
|
return;
|
|
153984
|
-
var result = [
|
|
153985
|
-
|
|
153986
|
-
|
|
153987
|
-
|
|
153988
|
-
ts.append(result, getActionForAddMissingInitializer(context, propertyDeclaration));
|
|
154143
|
+
var result = [];
|
|
154144
|
+
ts.append(result, getActionForAddMissingUndefinedType(context, info));
|
|
154145
|
+
ts.append(result, getActionForAddMissingDefiniteAssignmentAssertion(context, info));
|
|
154146
|
+
ts.append(result, getActionForAddMissingInitializer(context, info));
|
|
153989
154147
|
return result;
|
|
153990
154148
|
},
|
|
153991
154149
|
fixIds: [fixIdAddDefiniteAssignmentAssertions, fixIdAddUndefinedType, fixIdAddInitializer],
|
|
153992
154150
|
getAllCodeActions: function (context) {
|
|
153993
154151
|
return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
|
|
153994
|
-
var
|
|
153995
|
-
if (!
|
|
154152
|
+
var info = getInfo(diag.file, diag.start);
|
|
154153
|
+
if (!info)
|
|
153996
154154
|
return;
|
|
153997
154155
|
switch (context.fixId) {
|
|
153998
154156
|
case fixIdAddDefiniteAssignmentAssertions:
|
|
153999
|
-
addDefiniteAssignmentAssertion(changes, diag.file,
|
|
154157
|
+
addDefiniteAssignmentAssertion(changes, diag.file, info.prop);
|
|
154000
154158
|
break;
|
|
154001
154159
|
case fixIdAddUndefinedType:
|
|
154002
|
-
addUndefinedType(changes, diag.file,
|
|
154160
|
+
addUndefinedType(changes, diag.file, info);
|
|
154003
154161
|
break;
|
|
154004
154162
|
case fixIdAddInitializer:
|
|
154005
154163
|
var checker = context.program.getTypeChecker();
|
|
154006
|
-
var initializer = getInitializer(checker,
|
|
154164
|
+
var initializer = getInitializer(checker, info.prop);
|
|
154007
154165
|
if (!initializer)
|
|
154008
154166
|
return;
|
|
154009
|
-
addInitializer(changes, diag.file,
|
|
154167
|
+
addInitializer(changes, diag.file, info.prop, initializer);
|
|
154010
154168
|
break;
|
|
154011
154169
|
default:
|
|
154012
154170
|
ts.Debug.fail(JSON.stringify(context.fixId));
|
|
@@ -154014,35 +154172,50 @@ var ts;
|
|
|
154014
154172
|
});
|
|
154015
154173
|
},
|
|
154016
154174
|
});
|
|
154017
|
-
function
|
|
154175
|
+
function getInfo(sourceFile, pos) {
|
|
154018
154176
|
var token = ts.getTokenAtPosition(sourceFile, pos);
|
|
154019
|
-
|
|
154177
|
+
if (ts.isIdentifier(token) && ts.isPropertyDeclaration(token.parent)) {
|
|
154178
|
+
var type = ts.getEffectiveTypeAnnotationNode(token.parent);
|
|
154179
|
+
if (type) {
|
|
154180
|
+
return { type: type, prop: token.parent, isJs: ts.isInJSFile(token.parent) };
|
|
154181
|
+
}
|
|
154182
|
+
}
|
|
154183
|
+
return undefined;
|
|
154020
154184
|
}
|
|
154021
|
-
function getActionForAddMissingDefiniteAssignmentAssertion(context,
|
|
154022
|
-
|
|
154023
|
-
|
|
154185
|
+
function getActionForAddMissingDefiniteAssignmentAssertion(context, info) {
|
|
154186
|
+
if (info.isJs)
|
|
154187
|
+
return undefined;
|
|
154188
|
+
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addDefiniteAssignmentAssertion(t, context.sourceFile, info.prop); });
|
|
154189
|
+
return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_definite_assignment_assertion_to_property_0, info.prop.getText()], fixIdAddDefiniteAssignmentAssertions, ts.Diagnostics.Add_definite_assignment_assertions_to_all_uninitialized_properties);
|
|
154024
154190
|
}
|
|
154025
154191
|
function addDefiniteAssignmentAssertion(changeTracker, propertyDeclarationSourceFile, propertyDeclaration) {
|
|
154026
154192
|
var property = ts.factory.updatePropertyDeclaration(propertyDeclaration, propertyDeclaration.decorators, propertyDeclaration.modifiers, propertyDeclaration.name, ts.factory.createToken(53 /* ExclamationToken */), propertyDeclaration.type, propertyDeclaration.initializer);
|
|
154027
154193
|
changeTracker.replaceNode(propertyDeclarationSourceFile, propertyDeclaration, property);
|
|
154028
154194
|
}
|
|
154029
|
-
function getActionForAddMissingUndefinedType(context,
|
|
154030
|
-
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addUndefinedType(t, context.sourceFile,
|
|
154031
|
-
return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_undefined_type_to_property_0,
|
|
154195
|
+
function getActionForAddMissingUndefinedType(context, info) {
|
|
154196
|
+
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addUndefinedType(t, context.sourceFile, info); });
|
|
154197
|
+
return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_undefined_type_to_property_0, info.prop.name.getText()], fixIdAddUndefinedType, ts.Diagnostics.Add_undefined_type_to_all_uninitialized_properties);
|
|
154032
154198
|
}
|
|
154033
|
-
function addUndefinedType(changeTracker,
|
|
154199
|
+
function addUndefinedType(changeTracker, sourceFile, info) {
|
|
154034
154200
|
var undefinedTypeNode = ts.factory.createKeywordTypeNode(152 /* UndefinedKeyword */);
|
|
154035
|
-
var
|
|
154036
|
-
var
|
|
154037
|
-
|
|
154201
|
+
var types = ts.isUnionTypeNode(info.type) ? info.type.types.concat(undefinedTypeNode) : [info.type, undefinedTypeNode];
|
|
154202
|
+
var unionTypeNode = ts.factory.createUnionTypeNode(types);
|
|
154203
|
+
if (info.isJs) {
|
|
154204
|
+
changeTracker.addJSDocTags(sourceFile, info.prop, [ts.factory.createJSDocTypeTag(/*tagName*/ undefined, ts.factory.createJSDocTypeExpression(unionTypeNode))]);
|
|
154205
|
+
}
|
|
154206
|
+
else {
|
|
154207
|
+
changeTracker.replaceNode(sourceFile, info.type, unionTypeNode);
|
|
154208
|
+
}
|
|
154038
154209
|
}
|
|
154039
|
-
function getActionForAddMissingInitializer(context,
|
|
154210
|
+
function getActionForAddMissingInitializer(context, info) {
|
|
154211
|
+
if (info.isJs)
|
|
154212
|
+
return undefined;
|
|
154040
154213
|
var checker = context.program.getTypeChecker();
|
|
154041
|
-
var initializer = getInitializer(checker,
|
|
154214
|
+
var initializer = getInitializer(checker, info.prop);
|
|
154042
154215
|
if (!initializer)
|
|
154043
154216
|
return undefined;
|
|
154044
|
-
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addInitializer(t, context.sourceFile,
|
|
154045
|
-
return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_initializer_to_property_0,
|
|
154217
|
+
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addInitializer(t, context.sourceFile, info.prop, initializer); });
|
|
154218
|
+
return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_initializer_to_property_0, info.prop.name.getText()], fixIdAddInitializer, ts.Diagnostics.Add_initializers_to_all_uninitialized_properties);
|
|
154046
154219
|
}
|
|
154047
154220
|
function addInitializer(changeTracker, propertyDeclarationSourceFile, propertyDeclaration, initializer) {
|
|
154048
154221
|
var property = ts.factory.updatePropertyDeclaration(propertyDeclaration, propertyDeclaration.decorators, propertyDeclaration.modifiers, propertyDeclaration.name, propertyDeclaration.questionToken, propertyDeclaration.type, initializer);
|