@@ -274,6 +274,7 @@ import {
274
274
getEmitModuleKind,
275
275
getEmitModuleResolutionKind,
276
276
getEmitScriptTarget,
277
+ getEmitStandardClassFields,
277
278
getEnclosingBlockScopeContainer,
278
279
getEnclosingContainer,
279
280
getEntityNameFromTypeNode,
@@ -1437,6 +1438,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1437
1438
var moduleKind = getEmitModuleKind(compilerOptions);
1438
1439
var legacyDecorators = !!compilerOptions.experimentalDecorators;
1439
1440
var useDefineForClassFields = getUseDefineForClassFields(compilerOptions);
1441
+ var emitStandardClassFields = getEmitStandardClassFields(compilerOptions);
1440
1442
var allowSyntheticDefaultImports = getAllowSyntheticDefaultImports(compilerOptions);
1441
1443
var strictNullChecks = getStrictOptionValue(compilerOptions, "strictNullChecks");
1442
1444
var strictFunctionTypes = getStrictOptionValue(compilerOptions, "strictFunctionTypes");
@@ -2785,8 +2787,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2785
2787
return !isPropertyImmediatelyReferencedWithinDeclaration(declaration, usage, /*stopAtAnyPropertyDeclaration*/ false);
2786
2788
}
2787
2789
else if (isParameterPropertyDeclaration(declaration, declaration.parent)) {
2788
- // foo = this.bar is illegal in esnext+useDefineForClassFields when bar is a parameter property
2789
- return !(getEmitScriptTarget(compilerOptions) === ScriptTarget.ESNext && useDefineForClassFields
2790
+ // foo = this.bar is illegal in emitStandardClassFields when bar is a parameter property
2791
+ return !(emitStandardClassFields
2790
2792
&& getContainingClass(declaration) === getContainingClass(usage)
2791
2793
&& isUsedInFunctionOrInstanceProperty(usage, declaration));
2792
2794
}
@@ -2798,7 +2800,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2798
2800
// 1. inside an export specifier
2799
2801
// 2. inside a function
2800
2802
// 3. inside an instance property initializer, a reference to a non-instance property
2801
- // (except when target: "esnext" and useDefineForClassFields : true and the reference is to a parameter property)
2803
+ // (except when emitStandardClassFields : true and the reference is to a parameter property)
2802
2804
// 4. inside a static property initializer, a reference to a static method in the same class
2803
2805
// 5. inside a TS export= declaration (since we will move the export statement during emit to avoid TDZ)
2804
2806
// or if usage is in a type context:
@@ -2817,7 +2819,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2817
2819
return true;
2818
2820
}
2819
2821
if (isUsedInFunctionOrInstanceProperty(usage, declaration)) {
2820
- if (getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2022 && useDefineForClassFields
2822
+ if (emitStandardClassFields
2821
2823
&& getContainingClass(declaration)
2822
2824
&& (isPropertyDeclaration(declaration) || isParameterPropertyDeclaration(declaration, declaration.parent))) {
2823
2825
return !isPropertyImmediatelyReferencedWithinDeclaration(declaration, usage, /*stopAtAnyPropertyDeclaration*/ true);
@@ -2974,7 +2976,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2974
2976
case SyntaxKind.PropertyDeclaration:
2975
2977
// static properties in classes introduce temporary variables
2976
2978
if (hasStaticModifier(node)) {
2977
- return target < ScriptTarget.ESNext || !useDefineForClassFields ;
2979
+ return !emitStandardClassFields ;
2978
2980
}
2979
2981
return requiresScopeChangeWorker((node as PropertyDeclaration).name);
2980
2982
default:
@@ -3392,10 +3394,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3392
3394
// 1. When result is undefined, after checking for a missing "this."
3393
3395
// 2. When result is defined
3394
3396
function checkAndReportErrorForInvalidInitializer() {
3395
- if (propertyWithInvalidInitializer && !(useDefineForClassFields && getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2022) ) {
3397
+ if (propertyWithInvalidInitializer && !emitStandardClassFields ) {
3396
3398
// We have a match, but the reference occurred within a property initializer and the identifier also binds
3397
3399
// to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
3398
- // with ESNext+useDefineForClassFields because the scope semantics are different.
3400
+ // with emitStandardClassFields because the scope semantics are different.
3399
3401
error(errorLocation,
3400
3402
errorLocation && propertyWithInvalidInitializer.type && textRangeContainsPositionInclusive(propertyWithInvalidInitializer.type, errorLocation.pos)
3401
3403
? Diagnostics.Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor
@@ -31739,7 +31741,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
31739
31741
&& !(isAccessExpression(node) && isAccessExpression(node.expression))
31740
31742
&& !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)
31741
31743
&& !(isMethodDeclaration(valueDeclaration) && getCombinedModifierFlagsCached(valueDeclaration) & ModifierFlags.Static)
31742
- && (compilerOptions. useDefineForClassFields || !isPropertyDeclaredInAncestorClass(prop))) {
31744
+ && (useDefineForClassFields || !isPropertyDeclaredInAncestorClass(prop))) {
31743
31745
diagnosticMessage = error(right, Diagnostics.Property_0_is_used_before_its_initialization, declarationName);
31744
31746
}
31745
31747
else if (valueDeclaration.kind === SyntaxKind.ClassDeclaration &&
@@ -38453,7 +38455,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
38453
38455
case "length":
38454
38456
case "caller":
38455
38457
case "arguments":
38456
- if (compilerOptions. useDefineForClassFields) {
38458
+ if (useDefineForClassFields) {
38457
38459
break;
38458
38460
}
38459
38461
// fall through
@@ -38658,7 +38660,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
38658
38660
// or the containing class declares instance member variables with initializers.
38659
38661
38660
38662
const superCallShouldBeRootLevel =
38661
- (getEmitScriptTarget(compilerOptions) !== ScriptTarget.ESNext || !useDefineForClassFields) &&
38663
+ !emitStandardClassFields &&
38662
38664
(some((node.parent as ClassDeclaration).members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
38663
38665
some(node.parameters, p => hasSyntacticModifier(p, ModifierFlags.ParameterPropertyModifier)));
38664
38666
@@ -42935,7 +42937,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
42935
42937
!legacyDecorators && languageVersion < ScriptTarget.ESNext &&
42936
42938
classOrConstructorParameterIsDecorated(/*useLegacyDecorators*/ false, node);
42937
42939
const willTransformPrivateElementsOrClassStaticBlocks = languageVersion <= ScriptTarget.ES2022;
42938
- const willTransformInitializers = !useDefineForClassFields || languageVersion < ScriptTarget.ES2022 ;
42940
+ const willTransformInitializers = !emitStandardClassFields ;
42939
42941
if (willTransformStaticElementsOfDecoratedClass || willTransformPrivateElementsOrClassStaticBlocks) {
42940
42942
for (const member of node.members) {
42941
42943
if (willTransformStaticElementsOfDecoratedClass && classElementOrClassElementParameterIsDecorated(/*useLegacyDecorators*/ false, member, node)) {
0 commit comments