Sha256: 663288bdb2fdb43f8a8c2dc35fb4c484a68bf0a8e2a632827a0df85afec4e1bb

Contents?: true

Size: 1.37 KB

Versions: 12

Compression:

Stored size: 1.37 KB

Contents

#!/usr/bin/env node

var fs = require("fs")

var acornSrc = fs.readFileSync(require.resolve("../dist/acorn"), "utf8")
var acorn = require("../dist/acorn"), walk = require("../dist/walk")

var ast = acorn.parse(acornSrc)
var touchups = [], uses = []

var makePred

walk.simple(ast, {
  FunctionDeclaration: function(node) {
    if (node.id.name == "makePredicate") {
      makePred = node
      touchups.push({text: "// Removed to create an eval-free library", from: node.start, to: node.end})
    }
  },
  ObjectExpression: function(node) {
    node.properties.forEach(function(prop) {
      if (prop.value.type == "CallExpression" &&
          prop.value.callee.name == "makePredicate")
        uses.push(prop.value)
    })
  }
})

var results = []
var dryRun = acornSrc.slice(0, makePred.end) + "; makePredicate = (function(mp) {" +
    "return function(words) { var r = mp(words); predicates.push(r); return r }})(makePredicate);" +
    acornSrc.slice(makePred.end)
;(new Function("predicates", dryRun))(results)

uses.forEach(function (node, i) {
  touchups.push({text: results[i].toString(), from: node.start, to: node.end})
})

var result = "", pos = 0
touchups.sort(function(a, b) { return a.from - b.from })
touchups.forEach(function(touchup) {
  result += acornSrc.slice(pos, touchup.from)
  result += touchup.text
  pos = touchup.to
})
result += acornSrc.slice(pos)

process.stdout.write(result)

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/acorn/bin/without_eval
minimum_viable_product-0.0.11 test/dummy/node_modules/acorn/bin/without_eval
brwy_rails-0.0.6 test/dummy/node_modules/acorn/bin/without_eval
brwy_rails-0.0.5 test/dummy/node_modules/acorn/bin/without_eval
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/acorn/bin/without_eval
brwy_rails-0.0.4 test/dummy/node_modules/acorn/bin/without_eval
brwy_rails-0.0.3 test/dummy/node_modules/acorn/bin/without_eval
brwy_rails-0.0.2 test/dummy/node_modules/acorn/bin/without_eval
brwy_rails-0.0.1 test/dummy/node_modules/acorn/bin/without_eval
gulp_assets-1.0.0.pre.5 template/node_modules/babel-core/node_modules/acorn-jsx/node_modules/acorn/bin/without_eval
gulp_assets-1.0.0.pre.4 template/node_modules/babel-core/node_modules/acorn-jsx/node_modules/acorn/bin/without_eval
gulp_assets-1.0.0.pre.3 template/node_modules/babel-core/node_modules/acorn-jsx/node_modules/acorn/bin/without_eval