Add test cases to report errors for decorators in js file

This commit is contained in:
Sheetal Nandi 2016-11-01 11:05:09 -07:00
parent 137c99bd34
commit d896d3f8a9
7 changed files with 71 additions and 0 deletions

View File

@ -943,6 +943,12 @@ namespace ts {
return false;
}
// Since these are syntactic diagnostics, parent might not have been set
// this means the sourceFile cannot be infered from the node
function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic {
return createDiagnosticForNodeInSourceFile(sourceFile, node, message, arg0, arg1, arg2);
}
});
}

View File

@ -498,6 +498,10 @@ namespace ts {
export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic {
const sourceFile = getSourceFileOfNode(node);
return createDiagnosticForNodeInSourceFile(sourceFile, node, message, arg0, arg1, arg2);
}
export function createDiagnosticForNodeInSourceFile(sourceFile: SourceFile, node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic {
const span = getErrorSpanForNode(sourceFile, node);
return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2);
}

View File

@ -0,0 +1,12 @@
=== tests/cases/compiler/a.js ===
@SomeDecorator
class SomeClass {
>SomeClass : Symbol(SomeClass, Decl(a.js, 0, 0))
foo(x: number) {
>foo : Symbol(SomeClass.foo, Decl(a.js, 2, 17))
>x : Symbol(x, Decl(a.js, 3, 8))
}
}

View File

@ -0,0 +1,14 @@
=== tests/cases/compiler/a.js ===
@SomeDecorator
>SomeDecorator : any
class SomeClass {
>SomeClass : SomeClass
foo(x: number) {
>foo : (x: number) => void
>x : number
}
}

View File

@ -0,0 +1,13 @@
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.
==== tests/cases/compiler/a.js (1 errors) ====
@SomeDecorator
~~~~~~~~~~~~~~
!!! 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.
class SomeClass {
foo(x: number) {
}
}

View File

@ -0,0 +1,12 @@
// @experimentaldecorators: true
// @emitdecoratormetadata: true
// @allowjs: true
// @noEmit: true
// @filename: a.js
@SomeDecorator
class SomeClass {
foo(x: number) {
}
}

View File

@ -0,0 +1,10 @@
// @allowjs: true
// @noEmit: true
// @filename: a.js
@SomeDecorator
class SomeClass {
foo(x: number) {
}
}