diff --git a/src/Statement.js b/src/Statement.js index c6c72f2..d5ec856 100644 --- a/src/Statement.js +++ b/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 ]); diff --git a/test/function/warn-on-eval/_config.js b/test/function/warn-on-eval/_config.js new file mode 100644 index 0000000..2c4dae9 --- /dev/null +++ b/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' ); + } +}; diff --git a/test/function/warn-on-eval/main.js b/test/function/warn-on-eval/main.js new file mode 100644 index 0000000..e6f891c --- /dev/null +++ b/test/function/warn-on-eval/main.js @@ -0,0 +1 @@ +var result = eval( '1 + 1' );