Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report all the js file errors and skip only the nodes that are not allowed in JS file #11978

Merged
merged 5 commits into from
Nov 10, 2016
Merged
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
227 changes: 115 additions & 112 deletions src/compiler/program.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/baselines/reference/decoratorInJsFile.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests/cases/compiler/a.js(4,12): error TS8010: 'types' can only be used in a .ts file.


==== tests/cases/compiler/a.js (1 errors) ====

@SomeDecorator
class SomeClass {
foo(x: number) {
~~~~~~
!!! error TS8010: 'types' can only be used in a .ts file.

}
}
16 changes: 16 additions & 0 deletions tests/baselines/reference/decoratorInJsFile1.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests/cases/compiler/a.js(3,7): 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(4,12): error TS8010: 'types' can only be used in a .ts file.


==== tests/cases/compiler/a.js (2 errors) ====

@SomeDecorator
class SomeClass {
~~~~~~~~~
!!! 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.
foo(x: number) {
~~~~~~
!!! error TS8010: 'types' can only be used in a .ts file.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
tests/cases/compiler/a.js(1,1): error TS8009: 'abstract' can only be used in a .ts file.
tests/cases/compiler/a.js(2,5): error TS8009: 'abstract' can only be used in a .ts file.


!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
==== tests/cases/compiler/a.js (2 errors) ====
abstract class c {
~~~~~~~~
!!! error TS8009: 'abstract' can only be used in a .ts file.
abstract x;
~~~~~~~~
!!! error TS8009: 'abstract' can only be used in a .ts file.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/compiler/a.js ===
const c = 10;
>c : Symbol(c, Decl(a.js, 0, 5))

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== tests/cases/compiler/a.js ===
const c = 10;
>c : 10
>10 : 10

12 changes: 12 additions & 0 deletions tests/cases/compiler/decoratorInJsFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @experimentaldecorators: true
// @emitdecoratormetadata: true
// @allowjs: true
// @noEmit: true

// @filename: a.js
@SomeDecorator
class SomeClass {
foo(x: number) {

}
}
10 changes: 10 additions & 0 deletions tests/cases/compiler/decoratorInJsFile1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @allowjs: true
// @noEmit: true

// @filename: a.js
@SomeDecorator
class SomeClass {
foo(x: number) {

}
}
5 changes: 5 additions & 0 deletions tests/cases/compiler/jsFileCompilationAbstractModifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @allowJs: true
// @filename: a.js
abstract class c {
abstract x;
}
4 changes: 4 additions & 0 deletions tests/cases/compiler/jsFileCompilationConstModifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @allowJs: true
// @filename: a.js
// @noEmit: true
const c = 10;
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ verify.getSyntacticDiagnostics(`[
"category": "error",
"code": 8010
},
{
"message": "\'types\' can only be used in a .ts file.",
"start": 52,
"length": 6,
"category": "error",
"code": 8010
},
{
"message": "Variable declaration expected.",
"start": 67,
Expand Down