Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/compiler/utilitiesPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import {
isClassStaticBlockDeclaration,
isDecorator,
isElementAccessExpression,
isExpandoPropertyDeclaration,
isExportAssignment,
isExportDeclaration,
isExportSpecifier,
Expand Down Expand Up @@ -1705,7 +1706,10 @@ export function isAutoAccessorPropertyDeclaration(node: Node): node is AutoAcces
}

/** @internal */
export function isClassFieldAndNotAutoAccessor(node: Node): boolean {
export function isClassFieldAndNotAutoAccessor(node: Declaration): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function isClassFieldAndNotAutoAccessor(node: Declaration): boolean {
export function isClassInstanceProperty(node: Declaration): boolean {

if (isInJSFile(node) && isExpandoPropertyDeclaration(node)) {
return true;
}
return node.parent && isClassLike(node.parent) && isPropertyDeclaration(node) && !hasAccessorModifier(node);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
index.js(20,22): error TS2855: Class field 'roots' defined by the parent class is not accessible in the child class via super.
index.js(23,22): error TS2855: Class field 'foo' defined by the parent class is not accessible in the child class via super.
index.js(26,22): error TS2855: Class field 'justProp' defined by the parent class is not accessible in the child class via super.
index.js(29,22): error TS2855: Class field ''literalElementAccess'' defined by the parent class is not accessible in the child class via super.


==== index.js (4 errors) ====
// https://github.com/microsoft/TypeScript/issues/55884

class YaddaBase {
constructor() {
this.roots = "hi";
/** @type number */
this.justProp;
/** @type string */
this['literalElementAccess'];

this.b()
}
accessor b = () => {
this.foo = 10
}
}

class DerivedYadda extends YaddaBase {
get rootTests() {
return super.roots;
~~~~~
!!! error TS2855: Class field 'roots' defined by the parent class is not accessible in the child class via super.
}
get fooTests() {
return super.foo;
~~~
!!! error TS2855: Class field 'foo' defined by the parent class is not accessible in the child class via super.
}
get justPropTests() {
return super.justProp;
~~~~~~~~
!!! error TS2855: Class field 'justProp' defined by the parent class is not accessible in the child class via super.
}
get literalElementAccessTests() {
return super.literalElementAccess;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for super["literalElementAccess"] as well?

Also, can you just add a test for super.b? I bet we have no test for super. on an accessor declaration at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for super["literalElementAccess"] as well?

Good catch. It doesn't work correctly today (TS playground) even in TS files. For that reason - I'd say that this is a separate issue. I can look into it as well but I'd prefer to explore it separately.

Also, can you just add a test for super.b? I bet we have no test for super. on an accessor declaration at all.

Sure thing, just added it.

~~~~~~~~~~~~~~~~~~~~
!!! error TS2855: Class field ''literalElementAccess'' defined by the parent class is not accessible in the child class via super.
}
}

78 changes: 78 additions & 0 deletions tests/baselines/reference/classFieldSuperNotAccessibleJs.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//// [tests/cases/compiler/classFieldSuperNotAccessibleJs.ts] ////

=== index.js ===
// https://github.com/microsoft/TypeScript/issues/55884

class YaddaBase {
>YaddaBase : Symbol(YaddaBase, Decl(index.js, 0, 0))

constructor() {
this.roots = "hi";
>this.roots : Symbol(YaddaBase.roots, Decl(index.js, 3, 19))
>this : Symbol(YaddaBase, Decl(index.js, 0, 0))
>roots : Symbol(YaddaBase.roots, Decl(index.js, 3, 19))

/** @type number */
this.justProp;
>this.justProp : Symbol(YaddaBase.justProp, Decl(index.js, 4, 26))
>this : Symbol(YaddaBase, Decl(index.js, 0, 0))
>justProp : Symbol(YaddaBase.justProp, Decl(index.js, 4, 26))

/** @type string */
this['literalElementAccess'];
>this : Symbol(YaddaBase, Decl(index.js, 0, 0))
>'literalElementAccess' : Symbol(YaddaBase['literalElementAccess'], Decl(index.js, 6, 22))

this.b()
>this.b : Symbol(YaddaBase.b, Decl(index.js, 11, 5))
>this : Symbol(YaddaBase, Decl(index.js, 0, 0))
>b : Symbol(YaddaBase.b, Decl(index.js, 11, 5))
}
accessor b = () => {
>b : Symbol(YaddaBase.b, Decl(index.js, 11, 5))

this.foo = 10
>this.foo : Symbol(YaddaBase.foo, Decl(index.js, 12, 24))
>this : Symbol(YaddaBase, Decl(index.js, 0, 0))
>foo : Symbol(YaddaBase.foo, Decl(index.js, 12, 24))
}
}

class DerivedYadda extends YaddaBase {
>DerivedYadda : Symbol(DerivedYadda, Decl(index.js, 15, 1))
>YaddaBase : Symbol(YaddaBase, Decl(index.js, 0, 0))

get rootTests() {
>rootTests : Symbol(DerivedYadda.rootTests, Decl(index.js, 17, 38))

return super.roots;
>super.roots : Symbol(YaddaBase.roots, Decl(index.js, 3, 19))
>super : Symbol(YaddaBase, Decl(index.js, 0, 0))
>roots : Symbol(YaddaBase.roots, Decl(index.js, 3, 19))
}
get fooTests() {
>fooTests : Symbol(DerivedYadda.fooTests, Decl(index.js, 20, 5))

return super.foo;
>super.foo : Symbol(YaddaBase.foo, Decl(index.js, 12, 24))
>super : Symbol(YaddaBase, Decl(index.js, 0, 0))
>foo : Symbol(YaddaBase.foo, Decl(index.js, 12, 24))
}
get justPropTests() {
>justPropTests : Symbol(DerivedYadda.justPropTests, Decl(index.js, 23, 5))

return super.justProp;
>super.justProp : Symbol(YaddaBase.justProp, Decl(index.js, 4, 26))
>super : Symbol(YaddaBase, Decl(index.js, 0, 0))
>justProp : Symbol(YaddaBase.justProp, Decl(index.js, 4, 26))
}
get literalElementAccessTests() {
>literalElementAccessTests : Symbol(DerivedYadda.literalElementAccessTests, Decl(index.js, 26, 5))

return super.literalElementAccess;
>super.literalElementAccess : Symbol(YaddaBase['literalElementAccess'], Decl(index.js, 6, 22))
>super : Symbol(YaddaBase, Decl(index.js, 0, 0))
>literalElementAccess : Symbol(YaddaBase['literalElementAccess'], Decl(index.js, 6, 22))
}
}

85 changes: 85 additions & 0 deletions tests/baselines/reference/classFieldSuperNotAccessibleJs.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//// [tests/cases/compiler/classFieldSuperNotAccessibleJs.ts] ////

=== index.js ===
// https://github.com/microsoft/TypeScript/issues/55884

class YaddaBase {
>YaddaBase : YaddaBase

constructor() {
this.roots = "hi";
>this.roots = "hi" : "hi"
>this.roots : any
>this : this
>roots : any
>"hi" : "hi"

/** @type number */
this.justProp;
>this.justProp : number
>this : this
>justProp : number

/** @type string */
this['literalElementAccess'];
>this['literalElementAccess'] : any
>this : this
>'literalElementAccess' : "literalElementAccess"

this.b()
>this.b() : void
>this.b : () => void
>this : this
>b : () => void
}
accessor b = () => {
>b : () => void
>() => { this.foo = 10 } : () => void

this.foo = 10
>this.foo = 10 : 10
>this.foo : number | undefined
>this : this
>foo : number | undefined
>10 : 10
}
}

class DerivedYadda extends YaddaBase {
>DerivedYadda : DerivedYadda
>YaddaBase : YaddaBase

get rootTests() {
>rootTests : string

return super.roots;
>super.roots : string
>super : YaddaBase
>roots : string
}
get fooTests() {
>fooTests : number | undefined

return super.foo;
>super.foo : number | undefined
>super : YaddaBase
>foo : number | undefined
}
get justPropTests() {
>justPropTests : number

return super.justProp;
>super.justProp : number
>super : YaddaBase
>justProp : number
}
get literalElementAccessTests() {
>literalElementAccessTests : any

return super.literalElementAccess;
>super.literalElementAccess : any
>super : YaddaBase
>literalElementAccess : any
}
}

38 changes: 38 additions & 0 deletions tests/cases/compiler/classFieldSuperNotAccessibleJs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @strict: true
// @checkJs: true
// @target: esnext
// @noEmit: true

// @filename: index.js

// https://github.com/microsoft/TypeScript/issues/55884

class YaddaBase {
constructor() {
this.roots = "hi";
/** @type number */
this.justProp;
/** @type string */
this['literalElementAccess'];

this.b()
}
accessor b = () => {
this.foo = 10
}
}

class DerivedYadda extends YaddaBase {
get rootTests() {
return super.roots;
}
get fooTests() {
return super.foo;
}
get justPropTests() {
return super.justProp;
}
get literalElementAccessTests() {
return super.literalElementAccess;
}
}