Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(823)

Unified Diff: node_modules/vulcanize/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js

Issue 800513006: Added vulcanize under third_party/npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: node_modules/vulcanize/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
diff --git a/node_modules/vulcanize/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js b/node_modules/vulcanize/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..2cea629e69daf240cb210a14a046e660b3552be4
--- /dev/null
+++ b/node_modules/vulcanize/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
@@ -0,0 +1,49 @@
+'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;
+}

Powered by Google App Engine
This is Rietveld 408576698