Fix use-before-def errors for ESNext property declarations#36465
Fix use-before-def errors for ESNext property declarations#36465
Conversation
| else if (isParameterPropertyDeclaration(declaration, declaration.parent)) { | ||
| const container = getEnclosingBlockScopeContainer(declaration.parent); | ||
| // foo = this.bar is illegal in esnext+useDefineForClassFields when bar is a parameter property | ||
| return !(compilerOptions.target === ScriptTarget.ESNext && !!compilerOptions.useDefineForClassFields |
There was a problem hiding this comment.
For some reason my brain wants this expression to be De Morgan’d, or maybe for whole function itself to return use-before-declared, not declared-before-used. Oh well.
There was a problem hiding this comment.
the WHOLE time I was working on this, except every change made things harder to read.
| || isInTypeQuery(usage) | ||
| || isUsedInFunctionOrInstanceProperty(usage, declaration, container) | ||
| && !(compilerOptions.target === ScriptTarget.ESNext && !!compilerOptions.useDefineForClassFields); | ||
| if (!!(usage.flags & NodeFlags.JSDoc) || isInTypeQuery(usage)) { |
There was a problem hiding this comment.
I bet this condition actually could be the same as isValidTypeOnlyAliasUseSite. But probably not worth changing.
src/compiler/checker.ts
Outdated
| case SyntaxKind.PropertyDeclaration: | ||
| return true; | ||
| case SyntaxKind.PropertyDeclaration: | ||
| return stopAtAllPropertyDeclarations ? "quit": true; |
There was a problem hiding this comment.
I can’t quite figure out what this means without stepping through one case that needs stopAtAllPropertyDeclarations as true and one that needs false, but are there any tests with a class expression as the initializer of a property declaration?
class Foo {
Bar = class extends Foo {
p2 = this.p1
}
p1 = 0
}(I don’t know, maybe there’s a more creative combo of these horrors)
There was a problem hiding this comment.
There is one:
class B2<V> {
anon = class extends A<V> { }
}Your example works on 3.7, so needs to keep working on 3.8:
Back to the drawing board I guess. What a test case!
There was a problem hiding this comment.
Commit to fix this looks good 👍
Fixes #36441
Fixes #36442