More variants of import added (#1738)

- `import * from "x.js"`
- `import * as Name from "x.js"`
This commit is contained in:
Ondřej Španěl
2017-03-31 11:52:56 +02:00
committed by Alex Lam S.L
parent a729c43e87
commit 2f93058c6e
3 changed files with 51 additions and 40 deletions

View File

@@ -2176,17 +2176,7 @@ function parse($TEXT, options) {
next();
}
if (is("punc", "{")) {
next();
imported_names = [];
while (!is("punc", "}")) {
imported_names.push(import_name());
if (is("punc", ",")) {
next();
}
}
next();
}
imported_names = import_names(true);
if (imported_names || imported_name) {
expect_token("name", "from");
@@ -2237,16 +2227,14 @@ function parse($TEXT, options) {
})
}
function import_nameAsterisk() {
function import_nameAsterisk(name) {
var start = S.token;
var foreign_name;
var name;
next();
var end = prev();
name = new AST_SymbolImport({
name = name || new AST_SymbolImport({
name: '*',
start: start,
end: end,
@@ -2266,6 +2254,30 @@ function parse($TEXT, options) {
})
}
function import_names(allow_as) {
var names;
if (is("punc", "{")) {
next();
names = [];
while (!is("punc", "}")) {
names.push(import_name());
if (is("punc", ",")) {
next();
}
}
next();
} else if (is("operator", "*")) {
var name;
next();
if (allow_as && is("name", "as")) {
next(); // The "as" word
name = as_symbol(AST_SymbolImportForeign);
}
names = [import_nameAsterisk(name)];
}
return names;
}
function export_() {
var start = S.token;
var is_default;
@@ -2278,20 +2290,7 @@ function parse($TEXT, options) {
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()];
}
exported_names = import_names(false);
if (exported_names) {
if (is("name", "from")) {