-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
syntax: don't treat
as
and from
as reserved keywords
ECMAScript allows using `as` and `from` as identifiers so follow suit and don't treat them specially while parsing. Extend the compiler logic instead to check for TK_LABEL tokens with the expected value to properly parse import and export statements. Signed-off-by: Jo-Philipp Wich <[email protected]>
- Loading branch information
Showing
4 changed files
with
91 additions
and
14 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
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 |
---|---|---|
|
@@ -119,8 +119,6 @@ typedef enum { | |
TK_TEMPLATE, | ||
TK_IMPORT, | ||
TK_EXPORT, | ||
TK_FROM, | ||
TK_AS, | ||
|
||
TK_EOF, | ||
TK_ERROR | ||
|
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Ensure that `as` and `from` are valid identifiers while their special | ||
meaning in import statements is retained. | ||
|
||
-- Testcase -- | ||
import { foo as bar } from 'mod'; | ||
import * as mod from 'mod'; | ||
|
||
function fn(as, from) { | ||
return as + from; | ||
} | ||
|
||
as = 1; | ||
from = true; | ||
|
||
printf("%.J\n", [ | ||
bar, | ||
mod, | ||
fn(1, 2), | ||
as, | ||
from | ||
]); | ||
-- End -- | ||
|
||
-- File mod.uc -- | ||
export let foo = false; | ||
export default 'test'; | ||
-- End -- | ||
|
||
-- Args -- | ||
-R -L files/ | ||
-- End -- | ||
|
||
-- Expect stdout -- | ||
[ | ||
false, | ||
{ | ||
"foo": false, | ||
"default": "test" | ||
}, | ||
3, | ||
1, | ||
true | ||
] | ||
-- End -- |