Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3830,6 +3830,10 @@
"category": "Error",
"code": 2823
},
"'super' cannot be used with 'new' keyword.": {
"category": "Error",
"code": 2824
},
"Cannot find namespace '{0}'. Did you mean '{1}'?": {
"category": "Error",
"code": 2833
Expand Down
11 changes: 11 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6801,6 +6801,17 @@ namespace Parser {
function parseNewExpressionOrNewDotTarget(): NewExpression | MetaProperty {
const pos = getNodePos();
parseExpected(SyntaxKind.NewKeyword);

// Validate that 'new' is not used with 'super' - this is not JavaScript syntax
if (token() === SyntaxKind.SuperKeyword) {
parseErrorAtCurrentToken(Diagnostics.super_cannot_be_used_with_new_keyword);
return finishNode(factoryCreateNewExpression(
createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false),
/*typeArguments*/ undefined,
/*argumentsArray*/ undefined
), pos);
Comment on lines +6805 to +6812
}

if (parseOptional(SyntaxKind.DotToken)) {
Comment on lines +6804 to 6815
const name = parseIdentifierName();
return finishNode(factory.createMetaProperty(SyntaxKind.NewKeyword, name), pos);
Expand Down
16 changes: 16 additions & 0 deletions tests/cases/compiler/newSuperError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @strict: true
// @target: ES2020

// Repro for #63451 - 'new super()' should be a parse error

class A extends class {} {
static {
new super(); // expect error TS2824
}

static f() {
new super(); // expect error TS2824
}
}

console.log("If you see this, the test failed (compilation should show error)");
Loading