mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-30 04:16:48 -05:00
fix(37287): check appropriate context with enabled useDefineForClassFields (#37323)
This commit is contained in:
@@ -1412,7 +1412,7 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
if (isUsedInFunctionOrInstanceProperty(usage, declaration, container)) {
|
||||
if (compilerOptions.target === ScriptTarget.ESNext && !!compilerOptions.useDefineForClassFields) {
|
||||
if (compilerOptions.target === ScriptTarget.ESNext && !!compilerOptions.useDefineForClassFields && getContainingClass(declaration)) {
|
||||
return (isPropertyDeclaration(declaration) || isParameterPropertyDeclaration(declaration, declaration.parent)) &&
|
||||
!isPropertyImmediatelyReferencedWithinDeclaration(declaration, usage, /*stopAtAnyPropertyDeclaration*/ true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
//// [defineVariables_useDefineForClassFields.ts]
|
||||
const a = () => b()
|
||||
const b = () => null
|
||||
a()
|
||||
|
||||
//// [defineVariables_useDefineForClassFields.js]
|
||||
const a = () => b();
|
||||
const b = () => null;
|
||||
a();
|
||||
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/defineVariables_useDefineForClassFields.ts ===
|
||||
const a = () => b()
|
||||
>a : Symbol(a, Decl(defineVariables_useDefineForClassFields.ts, 0, 5))
|
||||
>b : Symbol(b, Decl(defineVariables_useDefineForClassFields.ts, 1, 5))
|
||||
|
||||
const b = () => null
|
||||
>b : Symbol(b, Decl(defineVariables_useDefineForClassFields.ts, 1, 5))
|
||||
|
||||
a()
|
||||
>a : Symbol(a, Decl(defineVariables_useDefineForClassFields.ts, 0, 5))
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/defineVariables_useDefineForClassFields.ts ===
|
||||
const a = () => b()
|
||||
>a : () => any
|
||||
>() => b() : () => any
|
||||
>b() : any
|
||||
>b : () => any
|
||||
|
||||
const b = () => null
|
||||
>b : () => any
|
||||
>() => null : () => any
|
||||
>null : null
|
||||
|
||||
a()
|
||||
>a() : any
|
||||
>a : () => any
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// @target: ESNext
|
||||
// @useDefineForClassFields: true
|
||||
|
||||
const a = () => b()
|
||||
const b = () => null
|
||||
a()
|
||||
Reference in New Issue
Block a user