Sha256: 01f695361809a5e6bb60020932557676224ef3bbe04da2a16b14553a21bbc394

Contents?: true

Size: 1.94 KB

Versions: 15

Compression:

Stored size: 1.94 KB

Contents

#! /usr/bin/env node

"use strict";

var U2 = require("../tools/node");
var fs = require("fs");
var yargs = require("yargs");
var ARGS = yargs
    .describe("o", "Output file")
    .argv;
var files = ARGS._.slice();
var output = {
    vars: {},
    props: {}
};

if (ARGS.o) try {
    output = JSON.parse(fs.readFileSync(ARGS.o, "utf8"));
} catch(ex) {}

files.forEach(getProps);

if (ARGS.o) {
    fs.writeFileSync(ARGS.o, JSON.stringify(output, null, 2), "utf8");
} else {
    console.log("%s", JSON.stringify(output, null, 2));
}

function getProps(filename) {
    var code = fs.readFileSync(filename, "utf8");
    var ast = U2.parse(code);

    ast.walk(new U2.TreeWalker(function(node){
        if (node instanceof U2.AST_ObjectKeyVal) {
            add(node.key);
        }
        else if (node instanceof U2.AST_ObjectProperty) {
            add(node.key.name);
        }
        else if (node instanceof U2.AST_Dot) {
            add(node.property);
        }
        else if (node instanceof U2.AST_Sub) {
            addStrings(node.property);
        }
    }));

    function addStrings(node) {
        var out = {};
        try {
            (function walk(node){
                node.walk(new U2.TreeWalker(function(node){
                    if (node instanceof U2.AST_Seq) {
                        walk(node.cdr);
                        return true;
                    }
                    if (node instanceof U2.AST_String) {
                        add(node.value);
                        return true;
                    }
                    if (node instanceof U2.AST_Conditional) {
                        walk(node.consequent);
                        walk(node.alternative);
                        return true;
                    }
                    throw out;
                }));
            })(node);
        } catch(ex) {
            if (ex !== out) throw ex;
        }
    }

    function add(name) {
        output.props[name] = true;
    }
}

Version data entries

15 entries across 15 versions & 8 rubygems

Version Path
epuber-stylus-source-0.56.0 vendor/node_modules/uglify-js/bin/extract-props.js
epuber-stylus-source-0.54.8 vendor/node_modules/uglify-js/bin/extract-props.js
ilog-0.4.1 node_modules/uglify-js/bin/extract-props.js
ilog-0.4.0 node_modules/uglify-js/bin/extract-props.js
ilog-0.3.3 node_modules/uglify-js/bin/extract-props.js
optimacms-0.4.3 spec/dummy/node_modules/uglify-js/bin/extract-props.js
optimacms-0.4.2 spec/dummy/node_modules/uglify-js/bin/extract-props.js
locomotivecms-3.4.0 app/javascript/node_modules/uglify-js/bin/extract-props.js
cortex-0.1.3 spec/dummy/node_modules/uglify-js/bin/extract-props.js
lanes-0.8.0 node_modules/uglify-js/bin/extract-props.js
eslint_node_modules-1.6.0.1 vendor/node_modules/eslint/node_modules/handlebars/node_modules/uglify-js/bin/extract-props.js
eslint_node_modules-1.6.0 vendor/node_modules/eslint/node_modules/handlebars/node_modules/uglify-js/bin/extract-props.js
gulp_assets-1.0.0.pre.5 template/node_modules/webpack/node_modules/uglify-js/bin/extract-props.js
gulp_assets-1.0.0.pre.4 template/node_modules/webpack/node_modules/uglify-js/bin/extract-props.js
gulp_assets-1.0.0.pre.3 template/node_modules/webpack/node_modules/uglify-js/bin/extract-props.js