support import statements (#4646)

This commit is contained in:
Alex Lam S.L
2021-02-13 20:26:43 +00:00
committed by GitHub
parent a6bb66931b
commit b7219ac489
8 changed files with 312 additions and 10 deletions

View File

@@ -1011,6 +1011,27 @@ function OutputStream(options) {
output.space();
force_statement(self.body, output);
});
DEFPRINT(AST_Import, function(output) {
var self = this;
output.print("import");
output.space();
if (self.default) self.default.print(output);
if (self.all) {
if (self.default) output.comma();
self.all.print(output);
}
if (self.properties) {
if (self.default) output.comma();
print_properties(self, output);
}
if (self.all || self.default || self.properties) {
output.space();
output.print("from");
output.space();
}
output.print_string(self.path, self.quote);
output.semicolon();
});
/* -----[ functions ]----- */
function print_funargs(self, output) {
@@ -1454,8 +1475,8 @@ function OutputStream(options) {
});
else print_braced_empty(this, output);
});
DEFPRINT(AST_Object, function(output) {
var props = this.properties;
function print_properties(self, output) {
var props = self.properties;
if (props.length > 0) output.with_block(function() {
props.forEach(function(prop, i) {
if (i) {
@@ -1467,7 +1488,10 @@ function OutputStream(options) {
});
output.newline();
});
else print_braced_empty(this, output);
else print_braced_empty(self, output);
}
DEFPRINT(AST_Object, function(output) {
print_properties(this, output);
});
function print_property_key(self, output) {
@@ -1512,9 +1536,22 @@ function OutputStream(options) {
}
DEFPRINT(AST_ObjectGetter, print_accessor("get"));
DEFPRINT(AST_ObjectSetter, print_accessor("set"));
function print_symbol(self, output) {
var def = self.definition();
output.print_name(def && def.mangled_name || self.name);
}
DEFPRINT(AST_Symbol, function(output) {
var def = this.definition();
output.print_name(def && def.mangled_name || this.name);
print_symbol(this, output);
});
DEFPRINT(AST_SymbolImport, function(output) {
var self = this;
if (self.key) {
output.print_name(self.key);
output.space();
output.print("as");
output.space();
}
print_symbol(self, output);
});
DEFPRINT(AST_Hole, noop);
DEFPRINT(AST_This, function(output) {