run mozilla AST I/O tests against all existing compress tests
This commit is contained in:
parent
0150e02dc4
commit
ca926600dd
|
|
@ -89,6 +89,7 @@
|
||||||
start: my_start_token(M),
|
start: my_start_token(M),
|
||||||
end: my_end_token(M),
|
end: my_end_token(M),
|
||||||
names: M.properties.map(from_moz),
|
names: M.properties.map(from_moz),
|
||||||
|
is_array: false
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
AssignmentPattern: function(M) {
|
AssignmentPattern: function(M) {
|
||||||
|
|
@ -198,11 +199,14 @@
|
||||||
Property: function(M) {
|
Property: function(M) {
|
||||||
var key = M.key;
|
var key = M.key;
|
||||||
var args = {
|
var args = {
|
||||||
start : my_start_token(key),
|
start : my_start_token(key || M.value),
|
||||||
end : my_end_token(M.value),
|
end : my_end_token(M.value),
|
||||||
key : key.type == "Identifier" ? key.name : key.value,
|
key : key.type == "Identifier" ? key.name : key.value,
|
||||||
value : from_moz(M.value)
|
value : from_moz(M.value)
|
||||||
};
|
};
|
||||||
|
if (M.computed) {
|
||||||
|
args.key = from_moz(M.key);
|
||||||
|
}
|
||||||
if (M.method) {
|
if (M.method) {
|
||||||
args.is_generator = M.value.generator;
|
args.is_generator = M.value.generator;
|
||||||
args.async = M.value.async;
|
args.async = M.value.async;
|
||||||
|
|
@ -214,14 +218,16 @@
|
||||||
return new AST_ConciseMethod(args);
|
return new AST_ConciseMethod(args);
|
||||||
}
|
}
|
||||||
if (M.kind == "init") {
|
if (M.kind == "init") {
|
||||||
if (key.type != "Identifier") {
|
if (key.type != "Identifier" && key.type != "Literal") {
|
||||||
args.key = from_moz(key);
|
args.key = from_moz(key);
|
||||||
}
|
}
|
||||||
return new AST_ObjectKeyVal(args);
|
return new AST_ObjectKeyVal(args);
|
||||||
}
|
}
|
||||||
|
if (typeof args.key === "string" || typeof args.key === "number") {
|
||||||
args.key = new AST_SymbolMethod({
|
args.key = new AST_SymbolMethod({
|
||||||
name: args.key
|
name: args.key
|
||||||
});
|
});
|
||||||
|
}
|
||||||
args.value = new AST_Accessor(args.value);
|
args.value = new AST_Accessor(args.value);
|
||||||
if (M.kind == "get") return new AST_ObjectGetter(args);
|
if (M.kind == "get") return new AST_ObjectGetter(args);
|
||||||
if (M.kind == "set") return new AST_ObjectSetter(args);
|
if (M.kind == "set") return new AST_ObjectSetter(args);
|
||||||
|
|
@ -264,6 +270,9 @@
|
||||||
start : my_start_token(M),
|
start : my_start_token(M),
|
||||||
end : my_end_token(M),
|
end : my_end_token(M),
|
||||||
properties : M.properties.map(function(prop){
|
properties : M.properties.map(function(prop){
|
||||||
|
if (prop.type === "SpreadElement") {
|
||||||
|
return from_moz(prop);
|
||||||
|
}
|
||||||
prop.type = "Property";
|
prop.type = "Property";
|
||||||
return from_moz(prop)
|
return from_moz(prop)
|
||||||
})
|
})
|
||||||
|
|
@ -414,6 +423,7 @@
|
||||||
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
|
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
|
||||||
: p.type == "ArrowFunctionExpression" ? (p.params.indexOf(M) !== -1) ? AST_SymbolFunarg : AST_SymbolRef
|
: p.type == "ArrowFunctionExpression" ? (p.params.indexOf(M) !== -1) ? AST_SymbolFunarg : AST_SymbolRef
|
||||||
: p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef)
|
: p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef)
|
||||||
|
: p.type == "Property" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolMethod)
|
||||||
: p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef)
|
: p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef)
|
||||||
: p.type == "MethodDefinition" ? (p.computed ? AST_SymbolRef : AST_SymbolMethod)
|
: p.type == "MethodDefinition" ? (p.computed ? AST_SymbolRef : AST_SymbolMethod)
|
||||||
: p.type == "CatchClause" ? AST_SymbolCatch
|
: p.type == "CatchClause" ? AST_SymbolCatch
|
||||||
|
|
@ -440,7 +450,7 @@
|
||||||
|
|
||||||
MOZ_TO_ME.ClassDeclaration =
|
MOZ_TO_ME.ClassDeclaration =
|
||||||
MOZ_TO_ME.ClassExpression = function From_Moz_Class(M) {
|
MOZ_TO_ME.ClassExpression = function From_Moz_Class(M) {
|
||||||
return new AST_Class({
|
return new (M.type === "ClassDeclaration" ? AST_DefClass : AST_ClassExpression)({
|
||||||
start : my_start_token(M),
|
start : my_start_token(M),
|
||||||
end : my_end_token(M),
|
end : my_end_token(M),
|
||||||
name : from_moz(M.id),
|
name : from_moz(M.id),
|
||||||
|
|
@ -471,6 +481,7 @@
|
||||||
map("CatchClause", AST_Catch, "param>argname, body%body");
|
map("CatchClause", AST_Catch, "param>argname, body%body");
|
||||||
|
|
||||||
map("ThisExpression", AST_This);
|
map("ThisExpression", AST_This);
|
||||||
|
map("SuperExpression", AST_Super);
|
||||||
map("BinaryExpression", AST_Binary, "operator=operator, left>left, right>right");
|
map("BinaryExpression", AST_Binary, "operator=operator, left>left, right>right");
|
||||||
map("LogicalExpression", AST_Binary, "operator=operator, left>left, right>right");
|
map("LogicalExpression", AST_Binary, "operator=operator, left>left, right>right");
|
||||||
map("AssignmentExpression", AST_Assign, "operator=operator, left>left, right>right");
|
map("AssignmentExpression", AST_Assign, "operator=operator, left>left, right>right");
|
||||||
|
|
@ -648,7 +659,7 @@
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
type: M.is_default ? "ExportDefaultDeclaration" : "ExportNamedDeclaration",
|
type: M.is_default ? "ExportDefaultDeclaration" : "ExportNamedDeclaration",
|
||||||
declaration: to_moz(M.is_default ? M.exported_value : M.exported_definition)
|
declaration: to_moz(M.exported_value || M.exported_definition)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -708,7 +719,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) {
|
def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) {
|
||||||
if (to_moz_in_destructuring()) {
|
if (M.operator == "=" && to_moz_in_destructuring()) {
|
||||||
return {
|
return {
|
||||||
type: "AssignmentPattern",
|
type: "AssignmentPattern",
|
||||||
left: to_moz(M.left),
|
left: to_moz(M.left),
|
||||||
|
|
@ -742,6 +753,12 @@
|
||||||
type: "Identifier",
|
type: "Identifier",
|
||||||
value: M.key
|
value: M.key
|
||||||
};
|
};
|
||||||
|
if (typeof M.key === "number") {
|
||||||
|
key = {
|
||||||
|
type: "Literal",
|
||||||
|
value: Number(M.key)
|
||||||
|
};
|
||||||
|
}
|
||||||
if (typeof M.key === "string") {
|
if (typeof M.key === "string") {
|
||||||
key = {
|
key = {
|
||||||
type: "Identifier",
|
type: "Identifier",
|
||||||
|
|
@ -749,10 +766,11 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var kind;
|
var kind;
|
||||||
var computed = typeof M.key === "string" ? false : !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef;
|
var string_or_num = typeof M.key === "string" || typeof M.key === "number";
|
||||||
|
var computed = string_or_num ? 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";
|
computed = !string_or_num;
|
||||||
} else
|
} else
|
||||||
if (M instanceof AST_ObjectGetter) {
|
if (M instanceof AST_ObjectGetter) {
|
||||||
kind = "get";
|
kind = "get";
|
||||||
|
|
|
||||||
|
|
@ -1455,7 +1455,13 @@ function OutputStream(options) {
|
||||||
output.space();
|
output.space();
|
||||||
self.module_name.print(output);
|
self.module_name.print(output);
|
||||||
}
|
}
|
||||||
if (!self.exported_definition) {
|
if (self.exported_value
|
||||||
|
&& !(self.exported_value instanceof AST_Defun ||
|
||||||
|
self.exported_value instanceof AST_Function ||
|
||||||
|
self.exported_value instanceof AST_Class)
|
||||||
|
|| self.module_name
|
||||||
|
|| self.exported_names
|
||||||
|
) {
|
||||||
output.semicolon();
|
output.semicolon();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1160,7 +1160,7 @@ function parse($TEXT, options) {
|
||||||
if (!is_token(peek(), "punc", "(")) {
|
if (!is_token(peek(), "punc", "(")) {
|
||||||
next();
|
next();
|
||||||
var node = export_();
|
var node = export_();
|
||||||
if (can_insert_semicolon()) semicolon();
|
if (is("punc", ";")) semicolon();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2712,7 +2712,8 @@ function parse($TEXT, options) {
|
||||||
next();
|
next();
|
||||||
args.push(new AST_Expansion({
|
args.push(new AST_Expansion({
|
||||||
start: prev(),
|
start: prev(),
|
||||||
expression: expression(false)
|
expression: expression(false),
|
||||||
|
end: prev()
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
args.push(expression(false));
|
args.push(expression(false));
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,7 @@ export_default_anonymous_function: {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: "export default function(){foo()};"
|
expect_exact: "export default function(){foo()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
export_default_arrow: {
|
export_default_arrow: {
|
||||||
|
|
@ -394,7 +394,7 @@ export_default_anonymous_class: {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
expect_exact: "export default class{constructor(){foo()}};"
|
expect_exact: "export default class{constructor(){foo()}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
export_default_anonymous_function_not_call: {
|
export_default_anonymous_function_not_call: {
|
||||||
|
|
|
||||||
|
|
@ -254,7 +254,7 @@ export_default_anon_function: {
|
||||||
console.log(1 + 2);
|
console.log(1 + 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: "export default function(){console.log(3)};"
|
expect_exact: "export default function(){console.log(3)}"
|
||||||
}
|
}
|
||||||
|
|
||||||
export_default_anon_class: {
|
export_default_anon_class: {
|
||||||
|
|
@ -266,7 +266,7 @@ export_default_anon_class: {
|
||||||
foo() { console.log(1 + 2); }
|
foo() { console.log(1 + 2); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: "export default class{foo(){console.log(3)}};"
|
expect_exact: "export default class{foo(){console.log(3)}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
export_module_statement: {
|
export_module_statement: {
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,16 @@ function run_compress_tests() {
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
var ast = input.to_mozilla_ast();
|
||||||
|
var ast_as_string = U.AST_Node.from_mozilla_ast(ast).print_to_string();
|
||||||
|
var input_string = input.print_to_string();
|
||||||
|
if (input_string !== ast_as_string) {
|
||||||
|
log("!!! Mozilla AST I/O corrupted input\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n\n", {
|
||||||
|
input: input_string,
|
||||||
|
output: ast_as_string,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var options = U.defaults(test.options, {
|
var options = U.defaults(test.options, {
|
||||||
warnings: false
|
warnings: false
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user