<commit_before>var fs = require("fs");
var path = require("path");
var esprima = require("../coms/esprima");
var getVariables = require("../coms/compile/variables");
var typescript = require("../coms/typescript");
var check = function (root) {
    var rest = [].concat.apply([], arguments);
    var map = {
        devicePixelRatio: 1,
        "screen": true,
        "window": true,
        "document": true,
        "location": true,
        "navigator": true,
        "XMLHttpRequest": true,
        "history": true,
        "Image": true,
        "Event": true,
        "self": true,
        "modules": true,
        "init": true,
        "put": true,
        "state": true
    }, needs = {};
    var list = function () {
        Object.keys(needs).filter(k => !map[k]).forEach(function (k) {
            var key = k;
            if (!global[key]) console.log(key, needs[k]);
        });
    }
    var run = function () {
        if (!rest.length) return list();
        var fullpath = rest.pop();
        fs.access(fullpath, function (error) {
            if (error) return console.error(error);
            fs.stat(fullpath, function (error, stats) {
                if (error) return console.error(error);
                if (stats.isDirectory()) {
                    fs.readdir(fullpath, function (error, names) {
                        if (error) return console.error(error);
                        rest.push.apply(rest, names.map(n => path.join(fullpath, n)));
                        run();
                    });
                    return;
                }
                if (stats.isFile()) {
                    var basename = path.relative(root, fullpath);
                    basename = basename.replace(/[\\\/]/g, '$');
                    if (/\.json$/i.test(basename)) {
                        map[basename.replace(/\.json$/i, "")] = true;
                    }
                    if (/\.(html?|xml)$/i.test(basename)) {
                        map[path.basename(basename).replace(/\.(html?|xml)$/i, "")] = true;
                    }
                    if (!/\.[jt]sx?$/i.test(fullpath)) return run();
                    map[basename.replace(/\.[jt]sx?$/i, "")] = true;
                    fs.readFile(fullpath, function (error, data) {
                        if (error) return console.error(error);
                        try {
                            var jst = esprima.parse(typescript.transpile(String(data)));
                            var {
                                unDeclaredVariables: undeclares
                            } = getVariables(jst);
                            delete undeclares[path.basename(fullpath).replace(/\.[jt]sx?$/i, '')];
                            Object.keys(undeclares).map(k => k).forEach(k => {
                                if (!needs[k]) needs[k] = [];
                                needs[k].push(basename);
                            });
                        } catch (e) {
                            console.error(basename, String(e));
                        }
                        run();
                    });
                    return;
                }
                run();
            });
        });
    }
    run();
}
check('coms/zimoli');<commit_msg>增加检查efront目录的全局变量<commit_after>var fs = require("fs");
var path = require("path");
var esprima = require("../coms/esprima");
var getVariables = require("../coms/compile/variables");
var typescript = require("../coms/typescript");
var check = function (root) {
    var rest = [].concat.apply([], arguments);
    var map = {
        devicePixelRatio: 1,
        "screen": true,
        "window": true,
        "document": true,
        "location": true,
        "navigator": true,
        "XMLHttpRequest": true,
        "history": true,
        "Image": true,
        "Event": true,
        "self": true,
        "modules": true,
        "init": true,
        "put": true,
        "state": true,
        "module": true,
        "exports": true,
        "require": true,
        "__dirname": true,
    }, needs = {};
    var list = function () {
        Object.keys(needs).filter(k => !map[k]).forEach(function (k) {
            var key = k;
            if (!global[key]) console.log(key, needs[k]);
        });
    }
    var run = function () {
        if (!rest.length) return list();
        var fullpath = rest.pop();
        fs.access(fullpath, function (error) {
            if (error) return console.error(error);
            fs.stat(fullpath, function (error, stats) {
                if (error) return console.error(error);
                if (stats.isDirectory()) {
                    fs.readdir(fullpath, function (error, names) {
                        if (error) return console.error(error);
                        rest.push.apply(rest, names.map(n => path.join(fullpath, n)));
                        run();
                    });
                    return;
                }
                if (stats.isFile()) {
                    var basename = path.relative(root, fullpath);
                    basename = basename.replace(/[\\\/]/g, '$');
                    if (/\.json$/i.test(basename)) {
                        map[basename.replace(/\.json$/i, "")] = true;
                    }
                    if (/\.(html?|xml)$/i.test(basename)) {
                        map[path.basename(basename).replace(/\.(html?|xml)$/i, "")] = true;
                    }
                    if (!/\.[jt]sx?$/i.test(fullpath)) return run();
                    map[basename.replace(/\.[jt]sx?$/i, "")] = true;
                    fs.readFile(fullpath, function (error, data) {
                        if (error) return console.error(error);
                        try {

                            var jst = esprima.parse(typescript.transpile(String(data).replace(/^\s*#!/, '//')));
                            var {
                                unDeclaredVariables: undeclares
                            } = getVariables(jst);
                            delete undeclares[path.basename(fullpath).replace(/\.[jt]sx?$/i, '')];
                            Object.keys(undeclares).map(k => k).forEach(k => {
                                if (!needs[k]) needs[k] = [];
                                needs[k].push(basename);
                            });
                        } catch (e) {
                            console.error(basename, String(e));
                        }
                        run();
                    });
                    return;
                }
                run();
            });
        });
    }
    run();
}
check('coms/efront');
check('coms/build');
check('coms/zimoli');
{'fraction_non_alphanumeric': 0.15591397849462366, 'fraction_numerical': 0.0002986857825567503, 'mean_word_length': 1.2109607131066358, 'pattern_counts': {'":': 32, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5180398', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1775, 'n_words': 339}