support string namespace in import & export (#5570)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
var acorn = require("acorn");
|
||||
var assert = require("assert");
|
||||
var UglifyJS = require("../node");
|
||||
|
||||
@@ -25,6 +26,7 @@ describe("export", function() {
|
||||
"export { * };",
|
||||
"export { * as A };",
|
||||
"export { 42 as A };",
|
||||
"export { 'A' as B };",
|
||||
"export { A as B-C };",
|
||||
"export { default as A };",
|
||||
].forEach(function(code) {
|
||||
@@ -51,8 +53,11 @@ describe("export", function() {
|
||||
it("Should reject invalid `export ... from ...` statement syntax", function() {
|
||||
[
|
||||
"export from 'path';",
|
||||
"export A from 'path';",
|
||||
"export * from `path`;",
|
||||
"export 'A' from 'path';",
|
||||
"export A as B from 'path';",
|
||||
"export 'A' as B from 'path';",
|
||||
"export default from 'path';",
|
||||
"export { A }, B from 'path';",
|
||||
"export * as A, B from 'path';",
|
||||
@@ -128,4 +133,49 @@ describe("export", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
it("Should interoperate with ESTree correctly", function() {
|
||||
[
|
||||
"export var A = 42;",
|
||||
"export default (class A {});",
|
||||
"var A; export { A as '42' };",
|
||||
"export { '42' } from 'path';",
|
||||
"export * as '42' from 'path';",
|
||||
].forEach(function(code) {
|
||||
var ast = UglifyJS.parse(code);
|
||||
try {
|
||||
var spidermonkey = ast.to_mozilla_ast();
|
||||
} catch (ex) {
|
||||
assert.fail("[to_mozilla_ast] " + ex.stack);
|
||||
}
|
||||
try {
|
||||
var ast2 = UglifyJS.AST_Node.from_mozilla_ast(spidermonkey);
|
||||
} catch (ex) {
|
||||
assert.fail("[from_mozilla_ast] " + ex.stack);
|
||||
}
|
||||
assert.strictEqual(ast2.print_to_string(), ast.print_to_string(), [
|
||||
"spidermonkey:",
|
||||
ast.print_to_string(),
|
||||
ast2.print_to_string(),
|
||||
].join("\n"));
|
||||
try {
|
||||
var acorn_est = acorn.parse(code, {
|
||||
ecmaVersion: "latest",
|
||||
locations: true,
|
||||
sourceType: "module",
|
||||
});
|
||||
} catch (ex) {
|
||||
assert.fail("[acorn.parse] " + ex.stack);
|
||||
}
|
||||
try {
|
||||
var ast3 = UglifyJS.AST_Node.from_mozilla_ast(acorn_est);
|
||||
} catch (ex) {
|
||||
assert.fail("[from_acorn] " + ex.stack);
|
||||
}
|
||||
assert.strictEqual(ast3.print_to_string(), ast.print_to_string(), [
|
||||
"acorn:",
|
||||
ast.print_to_string(),
|
||||
ast3.print_to_string(),
|
||||
].join("\n"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user