Sha256: 75c5627ecca2275accc40cc7947e1d217b17fac130543e61f22e30bbe59ffdc9

Contents?: true

Size: 1.61 KB

Versions: 62

Compression:

Stored size: 1.61 KB

Contents

'use strict'

var fs = require('fs')
var PassThrough = require('stream').PassThrough
var Transform = require('stream').Transform

if (typeof Transform === 'undefined') {
  throw new Error('UglifyJS only supports browserify when using node >= 0.10.x')
}

var cache = {}
module.exports = transform
function transform(file) {
  if (!/tools\/node\.js$/.test(file.replace(/\\/g,'/'))) return new PassThrough();
  if (cache[file]) return makeStream(cache[file])
  var uglify = require(file)
  var src = 'var sys = require("util");\nvar MOZ_SourceMap = require("source-map");\nvar UglifyJS = exports;\n' + uglify.FILES.map(function (path) { return fs.readFileSync(path, 'utf8') }).join('\n')

  var ast = uglify.parse(src)
  ast.figure_out_scope()

  var variables = ast.variables
    .map(function (node, name) {
      return name
    })

  src += '\n\n' + variables.map(function (v) { return 'exports.' + v + ' = ' + v + ';' }).join('\n') + '\n\n'

  src += 'exports.AST_Node.warn_function = function (txt) { if (typeof console != "undefined" && typeof console.warn === "function") console.warn(txt) }\n\n'

  src += 'exports.minify = ' + uglify.minify.toString() + ';\n\n'
  src += 'exports.describe_ast = ' + uglify.describe_ast.toString() + ';'

  // TODO: remove once https://github.com/substack/node-browserify/issues/631 is resolved
  src = src.replace(/"for"/g, '"fo" + "r"')

  cache[file] = src
  return makeStream(src);
}

function makeStream(src) {
  var res = new Transform();
  res._transform = function (chunk, encoding, callback) { callback() }
  res._flush = function (callback) {
    res.push(src)
    callback()
  }
  return res;
}

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
smock-0.1.268 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.267 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.266 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.265 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.264 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.263 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.262 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.261 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.260 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.259 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.258 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.256 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.255 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.254 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.253 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.252 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.251 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.250 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.249 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
smock-0.1.247 node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js