test feeding spidermonkey AST through escodegen
This commit is contained in:
parent
2655e84f0d
commit
d310bcdf2a
|
|
@ -659,7 +659,12 @@
|
||||||
local: to_moz(M.imported_name)
|
local: to_moz(M.imported_name)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (M.imported_names) {
|
if (M.imported_names && M.imported_names[0].foreign_name.name === '*') {
|
||||||
|
specifiers.push({
|
||||||
|
type: "ImportNamespaceSpecifier",
|
||||||
|
local: to_moz(M.imported_names[0].name)
|
||||||
|
});
|
||||||
|
} else if (M.imported_names) {
|
||||||
M.imported_names.forEach(function(name_mapping) {
|
M.imported_names.forEach(function(name_mapping) {
|
||||||
specifiers.push({
|
specifiers.push({
|
||||||
type: "ImportSpecifier",
|
type: "ImportSpecifier",
|
||||||
|
|
@ -743,8 +748,10 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var kind;
|
var kind;
|
||||||
|
var computed = typeof M.key === "string" ? false : !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef;
|
||||||
if (M instanceof AST_ObjectKeyVal) {
|
if (M instanceof AST_ObjectKeyVal) {
|
||||||
kind = "init";
|
kind = "init";
|
||||||
|
computed = typeof M.key !== "string";
|
||||||
} else
|
} else
|
||||||
if (M instanceof AST_ObjectGetter) {
|
if (M instanceof AST_ObjectGetter) {
|
||||||
kind = "get";
|
kind = "get";
|
||||||
|
|
@ -755,7 +762,7 @@
|
||||||
if (parent instanceof AST_Class) {
|
if (parent instanceof AST_Class) {
|
||||||
return {
|
return {
|
||||||
type: "MethodDefinition",
|
type: "MethodDefinition",
|
||||||
computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
|
computed: computed,
|
||||||
kind: kind,
|
kind: kind,
|
||||||
static: M.static,
|
static: M.static,
|
||||||
key: to_moz(M.key),
|
key: to_moz(M.key),
|
||||||
|
|
@ -764,6 +771,7 @@
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
type: "Property",
|
type: "Property",
|
||||||
|
computed: computed,
|
||||||
kind: kind,
|
kind: kind,
|
||||||
key: key,
|
key: key,
|
||||||
value: to_moz(M.value)
|
value: to_moz(M.value)
|
||||||
|
|
@ -819,7 +827,13 @@
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
def_to_moz(AST_Symbol, function To_Moz_Identifier(M) {
|
def_to_moz(AST_Symbol, function To_Moz_Identifier(M, parent) {
|
||||||
|
if (M instanceof AST_SymbolMethod && parent.quote) {
|
||||||
|
return {
|
||||||
|
type: "Literal",
|
||||||
|
value: M.name
|
||||||
|
};
|
||||||
|
}
|
||||||
var def = M.definition();
|
var def = M.definition();
|
||||||
return {
|
return {
|
||||||
type: "Identifier",
|
type: "Identifier",
|
||||||
|
|
|
||||||
|
|
@ -1455,7 +1455,9 @@ function OutputStream(options) {
|
||||||
output.space();
|
output.space();
|
||||||
self.module_name.print(output);
|
self.module_name.print(output);
|
||||||
}
|
}
|
||||||
output.semicolon();
|
if (!self.exported_definition) {
|
||||||
|
output.semicolon();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function parenthesize_for_noin(node, output, noin) {
|
function parenthesize_for_noin(node, output, noin) {
|
||||||
|
|
|
||||||
|
|
@ -1159,7 +1159,9 @@ function parse($TEXT, options) {
|
||||||
case "export":
|
case "export":
|
||||||
if (!is_token(peek(), "punc", "(")) {
|
if (!is_token(peek(), "punc", "(")) {
|
||||||
next();
|
next();
|
||||||
return export_();
|
var node = export_();
|
||||||
|
semicolon();
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acorn": "~5.4.1",
|
"acorn": "~5.4.1",
|
||||||
|
"escodegen": "^1.9.1",
|
||||||
"mocha": "~3.5.1",
|
"mocha": "~3.5.1",
|
||||||
"semver": "~5.5.0"
|
"semver": "~5.5.0"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ function f () {
|
||||||
console.log([10, ...[], 20, ...[30, 40], 50]["length"]);
|
console.log([10, ...[], 20, ...[30, 40], 50]["length"]);
|
||||||
var { w: w1, ...V } = { w: 7, x: 1, y: 2 };
|
var { w: w1, ...V } = { w: 7, x: 1, y: 2 };
|
||||||
for (const x of y) {}
|
for (const x of y) {}
|
||||||
async function f1() { await x + y; }
|
async function f1() { await x; }
|
||||||
|
|
||||||
``;
|
``;
|
||||||
`x`;
|
`x`;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ var assert = require("assert");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var exec = require("child_process").exec;
|
var exec = require("child_process").exec;
|
||||||
var acorn = require("acorn");
|
var acorn = require("acorn");
|
||||||
|
var escodegen = require("escodegen");
|
||||||
var uglify = require("../node");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("spidermonkey export/import sanity test", function() {
|
describe("spidermonkey export/import sanity test", function() {
|
||||||
|
|
@ -136,4 +137,35 @@ describe("spidermonkey export/import sanity test", function() {
|
||||||
uglify_ast.print_to_string()
|
uglify_ast.print_to_string()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should produce an AST compatible with escodegen", function() {
|
||||||
|
var code = fs.readFileSync("test/input/spidermonkey/input.js", "utf-8");
|
||||||
|
var uglify_ast = uglify.parse(code);
|
||||||
|
var moz_ast = uglify_ast.to_mozilla_ast();
|
||||||
|
assert.strictEqual(
|
||||||
|
escodegen.generate(moz_ast, {
|
||||||
|
format: {
|
||||||
|
indent: {
|
||||||
|
style: "",
|
||||||
|
},
|
||||||
|
newline: "",
|
||||||
|
space: "",
|
||||||
|
quotes: "double"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.replace(/;}/g, "}")
|
||||||
|
.replace(/var {/g, "var{")
|
||||||
|
.replace(/var \[/g, "var[")
|
||||||
|
.replace(/const {/g, "const{")
|
||||||
|
.replace(/const \[/g, "const[")
|
||||||
|
.replace(/get \"/g, "get\"")
|
||||||
|
.replace(/set \"/g, "set\"")
|
||||||
|
.replace(/\[object Object\].\[object Object\]/g, "new.target") // escodegen issue
|
||||||
|
.replace(/\(await x\)/, "await x")
|
||||||
|
,
|
||||||
|
uglify_ast.print_to_string({
|
||||||
|
keep_quoted_props: true
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user