typescript 4.6.0-dev.20220112 → 4.6.0-dev.20220116
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 +187 -77
- package/lib/tsserver.js +264 -110
- package/lib/tsserverlibrary.js +264 -110
- package/lib/typescript.js +264 -110
- package/lib/typescriptServices.js +264 -110
- package/lib/typingsInstaller.js +234 -96
- package/package.json +1 -1
package/lib/typingsInstaller.js
CHANGED
|
@@ -89,7 +89,7 @@ var ts;
|
|
|
89
89
|
// The following is baselined as a literal template type without intervention
|
|
90
90
|
/** The version of the TypeScript compiler release */
|
|
91
91
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
92
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
92
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220116";
|
|
93
93
|
/* @internal */
|
|
94
94
|
var Comparison;
|
|
95
95
|
(function (Comparison) {
|
|
@@ -8277,7 +8277,7 @@ var ts;
|
|
|
8277
8277
|
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."),
|
|
8278
8278
|
Duplicate_index_signature_for_type_0: diag(2374, ts.DiagnosticCategory.Error, "Duplicate_index_signature_for_type_0_2374", "Duplicate index signature for type '{0}'."),
|
|
8279
8279
|
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."),
|
|
8280
|
-
|
|
8280
|
+
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."),
|
|
8281
8281
|
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."),
|
|
8282
8282
|
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."),
|
|
8283
8283
|
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."),
|
|
@@ -8300,6 +8300,7 @@ var ts;
|
|
|
8300
8300
|
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."),
|
|
8301
8301
|
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."),
|
|
8302
8302
|
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."),
|
|
8303
|
+
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."),
|
|
8303
8304
|
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."),
|
|
8304
8305
|
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}'."),
|
|
8305
8306
|
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."),
|
|
@@ -15460,6 +15461,34 @@ var ts;
|
|
|
15460
15461
|
}
|
|
15461
15462
|
}
|
|
15462
15463
|
ts.getThisContainer = getThisContainer;
|
|
15464
|
+
/**
|
|
15465
|
+
* @returns Whether the node creates a new 'this' scope for its children.
|
|
15466
|
+
*/
|
|
15467
|
+
function isThisContainerOrFunctionBlock(node) {
|
|
15468
|
+
switch (node.kind) {
|
|
15469
|
+
// Arrow functions use the same scope, but may do so in a "delayed" manner
|
|
15470
|
+
// For example, `const getThis = () => this` may be before a super() call in a derived constructor
|
|
15471
|
+
case 213 /* ArrowFunction */:
|
|
15472
|
+
case 255 /* FunctionDeclaration */:
|
|
15473
|
+
case 212 /* FunctionExpression */:
|
|
15474
|
+
case 166 /* PropertyDeclaration */:
|
|
15475
|
+
return true;
|
|
15476
|
+
case 234 /* Block */:
|
|
15477
|
+
switch (node.parent.kind) {
|
|
15478
|
+
case 170 /* Constructor */:
|
|
15479
|
+
case 168 /* MethodDeclaration */:
|
|
15480
|
+
case 171 /* GetAccessor */:
|
|
15481
|
+
case 172 /* SetAccessor */:
|
|
15482
|
+
// Object properties can have computed names; only method-like bodies start a new scope
|
|
15483
|
+
return true;
|
|
15484
|
+
default:
|
|
15485
|
+
return false;
|
|
15486
|
+
}
|
|
15487
|
+
default:
|
|
15488
|
+
return false;
|
|
15489
|
+
}
|
|
15490
|
+
}
|
|
15491
|
+
ts.isThisContainerOrFunctionBlock = isThisContainerOrFunctionBlock;
|
|
15463
15492
|
function isInTopLevelContext(node) {
|
|
15464
15493
|
// The name of a class or function declaration is a BindingIdentifier in its surrounding scope.
|
|
15465
15494
|
if (ts.isIdentifier(node) && (ts.isClassDeclaration(node.parent) || ts.isFunctionDeclaration(node.parent)) && node.parent.name === node) {
|
|
@@ -26046,7 +26075,7 @@ var ts;
|
|
|
26046
26075
|
* @param visitor Optional callback used to visit any custom prologue directives.
|
|
26047
26076
|
*/
|
|
26048
26077
|
function copyPrologue(source, target, ensureUseStrict, visitor) {
|
|
26049
|
-
var offset = copyStandardPrologue(source, target, ensureUseStrict);
|
|
26078
|
+
var offset = copyStandardPrologue(source, target, 0, ensureUseStrict);
|
|
26050
26079
|
return copyCustomPrologue(source, target, offset, visitor);
|
|
26051
26080
|
}
|
|
26052
26081
|
function isUseStrictPrologue(node) {
|
|
@@ -26059,12 +26088,14 @@ var ts;
|
|
|
26059
26088
|
* Copies only the standard (string-expression) prologue-directives into the target statement-array.
|
|
26060
26089
|
* @param source origin statements array
|
|
26061
26090
|
* @param target result statements array
|
|
26091
|
+
* @param statementOffset The offset at which to begin the copy.
|
|
26062
26092
|
* @param ensureUseStrict boolean determining whether the function need to add prologue-directives
|
|
26093
|
+
* @returns Count of how many directive statements were copied.
|
|
26063
26094
|
*/
|
|
26064
|
-
function copyStandardPrologue(source, target, ensureUseStrict) {
|
|
26095
|
+
function copyStandardPrologue(source, target, statementOffset, ensureUseStrict) {
|
|
26096
|
+
if (statementOffset === void 0) { statementOffset = 0; }
|
|
26065
26097
|
ts.Debug.assert(target.length === 0, "Prologue directives should be at the first statement in the target statements array");
|
|
26066
26098
|
var foundUseStrict = false;
|
|
26067
|
-
var statementOffset = 0;
|
|
26068
26099
|
var numStatements = source.length;
|
|
26069
26100
|
while (statementOffset < numStatements) {
|
|
26070
26101
|
var statement = source[statementOffset];
|
|
@@ -27487,7 +27518,7 @@ var ts;
|
|
|
27487
27518
|
importName: "__createBinding",
|
|
27488
27519
|
scoped: false,
|
|
27489
27520
|
priority: 1,
|
|
27490
|
-
text: "\n var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n Object.
|
|
27521
|
+
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 }));"
|
|
27491
27522
|
};
|
|
27492
27523
|
ts.setModuleDefaultHelper = {
|
|
27493
27524
|
name: "typescript:commonjscreatevalue",
|
|
@@ -41122,7 +41153,7 @@ var ts;
|
|
|
41122
41153
|
? 1 /* Recursive */ : 0 /* None */
|
|
41123
41154
|
};
|
|
41124
41155
|
}
|
|
41125
|
-
if (ts.isImplicitGlob(spec)) {
|
|
41156
|
+
if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) {
|
|
41126
41157
|
return {
|
|
41127
41158
|
key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec),
|
|
41128
41159
|
flags: 1 /* Recursive */
|
|
@@ -78507,32 +78538,38 @@ var ts;
|
|
|
78507
78538
|
if (classExtendsNull) {
|
|
78508
78539
|
error(superCall, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
|
|
78509
78540
|
}
|
|
78510
|
-
//
|
|
78511
|
-
// if both of the following are true:
|
|
78541
|
+
// A super call must be root-level in a constructor if both of the following are true:
|
|
78512
78542
|
// - The containing class is a derived class.
|
|
78513
78543
|
// - The constructor declares parameter properties
|
|
78514
78544
|
// or the containing class declares instance member variables with initializers.
|
|
78515
|
-
var
|
|
78545
|
+
var superCallShouldBeRootLevel = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
|
|
78516
78546
|
(ts.some(node.parent.members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
|
|
78517
78547
|
ts.some(node.parameters, function (p) { return ts.hasSyntacticModifier(p, 16476 /* ParameterPropertyModifier */); }));
|
|
78518
|
-
|
|
78519
|
-
|
|
78520
|
-
|
|
78521
|
-
|
|
78522
|
-
|
|
78523
|
-
|
|
78524
|
-
|
|
78525
|
-
|
|
78526
|
-
|
|
78527
|
-
|
|
78548
|
+
if (superCallShouldBeRootLevel) {
|
|
78549
|
+
// Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
|
|
78550
|
+
// See GH #8277
|
|
78551
|
+
if (!superCallIsRootLevelInConstructor(superCall, node.body)) {
|
|
78552
|
+
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);
|
|
78553
|
+
}
|
|
78554
|
+
// Skip past any prologue directives to check statements for referring to 'super' or 'this' before a super call
|
|
78555
|
+
else {
|
|
78556
|
+
var superCallStatement = void 0;
|
|
78557
|
+
for (var _i = 0, _a = node.body.statements; _i < _a.length; _i++) {
|
|
78558
|
+
var statement = _a[_i];
|
|
78559
|
+
if (ts.isExpressionStatement(statement) && ts.isSuperCall(ts.skipOuterExpressions(statement.expression))) {
|
|
78560
|
+
superCallStatement = statement;
|
|
78561
|
+
break;
|
|
78562
|
+
}
|
|
78563
|
+
if (!ts.isPrologueDirective(statement) && nodeImmediatelyReferencesSuperOrThis(statement)) {
|
|
78564
|
+
break;
|
|
78565
|
+
}
|
|
78528
78566
|
}
|
|
78529
|
-
|
|
78530
|
-
|
|
78567
|
+
// Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
|
|
78568
|
+
// See GH #8277
|
|
78569
|
+
if (superCallStatement === undefined) {
|
|
78570
|
+
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);
|
|
78531
78571
|
}
|
|
78532
78572
|
}
|
|
78533
|
-
if (!superCallStatement) {
|
|
78534
|
-
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);
|
|
78535
|
-
}
|
|
78536
78573
|
}
|
|
78537
78574
|
}
|
|
78538
78575
|
else if (!classExtendsNull) {
|
|
@@ -78540,6 +78577,19 @@ var ts;
|
|
|
78540
78577
|
}
|
|
78541
78578
|
}
|
|
78542
78579
|
}
|
|
78580
|
+
function superCallIsRootLevelInConstructor(superCall, body) {
|
|
78581
|
+
var superCallParent = ts.walkUpParenthesizedExpressions(superCall.parent);
|
|
78582
|
+
return ts.isExpressionStatement(superCallParent) && superCallParent.parent === body;
|
|
78583
|
+
}
|
|
78584
|
+
function nodeImmediatelyReferencesSuperOrThis(node) {
|
|
78585
|
+
if (node.kind === 106 /* SuperKeyword */ || node.kind === 108 /* ThisKeyword */) {
|
|
78586
|
+
return true;
|
|
78587
|
+
}
|
|
78588
|
+
if (ts.isThisContainerOrFunctionBlock(node)) {
|
|
78589
|
+
return false;
|
|
78590
|
+
}
|
|
78591
|
+
return !!ts.forEachChild(node, nodeImmediatelyReferencesSuperOrThis);
|
|
78592
|
+
}
|
|
78543
78593
|
function checkAccessorDeclaration(node) {
|
|
78544
78594
|
if (produceDiagnostics) {
|
|
78545
78595
|
// Grammar checking accessors
|
|
@@ -88662,34 +88712,31 @@ var ts;
|
|
|
88662
88712
|
}
|
|
88663
88713
|
ts.getNonAssignmentOperatorForCompoundAssignment = getNonAssignmentOperatorForCompoundAssignment;
|
|
88664
88714
|
/**
|
|
88665
|
-
*
|
|
88666
|
-
|
|
88667
|
-
|
|
88668
|
-
|
|
88669
|
-
|
|
88670
|
-
|
|
88715
|
+
* @returns Contained super() call from descending into the statement ignoring parentheses, if that call exists.
|
|
88716
|
+
*/
|
|
88717
|
+
function getSuperCallFromStatement(statement) {
|
|
88718
|
+
if (!ts.isExpressionStatement(statement)) {
|
|
88719
|
+
return undefined;
|
|
88720
|
+
}
|
|
88721
|
+
var expression = ts.skipParentheses(statement.expression);
|
|
88722
|
+
return ts.isSuperCall(expression)
|
|
88723
|
+
? expression
|
|
88724
|
+
: undefined;
|
|
88725
|
+
}
|
|
88726
|
+
ts.getSuperCallFromStatement = getSuperCallFromStatement;
|
|
88727
|
+
/**
|
|
88728
|
+
* @returns The index (after prologue statements) of a super call, or -1 if not found.
|
|
88671
88729
|
*/
|
|
88672
|
-
function
|
|
88673
|
-
|
|
88674
|
-
var
|
|
88675
|
-
|
|
88676
|
-
|
|
88677
|
-
if (index === statements.length) {
|
|
88678
|
-
// list contains nothing but prologue directives (or empty) - exit
|
|
88679
|
-
return index;
|
|
88680
|
-
}
|
|
88681
|
-
var superIndex = ts.findIndex(statements, function (s) { return ts.isExpressionStatement(s) && ts.isSuperCall(s.expression); }, index);
|
|
88682
|
-
if (superIndex > -1) {
|
|
88683
|
-
for (var i = index; i <= superIndex; i++) {
|
|
88684
|
-
result.push(ts.visitNode(statements[i], visitor, ts.isStatement));
|
|
88685
|
-
}
|
|
88686
|
-
return superIndex + 1;
|
|
88730
|
+
function findSuperStatementIndex(statements, indexAfterLastPrologueStatement) {
|
|
88731
|
+
for (var i = indexAfterLastPrologueStatement; i < statements.length; i += 1) {
|
|
88732
|
+
var statement = statements[i];
|
|
88733
|
+
if (getSuperCallFromStatement(statement)) {
|
|
88734
|
+
return i;
|
|
88687
88735
|
}
|
|
88688
|
-
return index;
|
|
88689
88736
|
}
|
|
88690
|
-
return
|
|
88737
|
+
return -1;
|
|
88691
88738
|
}
|
|
88692
|
-
ts.
|
|
88739
|
+
ts.findSuperStatementIndex = findSuperStatementIndex;
|
|
88693
88740
|
function getProperties(node, requireInitializer, isStatic) {
|
|
88694
88741
|
return ts.filter(node.members, function (m) { return isInitializedOrStaticProperty(m, requireInitializer, isStatic); });
|
|
88695
88742
|
}
|
|
@@ -90588,6 +90635,7 @@ var ts;
|
|
|
90588
90635
|
case 176 /* TypePredicate */:
|
|
90589
90636
|
case 133 /* BooleanKeyword */:
|
|
90590
90637
|
return factory.createIdentifier("Boolean");
|
|
90638
|
+
case 197 /* TemplateLiteralType */:
|
|
90591
90639
|
case 149 /* StringKeyword */:
|
|
90592
90640
|
return factory.createIdentifier("String");
|
|
90593
90641
|
case 147 /* ObjectKeyword */:
|
|
@@ -90926,10 +90974,14 @@ var ts;
|
|
|
90926
90974
|
return ts.visitFunctionBody(body, visitor, context);
|
|
90927
90975
|
}
|
|
90928
90976
|
var statements = [];
|
|
90929
|
-
var indexOfFirstStatement = 0;
|
|
90930
90977
|
resumeLexicalEnvironment();
|
|
90931
|
-
|
|
90932
|
-
|
|
90978
|
+
var indexAfterLastPrologueStatement = factory.copyPrologue(body.statements, statements, /*ensureUseStrict*/ false, visitor);
|
|
90979
|
+
var superStatementIndex = ts.findSuperStatementIndex(body.statements, indexAfterLastPrologueStatement);
|
|
90980
|
+
// If there was a super call, visit existing statements up to and including it
|
|
90981
|
+
if (superStatementIndex >= 0) {
|
|
90982
|
+
ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, indexAfterLastPrologueStatement, superStatementIndex + 1 - indexAfterLastPrologueStatement));
|
|
90983
|
+
}
|
|
90984
|
+
// Transform parameters into property assignments. Transforms this:
|
|
90933
90985
|
//
|
|
90934
90986
|
// constructor (public x, public y) {
|
|
90935
90987
|
// }
|
|
@@ -90941,9 +90993,17 @@ var ts;
|
|
|
90941
90993
|
// this.y = y;
|
|
90942
90994
|
// }
|
|
90943
90995
|
//
|
|
90944
|
-
|
|
90945
|
-
//
|
|
90946
|
-
|
|
90996
|
+
var parameterPropertyAssignments = ts.mapDefined(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment);
|
|
90997
|
+
// If there is a super() call, the parameter properties go immediately after it
|
|
90998
|
+
if (superStatementIndex >= 0) {
|
|
90999
|
+
ts.addRange(statements, parameterPropertyAssignments);
|
|
91000
|
+
}
|
|
91001
|
+
// Since there was no super() call, parameter properties are the first statements in the constructor
|
|
91002
|
+
else {
|
|
91003
|
+
statements = ts.addRange(parameterPropertyAssignments, statements);
|
|
91004
|
+
}
|
|
91005
|
+
// Add remaining statements from the body, skipping the super() call if it was found
|
|
91006
|
+
ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, superStatementIndex + 1));
|
|
90947
91007
|
// End the lexical environment.
|
|
90948
91008
|
statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
|
|
90949
91009
|
var block = factory.createBlock(ts.setTextRange(factory.createNodeArray(statements), body.statements), /*multiLine*/ true);
|
|
@@ -92841,6 +92901,7 @@ var ts;
|
|
|
92841
92901
|
/*modifiers*/ undefined, parameters !== null && parameters !== void 0 ? parameters : [], body), constructor || node), constructor));
|
|
92842
92902
|
}
|
|
92843
92903
|
function transformConstructorBody(node, constructor, isDerivedClass) {
|
|
92904
|
+
var _a;
|
|
92844
92905
|
var properties = ts.getProperties(node, /*requireInitializer*/ false, /*isStatic*/ false);
|
|
92845
92906
|
if (!useDefineForClassFields) {
|
|
92846
92907
|
properties = ts.filter(properties, function (property) { return !!property.initializer || ts.isPrivateIdentifier(property.name); });
|
|
@@ -92852,9 +92913,21 @@ var ts;
|
|
|
92852
92913
|
return ts.visitFunctionBody(/*node*/ undefined, visitor, context);
|
|
92853
92914
|
}
|
|
92854
92915
|
resumeLexicalEnvironment();
|
|
92855
|
-
var
|
|
92916
|
+
var needsSyntheticConstructor = !constructor && isDerivedClass;
|
|
92917
|
+
var indexOfFirstStatementAfterSuper = 0;
|
|
92918
|
+
var prologueStatementCount = 0;
|
|
92919
|
+
var superStatementIndex = -1;
|
|
92856
92920
|
var statements = [];
|
|
92857
|
-
if (
|
|
92921
|
+
if ((_a = constructor === null || constructor === void 0 ? void 0 : constructor.body) === null || _a === void 0 ? void 0 : _a.statements) {
|
|
92922
|
+
prologueStatementCount = factory.copyPrologue(constructor.body.statements, statements, /*ensureUseStrict*/ false, visitor);
|
|
92923
|
+
superStatementIndex = ts.findSuperStatementIndex(constructor.body.statements, prologueStatementCount);
|
|
92924
|
+
// If there was a super call, visit existing statements up to and including it
|
|
92925
|
+
if (superStatementIndex >= 0) {
|
|
92926
|
+
indexOfFirstStatementAfterSuper = superStatementIndex + 1;
|
|
92927
|
+
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);
|
|
92928
|
+
}
|
|
92929
|
+
}
|
|
92930
|
+
if (needsSyntheticConstructor) {
|
|
92858
92931
|
// Add a synthetic `super` call:
|
|
92859
92932
|
//
|
|
92860
92933
|
// super(...arguments);
|
|
@@ -92862,9 +92935,6 @@ var ts;
|
|
|
92862
92935
|
statements.push(factory.createExpressionStatement(factory.createCallExpression(factory.createSuper(),
|
|
92863
92936
|
/*typeArguments*/ undefined, [factory.createSpreadElement(factory.createIdentifier("arguments"))])));
|
|
92864
92937
|
}
|
|
92865
|
-
if (constructor) {
|
|
92866
|
-
indexOfFirstStatement = ts.addPrologueDirectivesAndInitialSuperCall(factory, constructor, statements, visitor);
|
|
92867
|
-
}
|
|
92868
92938
|
// Add the property initializers. Transforms this:
|
|
92869
92939
|
//
|
|
92870
92940
|
// public x = 1;
|
|
@@ -92875,31 +92945,59 @@ var ts;
|
|
|
92875
92945
|
// this.x = 1;
|
|
92876
92946
|
// }
|
|
92877
92947
|
//
|
|
92948
|
+
// If we do useDefineForClassFields, they'll be converted elsewhere.
|
|
92949
|
+
// We instead *remove* them from the transformed output at this stage.
|
|
92950
|
+
var parameterPropertyDeclarationCount = 0;
|
|
92878
92951
|
if (constructor === null || constructor === void 0 ? void 0 : constructor.body) {
|
|
92879
|
-
|
|
92880
|
-
|
|
92881
|
-
afterParameterProperties = constructor.body.statements.length;
|
|
92952
|
+
if (useDefineForClassFields) {
|
|
92953
|
+
statements = statements.filter(function (statement) { return !ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor); });
|
|
92882
92954
|
}
|
|
92883
|
-
|
|
92884
|
-
|
|
92885
|
-
|
|
92955
|
+
else {
|
|
92956
|
+
for (var _i = 0, _b = constructor.body.statements; _i < _b.length; _i++) {
|
|
92957
|
+
var statement = _b[_i];
|
|
92958
|
+
if (ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor)) {
|
|
92959
|
+
parameterPropertyDeclarationCount++;
|
|
92960
|
+
}
|
|
92961
|
+
}
|
|
92962
|
+
if (parameterPropertyDeclarationCount > 0) {
|
|
92963
|
+
var parameterProperties = ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, indexOfFirstStatementAfterSuper, parameterPropertyDeclarationCount);
|
|
92964
|
+
// If there was a super() call found, add parameter properties immediately after it
|
|
92965
|
+
if (superStatementIndex >= 0) {
|
|
92966
|
+
ts.addRange(statements, parameterProperties);
|
|
92967
|
+
}
|
|
92968
|
+
// If a synthetic super() call was added, add them just after it
|
|
92969
|
+
else if (needsSyntheticConstructor) {
|
|
92970
|
+
statements = __spreadArray(__spreadArray([
|
|
92971
|
+
statements[0]
|
|
92972
|
+
], parameterProperties, true), statements.slice(1), true);
|
|
92973
|
+
}
|
|
92974
|
+
// Since there wasn't a super() call, add them to the top of the constructor
|
|
92975
|
+
else {
|
|
92976
|
+
statements = __spreadArray(__spreadArray([], parameterProperties, true), statements, true);
|
|
92977
|
+
}
|
|
92978
|
+
indexOfFirstStatementAfterSuper += parameterPropertyDeclarationCount;
|
|
92886
92979
|
}
|
|
92887
|
-
indexOfFirstStatement = afterParameterProperties;
|
|
92888
92980
|
}
|
|
92889
92981
|
}
|
|
92890
92982
|
var receiver = factory.createThis();
|
|
92891
92983
|
// private methods can be called in property initializers, they should execute first.
|
|
92892
92984
|
addMethodStatements(statements, privateMethodsAndAccessors, receiver);
|
|
92893
92985
|
addPropertyOrClassStaticBlockStatements(statements, properties, receiver);
|
|
92894
|
-
// Add existing statements
|
|
92986
|
+
// Add existing statements after the initial prologues and super call
|
|
92895
92987
|
if (constructor) {
|
|
92896
|
-
ts.addRange(statements, ts.visitNodes(constructor.body.statements,
|
|
92988
|
+
ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitBodyStatement, ts.isStatement, indexOfFirstStatementAfterSuper + prologueStatementCount));
|
|
92897
92989
|
}
|
|
92898
92990
|
statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
|
|
92899
92991
|
return ts.setTextRange(factory.createBlock(ts.setTextRange(factory.createNodeArray(statements),
|
|
92900
92992
|
/*location*/ constructor ? constructor.body.statements : node.members),
|
|
92901
92993
|
/*multiLine*/ true),
|
|
92902
92994
|
/*location*/ constructor ? constructor.body : undefined);
|
|
92995
|
+
function visitBodyStatement(statement) {
|
|
92996
|
+
if (useDefineForClassFields && ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor)) {
|
|
92997
|
+
return undefined;
|
|
92998
|
+
}
|
|
92999
|
+
return visitor(statement);
|
|
93000
|
+
}
|
|
92903
93001
|
}
|
|
92904
93002
|
/**
|
|
92905
93003
|
* Generates assignment statements for property initializers.
|
|
@@ -96691,37 +96789,39 @@ var ts;
|
|
|
96691
96789
|
var prologue = [];
|
|
96692
96790
|
var statements = [];
|
|
96693
96791
|
resumeLexicalEnvironment();
|
|
96792
|
+
// In derived classes, there may be code before the necessary super() call
|
|
96793
|
+
// We'll remove pre-super statements to be tacked on after the rest of the body
|
|
96794
|
+
var existingPrologue = ts.takeWhile(constructor.body.statements, ts.isPrologueDirective);
|
|
96795
|
+
var _a = findSuperCallAndStatementIndex(constructor.body.statements, existingPrologue), superCall = _a.superCall, superStatementIndex = _a.superStatementIndex;
|
|
96796
|
+
var postSuperStatementsStart = superStatementIndex === -1 ? existingPrologue.length : superStatementIndex + 1;
|
|
96694
96797
|
// If a super call has already been synthesized,
|
|
96695
96798
|
// we're going to assume that we should just transform everything after that.
|
|
96696
96799
|
// The assumption is that no prior step in the pipeline has added any prologue directives.
|
|
96697
|
-
var statementOffset =
|
|
96800
|
+
var statementOffset = postSuperStatementsStart;
|
|
96698
96801
|
if (!hasSynthesizedSuper)
|
|
96699
|
-
statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, /*ensureUseStrict*/ false);
|
|
96700
|
-
addDefaultValueAssignmentsIfNeeded(statements, constructor);
|
|
96701
|
-
addRestParameterIfNeeded(statements, constructor, hasSynthesizedSuper);
|
|
96802
|
+
statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, statementOffset, /*ensureUseStrict*/ false);
|
|
96702
96803
|
if (!hasSynthesizedSuper)
|
|
96703
|
-
statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor);
|
|
96704
|
-
// If
|
|
96804
|
+
statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor, /*filter*/ undefined);
|
|
96805
|
+
// If there already exists a call to `super()`, visit the statement directly
|
|
96705
96806
|
var superCallExpression;
|
|
96706
96807
|
if (hasSynthesizedSuper) {
|
|
96707
96808
|
superCallExpression = createDefaultSuperCallOrThis();
|
|
96708
96809
|
}
|
|
96709
|
-
else if (
|
|
96710
|
-
|
|
96711
|
-
if (ts.isExpressionStatement(firstStatement) && ts.isSuperCall(firstStatement.expression)) {
|
|
96712
|
-
superCallExpression = visitImmediateSuperCallInBody(firstStatement.expression);
|
|
96713
|
-
}
|
|
96810
|
+
else if (superCall) {
|
|
96811
|
+
superCallExpression = visitSuperCallInBody(superCall);
|
|
96714
96812
|
}
|
|
96715
96813
|
if (superCallExpression) {
|
|
96716
96814
|
hierarchyFacts |= 8192 /* ConstructorWithCapturedSuper */;
|
|
96717
|
-
statementOffset++; // skip this statement, we will add it after visiting the rest of the body.
|
|
96718
96815
|
}
|
|
96816
|
+
// Add parameter defaults at the beginning of the output, with prologue statements
|
|
96817
|
+
addDefaultValueAssignmentsIfNeeded(prologue, constructor);
|
|
96818
|
+
addRestParameterIfNeeded(prologue, constructor, hasSynthesizedSuper);
|
|
96719
96819
|
// visit the remaining statements
|
|
96720
96820
|
ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, /*start*/ statementOffset));
|
|
96721
96821
|
factory.mergeLexicalEnvironment(prologue, endLexicalEnvironment());
|
|
96722
96822
|
insertCaptureNewTargetIfNeeded(prologue, constructor, /*copyOnWrite*/ false);
|
|
96723
|
-
if (isDerivedClass) {
|
|
96724
|
-
if (superCallExpression &&
|
|
96823
|
+
if (isDerivedClass || superCallExpression) {
|
|
96824
|
+
if (superCallExpression && postSuperStatementsStart === constructor.body.statements.length && !(constructor.body.transformFlags & 8192 /* ContainsLexicalThis */)) {
|
|
96725
96825
|
// If the subclass constructor does *not* contain `this` and *ends* with a `super()` call, we will use the
|
|
96726
96826
|
// following representation:
|
|
96727
96827
|
//
|
|
@@ -96741,10 +96841,10 @@ var ts;
|
|
|
96741
96841
|
// return C;
|
|
96742
96842
|
// })(Base);
|
|
96743
96843
|
// ```
|
|
96744
|
-
var
|
|
96844
|
+
var superCall_1 = ts.cast(ts.cast(superCallExpression, ts.isBinaryExpression).left, ts.isCallExpression);
|
|
96745
96845
|
var returnStatement = factory.createReturnStatement(superCallExpression);
|
|
96746
|
-
ts.setCommentRange(returnStatement, ts.getCommentRange(
|
|
96747
|
-
ts.setEmitFlags(
|
|
96846
|
+
ts.setCommentRange(returnStatement, ts.getCommentRange(superCall_1));
|
|
96847
|
+
ts.setEmitFlags(superCall_1, 1536 /* NoComments */);
|
|
96748
96848
|
statements.push(returnStatement);
|
|
96749
96849
|
}
|
|
96750
96850
|
else {
|
|
@@ -96769,9 +96869,19 @@ var ts;
|
|
|
96769
96869
|
// return C;
|
|
96770
96870
|
// })(Base);
|
|
96771
96871
|
// ```
|
|
96772
|
-
//
|
|
96773
|
-
|
|
96774
|
-
|
|
96872
|
+
// If the super() call is the first statement, we can directly create and assign its result to `_this`
|
|
96873
|
+
if (superStatementIndex <= existingPrologue.length) {
|
|
96874
|
+
insertCaptureThisForNode(statements, constructor, superCallExpression || createActualThis());
|
|
96875
|
+
}
|
|
96876
|
+
// Since the `super()` call isn't the first statement, it's split across 1-2 statements:
|
|
96877
|
+
// * A prologue `var _this = this;`, in case the constructor accesses this before super()
|
|
96878
|
+
// * If it exists, a reassignment to that `_this` of the super() call
|
|
96879
|
+
else {
|
|
96880
|
+
insertCaptureThisForNode(prologue, constructor, createActualThis());
|
|
96881
|
+
if (superCallExpression) {
|
|
96882
|
+
insertSuperThisCaptureThisForNode(statements, superCallExpression);
|
|
96883
|
+
}
|
|
96884
|
+
}
|
|
96775
96885
|
if (!isSufficientlyCoveredByReturnStatements(constructor.body)) {
|
|
96776
96886
|
statements.push(factory.createReturnStatement(factory.createUniqueName("_this", 16 /* Optimistic */ | 32 /* FileLevel */)));
|
|
96777
96887
|
}
|
|
@@ -96794,11 +96904,27 @@ var ts;
|
|
|
96794
96904
|
// ```
|
|
96795
96905
|
insertCaptureThisForNodeIfNeeded(prologue, constructor);
|
|
96796
96906
|
}
|
|
96797
|
-
var
|
|
96907
|
+
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)),
|
|
96798
96908
|
/*location*/ constructor.body.statements),
|
|
96799
96909
|
/*multiLine*/ true);
|
|
96800
|
-
ts.setTextRange(
|
|
96801
|
-
return
|
|
96910
|
+
ts.setTextRange(body, constructor.body);
|
|
96911
|
+
return body;
|
|
96912
|
+
}
|
|
96913
|
+
function findSuperCallAndStatementIndex(originalBodyStatements, existingPrologue) {
|
|
96914
|
+
for (var i = existingPrologue.length; i < originalBodyStatements.length; i += 1) {
|
|
96915
|
+
var superCall = ts.getSuperCallFromStatement(originalBodyStatements[i]);
|
|
96916
|
+
if (superCall) {
|
|
96917
|
+
// With a super() call, split the statements into pre-super() and 'body' (post-super())
|
|
96918
|
+
return {
|
|
96919
|
+
superCall: superCall,
|
|
96920
|
+
superStatementIndex: i,
|
|
96921
|
+
};
|
|
96922
|
+
}
|
|
96923
|
+
}
|
|
96924
|
+
// Since there was no super() call found, consider all statements to be in the main 'body' (post-super())
|
|
96925
|
+
return {
|
|
96926
|
+
superStatementIndex: -1,
|
|
96927
|
+
};
|
|
96802
96928
|
}
|
|
96803
96929
|
/**
|
|
96804
96930
|
* We want to try to avoid emitting a return statement in certain cases if a user already returned something.
|
|
@@ -97027,6 +97153,18 @@ var ts;
|
|
|
97027
97153
|
}
|
|
97028
97154
|
return false;
|
|
97029
97155
|
}
|
|
97156
|
+
/**
|
|
97157
|
+
* Assigns the `this` in a constructor to the result of its `super()` call.
|
|
97158
|
+
*
|
|
97159
|
+
* @param statements Statements in the constructor body.
|
|
97160
|
+
* @param superExpression Existing `super()` call for the constructor.
|
|
97161
|
+
*/
|
|
97162
|
+
function insertSuperThisCaptureThisForNode(statements, superExpression) {
|
|
97163
|
+
enableSubstitutionsForCapturedThis();
|
|
97164
|
+
var assignSuperExpression = factory.createExpressionStatement(factory.createBinaryExpression(factory.createThis(), 63 /* EqualsToken */, superExpression));
|
|
97165
|
+
ts.insertStatementAfterCustomPrologue(statements, assignSuperExpression);
|
|
97166
|
+
ts.setCommentRange(assignSuperExpression, ts.getOriginalNode(superExpression).parent);
|
|
97167
|
+
}
|
|
97030
97168
|
function insertCaptureThisForNode(statements, node, initializer) {
|
|
97031
97169
|
enableSubstitutionsForCapturedThis();
|
|
97032
97170
|
var captureThisStatement = factory.createVariableStatement(
|
|
@@ -97336,7 +97474,7 @@ var ts;
|
|
|
97336
97474
|
if (ts.isBlock(body)) {
|
|
97337
97475
|
// ensureUseStrict is false because no new prologue-directive should be added.
|
|
97338
97476
|
// addStandardPrologue will put already-existing directives at the beginning of the target statement-array
|
|
97339
|
-
statementOffset = factory.copyStandardPrologue(body.statements, prologue, /*ensureUseStrict*/ false);
|
|
97477
|
+
statementOffset = factory.copyStandardPrologue(body.statements, prologue, 0, /*ensureUseStrict*/ false);
|
|
97340
97478
|
statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedFunction);
|
|
97341
97479
|
statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedVariableStatement);
|
|
97342
97480
|
}
|
|
@@ -98707,7 +98845,7 @@ var ts;
|
|
|
98707
98845
|
/*type*/ undefined, factory.updateBlock(func.body, statements))),
|
|
98708
98846
|
/*typeArguments*/ undefined, call.arguments))));
|
|
98709
98847
|
}
|
|
98710
|
-
function
|
|
98848
|
+
function visitSuperCallInBody(node) {
|
|
98711
98849
|
return visitCallExpressionWithPotentialCapturedThisAssignment(node, /*assignToCapturedThis*/ false);
|
|
98712
98850
|
}
|
|
98713
98851
|
function visitCallExpressionWithPotentialCapturedThisAssignment(node, assignToCapturedThis) {
|
|
@@ -119935,8 +120073,8 @@ var ts;
|
|
|
119935
120073
|
}
|
|
119936
120074
|
function getPathRelativeToRootDirs(path, rootDirs, getCanonicalFileName) {
|
|
119937
120075
|
return ts.firstDefined(rootDirs, function (rootDir) {
|
|
119938
|
-
var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
|
|
119939
|
-
return isPathRelativeToParent(relativePath) ? undefined : relativePath;
|
|
120076
|
+
var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
|
|
120077
|
+
return relativePath !== undefined && isPathRelativeToParent(relativePath) ? undefined : relativePath;
|
|
119940
120078
|
});
|
|
119941
120079
|
}
|
|
119942
120080
|
function removeExtensionAndIndexPostFix(fileName, ending, options) {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "typescript",
|
|
3
3
|
"author": "Microsoft Corp.",
|
|
4
4
|
"homepage": "https://www.typescriptlang.org/",
|
|
5
|
-
"version": "4.6.0-dev.
|
|
5
|
+
"version": "4.6.0-dev.20220116",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"description": "TypeScript is a language for application scale JavaScript development",
|
|
8
8
|
"keywords": [
|