diff --git a/src/node.cc b/src/node.cc index 853e0aa796ce4e..f1a3493bf1a252 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3816,6 +3816,12 @@ static void ParseArgs(int* argc, } #endif + if (eval_string != nullptr && syntax_check_only) { + fprintf(stderr, + "%s: either --check or --eval can be used, not both\n", argv[0]); + exit(9); + } + // Copy remaining arguments. const unsigned int args_left = nargs - index; memcpy(new_argv + new_argc, argv + index, args_left * sizeof(*argv)); diff --git a/test/parallel/test-cli-syntax.js b/test/parallel/test-cli-syntax.js index 07dd3c4712e751..953e8dbcf60630 100644 --- a/test/parallel/test-cli-syntax.js +++ b/test/parallel/test-cli-syntax.js @@ -99,7 +99,7 @@ syntaxArgs.forEach(function(args) { assert.strictEqual(c.status, 0, 'code === ' + c.status); }); -// should should throw if code piped from stdin with --check has bad syntax +// should throw if code piped from stdin with --check has bad syntax // loop each possible option, `-c` or `--check` syntaxArgs.forEach(function(args) { const stdin = 'var foo bar;'; @@ -117,3 +117,18 @@ syntaxArgs.forEach(function(args) { assert.strictEqual(c.status, 1, 'code === ' + c.status); }); + +// should throw if -c and -e flags are both passed +['-c', '--check'].forEach(function(checkFlag) { + ['-e', '--eval'].forEach(function(evalFlag) { + const args = [checkFlag, evalFlag, 'foo']; + const c = spawnSync(node, args, {encoding: 'utf8'}); + + assert.strictEqual( + c.stderr, + `${node}: either --check or --eval can be used, not both\n` + ); + + assert.strictEqual(c.status, 9, 'code === ' + c.status); + }); +});