[Pkg-javascript-commits] [node-browser-unpack] 10/40: Permit parsing standalone bundles.
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 050bbfa5457fa2301b57545686a522707e90b1a2
Author: Hugh Kennedy <hughskennedy at gmail.com>
Date: Sun Feb 23 23:47:06 2014 +1100
Permit parsing standalone bundles.
Much like when uglifying a bundle, using the --standalone flag
will result in modifying the output AST.
---
index.js | 13 ++++++++
test/files/standalone.js | 81 ++++++++++++++++++++++++++++++++++++++++++++++++
test/standalone.js | 13 ++++++++
3 files changed, 107 insertions(+)
diff --git a/index.js b/index.js
index 3cc297d..b5d5288 100644
--- a/index.js
+++ b/index.js
@@ -13,6 +13,7 @@ module.exports = function (src) {
if (body.type !== 'CallExpression') return;
var args = body.arguments;
+ if (args.length === 1) args = extractStandalone(args) || args;
if (args.length !== 3) return;
if (args[0].type !== 'ObjectExpression') return;
@@ -51,3 +52,15 @@ module.exports = function (src) {
return row;
});
};
+
+function extractStandalone (args) {
+ if (args[0].type !== 'FunctionExpression') return;
+ if (args[0].body.length < 2) return;
+ if (args[0].body.body.length < 2) return;
+
+ args = args[0].body.body[1].argument;
+ if (args.type !== 'CallExpression') return;
+ if (args.callee.type !== 'CallExpression') return;
+
+ return args.callee.arguments;
+};
diff --git a/test/files/standalone.js b/test/files/standalone.js
new file mode 100644
index 0000000..ce5e031
--- /dev/null
+++ b/test/files/standalone.js
@@ -0,0 +1,81 @@
+!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.StandAlone=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[ [...]
+module.exports = function (n) { return n * 111 }
+
+},{}],2:[function(_dereq_,module,exports){
+var foo = _dereq_('./foo.js');
+var gamma = _dereq_('gamma');
+
+console.log(Math.floor(foo(gamma(3.8))));
+
+},{"./foo.js":1,"gamma":3}],3:[function(_dereq_,module,exports){
+// transliterated from the python snippet here:
+// http://en.wikipedia.org/wiki/Lanczos_approximation
+
+var g = 7;
+var p = [
+ 0.99999999999980993,
+ 676.5203681218851,
+ -1259.1392167224028,
+ 771.32342877765313,
+ -176.61502916214059,
+ 12.507343278686905,
+ -0.13857109526572012,
+ 9.9843695780195716e-6,
+ 1.5056327351493116e-7
+];
+
+var g_ln = 607/128;
+var p_ln = [
+ 0.99999999999999709182,
+ 57.156235665862923517,
+ -59.597960355475491248,
+ 14.136097974741747174,
+ -0.49191381609762019978,
+ 0.33994649984811888699e-4,
+ 0.46523628927048575665e-4,
+ -0.98374475304879564677e-4,
+ 0.15808870322491248884e-3,
+ -0.21026444172410488319e-3,
+ 0.21743961811521264320e-3,
+ -0.16431810653676389022e-3,
+ 0.84418223983852743293e-4,
+ -0.26190838401581408670e-4,
+ 0.36899182659531622704e-5
+];
+
+// Spouge approximation (suitable for large arguments)
+function lngamma(z) {
+
+ if(z < 0) return Number('0/0');
+ var x = p_ln[0];
+ for(var i = p_ln.length - 1; i > 0; --i) x += p_ln[i] / (z + i);
+ var t = z + g_ln + 0.5;
+ return .5*Math.log(2*Math.PI)+(z+.5)*Math.log(t)-t+Math.log(x)-Math.log(z);
+}
+
+module.exports = function gamma (z) {
+ if (z < 0.5) {
+ return Math.PI / (Math.sin(Math.PI * z) * gamma(1 - z));
+ }
+ else if(z > 100) return Math.exp(lngamma(z));
+ else {
+ z -= 1;
+ var x = p[0];
+ for (var i = 1; i < g + 2; i++) {
+ x += p[i] / (z + i);
+ }
+ var t = z + g + 0.5;
+
+ return Math.sqrt(2 * Math.PI)
+ * Math.pow(t, z + 0.5)
+ * Math.exp(-t)
+ * x
+ ;
+ }
+};
+
+module.exports.log = lngamma;
+
+},{}]},{},[2])
+(2)
+});
diff --git a/test/standalone.js b/test/standalone.js
new file mode 100644
index 0000000..02decae
--- /dev/null
+++ b/test/standalone.js
@@ -0,0 +1,13 @@
+var test = require('tape');
+var unpack = require('../');
+
+var fs = require('fs');
+var src = fs.readFileSync(__dirname + '/files/standalone.js', 'utf8');
+
+test('standalone', function (t) {
+ t.plan(2);
+ t.doesNotThrow(function() {
+ 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