toolkit/mozapps/installer/js-compare-ast.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/installer/js-compare-ast.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,28 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/**
     1.9 + * This script compares the AST of two JavaScript files passed as arguments.
    1.10 + * The script exits with a 0 status code if both files parse properly and the
    1.11 + * ASTs of both files are identical modulo location differences. The script
    1.12 + * exits with status code 1 if any of these conditions don't hold.
    1.13 + *
    1.14 + * This script is used as part of packaging to verify minified JavaScript files
    1.15 + * are identical to their original files.
    1.16 + */
    1.17 +
    1.18 +"use strict";
    1.19 +
    1.20 +function ast(filename) {
    1.21 +  return JSON.stringify(Reflect.parse(snarf(filename), {loc: 0}));
    1.22 +}
    1.23 +
    1.24 +if (scriptArgs.length !== 2) {
    1.25 +  throw "usage: js js-compare-ast.js FILE1.js FILE2.js";
    1.26 +}
    1.27 +
    1.28 +let ast0 = ast(scriptArgs[0]);
    1.29 +let ast1 = ast(scriptArgs[1]);
    1.30 +
    1.31 +quit(ast0 == ast1 ? 0 : 1);

mercurial