From 960f9ccb2e700332dc576163b62c518120c73f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 22 May 2020 19:23:35 +0200 Subject: fix: SWC lexer settings and silent errors (#5752) This commit changes how error occurring in SWC are handled. Changed lexer settings to properly handle TS decorators. Changed output of SWC error to annotate with position in file. --- cli/tests/integration_tests.rs | 12 +++++++++++- cli/tests/swc_syntax_error.ts | 3 +++ cli/tests/swc_syntax_error.ts.out | 1 + cli/tests/ts_decorators.ts | 14 ++++++++++++++ cli/tests/ts_decorators.ts.out | 2 ++ cli/tests/tsconfig.decorators.json | 5 +++++ 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 cli/tests/swc_syntax_error.ts create mode 100644 cli/tests/swc_syntax_error.ts.out create mode 100644 cli/tests/ts_decorators.ts create mode 100644 cli/tests/ts_decorators.ts.out create mode 100644 cli/tests/tsconfig.decorators.json (limited to 'cli/tests') diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 9f73c91b3..457a345dd 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1575,7 +1575,17 @@ itest!(ts_type_imports { args: "run --reload ts_type_imports.ts", output: "ts_type_imports.ts.out", exit_code: 1, - http_server: true, +}); + +itest!(ts_decorators { + args: "run --reload -c tsconfig.decorators.json ts_decorators.ts", + output: "ts_decorators.ts.out", +}); + +itest!(swc_syntax_error { + args: "run --reload swc_syntax_error.ts", + output: "swc_syntax_error.ts.out", + exit_code: 1, }); itest!(types { diff --git a/cli/tests/swc_syntax_error.ts b/cli/tests/swc_syntax_error.ts new file mode 100644 index 000000000..70e0de97d --- /dev/null +++ b/cli/tests/swc_syntax_error.ts @@ -0,0 +1,3 @@ +for await (const req of s) { + let something: +} diff --git a/cli/tests/swc_syntax_error.ts.out b/cli/tests/swc_syntax_error.ts.out new file mode 100644 index 000000000..0896faf68 --- /dev/null +++ b/cli/tests/swc_syntax_error.ts.out @@ -0,0 +1 @@ +error: Unexpected token Some(RBrace) at [WILDCARD]syntax_error.ts:3:0 diff --git a/cli/tests/ts_decorators.ts b/cli/tests/ts_decorators.ts new file mode 100644 index 000000000..67fd0604f --- /dev/null +++ b/cli/tests/ts_decorators.ts @@ -0,0 +1,14 @@ +/* eslint-disable */ + +function Decorate() { + return function (constructor: any): any { + return class extends constructor { + protected someField: string = "asdf"; + }; + }; +} + +@Decorate() +class SomeClass {} + +console.log(new SomeClass()); diff --git a/cli/tests/ts_decorators.ts.out b/cli/tests/ts_decorators.ts.out new file mode 100644 index 000000000..69d5937a9 --- /dev/null +++ b/cli/tests/ts_decorators.ts.out @@ -0,0 +1,2 @@ +Compile [WILDCARD] +SomeClass { someField: "asdf" } diff --git a/cli/tests/tsconfig.decorators.json b/cli/tests/tsconfig.decorators.json new file mode 100644 index 000000000..504cd646e --- /dev/null +++ b/cli/tests/tsconfig.decorators.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "experimentalDecorators": true + } +} -- cgit v1.2.3