Commit 9b254c32 authored by Hugh Kennedy's avatar Hugh Kennedy Committed by James Halliday

Permit uglified bundles to be parsed.

uglify-js prefixes a bundle's IIFE with a not (!) operator to
save space, which alters the AST in a way that browser-pack
could not previously accomodate.

Perhaps outside of the scope of browser-unpack, but a common
use case none the less.
parent 85dcf98a
......@@ -4,9 +4,15 @@ module.exports = function (src) {
var ast = parse(src, { range: true });
if (ast.body.length !== 1) return;
if (ast.body[0].type !== 'ExpressionStatement') return;
if (ast.body[0].expression.type !== 'CallExpression') return;
var args = ast.body[0].expression.arguments;
if (ast.body[0].expression.type === 'UnaryExpression') {
var body = ast.body[0].expression.argument;
} else {
var body = ast.body[0].expression;
}
if (body.type !== 'CallExpression') return;
var args = body.arguments;
if (args.length !== 3) return;
if (args[0].type !== 'ObjectExpression') return;
......
!function r(t,e,o){function n(u,f){if(!e[u]){if(!t[u]){var i="function"==typeof require&&require;if(!f&&i)return i(u,!0);if(a)return a(u,!0);throw new Error("Cannot find module '"+u+"'")}var h=e[u]={exports:{}};t[u][0].call(h.exports,function(r){var e=t[u][1][r];return n(e?e:r)},h,h.exports,r,t,e,o)}return e[u].exports}for(var a="function"==typeof require&&require,u=0;u<o.length;u++)n(o[u]);return n}({1:[function(r,t){function e(r){if(0>r)return Number("0/0");for(var t=u[0],e=u.length-1;e>0;--e)t+=u[e]/(r+e);var o=r+a+.5;return.5*Math.log(2*Math.PI)+(r+.5)*Math.log(o)-o+Math.log(t)-Math.log(r)}var o=7,n=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7],a=607/128,u=[.9999999999999971,57.15623566586292,-59.59796035547549,14.136097974741746,-.4919138160976202,3399464998481189e-20,4652362892704858e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.00021743961811521265,-.0001643181065367639,8441822398385275e-20,-26190838401581408e-21,36899182659531625e-22];t.exports=function f(r){if(.5>r)return Math.PI/(Math.sin(Math.PI*r)*f(1-r));if(r>100)return Math.exp(e(r));r-=1;for(var t=n[0],a=1;o+2>a;a++)t+=n[a]/(r+a);var u=r+o+.5;return Math.sqrt(2*Math.PI)*Math.pow(u,r+.5)*Math.exp(-u)*t},t.exports.log=e},{}],2:[function(r,t){t.exports=function(r){return 111*r}},{}],3:[function(r){var t=r("./foo.js"),e=r("gamma");console.log(Math.floor(t(e(3.8))))},{"./foo.js":2,gamma:1}]},{},[3]);
\ No newline at end of file
var test = require('tape');
var unpack = require('../');
var pack = require('browser-pack');
var concat = require('concat-stream');
var vm = require('vm');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/uglified.js', 'utf8');
test('uglified', function (t) {
t.plan(2);
t.doesNotThrow(function() {
var p = pack({ raw: true });
var rows = unpack(src);
t.equal(rows.length, 3, 'should unpack 3 rows');
}, 'should not throw');
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment