react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / umd / node_modules / uglify-js / bin / extract-props.js
80743 views#! /usr/bin/env node12"use strict";34var U2 = require("../tools/node");5var fs = require("fs");6var yargs = require("yargs");7var ARGS = yargs8.describe("o", "Output file")9.argv;10var files = ARGS._.slice();11var output = {12vars: {},13props: {}14};1516if (ARGS.o) try {17output = JSON.parse(fs.readFileSync(ARGS.o, "utf8"));18} catch(ex) {}1920files.forEach(getProps);2122if (ARGS.o) {23fs.writeFileSync(ARGS.o, JSON.stringify(output, null, 2), "utf8");24} else {25console.log("%s", JSON.stringify(output, null, 2));26}2728function getProps(filename) {29var code = fs.readFileSync(filename, "utf8");30var ast = U2.parse(code);3132ast.walk(new U2.TreeWalker(function(node){33if (node instanceof U2.AST_ObjectKeyVal) {34add(node.key);35}36else if (node instanceof U2.AST_ObjectProperty) {37add(node.key.name);38}39else if (node instanceof U2.AST_Dot) {40add(node.property);41}42else if (node instanceof U2.AST_Sub) {43addStrings(node.property);44}45}));4647function addStrings(node) {48var out = {};49try {50(function walk(node){51node.walk(new U2.TreeWalker(function(node){52if (node instanceof U2.AST_Seq) {53walk(node.cdr);54return true;55}56if (node instanceof U2.AST_String) {57add(node.value);58return true;59}60if (node instanceof U2.AST_Conditional) {61walk(node.consequent);62walk(node.alternative);63return true;64}65throw out;66}));67})(node);68} catch(ex) {69if (ex !== out) throw ex;70}71}7273function add(name) {74output.props[name] = true;75}76}777879