checkpoint
This commit is contained in:
22
lib/ast.js
22
lib/ast.js
@@ -104,16 +104,11 @@ AST_Node.warn = function(txt, props) {
|
|||||||
AST_Node.warn_function(string_template(txt, props));
|
AST_Node.warn_function(string_template(txt, props));
|
||||||
};
|
};
|
||||||
|
|
||||||
var AST_Debugger = DEFNODE("Debugger", null, {
|
/* -----[ statements ]----- */
|
||||||
$documentation: "Represents a debugger statement"
|
|
||||||
});
|
|
||||||
|
|
||||||
var AST_Directive = DEFNODE("Directive", "value", {
|
var AST_StatementBase = DEFNODE("StatementBase", null, {
|
||||||
$documentation: "Represents a directive, like \"use strict\";"
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/* -----[ loops ]----- */
|
|
||||||
|
|
||||||
var AST_Statement = DEFNODE("Statement", "body", {
|
var AST_Statement = DEFNODE("Statement", "body", {
|
||||||
$documentation: "Base class of all statements",
|
$documentation: "Base class of all statements",
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
@@ -121,7 +116,15 @@ var AST_Statement = DEFNODE("Statement", "body", {
|
|||||||
this.body._walk(visitor);
|
this.body._walk(visitor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}, AST_StatementBase);
|
||||||
|
|
||||||
|
var AST_Debugger = DEFNODE("Debugger", null, {
|
||||||
|
$documentation: "Represents a debugger statement"
|
||||||
|
}, AST_StatementBase);
|
||||||
|
|
||||||
|
var AST_Directive = DEFNODE("Directive", "value", {
|
||||||
|
$documentation: "Represents a directive, like \"use strict\";"
|
||||||
|
}, AST_StatementBase);
|
||||||
|
|
||||||
var AST_SimpleStatement = DEFNODE("SimpleStatement", null, {
|
var AST_SimpleStatement = DEFNODE("SimpleStatement", null, {
|
||||||
$documentation: "A statement consisting of an expression, i.e. a = 1 + 2."
|
$documentation: "A statement consisting of an expression, i.e. a = 1 + 2."
|
||||||
@@ -141,7 +144,8 @@ var AST_BlockStatement = DEFNODE("BlockStatement", null, {
|
|||||||
function walk_body(node, visitor) {
|
function walk_body(node, visitor) {
|
||||||
if (node.body instanceof Array) node.body.forEach(function(stat){
|
if (node.body instanceof Array) node.body.forEach(function(stat){
|
||||||
stat._walk(visitor);
|
stat._walk(visitor);
|
||||||
}); else node.body._walk(visitor);
|
});
|
||||||
|
else if (node.body instanceof AST_Statement) node.body._walk(visitor);
|
||||||
};
|
};
|
||||||
|
|
||||||
var AST_Block = DEFNODE("Block", null, {
|
var AST_Block = DEFNODE("Block", null, {
|
||||||
|
|||||||
@@ -44,6 +44,13 @@ function test_directory(dir) {
|
|||||||
return path.resolve(tests_dir, dir);
|
return path.resolve(tests_dir, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function as_toplevel(input) {
|
||||||
|
if (input instanceof U.AST_BlockStatement) input = input.body;
|
||||||
|
else if (input instanceof U.AST_StatementBase) input = [ input ];
|
||||||
|
else throw new Error("Unsupported input syntax");
|
||||||
|
return new U.AST_Toplevel({ body: input });
|
||||||
|
}
|
||||||
|
|
||||||
function run_compress_tests() {
|
function run_compress_tests() {
|
||||||
var dir = test_directory("compress");
|
var dir = test_directory("compress");
|
||||||
log_directory("compress");
|
log_directory("compress");
|
||||||
@@ -53,8 +60,10 @@ function run_compress_tests() {
|
|||||||
function test_case(test) {
|
function test_case(test) {
|
||||||
log_test(test.name);
|
log_test(test.name);
|
||||||
var cmp = new U.Compressor(test.options || {}, true);
|
var cmp = new U.Compressor(test.options || {}, true);
|
||||||
var expect = make_code(test.expect, false);
|
var expect = make_code(as_toplevel(test.expect), false);
|
||||||
var output = make_code(test.input.squeeze(cmp), false);
|
var input = as_toplevel(test.input);
|
||||||
|
input.figure_out_scope();
|
||||||
|
var output = make_code(input.squeeze(cmp), false);
|
||||||
if (expect != output) {
|
if (expect != output) {
|
||||||
log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", {
|
log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", {
|
||||||
input: make_code(test.input),
|
input: make_code(test.input),
|
||||||
|
|||||||
Reference in New Issue
Block a user