[Pkg-javascript-commits] [node-browser-unpack] 08/40: Permit uglified bundles to be parsed.
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Nov 9 12:27:23 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-browser-unpack.
commit 9b254c32a65a1ad0b25e495477886d5b3ee72d55
Author: Hugh Kennedy <hughskennedy at gmail.com>
Date: Sun Feb 23 01:54:45 2014 +1100
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.
---
index.js | 12 +++++++++---
test/files/uglified.js | 1 +
test/uglified.js | 17 +++++++++++++++++
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/index.js b/index.js
index 57d597f..3cc297d 100644
--- a/index.js
+++ b/index.js
@@ -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;
diff --git a/test/files/uglified.js b/test/files/uglified.js
new file mode 100644
index 0000000..ccab966
--- /dev/null
+++ b/test/files/uglified.js
@@ -0,0 +1 @@
+!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; [...]
\ No newline at end of file
diff --git a/test/uglified.js b/test/uglified.js
new file mode 100644
index 0000000..8a33490
--- /dev/null
+++ b/test/uglified.js
@@ -0,0 +1,17 @@
+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');
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-browser-unpack.git
More information about the Pkg-javascript-commits
mailing list