diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-03-18 01:56:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-18 01:56:15 +0800 |
commit | fb092839c26ddaa0614df5295be85ea207bda9f7 (patch) | |
tree | a2e30e98953c57bd7faecbf6c2541a3707bb02ea /test/run-tests.js | |
parent | b7c112eefe4b7840cefd85287e3f858784c56a59 (diff) | |
download | tracifyjs-fb092839c26ddaa0614df5295be85ea207bda9f7.tar.gz tracifyjs-fb092839c26ddaa0614df5295be85ea207bda9f7.zip |
fix top-level directives in compress tests (#1615)
`input` and `expect` are parsed as `AST_BlockStatement` which does not support `AST_Directive` by default.
Emulate that by transforming preceding `AST_SimpleStatement`s of `AST_String` into `AST_Directive`.
Diffstat (limited to 'test/run-tests.js')
-rwxr-xr-x | test/run-tests.js | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/test/run-tests.js b/test/run-tests.js index 898bb793..c3c142d1 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -72,10 +72,15 @@ function test_directory(dir) { } function as_toplevel(input, mangle_options) { - if (input instanceof U.AST_BlockStatement) input = input.body; - else if (input instanceof U.AST_Statement) input = [ input ]; - else throw new Error("Unsupported input syntax"); - var toplevel = new U.AST_Toplevel({ body: input }); + if (!(input instanceof U.AST_BlockStatement)) + throw new Error("Unsupported input syntax"); + for (var i = 0; i < input.body.length; i++) { + var stat = input.body[i]; + if (stat instanceof U.AST_SimpleStatement && stat.body instanceof U.AST_String) + input.body[i] = new U.AST_Directive(stat.body); + else break; + } + var toplevel = new U.AST_Toplevel(input); toplevel.figure_out_scope(mangle_options); return toplevel; } @@ -299,10 +304,6 @@ function parse_test(file) { }) ); var stat = node.body; - if (stat instanceof U.AST_BlockStatement) { - if (stat.body.length == 1) stat = stat.body[0]; - else if (stat.body.length == 0) stat = new U.AST_EmptyStatement(); - } if (label.name == "expect_exact") { test[label.name] = read_string(stat); } else if (label.name == "expect_stdout") { |