mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-23 10:29:01 -06:00
Add test cases to report errors for decorators in js file
This commit is contained in:
parent
137c99bd34
commit
d896d3f8a9
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
12
tests/baselines/reference/decoratorInJsFile.symbols
Normal file
12
tests/baselines/reference/decoratorInJsFile.symbols
Normal 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))
|
||||
|
||||
}
|
||||
}
|
||||
14
tests/baselines/reference/decoratorInJsFile.types
Normal file
14
tests/baselines/reference/decoratorInJsFile.types
Normal 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
|
||||
|
||||
}
|
||||
}
|
||||
13
tests/baselines/reference/decoratorInJsFile1.errors.txt
Normal file
13
tests/baselines/reference/decoratorInJsFile1.errors.txt
Normal 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) {
|
||||
|
||||
}
|
||||
}
|
||||
12
tests/cases/compiler/decoratorInJsFile.ts
Normal file
12
tests/cases/compiler/decoratorInJsFile.ts
Normal file
@ -0,0 +1,12 @@
|
||||
// @experimentaldecorators: true
|
||||
// @emitdecoratormetadata: true
|
||||
// @allowjs: true
|
||||
// @noEmit: true
|
||||
|
||||
// @filename: a.js
|
||||
@SomeDecorator
|
||||
class SomeClass {
|
||||
foo(x: number) {
|
||||
|
||||
}
|
||||
}
|
||||
10
tests/cases/compiler/decoratorInJsFile1.ts
Normal file
10
tests/cases/compiler/decoratorInJsFile1.ts
Normal file
@ -0,0 +1,10 @@
|
||||
// @allowjs: true
|
||||
// @noEmit: true
|
||||
|
||||
// @filename: a.js
|
||||
@SomeDecorator
|
||||
class SomeClass {
|
||||
foo(x: number) {
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user