Parse another import variant: import * as Name from 'a.js'.

This commit is contained in:
Ondřej Španěl 2017-03-30 20:12:37 +02:00
parent 9031b93f93
commit 09680c7d5c
3 changed files with 22 additions and 12 deletions

View File

@ -1233,7 +1233,7 @@ function OutputStream(options) {
output.space();
}
if (self.imported_names) {
if (self.imported_names.length === 1 && self.imported_names[0].name.name === "*") {
if (self.imported_names.length === 1 && self.imported_names[0].foreign_name.name === "*") {
self.imported_names[0].print(output);
} else {
output.print("{");

View File

@ -2176,7 +2176,7 @@ function parse($TEXT, options) {
next();
}
imported_names = import_names();
imported_names = import_names(true);
if (imported_names || imported_name) {
expect_token("name", "from");
@ -2227,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,
@ -2256,7 +2254,7 @@ function parse($TEXT, options) {
})
}
function import_names() {
function import_names(allow_as) {
var names;
if (is("punc", "{")) {
next();
@ -2269,8 +2267,13 @@ function parse($TEXT, options) {
}
next();
} else if (is("operator", "*")) {
var st = prev();
names = [import_nameAsterisk()];
var name;
next();
if (allow_as && is("name", "as")) {
next(); // The "as" word
name = as_symbol(AST_SymbolImportForeign);
}
names = [import_nameAsterisk(name)];
}
return names;
}
@ -2286,7 +2289,7 @@ function parse($TEXT, options) {
next();
}
exported_names = import_names();
exported_names = import_names(false);
if (exported_names) {
expect_token("name", "from");

View File

@ -183,9 +183,16 @@ import_statement: {
import { Bar, Baz } from 'lel';
import Bar, { Foo } from 'lel';
import { Bar as kex, Baz as food } from 'lel';
import * from 'lel';
}
expect_exact: 'import"mod-name";import Foo from"bar";import{Bar,Baz}from"lel";import Bar,{Foo}from"lel";import{Bar as kex,Baz as food}from"lel";import*from"lel";'
expect_exact: 'import"mod-name";import Foo from"bar";import{Bar,Baz}from"lel";import Bar,{Foo}from"lel";import{Bar as kex,Baz as food}from"lel";'
}
import_all_statement: {
input: {
import * from 'lel';
import * as Lel from 'lel';
}
expect_exact: 'import*from"lel";import*as Lel from"lel";'
}
export_statement: {