[ES6] Implemented parse for export Name from Module variants. (#1701)

- add `AST_Export` new variants output
- add tests to `test/compress/`
- update `$propdoc` of `AST_Export` ("exported_names" & "module_name")
- add tests for `export ...  as ...` variants
This commit is contained in:
Ondřej Španěl
2017-03-30 11:07:50 +02:00
committed by Alex Lam S.L
parent fccefbeaca
commit 5dea52266b
6 changed files with 182 additions and 2 deletions

View File

@@ -2237,17 +2237,85 @@ function parse($TEXT, options) {
})
}
function import_nameAsterisk() {
var start = S.token;
var foreign_name;
var name;
next();
var end = prev();
name = new AST_SymbolImport({
name: '*',
start: start,
end: end,
});
foreign_name = new AST_SymbolImportForeign({
name: '*',
start: start,
end: end,
});
return new AST_NameImport({
start: start,
foreign_name: foreign_name,
name: name,
end: end,
})
}
function export_() {
var start = S.token;
var is_default;
var exported_value;
var exported_definition;
var exported_names;
if (is("keyword", "default")) {
is_default = true;
next();
}
if (is("punc", "{")) {
next();
exported_names = [];
while (!is("punc", "}")) {
exported_names.push(import_name());
if (is("punc", ",")) {
next();
}
}
next();
} else if (is("operator", "*")) {
var st = prev();
exported_names = [import_nameAsterisk()];
}
if (exported_names) {
expect_token("name", "from");
var mod_str = S.token;
if (mod_str.type !== 'string') {
unexpected();
}
next();
return new AST_Export({
start: start,
is_default: is_default,
exported_names: exported_names,
module_name: new AST_String({
start: mod_str,
value: mod_str.value,
quote: mod_str.quote,
end: mod_str,
}),
end: prev(),
});
}
var is_definition =
is("keyword", "var") || is("keyword", "let") || is("keyword", "const") ||
is("keyword", "class") || is("keyword", "function");