Skip to content

Commit d896d3f

Browse files
committed
Add test cases to report errors for decorators in js file
1 parent 137c99b commit d896d3f

File tree

7 files changed

+71
-0
lines changed

7 files changed

+71
-0
lines changed

src/compiler/program.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,12 @@ namespace ts {
943943

944944
return false;
945945
}
946+
947+
// Since these are syntactic diagnostics, parent might not have been set
948+
// this means the sourceFile cannot be infered from the node
949+
function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic {
950+
return createDiagnosticForNodeInSourceFile(sourceFile, node, message, arg0, arg1, arg2);
951+
}
946952
});
947953
}
948954

src/compiler/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ namespace ts {
498498

499499
export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic {
500500
const sourceFile = getSourceFileOfNode(node);
501+
return createDiagnosticForNodeInSourceFile(sourceFile, node, message, arg0, arg1, arg2);
502+
}
503+
504+
export function createDiagnosticForNodeInSourceFile(sourceFile: SourceFile, node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic {
501505
const span = getErrorSpanForNode(sourceFile, node);
502506
return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2);
503507
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/a.js ===
2+
3+
@SomeDecorator
4+
class SomeClass {
5+
>SomeClass : Symbol(SomeClass, Decl(a.js, 0, 0))
6+
7+
foo(x: number) {
8+
>foo : Symbol(SomeClass.foo, Decl(a.js, 2, 17))
9+
>x : Symbol(x, Decl(a.js, 3, 8))
10+
11+
}
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/a.js ===
2+
3+
@SomeDecorator
4+
>SomeDecorator : any
5+
6+
class SomeClass {
7+
>SomeClass : SomeClass
8+
9+
foo(x: number) {
10+
>foo : (x: number) => void
11+
>x : number
12+
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/cases/compiler/a.js(2,1): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
2+
3+
4+
==== tests/cases/compiler/a.js (1 errors) ====
5+
6+
@SomeDecorator
7+
~~~~~~~~~~~~~~
8+
!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
9+
class SomeClass {
10+
foo(x: number) {
11+
12+
}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @experimentaldecorators: true
2+
// @emitdecoratormetadata: true
3+
// @allowjs: true
4+
// @noEmit: true
5+
6+
// @filename: a.js
7+
@SomeDecorator
8+
class SomeClass {
9+
foo(x: number) {
10+
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @allowjs: true
2+
// @noEmit: true
3+
4+
// @filename: a.js
5+
@SomeDecorator
6+
class SomeClass {
7+
foo(x: number) {
8+
9+
}
10+
}

0 commit comments

Comments
 (0)