Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove eval usage. Fixes CSP cases. #1133

Merged
merged 3 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/builtins/hmr-runtime.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var OVERLAY_ID = '__parcel__error__overlay__';

var global = (1, eval)('this');
var OldModule = module.bundle.Module;

function Module(moduleName) {
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/prelude.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ parcelRequire = (function (modules, cache, entry) {

var module = cache[name] = new newRequire.Module(name);

modules[name][0].call(module.exports, localRequire, module, module.exports);
modules[name][0].call(module.exports, localRequire, module, module.exports, this);
}

return cache[name].exports;
Expand Down
2 changes: 1 addition & 1 deletion src/visitors/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const VARS = {
asset.addDependency('process');
return 'var process = require("process");';
},
global: () => 'var global = (1,eval)("this");',
global: () => 'var global = arguments[3];',
__dirname: asset =>
`var __dirname = ${JSON.stringify(Path.dirname(asset.name))};`,
__filename: asset => `var __filename = ${JSON.stringify(asset.name)};`,
Expand Down
4 changes: 4 additions & 0 deletions test/integration/global-redeclare/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const global = {};
module.exports = function () {
return !!global.document;
};
5 changes: 5 additions & 0 deletions test/integration/global-redeclare/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "parcel-test-global-redeclare",
"private": true,
"browserslist": ["last 2 Chrome versions"]
}
7 changes: 7 additions & 0 deletions test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ describe('javascript', function() {
});
});

it('should handle re-declaration of the global constant', async function() {
let b = await bundle(__dirname + '/integration/global-redeclare/index.js');

let output = run(b);
assert.deepEqual(output(), false);
});

it('should insert environment variables', async function() {
let b = await bundle(__dirname + '/integration/env/index.js');

Expand Down