typescript 4.6.0-dev.20220204 → 4.6.0-dev.20220205

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.20220204";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220205";
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?"),
@@ -72941,23 +72940,6 @@ var ts;
72941
72940
  if (assignmentKind && lexicallyScopedSymbol && lexicallyScopedSymbol.valueDeclaration && ts.isMethodDeclaration(lexicallyScopedSymbol.valueDeclaration)) {
72942
72941
  grammarErrorOnNode(right, ts.Diagnostics.Cannot_assign_to_private_method_0_Private_methods_are_not_writable, ts.idText(right));
72943
72942
  }
72944
- if ((lexicallyScopedSymbol === null || lexicallyScopedSymbol === void 0 ? void 0 : lexicallyScopedSymbol.valueDeclaration) && (ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && !useDefineForClassFields)) {
72945
- var lexicalClass_1 = ts.getContainingClass(lexicallyScopedSymbol.valueDeclaration);
72946
- var parentStaticFieldInitializer = ts.findAncestor(node, function (n) {
72947
- if (n === lexicalClass_1)
72948
- return "quit";
72949
- if (ts.isPropertyDeclaration(n.parent) && ts.hasStaticModifier(n.parent) && n.parent.initializer === n && n.parent.parent === lexicalClass_1) {
72950
- return true;
72951
- }
72952
- return false;
72953
- });
72954
- if (parentStaticFieldInitializer) {
72955
- var parentStaticFieldInitializerSymbol = getSymbolOfNode(parentStaticFieldInitializer.parent);
72956
- ts.Debug.assert(parentStaticFieldInitializerSymbol, "Initializer without declaration symbol");
72957
- 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));
72958
- ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(parentStaticFieldInitializer.parent, ts.Diagnostics.Initializer_for_property_0, ts.symbolName(parentStaticFieldInitializerSymbol)));
72959
- }
72960
- }
72961
72943
  if (isAnyLike) {
72962
72944
  if (lexicallyScopedSymbol) {
72963
72945
  return isErrorType(apparentType) ? errorType : apparentType;
@@ -78593,9 +78575,6 @@ var ts;
78593
78575
  checkGrammarComputedPropertyName(node.name);
78594
78576
  checkVariableLikeDeclaration(node);
78595
78577
  setNodeLinksForPrivateIdentifierScope(node);
78596
- if (ts.isPrivateIdentifier(node.name) && ts.hasStaticModifier(node) && node.initializer && languageVersion === 99 /* ESNext */ && !compilerOptions.useDefineForClassFields) {
78597
- 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);
78598
- }
78599
78578
  // property signatures already report "initializer not allowed in ambient context" elsewhere
78600
78579
  if (ts.hasSyntacticModifier(node, 128 /* Abstract */) && node.kind === 166 /* PropertyDeclaration */ && node.initializer) {
78601
78580
  error(node, ts.Diagnostics.Property_0_cannot_have_an_initializer_because_it_is_marked_abstract, ts.declarationNameToString(node.name));
@@ -92285,10 +92264,12 @@ var ts;
92285
92264
  var languageVersion = ts.getEmitScriptTarget(compilerOptions);
92286
92265
  var useDefineForClassFields = ts.getUseDefineForClassFields(compilerOptions);
92287
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 */;
92288
92270
  // We don't need to transform `super` property access when targeting ES5, ES3 because
92289
92271
  // the es2015 transformation handles those.
92290
- var shouldTransformSuperInStaticInitializers = (languageVersion <= 8 /* ES2021 */ || !useDefineForClassFields) && languageVersion >= 2 /* ES2015 */;
92291
- var shouldTransformThisInStaticInitializers = languageVersion <= 8 /* ES2021 */ || !useDefineForClassFields;
92272
+ var shouldTransformSuperInStaticInitializers = shouldTransformThisInStaticInitializers && languageVersion >= 2 /* ES2015 */;
92292
92273
  var previousOnSubstituteNode = context.onSubstituteNode;
92293
92274
  context.onSubstituteNode = onSubstituteNode;
92294
92275
  var previousOnEmitNode = context.onEmitNode;
@@ -92517,6 +92498,10 @@ var ts;
92517
92498
  ts.Debug.assert(!ts.some(node.decorators));
92518
92499
  if (ts.isPrivateIdentifier(node.name)) {
92519
92500
  if (!shouldTransformPrivateElementsOrClassStaticBlocks) {
92501
+ if (ts.isStatic(node)) {
92502
+ // static fields are left as is
92503
+ return ts.visitEachChild(node, visitor, context);
92504
+ }
92520
92505
  // Initializer is elided as the field is initialized in transformConstructor.
92521
92506
  return factory.updatePropertyDeclaration(node,
92522
92507
  /*decorators*/ undefined, ts.visitNodes(node.modifiers, visitor, ts.isModifier), node.name,
@@ -92538,6 +92523,22 @@ var ts;
92538
92523
  if (expr && !ts.isSimpleInlineableExpression(expr)) {
92539
92524
  getPendingExpressions().push(expr);
92540
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
+ }
92541
92542
  return undefined;
92542
92543
  }
92543
92544
  function createPrivateIdentifierAccess(info, receiver) {
@@ -92925,7 +92926,6 @@ var ts;
92925
92926
  if (facts & 8 /* NeedsSubstitutionForThisInClassStaticField */) {
92926
92927
  enableSubstitutionForClassStaticThisOrSuperReference();
92927
92928
  }
92928
- var staticProperties = ts.getStaticPropertiesAndClassStaticBlock(node);
92929
92929
  // If a class has private static fields, or a static field has a `this` or `super` reference,
92930
92930
  // then we need to allocate a temp variable to hold on to that reference.
92931
92931
  var pendingClassReferenceAssignment;
@@ -92953,6 +92953,7 @@ var ts;
92953
92953
  // From ES6 specification:
92954
92954
  // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using
92955
92955
  // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration.
92956
+ var staticProperties = ts.getStaticPropertiesAndClassStaticBlock(node);
92956
92957
  if (ts.some(staticProperties)) {
92957
92958
  addPropertyOrClassStaticBlockStatements(statements, staticProperties, factory.getInternalName(node));
92958
92959
  }
@@ -92991,7 +92992,7 @@ var ts;
92991
92992
  }
92992
92993
  var classExpression = factory.updateClassExpression(node, ts.visitNodes(node.decorators, visitor, ts.isDecorator), node.modifiers, node.name,
92993
92994
  /*typeParameters*/ undefined, ts.visitNodes(node.heritageClauses, heritageClauseVisitor, ts.isHeritageClause), transformClassMembers(node, isDerivedClass));
92994
- 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); });
92995
92996
  if (hasTransformableStatics || ts.some(pendingExpressions)) {
92996
92997
  if (isDecoratedClassDeclaration) {
92997
92998
  ts.Debug.assertIsDefined(pendingStatements, "Decorated classes transformed by TypeScript are expected to be within a variable declaration.");
@@ -93038,6 +93039,7 @@ var ts;
93038
93039
  return undefined;
93039
93040
  }
93040
93041
  function transformClassMembers(node, isDerivedClass) {
93042
+ var members = [];
93041
93043
  if (shouldTransformPrivateElementsOrClassStaticBlocks) {
93042
93044
  // Declare private names.
93043
93045
  for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
@@ -93050,12 +93052,20 @@ var ts;
93050
93052
  createBrandCheckWeakSetForPrivateMethods();
93051
93053
  }
93052
93054
  }
93053
- var members = [];
93054
93055
  var constructor = transformConstructor(node, isDerivedClass);
93056
+ var visitedMembers = ts.visitNodes(node.members, classElementVisitor, ts.isClassElement);
93055
93057
  if (constructor) {
93056
93058
  members.push(constructor);
93057
93059
  }
93058
- 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);
93059
93069
  return ts.setTextRange(factory.createNodeArray(members), /*location*/ node.members);
93060
93070
  }
