diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c3fdad71e11..76c92ad74bb 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1833,6 +1833,7 @@ namespace ts { switch (parent.kind) { case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -1842,7 +1843,7 @@ namespace ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: // Check type parameters - if (nodes === (parent).typeParameters) { + if (nodes === (parent).typeParameters) { diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file)); return; } diff --git a/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClassExpression.errors.txt b/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClassExpression.errors.txt new file mode 100644 index 00000000000..61bf225dddc --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClassExpression.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/a.js(1,19): error TS8004: 'type parameter declarations' can only be used in a .ts file. + + +==== tests/cases/compiler/a.js (1 errors) ==== + const Bar = class {}; + ~ +!!! error TS8004: 'type parameter declarations' can only be used in a .ts file. + \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClassExpression.symbols b/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClassExpression.symbols new file mode 100644 index 00000000000..f3aa9cd5926 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClassExpression.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/a.js === +const Bar = class {}; +>Bar : Symbol(Bar, Decl(a.js, 0, 5)) +>T : Symbol(T, Decl(a.js, 0, 18)) + diff --git a/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClassExpression.types b/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClassExpression.types new file mode 100644 index 00000000000..5538564ec86 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClassExpression.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/a.js === +const Bar = class {}; +>Bar : typeof Bar +>class {} : typeof Bar + diff --git a/tests/cases/compiler/jsFileCompilationTypeParameterSyntaxOfClassExpression.ts b/tests/cases/compiler/jsFileCompilationTypeParameterSyntaxOfClassExpression.ts new file mode 100644 index 00000000000..81b07637422 --- /dev/null +++ b/tests/cases/compiler/jsFileCompilationTypeParameterSyntaxOfClassExpression.ts @@ -0,0 +1,4 @@ +// @allowJs: true +// @noEmit: true +// @filename: a.js +const Bar = class {};