aboutsummaryrefslogtreecommitdiff
// Testing UglifyJS <-> SpiderMonkey AST conversion
"use strict";

var acorn = require("acorn");
var ufuzz = require("./ufuzz");
var UglifyJS = require("..");

function beautify(ast) {
    var beautified = UglifyJS.minify(ast, {
        compress: false,
        mangle: false,
        output: {
            beautify: true,
            braces: true,
        },
    });
    if (beautified.error) return beautified;
    return UglifyJS.minify(beautified.code, {
        compress: false,
        mangle: false,
        output: {
            ast: true,
        },
    });
}

function validate(ast) {
    try {
        ast.walk(new UglifyJS.TreeWalker(function(node) {
            node.validate();
        }));
    } catch (e) {
        return { error: e };
    }
    return UglifyJS.minify(ast, {
        compress: false,
        mangle: false,
        output: {
            ast: true,
        },
        validate: true,
    });
}

function patch_import(code) {
    return code.replace(/\bimport\s*\{\s*\}\s*from\s*(['"])/g, "import$1")
        .replace(/\b(import\b.*?)\s*,\s*\{\s*\}\s*(from\s*['"])/g, "$1 $2");
}

function equals(input, transformed) {
    if (input.code === transformed.code) return true;
    return patch_import(input.code) === patch_import(transformed.code);
}

function test(input, to_moz, description, skip_on_error, beautified) {
    try {
        var ast = UglifyJS.AST_Node.from_mozilla_ast(to_moz(input));
    } catch (e) {
        if (skip_on_error) return true;
        console.log("//=============================================================");
        console.log("//", description, "failed... round", round);
        console.log(e);
        console.log("// original code");
        if (beautified === true) console.log("// (beautified)");
        console.log(input.code);
        return false;
    }
    var transformed = validate(ast);
    if (transformed.error || !equals(input, transformed)) {
        if (!beautified) {
            beautified = beautify(input.ast);
            if (!beautified.error) {
                beautified.raw = beautified.code;
                if (!test(beautified, to_moz, description, skip_on_error, true)) return false;
            }
        }
        console.log("//=============================================================");
        console.log("// !!!!!! Failed... round", round);
        console.log("// original code");
        if (beautified.error) {
            console.log("// !!! beautify failed !!!");
            console.log(beautified.error.stack);
        } else if (beautified === true) {
            console.log("// (beautified)");
        }
        console.log(input.raw);
        console.log();
        console.log();
        console.log("//-------------------------------------------------------------");
        console.log("//", description);
        if (transformed.error) {
            console.log(transformed.error.stack);
        } else {
            beautified = beautify(transformed.ast);
            if (beautified.error) {
                console.log("// !!! beautify failed !!!");
                console.log(beautified.error.stack);
                console.log(transformed.code);
            } else {
                console.log("// (beautified)");
                console.log(beautified.code);
            }
        }
        console.log("!!!!!! Failed... round", round);
        return false;
    }
    return true;
}

var num_iterations = ufuzz.num_iterations;
var minify_options = require("./ufuzz/options.json").map(JSON.stringify);
minify_options.unshift(null);
for (var round = 1; round <= num_iterations; round++) {
    process.stdout.write(round + " of " + num_iterations + "\r");
    var code = ufuzz.createTopLevelCode();
    minify_options.forEach(function(options) {
        var ok = true;
        var input = UglifyJS.minify(options ? UglifyJS.minify(code, JSON.parse(options)).code : code, {
            compress: false,
            mangle: false,
            output: {
                ast: true,
            },
        });
        input.raw = options ? input.code : code;
        if (input.error) {
            ok = false;
            console.log("//=============================================================");
            console.log("// minify() failed... round", round);
            console.log(input.error);
            console.log("// original code");
            console.log(code);
        }
        if (ok) ok = test(input, function(input) {
            return input.ast.to_mozilla_ast();
        }, "AST_Node.to_mozilla_ast()");
        if (ok) ok = test(input, function(input) {
            return acorn.parse(input.raw, {
                ecmaVersion: "latest",
                locations: true,
                sourceType: "module",
            });
        }, "acorn.parse()", !ufuzz.verbose);
        if (!ok) process.exit(1);
    });
}
console.log();
nd): New procedure. * gnu/installer.scm (compute-locale-step): Add #:dry-run? parameter. Use it to avoid actually applying locale. (compute-keymap-step): Add dry-run? parameter. Pass it to keymap-page. (installer-program): Add #:dry-run? parameter. If #:true avoid writing to /proc, use dry-run-command, skip sync and reboot, and pass dry-run? to... (installer-steps): ...here. Add #:dry-run? parameter. Use it to disable skip network, substitutes, partitioning pages, and pass it to... compute-locale-step, compute-keymap-step, and final-page. Change-Id: I0ff4c3b0a0c69539af617c27ba37654beed44619 Janneke Nieuwenhuizen 2024-11-11installer: Use `%' for parameter %run-command-in-installer....* gnu/installer/utils.scm (run-command-in-installer): Rename to... (%run-command-in-installer): ...this. * gnu/installer.scm (installer-program): Update accordingly. * gnu/installer/parted.scm (remove-logical-devices, create-btrfs-file-system, create-ext4-file-system, create-fat16-file-system, create-fat32-file-system, create-jfs-file-system, create-ntfs-file-system, create-xfs-file-system, create-swap-partition, luks-format-and-open, luks-ensure-open, luks-close): Update accordingly. Change-Id: I96ebc59ebc85fd8ebccb0cc57130b4e7532d287f Janneke Nieuwenhuizen 2024-11-11installer: Use "partitioning-page" consistently....Having `partition-page' function call `RUN-partititionING-page' where all other proxy functions call `RUN-<name>' hurts my brain while refactoring. * gnu/installer/record.scm (<installer>)[partition-page]: Rename to... [partitioning-page]: ...this. * gnu/installer/newt.scm (partitioning-page, newt-installer): Update accordingly. * gnu/installer.scm (installer-steps): Update accordingly. Change-Id: I6b2f3459a3d0a7a89260224b7d8438676e3411ba Janneke Nieuwenhuizen 2024-11-11installer: Align comments....* gnu/installer.scm (installer-program): Align comments. Change-Id: I50c173c46ea9bfdb3da0562146bc969d46f0edd9 Janneke Nieuwenhuizen 2024-09-28installer: Use the latest ‘iso-codes’....Fixes <https://issues.guix.gnu.org/73081>. * gnu/installer.scm (compute-locale-step): Use Use iso-codes. Change-Id: I9a69f7accee965cf5deb2c1b23ce3fda579d465a Signed-off-by: Ludovic Courtès <ludo@gnu.org> Reported-by: Ricardo Wurmus <rekado@elephly.net> Roman Scherer 2024-09-28gnu: iso-codes: Rename to iso-codes/pinned....* gnu/packages/iso-codes.scm (iso-codes): Rename to… (iso-codes/pinned): … this. * doc/build.scm, gnu/installer.scm, gnu/packages/fcitx.scm, gnu/packages/fcitx5.scm, gnu/packages/gnome.scm, gnu/packages/gstreamer.scm, gnu/packages/gtk.scm, gnu/packages/ibus.scm, gnu/packages/kde-frameworks.scm, gnu/packages/kde-plasma.scm, gnu/packages/mate.scm, gnu/packages/photo.scm, gnu/packages/video.scm: Adjust accordingly. Change-Id: Ia98fee15a27009583fee822cf411512727b1aa27 Signed-off-by: Ludovic Courtès <ludo@gnu.org> Roman Scherer 2024-05-29gnu: linux-libre: Enable Zstd compression of kernel modules....This brings the on disk size of the kernel from 164 MiB to 144 MiB, or about 12%. * gnu/packages/linux.scm (default-extra-linux-options) [version>=5.13]: Enable CONFIG_MODULE_COMPRESS_ZSTD, else CONFIG_MODULE_COMPRESS_GZIP. (make-linux-libre*) [phases] {set-environment}: Set ZSTD_CLEVEL environment variable to 19. [native-inputs]: Add zstd. * gnu/build/linux-modules.scm (module-regex): Add .zst to regexp. Update doc. (modinfo-section-contents): Extend support to Zstd compressed module. (dot-ko): Register the 'zstd compression type. (ensure-dot-ko, file-name->module-name, load-linux-module*) (module-name->file-name/guess, write-module-name-database) (write-module-alias-database, write-module-device-database): Update doc. (module-name-lookup): Also consider zstd-compressed modules. * gnu/installer.scm (installer-program): Add guile-zstd extension to gexp. * gnu/system/linux-initrd.scm (flat-linux-module-directory): Likewise. Decompress zstd-compressed modules for use in initrd. * guix/profiles.scm (linux-module-database): Add guile-zstd extension to gexp. Change-Id: Ide899dc5c58ea5033583b1a91a92c025fc8d901a Maxim Cournoyer 2023-12-25gnu: Adjust to removing ed.scm and nano.scm...This is a follow-up to f6817e71dff7d0d9fdb55db8b85a1d3d04e2bf5a and e11e65a9ad08e18ea2faac3c9f4639a7b189bf76. * gnu/installer.scm, gnu/packages/algebra.scm, gnu/packages/base.scm, gnu/packages/cook.scm, gnu/packages/lisp.scm, gnu/packages/patchutils.scm, gnu/packages/version-control.scm, gnu/packages/web-browsers.scm, gnu/system.scm: Adjust module imports. Change-Id: I25e5519fa003c35a14b81c3dda37b24527858634 Efraim Flashner 2023-12-02gnu: Use ‘libc-utf8-locales-for-target’....* guix/packages.scm (%standard-patch-inputs): Use ‘libc-utf8-locales-for-target’ instead of ‘glibc-utf8-locales’. * guix/self.scm (%packages): Likewise. * gnu/home/services/ssh.scm (file-join): Likewise * gnu/installer.scm (build-compiled-file): Likewise. * gnu/packages/chromium.scm (ungoogled-chromium/wayland): Likewise. * gnu/packages/gnome.scm (libgweather4, tracker): Likewise. * gnu/packages/javascript.scm (js-mathjax): Likewise. * gnu/packages/package-management.scm (guix, flatpak): Likewise. * gnu/packages/raspberry-pi.scm (raspi-arm64-chainloader): Likewise. * gnu/packages/suckless.scm (svkbd): Likewise. * gnu/services.scm (cleanup-gexp): Likewise. * gnu/services/base.scm (guix-publish-shepherd-service): Likewise. * gnu/services/guix.scm (guix-build-coordinator-shepherd-services) (guix-build-coordinator-agent-shepherd-services): Likewise. * gnu/services/guix.scm (guix-build-coordinator-queue-builds-shepherd-services): (guix-data-service-shepherd-services) (nar-herder-shepherd-services) (bffe-shepherd-services): Likewise. * gnu/services/web.scm (anonip-shepherd-service) (mumi-shepherd-services): Likewise. * gnu/system/image.scm (system-disk-image, system-iso9660-image) (system-docker-image, system-tarball-image): Likewise. * gnu/system/install.scm (%installation-services): Likewise. * guix/profiles.scm (info-dir-file): Likewise. (ca-certificate-bundle, profile-derivation): Likewise. * guix/scripts/pack.scm (store-database, set-utf8-locale): Likewise. * tests/pack.scm: Likewise. * tests/profiles.scm ("profile-derivation, cross-compilation"): Likewise. Co-authored-by: Ludovic Courtès <ludo@gnu.org> Co-authored-by: Christopher Baines <mail@cbaines.net> Change-Id: I24239f427bcc930c29d2ba5d00dc615960a6c374 Janneke Nieuwenhuizen