insert-module-globals
Advanced tools
Comparing version 7.2.0 to 7.2.1
13
index.js
@@ -157,6 +157,9 @@ var undeclaredIdentifiers = require('undeclared-identifiers'); | ||
var wrappedSource; | ||
// we double-wrap the source in IIFEs to prevent code like | ||
// (function(Buffer){ const Buffer = null }()) | ||
// which causes a parse error. | ||
var wrappedSource = '(function (){\n' + src + '\n}).call(this)'; | ||
if (keys.length <= 3) { | ||
wrappedSource = '(function (' + keys.join(',') + '){\n' | ||
+ src + '\n}).call(this,' + values.join(',') + ')' | ||
wrappedSource = '(function (' + keys.join(',') + '){' | ||
+ wrappedSource + '}).call(this,' + values.join(',') + ')' | ||
; | ||
@@ -173,4 +176,4 @@ } | ||
); | ||
wrappedSource = '(function (' + names.join(',') + '){\n' | ||
+ src + '\n}).call(this,' + values.join(',') + ')'; | ||
wrappedSource = '(function (' + names.join(',') + '){' | ||
+ wrappedSource + '}).call(this,' + values.join(',') + ')'; | ||
} | ||
@@ -177,0 +180,0 @@ |
{ | ||
"name": "insert-module-globals", | ||
"version": "7.2.0", | ||
"version": "7.2.1", | ||
"description": "insert implicit module globals into a module-deps stream", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -104,2 +104,30 @@ var test = require('tape') | ||
test('inserted names do not cause const name collisions', function (t) { | ||
t.plan(1); | ||
var s = mdeps({ | ||
modules: { | ||
buffer: require.resolve('buffer/'), | ||
timers: require.resolve('timers-browserify') | ||
} | ||
}); | ||
s.on('error', t.fail); | ||
s.pipe(bpack({ raw: true })).pipe(concat(function (src) { | ||
var c = { | ||
t: t, | ||
Buffer: 'sandbox Buffer' | ||
}; | ||
vm.runInNewContext(src, c); | ||
})); | ||
s.write({ | ||
transform: inserter({ | ||
always: true, | ||
vars: { | ||
Buffer: function() { return '"sandbox Buffer"' } | ||
} | ||
}), | ||
global: true | ||
}); | ||
s.end(__dirname + '/always/collision.js'); | ||
}); | ||
function inserter (opts) { | ||
@@ -106,0 +134,0 @@ return function (file) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33633
45
776