Browse Source

warn on eval

better-aggressive
Rich-Harris 9 years ago
parent
commit
13d5c3ceec
  1. 5
      src/Statement.js
  2. 17
      test/function/warn-on-eval/_config.js
  3. 1
      test/function/warn-on-eval/main.js

5
src/Statement.js

@ -95,6 +95,11 @@ export default class Statement {
walk( this.node, {
enter ( node, parent ) {
// warn about eval
if ( node.type === 'CallExpression' && node.callee.name === 'eval' && !scope.contains( 'eval' ) ) {
module.bundle.onwarn( `Use of \`eval\` (in ${module.id}) is discouraged, as it may cause issues with minification. See https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval for more details` );
}
if ( node.type === 'TemplateElement' ) stringLiteralRanges.push([ node.start, node.end ]);
if ( node.type === 'Literal' && typeof node.value === 'string' && /\n/.test( node.raw ) ) {
stringLiteralRanges.push([ node.start + 1, node.end - 1 ]);

17
test/function/warn-on-eval/_config.js

@ -0,0 +1,17 @@
var path = require( 'path' );
var assert = require( 'assert' );
var warned = false;
module.exports = {
description: 'warns about use of eval',
options: {
onwarn: function ( message ) {
warned = true;
assert.equal( message, 'Use of `eval` (in ' + path.resolve( __dirname, 'main.js' ) + ') is discouraged, as it may cause issues with minification. See https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval for more details' );
}
},
exports: function () {
assert.ok( warned, 'did not warn' );
}
};

1
test/function/warn-on-eval/main.js

@ -0,0 +1 @@
var result = eval( '1 + 1' );
Loading…
Cancel
Save