typescript 5.2.0-dev.20230623 → 5.2.0-dev.20230624

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/tsserver.js CHANGED
@@ -693,6 +693,7 @@ __export(server_exports, {
693
693
  getContainerFlags: () => getContainerFlags,
694
694
  getContainerNode: () => getContainerNode,
695
695
  getContainingClass: () => getContainingClass,
696
+ getContainingClassExcludingClassDecorators: () => getContainingClassExcludingClassDecorators,
696
697
  getContainingClassStaticBlock: () => getContainingClassStaticBlock,
697
698
  getContainingFunction: () => getContainingFunction,
698
699
  getContainingFunctionDeclaration: () => getContainingFunctionDeclaration,
@@ -2326,7 +2327,7 @@ module.exports = __toCommonJS(server_exports);
2326
2327
 
2327
2328
  // src/compiler/corePublic.ts
2328
2329
  var versionMajorMinor = "5.2";
2329
- var version = `${versionMajorMinor}.0-dev.20230623`;
2330
+ var version = `${versionMajorMinor}.0-dev.20230624`;
2330
2331
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2331
2332
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2332
2333
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -9312,6 +9313,7 @@ var Diagnostics = {
9312
9313
  A_return_statement_can_only_be_used_within_a_function_body: diag(1108, 1 /* Error */, "A_return_statement_can_only_be_used_within_a_function_body_1108", "A 'return' statement can only be used within a function body."),
9313
9314
  Expression_expected: diag(1109, 1 /* Error */, "Expression_expected_1109", "Expression expected."),
9314
9315
  Type_expected: diag(1110, 1 /* Error */, "Type_expected_1110", "Type expected."),
9316
+ Private_field_0_must_be_declared_in_an_enclosing_class: diag(1111, 1 /* Error */, "Private_field_0_must_be_declared_in_an_enclosing_class_1111", "Private field '{0}' must be declared in an enclosing class."),
9315
9317
  A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: diag(1113, 1 /* Error */, "A_default_clause_cannot_appear_more_than_once_in_a_switch_statement_1113", "A 'default' clause cannot appear more than once in a 'switch' statement."),
9316
9318
  Duplicate_label_0: diag(1114, 1 /* Error */, "Duplicate_label_0_1114", "Duplicate label '{0}'."),
9317
9319
  A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement: diag(1115, 1 /* Error */, "A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement_1115", "A 'continue' statement can only jump to a label of an enclosing iteration statement."),
@@ -16749,6 +16751,10 @@ function getContainingClassStaticBlock(node) {
16749
16751
  function getContainingFunctionOrClassStaticBlock(node) {
16750
16752
  return findAncestor(node.parent, isFunctionLikeOrClassStaticBlockDeclaration);
16751
16753
  }
16754
+ function getContainingClassExcludingClassDecorators(node) {
16755
+ const decorator = findAncestor(node.parent, (n) => isClassLike(n) ? "quit" : isDecorator(n));
16756
+ return decorator && isClassLike(decorator.parent) ? getContainingClass(decorator.parent) : getContainingClass(decorator ?? node);
16757
+ }
16752
16758
  function getThisContainer(node, includeArrowFunctions, includeClassComputedPropertyName) {
16753
16759
  Debug.assert(node.kind !== 312 /* SourceFile */);
16754
16760
  while (true) {
@@ -27251,10 +27257,12 @@ function createEmitHelperFactory(context) {
27251
27257
  );
27252
27258
  }
27253
27259
  function createESDecorateClassContextObject(contextIn) {
27254
- return factory2.createObjectLiteralExpression([
27260
+ const properties = [
27255
27261
  factory2.createPropertyAssignment(factory2.createIdentifier("kind"), factory2.createStringLiteral("class")),
27256
- factory2.createPropertyAssignment(factory2.createIdentifier("name"), contextIn.name)
27257
- ]);
27262
+ factory2.createPropertyAssignment(factory2.createIdentifier("name"), contextIn.name),
27263
+ factory2.createPropertyAssignment(factory2.createIdentifier("metadata"), contextIn.metadata)
27264
+ ];
27265
+ return factory2.createObjectLiteralExpression(properties);
27258
27266
  }
27259
27267
  function createESDecorateClassElementAccessGetMethod(elementName) {
27260
27268
  const accessor = elementName.computed ? factory2.createElementAccessExpression(factory2.createIdentifier("obj"), elementName.name) : factory2.createPropertyAccessExpression(factory2.createIdentifier("obj"), elementName.name);
@@ -27358,13 +27366,15 @@ function createEmitHelperFactory(context) {
27358
27366
  return factory2.createObjectLiteralExpression(properties);
27359
27367
  }
27360
27368
  function createESDecorateClassElementContextObject(contextIn) {
27361
- return factory2.createObjectLiteralExpression([
27369
+ const properties = [
27362
27370
  factory2.createPropertyAssignment(factory2.createIdentifier("kind"), factory2.createStringLiteral(contextIn.kind)),
27363
27371
  factory2.createPropertyAssignment(factory2.createIdentifier("name"), contextIn.name.computed ? contextIn.name.name : factory2.createStringLiteralFromNode(contextIn.name.name)),
27364
27372
  factory2.createPropertyAssignment(factory2.createIdentifier("static"), contextIn.static ? factory2.createTrue() : factory2.createFalse()),
27365
27373
  factory2.createPropertyAssignment(factory2.createIdentifier("private"), contextIn.private ? factory2.createTrue() : factory2.createFalse()),
27366
- factory2.createPropertyAssignment(factory2.createIdentifier("access"), createESDecorateClassElementAccessObject(contextIn.name, contextIn.access))
27367
- ]);
27374
+ factory2.createPropertyAssignment(factory2.createIdentifier("access"), createESDecorateClassElementAccessObject(contextIn.name, contextIn.access)),
27375
+ factory2.createPropertyAssignment(factory2.createIdentifier("metadata"), contextIn.metadata)
27376
+ ];
27377
+ return factory2.createObjectLiteralExpression(properties);
27368
27378
  }
27369
27379
  function createESDecorateContextObject(contextIn) {
27370
27380
  return contextIn.kind === "class" ? createESDecorateClassContextObject(contextIn) : createESDecorateClassElementContextObject(contextIn);
@@ -38074,6 +38084,7 @@ var libEntries = [
38074
38084
  ["esnext.string", "lib.es2022.string.d.ts"],
38075
38085
  ["esnext.promise", "lib.es2021.promise.d.ts"],
38076
38086
  ["esnext.weakref", "lib.es2021.weakref.d.ts"],
38087
+ ["esnext.decorators", "lib.esnext.decorators.d.ts"],
38077
38088
  ["decorators", "lib.decorators.d.ts"],
38078
38089
  ["decorators.legacy", "lib.decorators.legacy.d.ts"]
38079
38090
  ];
@@ -70707,7 +70718,7 @@ function createTypeChecker(host) {
70707
70718
  location = location.parent;
70708
70719
  }
70709
70720
  if (isExpressionNode(location) && (!isAssignmentTarget(location) || isWriteAccess(location))) {
70710
- const type = getTypeOfExpression(location);
70721
+ const type = removeOptionalTypeMarker(getTypeOfExpression(location));
70711
70722
  if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) {
70712
70723
  return type;
70713
70724
  }
@@ -73718,7 +73729,7 @@ function createTypeChecker(host) {
73718
73729
  return isCallOrNewExpression(node.parent) && node.parent.expression === node;
73719
73730
  }
73720
73731
  function lookupSymbolForPrivateIdentifierDeclaration(propName, location) {
73721
- for (let containingClass = getContainingClass(location); !!containingClass; containingClass = getContainingClass(containingClass)) {
73732
+ for (let containingClass = getContainingClassExcludingClassDecorators(location); !!containingClass; containingClass = getContainingClass(containingClass)) {
73722
73733
  const { symbol } = containingClass;
73723
73734
  const name = getSymbolNameForPrivateIdentifier(symbol, propName);
73724
73735
  const prop = symbol.members && symbol.members.get(name) || symbol.exports && symbol.exports.get(name);
@@ -73854,16 +73865,22 @@ function createTypeChecker(host) {
73854
73865
  if (lexicallyScopedSymbol) {
73855
73866
  return isErrorType(apparentType) ? errorType : apparentType;
73856
73867
  }
73857
- if (!getContainingClass(right)) {
73868
+ if (getContainingClassExcludingClassDecorators(right) === void 0) {
73858
73869
  grammarErrorOnNode(right, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies);
73859
73870
  return anyType;
73860
73871
  }
73861
73872
  }
73862
- prop = lexicallyScopedSymbol ? getPrivateIdentifierPropertyOfType(leftType, lexicallyScopedSymbol) : void 0;
73863
- if (!prop && checkPrivateIdentifierPropertyAccess(leftType, right, lexicallyScopedSymbol)) {
73864
- return errorType;
73873
+ prop = lexicallyScopedSymbol && getPrivateIdentifierPropertyOfType(leftType, lexicallyScopedSymbol);
73874
+ if (prop === void 0) {
73875
+ if (checkPrivateIdentifierPropertyAccess(leftType, right, lexicallyScopedSymbol)) {
73876
+ return errorType;
73877
+ }
73878
+ const containingClass = getContainingClassExcludingClassDecorators(right);
73879
+ if (containingClass && isPlainJsFile(getSourceFileOfNode(containingClass), compilerOptions.checkJs)) {
73880
+ grammarErrorOnNode(right, Diagnostics.Private_field_0_must_be_declared_in_an_enclosing_class, idText(right));
73881
+ }
73865
73882
  } else {
73866
- const isSetonlyAccessor = prop && prop.flags & 65536 /* SetAccessor */ && !(prop.flags & 32768 /* GetAccessor */);
73883
+ const isSetonlyAccessor = prop.flags & 65536 /* SetAccessor */ && !(prop.flags & 32768 /* GetAccessor */);
73867
73884
  if (isSetonlyAccessor && assignmentKind !== 1 /* Definite */) {
73868
73885
  error2(node, Diagnostics.Private_accessor_was_defined_without_a_getter);
73869
73886
  }
@@ -94622,9 +94639,12 @@ function transformClassFields(context) {
94622
94639
  return getClassLexicalEnvironment().classConstructor = node.emitNode.classThis;
94623
94640
  }
94624
94641
  const classCheckFlags = resolver.getNodeCheckFlags(node);
94625
- const isClassWithConstructorReference2 = classCheckFlags & 1048576 /* ClassWithConstructorReference */;
94626
94642
  const requiresBlockScopedVar = classCheckFlags & 32768 /* BlockScopedBindingInLoop */;
94627
- const temp2 = factory2.createTempVariable(requiresBlockScopedVar ? addBlockScopedVariable : hoistVariableDeclaration, !!isClassWithConstructorReference2);
94643
+ const temp2 = factory2.createTempVariable(
94644
+ requiresBlockScopedVar ? addBlockScopedVariable : hoistVariableDeclaration,
94645
+ /*reservedInNestedScopes*/
94646
+ true
94647
+ );
94628
94648
  getClassLexicalEnvironment().classConstructor = factory2.cloneNode(temp2);
94629
94649
  return temp2;
94630
94650
  }
@@ -96787,6 +96807,7 @@ function transformESDecorators(context) {
96787
96807
  );
96788
96808
  }
96789
96809
  function createClassInfo(node) {
96810
+ const metadataReference = factory2.createUniqueName("_metadata", 16 /* Optimistic */ | 32 /* FileLevel */);
96790
96811
  let instanceExtraInitializersName;
96791
96812
  let staticExtraInitializersName;
96792
96813
  let hasStaticInitializers = false;
@@ -96825,6 +96846,7 @@ function transformESDecorators(context) {
96825
96846
  }
96826
96847
  return {
96827
96848
  class: node,
96849
+ metadataReference,
96828
96850
  instanceExtraInitializersName,
96829
96851
  staticExtraInitializersName,
96830
96852
  hasStaticInitializers,
@@ -96832,16 +96854,6 @@ function transformESDecorators(context) {
96832
96854
  hasStaticPrivateClassElements
96833
96855
  };
96834
96856
  }
96835
- function containsLexicalSuperInStaticInitializer(node) {
96836
- for (const member of node.members) {
96837
- if (isClassStaticBlockDeclaration(member) || isPropertyDeclaration(member) && hasStaticModifier(member)) {
96838
- if (member.transformFlags & 134217728 /* ContainsLexicalSuper */) {
96839
- return true;
96840
- }
96841
- }
96842
- }
96843
- return false;
96844
- }
96845
96857
  function transformClassLike(node) {
96846
96858
  startLexicalEnvironment();
96847
96859
  if (!classHasDeclaredOrExplicitlyAssignedName(node) && classOrConstructorParameterIsDecorated(
@@ -96885,29 +96897,26 @@ function transformESDecorators(context) {
96885
96897
  shouldTransformPrivateStaticElementsInFile = true;
96886
96898
  }
96887
96899
  }
96888
- if (classDecorators && containsLexicalSuperInStaticInitializer(node)) {
96889
- const extendsClause = getHeritageClause(node.heritageClauses, 96 /* ExtendsKeyword */);
96890
- const extendsElement = extendsClause && firstOrUndefined(extendsClause.types);
96891
- const extendsExpression = extendsElement && visitNode(extendsElement.expression, visitor, isExpression);
96892
- if (extendsExpression) {
96893
- classInfo2.classSuper = factory2.createUniqueName("_classSuper", 16 /* Optimistic */ | 32 /* FileLevel */);
96894
- const unwrapped = skipOuterExpressions(extendsExpression);
96895
- const safeExtendsExpression = isClassExpression(unwrapped) && !unwrapped.name || isFunctionExpression(unwrapped) && !unwrapped.name || isArrowFunction(unwrapped) ? factory2.createComma(factory2.createNumericLiteral(0), extendsExpression) : extendsExpression;
96896
- classDefinitionStatements.push(createLet(classInfo2.classSuper, safeExtendsExpression));
96897
- const updatedExtendsElement = factory2.updateExpressionWithTypeArguments(
96898
- extendsElement,
96899
- classInfo2.classSuper,
96900
- /*typeArguments*/
96901
- void 0
96902
- );
96903
- const updatedExtendsClause = factory2.updateHeritageClause(extendsClause, [updatedExtendsElement]);
96904
- heritageClauses = factory2.createNodeArray([updatedExtendsClause]);
96905
- }
96906
- } else {
96907
- heritageClauses = visitNodes2(node.heritageClauses, visitor, isHeritageClause);
96900
+ const extendsClause = getHeritageClause(node.heritageClauses, 96 /* ExtendsKeyword */);
96901
+ const extendsElement = extendsClause && firstOrUndefined(extendsClause.types);
96902
+ const extendsExpression = extendsElement && visitNode(extendsElement.expression, visitor, isExpression);
96903
+ if (extendsExpression) {
96904
+ classInfo2.classSuper = factory2.createUniqueName("_classSuper", 16 /* Optimistic */ | 32 /* FileLevel */);
96905
+ const unwrapped = skipOuterExpressions(extendsExpression);
96906
+ const safeExtendsExpression = isClassExpression(unwrapped) && !unwrapped.name || isFunctionExpression(unwrapped) && !unwrapped.name || isArrowFunction(unwrapped) ? factory2.createComma(factory2.createNumericLiteral(0), extendsExpression) : extendsExpression;
96907
+ classDefinitionStatements.push(createLet(classInfo2.classSuper, safeExtendsExpression));
96908
+ const updatedExtendsElement = factory2.updateExpressionWithTypeArguments(
96909
+ extendsElement,
96910
+ classInfo2.classSuper,
96911
+ /*typeArguments*/
96912
+ void 0
96913
+ );
96914
+ const updatedExtendsClause = factory2.updateHeritageClause(extendsClause, [updatedExtendsElement]);
96915
+ heritageClauses = factory2.createNodeArray([updatedExtendsClause]);
96908
96916
  }
96909
96917
  const renamedClassThis = classInfo2.classThis ?? factory2.createThis();
96910
96918
  enterClass(classInfo2);
96919
+ leadingBlockStatements = append(leadingBlockStatements, createMetadata(classInfo2.metadataReference, classInfo2.classSuper));
96911
96920
  let members = visitNodes2(node.members, classElementVisitor, isClassElement);
96912
96921
  if (pendingExpressions) {
96913
96922
  let outerThis;
@@ -97013,7 +97022,7 @@ function transformESDecorators(context) {
97013
97022
  factory2.createNull(),
97014
97023
  classDescriptorAssignment,
97015
97024
  classInfo2.classDecoratorsName,
97016
- { kind: "class", name: classNameReference },
97025
+ { kind: "class", name: classNameReference, metadata: classInfo2.metadataReference },
97017
97026
  factory2.createNull(),
97018
97027
  classInfo2.classExtraInitializersName
97019
97028
  );
@@ -97025,6 +97034,7 @@ function transformESDecorators(context) {
97025
97034
  const classReferenceAssignment = factory2.createAssignment(classReference, classThisAssignment);
97026
97035
  leadingBlockStatements.push(factory2.createExpressionStatement(classReferenceAssignment));
97027
97036
  }
97037
+ leadingBlockStatements.push(createSymbolMetadata(renamedClassThis, classInfo2.metadataReference));
97028
97038
  if (classInfo2.staticExtraInitializersName) {
97029
97039
  const runStaticInitializersHelper = emitHelpers().createRunInitializersHelper(renamedClassThis, classInfo2.staticExtraInitializersName);
97030
97040
  const runStaticInitializersStatement = factory2.createExpressionStatement(runStaticInitializersHelper);
@@ -97403,7 +97413,8 @@ function transformESDecorators(context) {
97403
97413
  get: isPropertyDeclaration(member) || isGetAccessorDeclaration(member) || isMethodDeclaration(member),
97404
97414
  // 3. If _kind_ is ~field~, ~accessor~, or ~setter~, then ...
97405
97415
  set: isPropertyDeclaration(member) || isSetAccessorDeclaration(member)
97406
- }
97416
+ },
97417
+ metadata: classInfo2.metadataReference
97407
97418
  };
97408
97419
  const extraInitializers = isStatic(member) ? classInfo2.staticExtraInitializersName ?? (classInfo2.staticExtraInitializersName = factory2.createUniqueName("_staticExtraInitializers", 16 /* Optimistic */ | 32 /* FileLevel */)) : classInfo2.instanceExtraInitializersName ?? (classInfo2.instanceExtraInitializersName = factory2.createUniqueName("_instanceExtraInitializers", 16 /* Optimistic */ | 32 /* FileLevel */));
97409
97420
  if (isMethodOrAccessor(member)) {
@@ -98193,6 +98204,60 @@ function transformESDecorators(context) {
98193
98204
  ])
98194
98205
  );
98195
98206
  }
98207
+ function createMetadata(name, classSuper2) {
98208
+ const varDecl = factory2.createVariableDeclaration(
98209
+ name,
98210
+ /*exclamationToken*/
98211
+ void 0,
98212
+ /*type*/
98213
+ void 0,
98214
+ factory2.createConditionalExpression(
98215
+ factory2.createLogicalAnd(
98216
+ factory2.createTypeCheck(factory2.createIdentifier("Symbol"), "function"),
98217
+ factory2.createPropertyAccessExpression(factory2.createIdentifier("Symbol"), "metadata")
98218
+ ),
98219
+ factory2.createToken(58 /* QuestionToken */),
98220
+ factory2.createCallExpression(
98221
+ factory2.createPropertyAccessExpression(factory2.createIdentifier("Object"), "create"),
98222
+ /*typeArguments*/
98223
+ void 0,
98224
+ [classSuper2 ? createSymbolMetadataReference(classSuper2) : factory2.createNull()]
98225
+ ),
98226
+ factory2.createToken(59 /* ColonToken */),
98227
+ factory2.createVoidZero()
98228
+ )
98229
+ );
98230
+ return factory2.createVariableStatement(
98231
+ /*modifiers*/
98232
+ void 0,
98233
+ factory2.createVariableDeclarationList([varDecl], 2 /* Const */)
98234
+ );
98235
+ }
98236
+ function createSymbolMetadata(target, value) {
98237
+ const defineProperty = factory2.createObjectDefinePropertyCall(
98238
+ target,
98239
+ factory2.createPropertyAccessExpression(factory2.createIdentifier("Symbol"), "metadata"),
98240
+ factory2.createPropertyDescriptor(
98241
+ { configurable: true, writable: true, enumerable: true, value },
98242
+ /*singleLine*/
98243
+ true
98244
+ )
98245
+ );
98246
+ return setEmitFlags(
98247
+ factory2.createIfStatement(value, factory2.createExpressionStatement(defineProperty)),
98248
+ 1 /* SingleLine */
98249
+ );
98250
+ }
98251
+ function createSymbolMetadataReference(classSuper2) {
98252
+ return factory2.createBinaryExpression(
98253
+ factory2.createElementAccessExpression(
98254
+ classSuper2,
98255
+ factory2.createPropertyAccessExpression(factory2.createIdentifier("Symbol"), "metadata")
98256
+ ),
98257
+ 61 /* QuestionQuestionToken */,
98258
+ factory2.createNull()
98259
+ );
98260
+ }
98196
98261
  }
98197
98262
 
98198
98263
  // src/compiler/transformers/es2017.ts
@@ -120042,6 +120107,7 @@ var plainJSErrors = /* @__PURE__ */ new Set([
120042
120107
  Diagnostics.Class_constructor_may_not_be_an_accessor.code,
120043
120108
  Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
120044
120109
  Diagnostics.await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
120110
+ Diagnostics.Private_field_0_must_be_declared_in_an_enclosing_class.code,
120045
120111
  // Type errors
120046
120112
  Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value.code
120047
120113
  ]);
@@ -172156,6 +172222,7 @@ __export(ts_exports2, {
172156
172222
  getContainerFlags: () => getContainerFlags,
172157
172223
  getContainerNode: () => getContainerNode,
172158
172224
  getContainingClass: () => getContainingClass,
172225
+ getContainingClassExcludingClassDecorators: () => getContainingClassExcludingClassDecorators,
172159
172226
  getContainingClassStaticBlock: () => getContainingClassStaticBlock,
172160
172227
  getContainingFunction: () => getContainingFunction,
172161
172228
  getContainingFunctionDeclaration: () => getContainingFunctionDeclaration,
@@ -186668,6 +186735,7 @@ start(initializeNodeSystem(), require("os").platform());
186668
186735
  getContainerFlags,
186669
186736
  getContainerNode,
186670
186737
  getContainingClass,
186738
+ getContainingClassExcludingClassDecorators,
186671
186739
  getContainingClassStaticBlock,
186672
186740
  getContainingFunction,
186673
186741
  getContainingFunctionDeclaration,
@@ -35,7 +35,7 @@ var ts = (() => {
35
35
  "src/compiler/corePublic.ts"() {
36
36
  "use strict";
37
37
  versionMajorMinor = "5.2";
38
- version = `${versionMajorMinor}.0-dev.20230623`;
38
+ version = `${versionMajorMinor}.0-dev.20230624`;
39
39
  Comparison = /* @__PURE__ */ ((Comparison3) => {
40
40
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
41
41
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -7096,6 +7096,7 @@ ${lanes.join("\n")}
7096
7096
  A_return_statement_can_only_be_used_within_a_function_body: diag(1108, 1 /* Error */, "A_return_statement_can_only_be_used_within_a_function_body_1108", "A 'return' statement can only be used within a function body."),
7097
7097
  Expression_expected: diag(1109, 1 /* Error */, "Expression_expected_1109", "Expression expected."),
7098
7098
  Type_expected: diag(1110, 1 /* Error */, "Type_expected_1110", "Type expected."),
7099
+ Private_field_0_must_be_declared_in_an_enclosing_class: diag(1111, 1 /* Error */, "Private_field_0_must_be_declared_in_an_enclosing_class_1111", "Private field '{0}' must be declared in an enclosing class."),
7099
7100
  A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: diag(1113, 1 /* Error */, "A_default_clause_cannot_appear_more_than_once_in_a_switch_statement_1113", "A 'default' clause cannot appear more than once in a 'switch' statement."),
7100
7101
  Duplicate_label_0: diag(1114, 1 /* Error */, "Duplicate_label_0_1114", "Duplicate label '{0}'."),
7101
7102
  A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement: diag(1115, 1 /* Error */, "A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement_1115", "A 'continue' statement can only jump to a label of an enclosing iteration statement."),
@@ -14530,6 +14531,10 @@ ${lanes.join("\n")}
14530
14531
  function getContainingFunctionOrClassStaticBlock(node) {
14531
14532
  return findAncestor(node.parent, isFunctionLikeOrClassStaticBlockDeclaration);
14532
14533
  }
14534
+ function getContainingClassExcludingClassDecorators(node) {
14535
+ const decorator = findAncestor(node.parent, (n) => isClassLike(n) ? "quit" : isDecorator(n));
14536
+ return decorator && isClassLike(decorator.parent) ? getContainingClass(decorator.parent) : getContainingClass(decorator ?? node);
14537
+ }
14533
14538
  function getThisContainer(node, includeArrowFunctions, includeClassComputedPropertyName) {
14534
14539
  Debug.assert(node.kind !== 312 /* SourceFile */);
14535
14540
  while (true) {
@@ -25082,10 +25087,12 @@ ${lanes.join("\n")}
25082
25087
  );
25083
25088
  }
25084
25089
  function createESDecorateClassContextObject(contextIn) {
25085
- return factory2.createObjectLiteralExpression([
25090
+ const properties = [
25086
25091
  factory2.createPropertyAssignment(factory2.createIdentifier("kind"), factory2.createStringLiteral("class")),
25087
- factory2.createPropertyAssignment(factory2.createIdentifier("name"), contextIn.name)
25088
- ]);
25092
+ factory2.createPropertyAssignment(factory2.createIdentifier("name"), contextIn.name),
25093
+ factory2.createPropertyAssignment(factory2.createIdentifier("metadata"), contextIn.metadata)
25094
+ ];
25095
+ return factory2.createObjectLiteralExpression(properties);
25089
25096
  }
25090
25097
  function createESDecorateClassElementAccessGetMethod(elementName) {
25091
25098
  const accessor = elementName.computed ? factory2.createElementAccessExpression(factory2.createIdentifier("obj"), elementName.name) : factory2.createPropertyAccessExpression(factory2.createIdentifier("obj"), elementName.name);
@@ -25189,13 +25196,15 @@ ${lanes.join("\n")}
25189
25196
  return factory2.createObjectLiteralExpression(properties);
25190
25197
  }
25191
25198
  function createESDecorateClassElementContextObject(contextIn) {
25192
- return factory2.createObjectLiteralExpression([
25199
+ const properties = [
25193
25200
  factory2.createPropertyAssignment(factory2.createIdentifier("kind"), factory2.createStringLiteral(contextIn.kind)),
25194
25201
  factory2.createPropertyAssignment(factory2.createIdentifier("name"), contextIn.name.computed ? contextIn.name.name : factory2.createStringLiteralFromNode(contextIn.name.name)),
25195
25202
  factory2.createPropertyAssignment(factory2.createIdentifier("static"), contextIn.static ? factory2.createTrue() : factory2.createFalse()),
25196
25203
  factory2.createPropertyAssignment(factory2.createIdentifier("private"), contextIn.private ? factory2.createTrue() : factory2.createFalse()),
25197
- factory2.createPropertyAssignment(factory2.createIdentifier("access"), createESDecorateClassElementAccessObject(contextIn.name, contextIn.access))
25198
- ]);
25204
+ factory2.createPropertyAssignment(factory2.createIdentifier("access"), createESDecorateClassElementAccessObject(contextIn.name, contextIn.access)),
25205
+ factory2.createPropertyAssignment(factory2.createIdentifier("metadata"), contextIn.metadata)
25206
+ ];
25207
+ return factory2.createObjectLiteralExpression(properties);
25199
25208
  }
25200
25209
  function createESDecorateContextObject(contextIn) {
25201
25210
  return contextIn.kind === "class" ? createESDecorateClassContextObject(contextIn) : createESDecorateClassElementContextObject(contextIn);
@@ -37557,6 +37566,7 @@ ${lanes.join("\n")}
37557
37566
  ["esnext.string", "lib.es2022.string.d.ts"],
37558
37567
  ["esnext.promise", "lib.es2021.promise.d.ts"],
37559
37568
  ["esnext.weakref", "lib.es2021.weakref.d.ts"],
37569
+ ["esnext.decorators", "lib.esnext.decorators.d.ts"],
37560
37570
  ["decorators", "lib.decorators.d.ts"],
37561
37571
  ["decorators.legacy", "lib.decorators.legacy.d.ts"]
37562
37572
  ];
@@ -68475,7 +68485,7 @@ ${lanes.join("\n")}
68475
68485
  location = location.parent;
68476
68486
  }
68477
68487
  if (isExpressionNode(location) && (!isAssignmentTarget(location) || isWriteAccess(location))) {
68478
- const type = getTypeOfExpression(location);
68488
+ const type = removeOptionalTypeMarker(getTypeOfExpression(location));
68479
68489
  if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) {
68480
68490
  return type;
68481
68491
  }
@@ -71486,7 +71496,7 @@ ${lanes.join("\n")}
71486
71496
  return isCallOrNewExpression(node.parent) && node.parent.expression === node;
71487
71497
  }
71488
71498
  function lookupSymbolForPrivateIdentifierDeclaration(propName, location) {
71489
- for (let containingClass = getContainingClass(location); !!containingClass; containingClass = getContainingClass(containingClass)) {
71499
+ for (let containingClass = getContainingClassExcludingClassDecorators(location); !!containingClass; containingClass = getContainingClass(containingClass)) {
71490
71500
  const { symbol } = containingClass;
71491
71501
  const name = getSymbolNameForPrivateIdentifier(symbol, propName);
71492
71502
  const prop = symbol.members && symbol.members.get(name) || symbol.exports && symbol.exports.get(name);
@@ -71622,16 +71632,22 @@ ${lanes.join("\n")}
71622
71632
  if (lexicallyScopedSymbol) {
71623
71633
  return isErrorType(apparentType) ? errorType : apparentType;
71624
71634
  }
71625
- if (!getContainingClass(right)) {
71635
+ if (getContainingClassExcludingClassDecorators(right) === void 0) {
71626
71636
  grammarErrorOnNode(right, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies);
71627
71637
  return anyType;
71628
71638
  }
71629
71639
  }
71630
- prop = lexicallyScopedSymbol ? getPrivateIdentifierPropertyOfType(leftType, lexicallyScopedSymbol) : void 0;
71631
- if (!prop && checkPrivateIdentifierPropertyAccess(leftType, right, lexicallyScopedSymbol)) {
71632
- return errorType;
71640
+ prop = lexicallyScopedSymbol && getPrivateIdentifierPropertyOfType(leftType, lexicallyScopedSymbol);
71641
+ if (prop === void 0) {
71642
+ if (checkPrivateIdentifierPropertyAccess(leftType, right, lexicallyScopedSymbol)) {
71643
+ return errorType;
71644
+ }
71645
+ const containingClass = getContainingClassExcludingClassDecorators(right);
71646
+ if (containingClass && isPlainJsFile(getSourceFileOfNode(containingClass), compilerOptions.checkJs)) {
71647
+ grammarErrorOnNode(right, Diagnostics.Private_field_0_must_be_declared_in_an_enclosing_class, idText(right));
71648
+ }
71633
71649
  } else {
71634
- const isSetonlyAccessor = prop && prop.flags & 65536 /* SetAccessor */ && !(prop.flags & 32768 /* GetAccessor */);
71650
+ const isSetonlyAccessor = prop.flags & 65536 /* SetAccessor */ && !(prop.flags & 32768 /* GetAccessor */);
71635
71651
  if (isSetonlyAccessor && assignmentKind !== 1 /* Definite */) {
71636
71652
  error2(node, Diagnostics.Private_accessor_was_defined_without_a_getter);
71637
71653
  }
@@ -92579,9 +92595,12 @@ ${lanes.join("\n")}
92579
92595
  return getClassLexicalEnvironment().classConstructor = node.emitNode.classThis;
92580
92596
  }
92581
92597
  const classCheckFlags = resolver.getNodeCheckFlags(node);
92582
- const isClassWithConstructorReference2 = classCheckFlags & 1048576 /* ClassWithConstructorReference */;
92583
92598
  const requiresBlockScopedVar = classCheckFlags & 32768 /* BlockScopedBindingInLoop */;
92584
- const temp2 = factory2.createTempVariable(requiresBlockScopedVar ? addBlockScopedVariable : hoistVariableDeclaration, !!isClassWithConstructorReference2);
92599
+ const temp2 = factory2.createTempVariable(
92600
+ requiresBlockScopedVar ? addBlockScopedVariable : hoistVariableDeclaration,
92601
+ /*reservedInNestedScopes*/
92602
+ true
92603
+ );
92585
92604
  getClassLexicalEnvironment().classConstructor = factory2.cloneNode(temp2);
92586
92605
  return temp2;
92587
92606
  }
@@ -94762,6 +94781,7 @@ ${lanes.join("\n")}
94762
94781
  );
94763
94782
  }
94764
94783
  function createClassInfo(node) {
94784
+ const metadataReference = factory2.createUniqueName("_metadata", 16 /* Optimistic */ | 32 /* FileLevel */);
94765
94785
  let instanceExtraInitializersName;
94766
94786
  let staticExtraInitializersName;
94767
94787
  let hasStaticInitializers = false;
@@ -94800,6 +94820,7 @@ ${lanes.join("\n")}
94800
94820
  }
94801
94821
  return {
94802
94822
  class: node,
94823
+ metadataReference,
94803
94824
  instanceExtraInitializersName,
94804
94825
  staticExtraInitializersName,
94805
94826
  hasStaticInitializers,
@@ -94807,16 +94828,6 @@ ${lanes.join("\n")}
94807
94828
  hasStaticPrivateClassElements
94808
94829
  };
94809
94830
  }
94810
- function containsLexicalSuperInStaticInitializer(node) {
94811
- for (const member of node.members) {
94812
- if (isClassStaticBlockDeclaration(member) || isPropertyDeclaration(member) && hasStaticModifier(member)) {
94813
- if (member.transformFlags & 134217728 /* ContainsLexicalSuper */) {
94814
- return true;
94815
- }
94816
- }
94817
- }
94818
- return false;
94819
- }
94820
94831
  function transformClassLike(node) {
94821
94832
  startLexicalEnvironment();
94822
94833
  if (!classHasDeclaredOrExplicitlyAssignedName(node) && classOrConstructorParameterIsDecorated(
@@ -94860,29 +94871,26 @@ ${lanes.join("\n")}
94860
94871
  shouldTransformPrivateStaticElementsInFile = true;
94861
94872
  }
94862
94873
  }
94863
- if (classDecorators && containsLexicalSuperInStaticInitializer(node)) {
94864
- const extendsClause = getHeritageClause(node.heritageClauses, 96 /* ExtendsKeyword */);
94865
- const extendsElement = extendsClause && firstOrUndefined(extendsClause.types);
94866
- const extendsExpression = extendsElement && visitNode(extendsElement.expression, visitor, isExpression);
94867
- if (extendsExpression) {
94868
- classInfo2.classSuper = factory2.createUniqueName("_classSuper", 16 /* Optimistic */ | 32 /* FileLevel */);
94869
- const unwrapped = skipOuterExpressions(extendsExpression);
94870
- const safeExtendsExpression = isClassExpression(unwrapped) && !unwrapped.name || isFunctionExpression(unwrapped) && !unwrapped.name || isArrowFunction(unwrapped) ? factory2.createComma(factory2.createNumericLiteral(0), extendsExpression) : extendsExpression;
94871
- classDefinitionStatements.push(createLet(classInfo2.classSuper, safeExtendsExpression));
94872
- const updatedExtendsElement = factory2.updateExpressionWithTypeArguments(
94873
- extendsElement,
94874
- classInfo2.classSuper,
94875
- /*typeArguments*/
94876
- void 0
94877
- );
94878
- const updatedExtendsClause = factory2.updateHeritageClause(extendsClause, [updatedExtendsElement]);
94879
- heritageClauses = factory2.createNodeArray([updatedExtendsClause]);
94880
- }
94881
- } else {
94882
- heritageClauses = visitNodes2(node.heritageClauses, visitor, isHeritageClause);
94874
+ const extendsClause = getHeritageClause(node.heritageClauses, 96 /* ExtendsKeyword */);
94875
+ const extendsElement = extendsClause && firstOrUndefined(extendsClause.types);
94876
+ const extendsExpression = extendsElement && visitNode(extendsElement.expression, visitor, isExpression);
94877
+ if (extendsExpression) {
94878
+ classInfo2.classSuper = factory2.createUniqueName("_classSuper", 16 /* Optimistic */ | 32 /* FileLevel */);
94879
+ const unwrapped = skipOuterExpressions(extendsExpression);
94880
+ const safeExtendsExpression = isClassExpression(unwrapped) && !unwrapped.name || isFunctionExpression(unwrapped) && !unwrapped.name || isArrowFunction(unwrapped) ? factory2.createComma(factory2.createNumericLiteral(0), extendsExpression) : extendsExpression;
94881
+ classDefinitionStatements.push(createLet(classInfo2.classSuper, safeExtendsExpression));
94882
+ const updatedExtendsElement = factory2.updateExpressionWithTypeArguments(
94883
+ extendsElement,
94884
+ classInfo2.classSuper,
94885
+ /*typeArguments*/
94886
+ void 0
94887
+ );
94888
+ const updatedExtendsClause = factory2.updateHeritageClause(extendsClause, [updatedExtendsElement]);
94889
+ heritageClauses = factory2.createNodeArray([updatedExtendsClause]);
94883
94890
  }
94884
94891
  const renamedClassThis = classInfo2.classThis ?? factory2.createThis();
94885
94892
  enterClass(classInfo2);
94893
+ leadingBlockStatements = append(leadingBlockStatements, createMetadata(classInfo2.metadataReference, classInfo2.classSuper));
94886
94894
  let members = visitNodes2(node.members, classElementVisitor, isClassElement);
94887
94895
  if (pendingExpressions) {
94888
94896
  let outerThis;
@@ -94988,7 +94996,7 @@ ${lanes.join("\n")}
94988
94996
  factory2.createNull(),
94989
94997
  classDescriptorAssignment,
94990
94998
  classInfo2.classDecoratorsName,
94991
- { kind: "class", name: classNameReference },
94999
+ { kind: "class", name: classNameReference, metadata: classInfo2.metadataReference },
94992
95000
  factory2.createNull(),
94993
95001
  classInfo2.classExtraInitializersName
94994
95002
  );
@@ -95000,6 +95008,7 @@ ${lanes.join("\n")}
95000
95008
  const classReferenceAssignment = factory2.createAssignment(classReference, classThisAssignment);
95001
95009
  leadingBlockStatements.push(factory2.createExpressionStatement(classReferenceAssignment));
95002
95010
  }
95011
+ leadingBlockStatements.push(createSymbolMetadata(renamedClassThis, classInfo2.metadataReference));
95003
95012
  if (classInfo2.staticExtraInitializersName) {
95004
95013
  const runStaticInitializersHelper = emitHelpers().createRunInitializersHelper(renamedClassThis, classInfo2.staticExtraInitializersName);
95005
95014
  const runStaticInitializersStatement = factory2.createExpressionStatement(runStaticInitializersHelper);
@@ -95378,7 +95387,8 @@ ${lanes.join("\n")}
95378
95387
  get: isPropertyDeclaration(member) || isGetAccessorDeclaration(member) || isMethodDeclaration(member),
95379
95388
  // 3. If _kind_ is ~field~, ~accessor~, or ~setter~, then ...
95380
95389
  set: isPropertyDeclaration(member) || isSetAccessorDeclaration(member)
95381
- }
95390
+ },
95391
+ metadata: classInfo2.metadataReference
95382
95392
  };
95383
95393
  const extraInitializers = isStatic(member) ? classInfo2.staticExtraInitializersName ?? (classInfo2.staticExtraInitializersName = factory2.createUniqueName("_staticExtraInitializers", 16 /* Optimistic */ | 32 /* FileLevel */)) : classInfo2.instanceExtraInitializersName ?? (classInfo2.instanceExtraInitializersName = factory2.createUniqueName("_instanceExtraInitializers", 16 /* Optimistic */ | 32 /* FileLevel */));
95384
95394
  if (isMethodOrAccessor(member)) {
@@ -96168,6 +96178,60 @@ ${lanes.join("\n")}
96168
96178
  ])
96169
96179
  );
96170
96180
  }
96181
+ function createMetadata(name, classSuper2) {
96182
+ const varDecl = factory2.createVariableDeclaration(
96183
+ name,
96184
+ /*exclamationToken*/
96185
+ void 0,
96186
+ /*type*/
96187
+ void 0,
96188
+ factory2.createConditionalExpression(
96189
+ factory2.createLogicalAnd(
96190
+ factory2.createTypeCheck(factory2.createIdentifier("Symbol"), "function"),
96191
+ factory2.createPropertyAccessExpression(factory2.createIdentifier("Symbol"), "metadata")
96192
+ ),
96193
+ factory2.createToken(58 /* QuestionToken */),
96194
+ factory2.createCallExpression(
96195
+ factory2.createPropertyAccessExpression(factory2.createIdentifier("Object"), "create"),
96196
+ /*typeArguments*/
96197
+ void 0,
96198
+ [classSuper2 ? createSymbolMetadataReference(classSuper2) : factory2.createNull()]
96199
+ ),
96200
+ factory2.createToken(59 /* ColonToken */),
96201
+ factory2.createVoidZero()
96202
+ )
96203
+ );
96204
+ return factory2.createVariableStatement(
96205
+ /*modifiers*/
96206
+ void 0,
96207
+ factory2.createVariableDeclarationList([varDecl], 2 /* Const */)
96208
+ );
96209
+ }
96210
+ function createSymbolMetadata(target, value) {
96211
+ const defineProperty = factory2.createObjectDefinePropertyCall(
96212
+ target,
96213
+ factory2.createPropertyAccessExpression(factory2.createIdentifier("Symbol"), "metadata"),
96214
+ factory2.createPropertyDescriptor(
96215
+ { configurable: true, writable: true, enumerable: true, value },
96216
+ /*singleLine*/
96217
+ true
96218
+ )
96219
+ );
96220
+ return setEmitFlags(
96221
+ factory2.createIfStatement(value, factory2.createExpressionStatement(defineProperty)),
96222
+ 1 /* SingleLine */
96223
+ );
96224
+ }
96225
+ function createSymbolMetadataReference(classSuper2) {
96226
+ return factory2.createBinaryExpression(
96227
+ factory2.createElementAccessExpression(
96228
+ classSuper2,
96229
+ factory2.createPropertyAccessExpression(factory2.createIdentifier("Symbol"), "metadata")
96230
+ ),
96231
+ 61 /* QuestionQuestionToken */,
96232
+ factory2.createNull()
96233
+ );
96234
+ }
96171
96235
  }
96172
96236
  var init_esDecorators = __esm({
96173
96237
  "src/compiler/transformers/esDecorators.ts"() {
@@ -121425,6 +121489,7 @@ ${lanes.join("\n")}
121425
121489
  Diagnostics.Class_constructor_may_not_be_an_accessor.code,
121426
121490
  Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
121427
121491
  Diagnostics.await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
121492
+ Diagnostics.Private_field_0_must_be_declared_in_an_enclosing_class.code,
121428
121493
  // Type errors
121429
121494
  Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value.code
121430
121495
  ]);
@@ -183297,6 +183362,7 @@ ${e.message}`;
183297
183362
  getContainerFlags: () => getContainerFlags,
183298
183363
  getContainerNode: () => getContainerNode,
183299
183364
  getContainingClass: () => getContainingClass,
183365
+ getContainingClassExcludingClassDecorators: () => getContainingClassExcludingClassDecorators,
183300
183366
  getContainingClassStaticBlock: () => getContainingClassStaticBlock,
183301
183367
  getContainingFunction: () => getContainingFunction,
183302
183368
  getContainingFunctionDeclaration: () => getContainingFunctionDeclaration,
@@ -185699,6 +185765,7 @@ ${e.message}`;
185699
185765
  getContainerFlags: () => getContainerFlags,
185700
185766
  getContainerNode: () => getContainerNode,
185701
185767
  getContainingClass: () => getContainingClass,
185768
+ getContainingClassExcludingClassDecorators: () => getContainingClassExcludingClassDecorators,
185702
185769
  getContainingClassStaticBlock: () => getContainingClassStaticBlock,
185703
185770
  getContainingFunction: () => getContainingFunction,
185704
185771
  getContainingFunctionDeclaration: () => getContainingFunctionDeclaration,