diff --git a/tsc/internal/transformers/jsxtransforms/jsx.go b/tsc/internal/transformers/jsxtransforms/jsx.go
index 8a8782c497b18..242221f6bc7f1 100644
--- a/tsc/internal/transformers/jsxtransforms/jsx.go
+++ b/tsc/internal/transformers/jsxtransforms/jsx.go
@@ -25,6 +25,7 @@ type JSXTransformer struct {
filenameDeclaration *ast.Node
utilizedImplicitRuntimeImports collections.OrderedMap[string, map[string]*ast.Node]
inJsxChild bool
+ inSuperCallArguments bool
currentSourceFile *ast.SourceFile
}
@@ -130,6 +131,33 @@ func (tx *JSXTransformer) visit(node *ast.Node) *ast.Node {
case ast.KindJsxExpression:
tx.setInChild(false)
return tx.visitJsxExpression(node.AsJsxExpression())
+ case ast.KindCallExpression:
+ if ast.IsSuperCall(node) {
+ // `this` is not available in the arguments of a super call.
+ previous := tx.inSuperCallArguments
+ tx.inSuperCallArguments = true
+ result := tx.Visitor().VisitEachChild(node)
+ tx.inSuperCallArguments = previous
+ return result
+ }
+ case ast.KindFunctionDeclaration,
+ ast.KindFunctionExpression,
+ ast.KindMethodDeclaration,
+ ast.KindGetAccessor,
+ ast.KindSetAccessor,
+ ast.KindConstructor,
+ ast.KindPropertyDeclaration,
+ ast.KindClassStaticBlockDeclaration,
+ ast.KindClassDeclaration,
+ ast.KindClassExpression:
+ // These introduce their own `this` scope. Arrow functions inherit the
+ // enclosing one, so they keep the flag.
+ previous := tx.inSuperCallArguments
+ tx.inSuperCallArguments = false
+ tx.setInChild(false)
+ result := tx.Visitor().VisitEachChild(node)
+ tx.inSuperCallArguments = previous
+ return result
}
tx.setInChild(false)
return tx.Visitor().VisitEachChild(node) // by default, do nothing
@@ -587,8 +615,12 @@ func (tx *JSXTransformer) visitJsxOpeningLikeElementOrFragmentJSX(
tx.Factory().NewPropertyAssignment(nil, tx.Factory().NewIdentifier("lineNumber"), nil, nil, tx.Factory().NewNumericLiteral(strconv.FormatInt(int64(line+1), 10), ast.TokenFlagsNone)),
tx.Factory().NewPropertyAssignment(nil, tx.Factory().NewIdentifier("columnNumber"), nil, nil, tx.Factory().NewNumericLiteral(strconv.FormatInt(int64(col)+1, 10), ast.TokenFlagsNone)),
}), false))
- // __self development flag
- args = append(args, tx.Factory().NewThisExpression())
+ // __self development flag. `this` is not available before super() returns.
+ if tx.inSuperCallArguments {
+ args = append(args, tx.Factory().NewVoidZeroExpression())
+ } else {
+ args = append(args, tx.Factory().NewThisExpression())
+ }
}
}
diff --git a/tsc/testdata/baselines/reference/compiler/jsxDevSelfInSuperArguments.js b/tsc/testdata/baselines/reference/compiler/jsxDevSelfInSuperArguments.js
new file mode 100644
index 0000000000000..fbe66e5070992
--- /dev/null
+++ b/tsc/testdata/baselines/reference/compiler/jsxDevSelfInSuperArguments.js
@@ -0,0 +1,57 @@
+//// [tests/cases/compiler/jsxDevSelfInSuperArguments.tsx] ////
+
+//// [index.d.ts]
+export namespace JSX {
+ interface Element {}
+ interface IntrinsicElements {
+ h2: {};
+ }
+}
+export function jsxDEV(type: any, props: any, key?: any, isStatic?: boolean, source?: any, self?: any): JSX.Element;
+
+//// [index.tsx]
+class Base {
+ content: any;
+ constructor(...args: any[]) { this.content = args[0]; }
+}
+class Card extends Base {
+ constructor(title: string) {
+ super(
{title}
);
+ }
+}
+class Nested extends Base {
+ constructor() {
+ super({ render() { return ; } });
+ }
+}
+class Outer extends Base {
+ constructor() {
+ super(class extends Base { constructor() { super(); } }, );
+ }
+}
+
+
+//// [index.js]
+import { jsxDEV as _jsxDEV } from "preact/jsx-dev-runtime";
+const _jsxFileName = "/index.tsx";
+class Base {
+ content;
+ constructor(...args) { this.content = args[0]; }
+}
+class Card extends Base {
+ constructor(title) {
+ super(_jsxDEV("h2", { children: title }, void 0, false, { fileName: _jsxFileName, lineNumber: 7, columnNumber: 15 }, void 0));
+ }
+}
+class Nested extends Base {
+ constructor() {
+ super({ render() { return _jsxDEV("h2", {}, void 0, false, { fileName: _jsxFileName, lineNumber: 12, columnNumber: 35 }, this); } });
+ }
+}
+class Outer extends Base {
+ constructor() {
+ super(class extends Base {
+ constructor() { super(_jsxDEV("h2", {}, void 0, false, { fileName: _jsxFileName, lineNumber: 17, columnNumber: 58 }, void 0)); }
+ }, _jsxDEV("h2", {}, void 0, false, { fileName: _jsxFileName, lineNumber: 17, columnNumber: 72 }, void 0));
+ }
+}
diff --git a/tsc/testdata/baselines/reference/compiler/jsxDevSelfInSuperArguments.symbols b/tsc/testdata/baselines/reference/compiler/jsxDevSelfInSuperArguments.symbols
new file mode 100644
index 0000000000000..f8831ee6deeb2
--- /dev/null
+++ b/tsc/testdata/baselines/reference/compiler/jsxDevSelfInSuperArguments.symbols
@@ -0,0 +1,80 @@
+//// [tests/cases/compiler/jsxDevSelfInSuperArguments.tsx] ////
+
+=== /node_modules/preact/jsx-dev-runtime/index.d.ts ===
+export namespace JSX {
+>JSX : Symbol(JSX, Decl(index.d.ts, 0, 0))
+
+ interface Element {}
+>Element : Symbol(Element, Decl(index.d.ts, 0, 22))
+
+ interface IntrinsicElements {
+>IntrinsicElements : Symbol(IntrinsicElements, Decl(index.d.ts, 1, 24))
+
+ h2: {};
+>h2 : Symbol(IntrinsicElements.h2, Decl(index.d.ts, 2, 33))
+ }
+}
+export function jsxDEV(type: any, props: any, key?: any, isStatic?: boolean, source?: any, self?: any): JSX.Element;
+>jsxDEV : Symbol(jsxDEV, Decl(index.d.ts, 5, 1))
+>type : Symbol(type, Decl(index.d.ts, 6, 23))
+>props : Symbol(props, Decl(index.d.ts, 6, 33))
+>key : Symbol(key, Decl(index.d.ts, 6, 45))
+>isStatic : Symbol(isStatic, Decl(index.d.ts, 6, 56))
+>source : Symbol(source, Decl(index.d.ts, 6, 76))
+>self : Symbol(self, Decl(index.d.ts, 6, 90))
+>JSX : Symbol(JSX, Decl(index.d.ts, 0, 0))
+>Element : Symbol(JSX.Element, Decl(index.d.ts, 0, 22))
+
+=== /index.tsx ===
+class Base {
+>Base : Symbol(Base, Decl(index.tsx, 0, 0))
+
+ content: any;
+>content : Symbol(Base.content, Decl(index.tsx, 0, 12))
+
+ constructor(...args: any[]) { this.content = args[0]; }
+>args : Symbol(args, Decl(index.tsx, 2, 16))
+>this.content : Symbol(Base.content, Decl(index.tsx, 0, 12))
+>this : Symbol(Base, Decl(index.tsx, 0, 0))
+>content : Symbol(Base.content, Decl(index.tsx, 0, 12))
+>args : Symbol(args, Decl(index.tsx, 2, 16))
+}
+class Card extends Base {
+>Card : Symbol(Card, Decl(index.tsx, 3, 1))
+>Base : Symbol(Base, Decl(index.tsx, 0, 0))
+
+ constructor(title: string) {
+>title : Symbol(title, Decl(index.tsx, 5, 16))
+
+ super({title}
);
+>super : Symbol(Base, Decl(index.tsx, 0, 0))
+>h2 : Symbol(JSX.IntrinsicElements.h2, Decl(index.d.ts, 2, 33))
+>title : Symbol(title, Decl(index.tsx, 5, 16))
+>h2 : Symbol(JSX.IntrinsicElements.h2, Decl(index.d.ts, 2, 33))
+ }
+}
+class Nested extends Base {
+>Nested : Symbol(Nested, Decl(index.tsx, 8, 1))
+>Base : Symbol(Base, Decl(index.tsx, 0, 0))
+
+ constructor() {
+ super({ render() { return ; } });
+>super : Symbol(Base, Decl(index.tsx, 0, 0))
+>render : Symbol(render, Decl(index.tsx, 11, 15))
+>h2 : Symbol(JSX.IntrinsicElements.h2, Decl(index.d.ts, 2, 33))
+ }
+}
+class Outer extends Base {
+>Outer : Symbol(Outer, Decl(index.tsx, 13, 1))
+>Base : Symbol(Base, Decl(index.tsx, 0, 0))
+
+ constructor() {
+ super(class extends Base { constructor() { super(); } }, );
+>super : Symbol(Base, Decl(index.tsx, 0, 0))
+>Base : Symbol(Base, Decl(index.tsx, 0, 0))
+>super : Symbol(Base, Decl(index.tsx, 0, 0))
+>h2 : Symbol(JSX.IntrinsicElements.h2, Decl(index.d.ts, 2, 33))
+>h2 : Symbol(JSX.IntrinsicElements.h2, Decl(index.d.ts, 2, 33))
+ }
+}
+
diff --git a/tsc/testdata/baselines/reference/compiler/jsxDevSelfInSuperArguments.types b/tsc/testdata/baselines/reference/compiler/jsxDevSelfInSuperArguments.types
new file mode 100644
index 0000000000000..c8bbf63fbdfda
--- /dev/null
+++ b/tsc/testdata/baselines/reference/compiler/jsxDevSelfInSuperArguments.types
@@ -0,0 +1,86 @@
+//// [tests/cases/compiler/jsxDevSelfInSuperArguments.tsx] ////
+
+=== /node_modules/preact/jsx-dev-runtime/index.d.ts ===
+export namespace JSX {
+ interface Element {}
+ interface IntrinsicElements {
+ h2: {};
+>h2 : {}
+ }
+}
+export function jsxDEV(type: any, props: any, key?: any, isStatic?: boolean, source?: any, self?: any): JSX.Element;
+>jsxDEV : (type: any, props: any, key?: any, isStatic?: boolean, source?: any, self?: any) => JSX.Element
+>type : any
+>props : any
+>key : any
+>isStatic : boolean | undefined
+>source : any
+>self : any
+>JSX : any
+
+=== /index.tsx ===
+class Base {
+>Base : Base
+
+ content: any;
+>content : any
+
+ constructor(...args: any[]) { this.content = args[0]; }
+>args : any[]
+>this.content = args[0] : any
+>this.content : any
+>this : this
+>content : any
+>args[0] : any
+>args : any[]
+>0 : 0
+}
+class Card extends Base {
+>Card : Card
+>Base : Base
+
+ constructor(title: string) {
+>title : string
+
+ super({title}
);
+>super({title}
) : void
+>super : typeof Base
+>{title}
: import("preact/jsx-dev-runtime").JSX.Element
+>h2 : any
+>title : string
+>h2 : any
+ }
+}
+class Nested extends Base {
+>Nested : Nested
+>Base : Base
+
+ constructor() {
+ super({ render() { return ; } });
+>super({ render() { return ; } }) : void
+>super : typeof Base
+>{ render() { return ; } } : { render(): import("preact/jsx-dev-runtime").JSX.Element; }
+>render : () => import("preact/jsx-dev-runtime").JSX.Element
+> : import("preact/jsx-dev-runtime").JSX.Element
+>h2 : any
+ }
+}
+class Outer extends Base {
+>Outer : Outer
+>Base : Base
+
+ constructor() {
+ super(class extends Base { constructor() { super(); } }, );
+>super(class extends Base { constructor() { super(); } }, ) : void
+>super : typeof Base
+>class extends Base { constructor() { super(); } } : typeof (Anonymous class)
+>Base : Base
+>super() : void
+>super : typeof Base
+> : import("preact/jsx-dev-runtime").JSX.Element
+>h2 : any
+> : import("preact/jsx-dev-runtime").JSX.Element
+>h2 : any
+ }
+}
+
diff --git a/tsc/testdata/tests/cases/compiler/jsxDevSelfInSuperArguments.tsx b/tsc/testdata/tests/cases/compiler/jsxDevSelfInSuperArguments.tsx
new file mode 100644
index 0000000000000..eb67ac21b8be2
--- /dev/null
+++ b/tsc/testdata/tests/cases/compiler/jsxDevSelfInSuperArguments.tsx
@@ -0,0 +1,34 @@
+// @jsx: react-jsxdev
+// @jsxImportSource: preact
+// @target: esnext
+// @module: esnext
+
+// @filename: /node_modules/preact/jsx-dev-runtime/index.d.ts
+export namespace JSX {
+ interface Element {}
+ interface IntrinsicElements {
+ h2: {};
+ }
+}
+export function jsxDEV(type: any, props: any, key?: any, isStatic?: boolean, source?: any, self?: any): JSX.Element;
+
+// @filename: /index.tsx
+class Base {
+ content: any;
+ constructor(...args: any[]) { this.content = args[0]; }
+}
+class Card extends Base {
+ constructor(title: string) {
+ super({title}
);
+ }
+}
+class Nested extends Base {
+ constructor() {
+ super({ render() { return ; } });
+ }
+}
+class Outer extends Base {
+ constructor() {
+ super(class extends Base { constructor() { super(); } }, );
+ }
+}