Support Import Assertions for re-export statement (#12249)

This commit is contained in:
Sosuke Suzuki
2020-10-26 23:18:45 +09:00
committed by GitHub
parent f5bd9f2013
commit faaebfe91f
33 changed files with 763 additions and 18 deletions

View File

@@ -53,6 +53,7 @@ export function ExportAllDeclaration(node: Object) {
this.word("from");
this.space();
this.print(node.source, node);
this.printAssertions(node);
this.semicolon();
}
@@ -131,6 +132,7 @@ function ExportDeclaration(node: Object) {
this.word("from");
this.space();
this.print(node.source, node);
this.printAssertions(node);
}
this.semicolon();
@@ -180,19 +182,10 @@ export function ImportDeclaration(node: Object) {
this.print(node.source, node);
if (node.assertions?.length) {
this.space();
this.word("assert");
this.space();
this.token("{");
this.space();
this.printList(node.assertions, node);
this.space();
this.token("}");
}
this.printAssertions(node);
// todo(Babel 8): remove this if branch
// `module-attributes` support is discontinued, use `import-assertions` instead.
else if (node.attributes?.length) {
if (node.attributes?.length) {
this.space();
this.word("with");
this.space();

View File

@@ -646,6 +646,19 @@ export default class Printer {
}
}
}
printAssertions(node: Node) {
if (node.assertions?.length) {
this.space();
this.word("assert");
this.space();
this.token("{");
this.space();
this.printList(node.assertions, node);
this.space();
this.token("}");
}
}
}
// Expose the node type functions and helpers on the prototype for easy usage.