From 3638ff19b3a9ed9b205fc764713f57fd490260bd Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 11 Jul 2017 10:16:35 -0700 Subject: [PATCH] Test:better error for wrong return token (: vs =>) --- .../parseErrorIncorrectReturnToken.errors.txt | 37 +++++++++++++++++++ .../parseErrorIncorrectReturnToken.js | 27 ++++++++++++++ .../parseErrorIncorrectReturnToken.ts | 13 +++++++ 3 files changed, 77 insertions(+) create mode 100644 tests/baselines/reference/parseErrorIncorrectReturnToken.errors.txt create mode 100644 tests/baselines/reference/parseErrorIncorrectReturnToken.js create mode 100644 tests/cases/compiler/parseErrorIncorrectReturnToken.ts diff --git a/tests/baselines/reference/parseErrorIncorrectReturnToken.errors.txt b/tests/baselines/reference/parseErrorIncorrectReturnToken.errors.txt new file mode 100644 index 00000000000..2cf728848e4 --- /dev/null +++ b/tests/baselines/reference/parseErrorIncorrectReturnToken.errors.txt @@ -0,0 +1,37 @@ +tests/cases/compiler/parseErrorIncorrectReturnToken.ts(2,17): error TS1005: ':' expected. +tests/cases/compiler/parseErrorIncorrectReturnToken.ts(4,22): error TS1005: '=>' expected. +tests/cases/compiler/parseErrorIncorrectReturnToken.ts(4,24): error TS2693: 'string' only refers to a type, but is being used as a value here. +tests/cases/compiler/parseErrorIncorrectReturnToken.ts(9,18): error TS1005: '{' expected. +tests/cases/compiler/parseErrorIncorrectReturnToken.ts(9,21): error TS2693: 'string' only refers to a type, but is being used as a value here. +tests/cases/compiler/parseErrorIncorrectReturnToken.ts(9,28): error TS1005: ';' expected. +tests/cases/compiler/parseErrorIncorrectReturnToken.ts(12,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/compiler/parseErrorIncorrectReturnToken.ts (7 errors) ==== + type F1 = { + (n: number) => string; // should be : not => + ~~ +!!! error TS1005: ':' expected. + } + type F2 = (n: number): string; // should be => not : + ~ +!!! error TS1005: '=>' expected. + ~~~~~~ +!!! error TS2693: 'string' only refers to a type, but is being used as a value here. + + // doesn't work in non-type contexts, where the return type is optional + let f = (n: number) => string => n.toString(); + let o = { + m(n: number) => string { + ~~ +!!! error TS1005: '{' expected. + ~~~~~~ +!!! error TS2693: 'string' only refers to a type, but is being used as a value here. + ~ +!!! error TS1005: ';' expected. + return n.toString(); + } + }; + ~ +!!! error TS1128: Declaration or statement expected. + \ No newline at end of file diff --git a/tests/baselines/reference/parseErrorIncorrectReturnToken.js b/tests/baselines/reference/parseErrorIncorrectReturnToken.js new file mode 100644 index 00000000000..3d2a1d17a4a --- /dev/null +++ b/tests/baselines/reference/parseErrorIncorrectReturnToken.js @@ -0,0 +1,27 @@ +//// [parseErrorIncorrectReturnToken.ts] +type F1 = { + (n: number) => string; // should be : not => +} +type F2 = (n: number): string; // should be => not : + +// doesn't work in non-type contexts, where the return type is optional +let f = (n: number) => string => n.toString(); +let o = { + m(n: number) => string { + return n.toString(); + } +}; + + +//// [parseErrorIncorrectReturnToken.js] +string; // should be => not : +// doesn't work in non-type contexts, where the return type is optional +var f = function (n) { return function (string) { return n.toString(); }; }; +var o = { + m: function (n) { } +}; +string; +{ + return n.toString(); +} +; diff --git a/tests/cases/compiler/parseErrorIncorrectReturnToken.ts b/tests/cases/compiler/parseErrorIncorrectReturnToken.ts new file mode 100644 index 00000000000..0f45c38a3b1 --- /dev/null +++ b/tests/cases/compiler/parseErrorIncorrectReturnToken.ts @@ -0,0 +1,13 @@ + +type F1 = { + (n: number) => string; // should be : not => +} +type F2 = (n: number): string; // should be => not : + +// doesn't work in non-type contexts, where the return type is optional +let f = (n: number) => string => n.toString(); +let o = { + m(n: number) => string { + return n.toString(); + } +};