From e282c426407f2df9fece05bffc6b98c6ec64ea3f Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Thu, 6 Oct 2016 12:15:44 +0200 Subject: [PATCH] (#610): Fix crash when calling require() with a number --- src/core/staticRequire.js | 3 ++- tests/src/rules/no-extraneous-dependencies.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/staticRequire.js b/src/core/staticRequire.js index c13c4b066..45ed79d79 100644 --- a/src/core/staticRequire.js +++ b/src/core/staticRequire.js @@ -5,5 +5,6 @@ export default function isStaticRequire(node) { node.callee.type === 'Identifier' && node.callee.name === 'require' && node.arguments.length === 1 && - node.arguments[0].type === 'Literal' + node.arguments[0].type === 'Literal' && + typeof node.arguments[0].value === 'string' } diff --git a/tests/src/rules/no-extraneous-dependencies.js b/tests/src/rules/no-extraneous-dependencies.js index 4d739ee71..1a743b545 100644 --- a/tests/src/rules/no-extraneous-dependencies.js +++ b/tests/src/rules/no-extraneous-dependencies.js @@ -45,6 +45,7 @@ ruleTester.run('no-extraneous-dependencies', rule, { options: [{devDependencies: ['*.test.js', '*.spec.js']}], filename: 'foo.spec.js', }), + test({ code: 'require(6)' }), ], invalid: [ test({