93061
93071
  function createBrandCheckWeakSetForPrivateMethods() {
@@ -93198,24 +93208,34 @@ var ts;
93198
93208
  function addPropertyOrClassStaticBlockStatements(statements, properties, receiver) {
93199
93209
  for (var _i = 0, properties_7 = properties; _i < properties_7.length; _i++) {
93200
93210
  var property = properties_7[_i];
93201
- var expression = ts.isClassStaticBlockDeclaration(property) ?
93202
- transformClassStaticBlockDeclaration(property) :
93203
- transformProperty(property, receiver);
93204
- if (!expression) {
93211
+ if (ts.isStatic(property) && !shouldTransformPrivateElementsOrClassStaticBlocks && !useDefineForClassFields) {
93212
+ continue;
93213
+ }
93214
+ var statement = transformPropertyOrClassStaticBlock(property, receiver);
93215
+ if (!statement) {
93205
93216
  continue;
93206
93217
  }
93207
- var statement = factory.createExpressionStatement(expression);
93208
- ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
93209
- ts.setCommentRange(statement, property);
93210
- ts.setOriginalNode(statement, property);
93211
- // `setOriginalNode` *copies* the `emitNode` from `property`, so now both
93212
- // `statement` and `expression` have a copy of the synthesized comments.
93213
- // Drop the comments from expression to avoid printing them twice.
93214
- ts.setSyntheticLeadingComments(expression, undefined);
93215
- ts.setSyntheticTrailingComments(expression, undefined);
93216
93218
  statements.push(statement);
93217
93219
  }
93218
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
+ }
93219
93239
  /**
93220
93240
  * Generates assignment expressions for property initializers.
93221
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.20220204",
5
+ "version": "4.6.0-dev.20220205",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [