diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-02-13 20:26:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-14 04:26:43 +0800 |
commit | b7219ac489e47091f17091a08d7ef50980d68972 (patch) | |
tree | c46da154cf918ec3573ddb9b4dfd9df244919556 /lib/parse.js | |
parent | a6bb66931bfdd04d6ce05b640d89a8deff7ca3de (diff) | |
download | tracifyjs-b7219ac489e47091f17091a08d7ef50980d68972.tar.gz tracifyjs-b7219ac489e47091f17091a08d7ef50980d68972.zip |
support `import` statements (#4646)
Diffstat (limited to 'lib/parse.js')
-rw-r--r-- | lib/parse.js | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/lib/parse.js b/lib/parse.js index 27803f2e..e287c40e 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -47,7 +47,7 @@ var KEYWORDS = "break case catch const continue debugger default delete do else finally for function if in instanceof let new return switch throw try typeof var void while with"; var KEYWORDS_ATOM = "false null true"; var RESERVED_WORDS = [ - "await abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized this throws transient volatile yield", + "abstract async await boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized this throws transient volatile yield", KEYWORDS_ATOM, KEYWORDS, ].join(" "); @@ -844,6 +844,9 @@ function parse($TEXT, options) { case "await": if (S.in_async) return simple_statement(); break; + case "import": + next(); + return import_(); case "yield": if (S.in_generator) return simple_statement(); break; @@ -1272,6 +1275,51 @@ function parse($TEXT, options) { }); } + function import_() { + var all = null; + var def = as_symbol(AST_SymbolImport, true); + var props = null; + if (def ? (def.key = "", is("punc", ",") && next()) : !is("string")) { + if (is("operator", "*")) { + next(); + expect_token("name", "as"); + all = as_symbol(AST_SymbolImport); + all.key = "*"; + } else { + expect("{"); + props = []; + while (is("name") || is_identifier_string(S.token.value)) { + var alias; + if (is_token(peek(), "name", "as")) { + var key = S.token.value; + next(); + next(); + alias = as_symbol(AST_SymbolImport); + alias.key = key; + } else { + alias = as_symbol(AST_SymbolImport); + alias.key = alias.name; + } + props.push(alias); + if (!is("punc", "}")) expect(","); + } + expect("}"); + } + } + if (all || def || props) expect_token("name", "from"); + if (!is("string")) unexpected(); + var path = S.token; + next(); + semicolon(); + return new AST_Import({ + all: all, + default: def, + path: path.value, + properties: props, + quote: path.quote, + }); + } + function block_() { expect("{"); var a = []; |