-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved lookahead for arrow functions.
Fixes issue #34. Specifically: * We no longer automatically assume "()" is a function expression. It must be followed by an arrow, colon, or curly brace. * If an arrow is missing following a signature, but a curly brace is present, we assume the user forgot the arrow and try to parse the body anyway.
- Loading branch information
1 parent
c8fc26a
commit 426e8e5
Showing
9 changed files
with
259 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
tests/baselines/reference/arrowFunctionsMissingTokens.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
==== tests/cases/compiler/arrowFunctionsMissingTokens.ts (39 errors) ==== | ||
|
||
module missingArrowsWithCurly { | ||
var a = () { }; | ||
~ | ||
!!! '=>' expected. | ||
|
||
var b = (): void { } | ||
~ | ||
!!! '=>' expected. | ||
|
||
var c = (x) { }; | ||
~ | ||
!!! ',' expected. | ||
~ | ||
!!! Cannot find name 'x'. | ||
|
||
var d = (x: number, y: string) { }; | ||
~ | ||
!!! ')' expected. | ||
~ | ||
!!! ',' expected. | ||
~ | ||
!!! Variable declaration expected. | ||
~ | ||
!!! Cannot find name 'x'. | ||
|
||
var e = (x: number, y: string): void { }; | ||
~ | ||
!!! ')' expected. | ||
~ | ||
!!! ',' expected. | ||
~ | ||
!!! Variable declaration expected. | ||
~~~~ | ||
!!! Variable declaration expected. | ||
~ | ||
!!! Cannot find name 'x'. | ||
} | ||
|
||
module missingCurliesWithArrow { | ||
module withStatement { | ||
var a = () => var k = 10;}; | ||
~~~ | ||
!!! '{' expected. | ||
|
||
var b = (): void => var k = 10;} | ||
~~~ | ||
!!! '{' expected. | ||
|
||
var c = (x) => var k = 10;}; | ||
~~~ | ||
!!! '{' expected. | ||
|
||
var d = (x: number, y: string) => var k = 10;}; | ||
~~~ | ||
!!! '{' expected. | ||
|
||
var e = (x: number, y: string): void => var k = 10;}; | ||
~~~ | ||
!!! '{' expected. | ||
|
||
var f = () => var k = 10;} | ||
~~~ | ||
!!! '{' expected. | ||
} | ||
|
||
module withoutStatement { | ||
var a = () => }; | ||
~ | ||
!!! Expression expected. | ||
|
||
var b = (): void => } | ||
~ | ||
!!! Expression expected. | ||
|
||
var c = (x) => }; | ||
~ | ||
!!! Expression expected. | ||
|
||
var d = (x: number, y: string) => }; | ||
~ | ||
!!! Expression expected. | ||
|
||
var e = (x: number, y: string): void => }; | ||
~ | ||
!!! Expression expected. | ||
|
||
var f = () => } | ||
~ | ||
!!! Expression expected. | ||
} | ||
~ | ||
!!! Declaration or statement expected. | ||
} | ||
~ | ||
!!! Declaration or statement expected. | ||
|
||
module ceci_nEst_pas_une_arrow_function { | ||
var a = (); | ||
~ | ||
!!! Expression expected. | ||
|
||
var b = (): void; | ||
~ | ||
!!! '=>' expected. | ||
|
||
var c = (x); | ||
~ | ||
!!! Cannot find name 'x'. | ||
|
||
var d = (x: number, y: string); | ||
~ | ||
!!! ')' expected. | ||
~ | ||
!!! ',' expected. | ||
~ | ||
!!! Cannot find name 'x'. | ||
|
||
var e = (x: number, y: string): void; | ||
~ | ||
!!! ')' expected. | ||
~ | ||
!!! ',' expected. | ||
~ | ||
!!! Variable declaration expected. | ||
~~~~ | ||
!!! Variable declaration expected. | ||
~ | ||
!!! Expression expected. | ||
~ | ||
!!! Cannot find name 'x'. | ||
} | ||
|
||
module okay { | ||
var a = () => { }; | ||
|
||
var b = (): void => { } | ||
|
||
var c = (x) => { }; | ||
|
||
var d = (x: number, y: string) => { }; | ||
|
||
var e = (x: number, y: string): void => { }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
==== tests/cases/compiler/emptyMemberAccess.ts (2 errors) ==== | ||
==== tests/cases/compiler/emptyMemberAccess.ts (1 errors) ==== | ||
function getObj() { | ||
|
||
().toString(); | ||
~ | ||
!!! '=>' expected. | ||
~~~~~~~~ | ||
!!! Cannot find name 'toString'. | ||
~ | ||
!!! Expression expected. | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser566700.ts (1 errors) ==== | ||
var v = ()({}); | ||
~ | ||
!!! '=>' expected. | ||
~ | ||
!!! Expression expected. |
8 changes: 3 additions & 5 deletions
8
tests/baselines/reference/parserEmptyParenthesizedExpression1.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserEmptyParenthesizedExpression1.ts (2 errors) ==== | ||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserEmptyParenthesizedExpression1.ts (1 errors) ==== | ||
function getObj() { | ||
().toString(); | ||
~ | ||
!!! '=>' expected. | ||
~~~~~~~~ | ||
!!! Cannot find name 'toString'. | ||
~ | ||
!!! Expression expected. | ||
} |
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/parserErrorRecovery_Expression1.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Expressions/parserErrorRecovery_Expression1.ts (1 errors) ==== | ||
var v = ()({}); | ||
~ | ||
!!! '=>' expected. | ||
~ | ||
!!! Expression expected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
==== tests/cases/compiler/uncaughtCompilerError2.ts (2 errors) ==== | ||
==== tests/cases/compiler/uncaughtCompilerError2.ts (1 errors) ==== | ||
function getObj() { | ||
().toString(); | ||
~ | ||
!!! '=>' expected. | ||
~~~~~~~~ | ||
!!! Cannot find name 'toString'. | ||
~ | ||
!!! Expression expected. | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
module missingArrowsWithCurly { | ||
var a = () { }; | ||
|
||
var b = (): void { } | ||
|
||
var c = (x) { }; | ||
|
||
var d = (x: number, y: string) { }; | ||
|
||
var e = (x: number, y: string): void { }; | ||
} | ||
|
||
module missingCurliesWithArrow { | ||
module withStatement { | ||
var a = () => var k = 10;}; | ||
|
||
var b = (): void => var k = 10;} | ||
|
||
var c = (x) => var k = 10;}; | ||
|
||
var d = (x: number, y: string) => var k = 10;}; | ||
|
||
var e = (x: number, y: string): void => var k = 10;}; | ||
|
||
var f = () => var k = 10;} | ||
} | ||
|
||
module withoutStatement { | ||
var a = () => }; | ||
|
||
var b = (): void => } | ||
|
||
var c = (x) => }; | ||
|
||
var d = (x: number, y: string) => }; | ||
|
||
var e = (x: number, y: string): void => }; | ||
|
||
var f = () => } | ||
} | ||
} | ||
|
||
module ceci_nEst_pas_une_arrow_function { | ||
var a = (); | ||
|
||
var b = (): void; | ||
|
||
var c = (x); | ||
|
||
var d = (x: number, y: string); | ||
|
||
var e = (x: number, y: string): void; | ||
} | ||
|
||
module okay { | ||
var a = () => { }; | ||
|
||
var b = (): void => { } | ||
|
||
var c = (x) => { }; | ||
|
||
var d = (x: number, y: string) => { }; | ||
|
||
var e = (x: number, y: string): void => { }; | ||
} |