typescript 4.6.0-dev.20220202 → 4.6.0-dev.20220206

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.
@@ -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.20220202";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220206";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -1263,11 +1263,11 @@ var ts;
1263
1263
  return result;
1264
1264
  }
1265
1265
  ts.getAllKeys = getAllKeys;
1266
- function getOwnValues(sparseArray) {
1266
+ function getOwnValues(collection) {
1267
1267
  var values = [];
1268
- for (var key in sparseArray) {
1269
- if (hasOwnProperty.call(sparseArray, key)) {
1270
- values.push(sparseArray[key]);
1268
+ for (var key in collection) {
1269
+ if (hasOwnProperty.call(collection, key)) {
1270
+ values.push(collection[key]);
1271
1271
  }
1272
1272
  }
1273
1273
  return values;
@@ -8670,12 +8670,10 @@ var ts;
8670
8670
  Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es2015_or_higher: diag(2802, ts.DiagnosticCategory.Error, "Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es201_2802", "Type '{0}' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher."),
8671
8671
  Cannot_assign_to_private_method_0_Private_methods_are_not_writable: diag(2803, ts.DiagnosticCategory.Error, "Cannot_assign_to_private_method_0_Private_methods_are_not_writable_2803", "Cannot assign to private method '{0}'. Private methods are not writable."),
8672
8672
  Duplicate_identifier_0_Static_and_instance_elements_cannot_share_the_same_private_name: diag(2804, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_Static_and_instance_elements_cannot_share_the_same_private_name_2804", "Duplicate identifier '{0}'. Static and instance elements cannot share the same private name."),
8673
- Static_fields_with_private_names_can_t_have_initializers_when_the_useDefineForClassFields_flag_is_not_specified_with_a_target_of_esnext_Consider_adding_the_useDefineForClassFields_flag: diag(2805, ts.DiagnosticCategory.Error, "Static_fields_with_private_names_can_t_have_initializers_when_the_useDefineForClassFields_flag_is_no_2805", "Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag."),
8674
8673
  Private_accessor_was_defined_without_a_getter: diag(2806, ts.DiagnosticCategory.Error, "Private_accessor_was_defined_without_a_getter_2806", "Private accessor was defined without a getter."),
8675
8674
  This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_one_in_0_Consider_upgrading_your_version_of_0: diag(2807, ts.DiagnosticCategory.Error, "This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_o_2807", "This syntax requires an imported helper named '{1}' with {2} parameters, which is not compatible with the one in '{0}'. Consider upgrading your version of '{0}'."),
8676
8675
  A_get_accessor_must_be_at_least_as_accessible_as_the_setter: diag(2808, ts.DiagnosticCategory.Error, "A_get_accessor_must_be_at_least_as_accessible_as_the_setter_2808", "A get accessor must be at least as accessible as the setter"),
8677
8676
  Declaration_or_statement_expected_This_follows_a_block_of_statements_so_if_you_intended_to_write_a_destructuring_assignment_you_might_need_to_wrap_the_the_whole_assignment_in_parentheses: diag(2809, ts.DiagnosticCategory.Error, "Declaration_or_statement_expected_This_follows_a_block_of_statements_so_if_you_intended_to_write_a_d_2809", "Declaration or statement expected. This '=' follows a block of statements, so if you intended to write a destructuring assignment, you might need to wrap the the whole assignment in parentheses."),
8678
- Property_0_may_not_be_used_in_a_static_property_s_initializer_in_the_same_class_when_target_is_esnext_and_useDefineForClassFields_is_false: diag(2810, ts.DiagnosticCategory.Error, "Property_0_may_not_be_used_in_a_static_property_s_initializer_in_the_same_class_when_target_is_esnex_2810", "Property '{0}' may not be used in a static property's initializer in the same class when 'target' is 'esnext' and 'useDefineForClassFields' is 'false'."),
8679
8677
  Initializer_for_property_0: diag(2811, ts.DiagnosticCategory.Error, "Initializer_for_property_0_2811", "Initializer for property '{0}'"),
8680
8678
  Property_0_does_not_exist_on_type_1_Try_changing_the_lib_compiler_option_to_include_dom: diag(2812, ts.DiagnosticCategory.Error, "Property_0_does_not_exist_on_type_1_Try_changing_the_lib_compiler_option_to_include_dom_2812", "Property '{0}' does not exist on type '{1}'. Try changing the 'lib' compiler option to include 'dom'."),
8681
8679
  Class_declaration_cannot_implement_overload_list_for_0: diag(2813, ts.DiagnosticCategory.Error, "Class_declaration_cannot_implement_overload_list_for_0_2813", "Class declaration cannot implement overload list for '{0}'."),
@@ -9626,6 +9624,7 @@ var ts;
9626
9624
  Add_missing_attributes: diag(95167, ts.DiagnosticCategory.Message, "Add_missing_attributes_95167", "Add missing attributes"),
9627
9625
  Add_all_missing_attributes: diag(95168, ts.DiagnosticCategory.Message, "Add_all_missing_attributes_95168", "Add all missing attributes"),
9628
9626
  Add_undefined_to_optional_property_type: diag(95169, ts.DiagnosticCategory.Message, "Add_undefined_to_optional_property_type_95169", "Add 'undefined' to optional property type"),
9627
+ Convert_named_imports_to_default_import: diag(95170, ts.DiagnosticCategory.Message, "Convert_named_imports_to_default_import_95170", "Convert named imports to default import"),
9629
9628
  No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer: diag(18004, ts.DiagnosticCategory.Error, "No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer_18004", "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer."),
9630
9629
  Classes_may_not_have_a_field_named_constructor: diag(18006, ts.DiagnosticCategory.Error, "Classes_may_not_have_a_field_named_constructor_18006", "Classes may not have a field named 'constructor'."),
9631
9630
  JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array: diag(18007, ts.DiagnosticCategory.Error, "JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array_18007", "JSX expressions may not use the comma operator. Did you mean to write an array?"),
@@ -12798,12 +12797,17 @@ var ts;
12798
12797
  /** Gets the text of a jsdoc comment, flattening links to their text. */
12799
12798
  function getTextOfJSDocComment(comment) {
12800
12799
  return typeof comment === "string" ? comment
12801
- : comment === null || comment === void 0 ? void 0 : comment.map(function (c) {
12802
- // TODO: Other kinds here
12803
- return c.kind === 319 /* JSDocText */ ? c.text : "{@link " + (c.name ? ts.entityNameToString(c.name) + " " : "") + c.text + "}";
12804
- }).join("");
12800
+ : comment === null || comment === void 0 ? void 0 : comment.map(function (c) { return c.kind === 319 /* JSDocText */ ? c.text : formatJSDocLink(c); }).join("");
12805
12801
  }
12806
12802
  ts.getTextOfJSDocComment = getTextOfJSDocComment;
12803
+ function formatJSDocLink(link) {
12804
+ var kind = link.kind === 322 /* JSDocLink */ ? "link"
12805
+ : link.kind === 323 /* JSDocLinkCode */ ? "linkcode"
12806
+ : "linkplain";
12807
+ var name = link.name ? ts.entityNameToString(link.name) : "";
12808
+ var space = link.name && link.text.startsWith("://") ? "" : " ";
12809
+ return "{@" + kind + " " + name + space + link.text + "}";
12810
+ }
12807
12811
  /**
12808
12812
  * Gets the effective type parameters. If the node was parsed in a
12809
12813
  * JavaScript file, gets the type parameters from the `@template` tag from JSDoc.
@@ -72936,23 +72940,6 @@ var ts;
72936
72940
  if (assignmentKind && lexicallyScopedSymbol && lexicallyScopedSymbol.valueDeclaration && ts.isMethodDeclaration(lexicallyScopedSymbol.valueDeclaration)) {
72937
72941
  grammarErrorOnNode(right, ts.Diagnostics.Cannot_assign_to_private_method_0_Private_methods_are_not_writable, ts.idText(right));
72938
72942
  }
72939
- if ((lexicallyScopedSymbol === null || lexicallyScopedSymbol === void 0 ? void 0 : lexicallyScopedSymbol.valueDeclaration) && (ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && !useDefineForClassFields)) {
72940
- var lexicalClass_1 = ts.getContainingClass(lexicallyScopedSymbol.valueDeclaration);
72941
- var parentStaticFieldInitializer = ts.findAncestor(node, function (n) {
72942
- if (n === lexicalClass_1)
72943
- return "quit";
72944
- if (ts.isPropertyDeclaration(n.parent) && ts.hasStaticModifier(n.parent) && n.parent.initializer === n && n.parent.parent === lexicalClass_1) {
72945
- return true;
72946
- }
72947
- return false;
72948
- });
72949
- if (parentStaticFieldInitializer) {
72950
- var parentStaticFieldInitializerSymbol = getSymbolOfNode(parentStaticFieldInitializer.parent);
72951
- ts.Debug.assert(parentStaticFieldInitializerSymbol, "Initializer without declaration symbol");
72952
- var diagnostic = error(node, ts.Diagnostics.Property_0_may_not_be_used_in_a_static_property_s_initializer_in_the_same_class_when_target_is_esnext_and_useDefineForClassFields_is_false, ts.symbolName(lexicallyScopedSymbol));
72953
- ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(parentStaticFieldInitializer.parent, ts.Diagnostics.Initializer_for_property_0, ts.symbolName(parentStaticFieldInitializerSymbol)));
72954
- }
72955
- }
72956
72943
  if (isAnyLike) {
72957
72944
  if (lexicallyScopedSymbol) {
72958
72945
  return isErrorType(apparentType) ? errorType : apparentType;
@@ -78588,9 +78575,6 @@ var ts;
78588
78575
  checkGrammarComputedPropertyName(node.name);
78589
78576
  checkVariableLikeDeclaration(node);
78590
78577
  setNodeLinksForPrivateIdentifierScope(node);
78591
- if (ts.isPrivateIdentifier(node.name) && ts.hasStaticModifier(node) && node.initializer && languageVersion === 99 /* ESNext */ && !compilerOptions.useDefineForClassFields) {
78592
- error(node.initializer, ts.Diagnostics.Static_fields_with_private_names_can_t_have_initializers_when_the_useDefineForClassFields_flag_is_not_specified_with_a_target_of_esnext_Consider_adding_the_useDefineForClassFields_flag);
78593
- }
78594
78578
  // property signatures already report "initializer not allowed in ambient context" elsewhere
78595
78579
  if (ts.hasSyntacticModifier(node, 128 /* Abstract */) && node.kind === 166 /* PropertyDeclaration */ && node.initializer) {
78596
78580
  error(node, ts.Diagnostics.Property_0_cannot_have_an_initializer_because_it_is_marked_abstract, ts.declarationNameToString(node.name));
@@ -92280,10 +92264,12 @@ var ts;
92280
92264
  var languageVersion = ts.getEmitScriptTarget(compilerOptions);
92281
92265
  var useDefineForClassFields = ts.getUseDefineForClassFields(compilerOptions);
92282
92266
  var shouldTransformPrivateElementsOrClassStaticBlocks = languageVersion < 9 /* ES2022 */;
92267
+ // We need to transform `this` in a static initializer into a reference to the class
92268
+ // when targeting < ES2022 since the assignment will be moved outside of the class body.
92269
+ var shouldTransformThisInStaticInitializers = languageVersion < 9 /* ES2022 */;
92283
92270
  // We don't need to transform `super` property access when targeting ES5, ES3 because
92284
92271
  // the es2015 transformation handles those.
92285
- var shouldTransformSuperInStaticInitializers = (languageVersion <= 8 /* ES2021 */ || !useDefineForClassFields) && languageVersion >= 2 /* ES2015 */;
92286
- var shouldTransformThisInStaticInitializers = languageVersion <= 8 /* ES2021 */ || !useDefineForClassFields;
92272
+ var shouldTransformSuperInStaticInitializers = shouldTransformThisInStaticInitializers && languageVersion >= 2 /* ES2015 */;
92287
92273
  var previousOnSubstituteNode = context.onSubstituteNode;
92288
92274
  context.onSubstituteNode = onSubstituteNode;
92289
92275
  var previousOnEmitNode = context.onEmitNode;
@@ -92512,6 +92498,10 @@ var ts;
92512
92498
  ts.Debug.assert(!ts.some(node.decorators));
92513
92499
  if (ts.isPrivateIdentifier(node.name)) {
92514
92500
  if (!shouldTransformPrivateElementsOrClassStaticBlocks) {
92501
+ if (ts.isStatic(node)) {
92502
+ // static fields are left as is
92503
+ return ts.visitEachChild(node, visitor, context);
92504
+ }
92515
92505
  // Initializer is elided as the field is initialized in transformConstructor.
92516
92506
  return factory.updatePropertyDeclaration(node,
92517
92507
  /*decorators*/ undefined, ts.visitNodes(node.modifiers, visitor, ts.isModifier), node.name,
@@ -92533,6 +92523,22 @@ var ts;
92533
92523
  if (expr && !ts.isSimpleInlineableExpression(expr)) {
92534
92524
  getPendingExpressions().push(expr);
92535
92525
  }
92526
+ if (ts.isStatic(node) && !shouldTransformPrivateElementsOrClassStaticBlocks && !useDefineForClassFields) {
92527
+ var initializerStatement = transformPropertyOrClassStaticBlock(node, factory.createThis());
92528
+ if (initializerStatement) {
92529
+ var staticBlock = factory.createClassStaticBlockDeclaration(
92530
+ /*decorators*/ undefined,
92531
+ /*modifiers*/ undefined, factory.createBlock([initializerStatement]));
92532
+ ts.setOriginalNode(staticBlock, node);
92533
+ ts.setCommentRange(staticBlock, node);
92534
+ // Set the comment range for the statement to an empty synthetic range
92535
+ // and drop synthetic comments from the statement to avoid printing them twice.
92536
+ ts.setCommentRange(initializerStatement, { pos: -1, end: -1 });
92537
+ ts.setSyntheticLeadingComments(initializerStatement, undefined);
92538
+ ts.setSyntheticTrailingComments(initializerStatement, undefined);
92539
+ return staticBlock;
92540
+ }
92541
+ }
92536
92542
  return undefined;
92537
92543
  }
92538
92544
  function createPrivateIdentifierAccess(info, receiver) {
@@ -92920,7 +92926,6 @@ var ts;
92920
92926
  if (facts & 8 /* NeedsSubstitutionForThisInClassStaticField */) {
92921
92927
  enableSubstitutionForClassStaticThisOrSuperReference();
92922
92928
  }
92923
- var staticProperties = ts.getStaticPropertiesAndClassStaticBlock(node);
92924
92929
  // If a class has private static fields, or a static field has a `this` or `super` reference,
92925
92930
  // then we need to allocate a temp variable to hold on to that reference.
92926
92931
  var pendingClassReferenceAssignment;
@@ -92948,6 +92953,7 @@ var ts;
92948
92953
  // From ES6 specification:
92949
92954
  // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using
92950
92955
  // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration.
92956
+ var staticProperties = ts.getStaticPropertiesAndClassStaticBlock(node);
92951
92957
  if (ts.some(staticProperties)) {
92952
92958
  addPropertyOrClassStaticBlockStatements(statements, staticProperties, factory.getInternalName(node));
92953
92959
  }
@@ -92986,7 +92992,7 @@ var ts;
92986
92992
  }
92987
92993
  var classExpression = factory.updateClassExpression(node, ts.visitNodes(node.decorators, visitor, ts.isDecorator), node.modifiers, node.name,
92988
92994
  /*typeParameters*/ undefined, ts.visitNodes(node.heritageClauses, heritageClauseVisitor, ts.isHeritageClause), transformClassMembers(node, isDerivedClass));
92989
- var hasTransformableStatics = ts.some(staticPropertiesOrClassStaticBlocks, function (p) { return ts.isClassStaticBlockDeclaration(p) || !!p.initializer || (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifier(p.name)); });
92995
+ var hasTransformableStatics = shouldTransformPrivateElementsOrClassStaticBlocks && ts.some(staticPropertiesOrClassStaticBlocks, function (p) { return ts.isClassStaticBlockDeclaration(p) || !!p.initializer || ts.isPrivateIdentifier(p.name); });
92990
92996
  if (hasTransformableStatics || ts.some(pendingExpressions)) {
92991
92997
  if (isDecoratedClassDeclaration) {
92992
92998
  ts.Debug.assertIsDefined(pendingStatements, "Decorated classes transformed by TypeScript are expected to be within a variable declaration.");
@@ -93033,6 +93039,7 @@ var ts;
93033
93039
  return undefined;
93034
93040
  }
93035
93041
  function transformClassMembers(node, isDerivedClass) {
93042
+ var members = [];
93036
93043
  if (shouldTransformPrivateElementsOrClassStaticBlocks) {
93037
93044
  // Declare private names.
93038
93045
  for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
@@ -93045,12 +93052,20 @@ var ts;
93045
93052
  createBrandCheckWeakSetForPrivateMethods();
93046
93053
  }
93047
93054
  }
93048
- var members = [];
93049
93055
  var constructor = transformConstructor(node, isDerivedClass);
93056
+ var visitedMembers = ts.visitNodes(node.members, classElementVisitor, ts.isClassElement);
93050
93057
  if (constructor) {
93051
93058
  members.push(constructor);
93052
93059
  }
93053
- ts.addRange(members, ts.visitNodes(node.members, classElementVisitor, ts.isClassElement));
93060
+ if (!shouldTransformPrivateElementsOrClassStaticBlocks && ts.some(pendingExpressions)) {
93061
+ members.push(factory.createClassStaticBlockDeclaration(
93062
+ /*decorators*/ undefined,
93063
+ /*modifiers*/ undefined, factory.createBlock([
93064
+ factory.createExpressionStatement(factory.inlineExpressions(pendingExpressions))
93065
+ ])));
93066
+ pendingExpressions = undefined;
93067
+ }
93068
+ ts.addRange(members, visitedMembers);
93054
93069
  return ts.setTextRange(factory.createNodeArray(members), /*location*/ node.members);
93055
93070
  }
93056
93071
  function createBrandCheckWeakSetForPrivateMethods() {
@@ -93193,24 +93208,34 @@ var ts;
93193
93208
  function addPropertyOrClassStaticBlockStatements(statements, properties, receiver) {
93194
93209
  for (var _i = 0, properties_7 = properties; _i < properties_7.length; _i++) {
93195
93210
  var property = properties_7[_i];
93196
- var expression = ts.isClassStaticBlockDeclaration(property) ?
93197
- transformClassStaticBlockDeclaration(property) :
93198
- transformProperty(property, receiver);
93199
- if (!expression) {
93211
+ if (ts.isStatic(property) && !shouldTransformPrivateElementsOrClassStaticBlocks && !useDefineForClassFields) {
93212
+ continue;
93213
+ }
93214
+ var statement = transformPropertyOrClassStaticBlock(property, receiver);
93215
+ if (!statement) {
93200
93216
  continue;
93201
93217
  }
93202
- var statement = factory.createExpressionStatement(expression);
93203
- ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
93204
- ts.setCommentRange(statement, property);
93205
- ts.setOriginalNode(statement, property);
93206
- // `setOriginalNode` *copies* the `emitNode` from `property`, so now both
93207
- // `statement` and `expression` have a copy of the synthesized comments.
93208
- // Drop the comments from expression to avoid printing them twice.
93209
- ts.setSyntheticLeadingComments(expression, undefined);
93210
- ts.setSyntheticTrailingComments(expression, undefined);
93211
93218
  statements.push(statement);
93212
93219
  }
93213
93220
  }
93221
+ function transformPropertyOrClassStaticBlock(property, receiver) {
93222
+ var expression = ts.isClassStaticBlockDeclaration(property) ?
93223
+ transformClassStaticBlockDeclaration(property) :
93224
+ transformProperty(property, receiver);
93225
+ if (!expression) {
93226
+ return undefined;
93227
+ }
93228
+ var statement = factory.createExpressionStatement(expression);
93229
+ ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
93230
+ ts.setCommentRange(statement, property);
93231
+ ts.setOriginalNode(statement, property);
93232
+ // `setOriginalNode` *copies* the `emitNode` from `property`, so now both
93233
+ // `statement` and `expression` have a copy of the synthesized comments.
93234
+ // Drop the comments from expression to avoid printing them twice.
93235
+ ts.setSyntheticLeadingComments(expression, undefined);
93236
+ ts.setSyntheticTrailingComments(expression, undefined);
93237
+ return statement;
93238
+ }
93214
93239
  /**
93215
93240
  * Generates assignment expressions for property initializers.
93216
93241
  *
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.20220202",
5
+ "version": "4.6.0-dev.20220206",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [