diff --git a/packages/babel-cli/src/babel/index.js b/packages/babel-cli/src/babel/index.js index 004527d965..6d80942134 100755 --- a/packages/babel-cli/src/babel/index.js +++ b/packages/babel-cli/src/babel/index.js @@ -221,6 +221,17 @@ if (commander.deleteDirOnStart && !commander.outDir) { errors.push("--delete-dir-on-start requires --out-dir"); } +if ( + !commander.outDir && + filenames.length === 0 && + typeof commander.filename !== "string" && + commander.babelrc !== false +) { + errors.push( + "stdin compilation requires either -f/--filename [filename] or --no-babelrc", + ); +} + if (errors.length) { console.error(errors.join(". ")); process.exit(2); diff --git a/packages/babel-cli/test/fixtures/babel/--config-file babelrc nocomment/options.json b/packages/babel-cli/test/fixtures/babel/--config-file babelrc nocomment/options.json index 40288838f2..a5d9f81b47 100644 --- a/packages/babel-cli/test/fixtures/babel/--config-file babelrc nocomment/options.json +++ b/packages/babel-cli/test/fixtures/babel/--config-file babelrc nocomment/options.json @@ -1,3 +1,3 @@ { - "args": ["--config-file", "../.othername_babelrc"] -} \ No newline at end of file + "args": ["--config-file", "../.othername_babelrc", "-f", "file.js"] +} diff --git a/packages/babel-cli/test/fixtures/babel/stdin --out-file/options.json b/packages/babel-cli/test/fixtures/babel/stdin --out-file/options.json index 5c5b1a4baa..7c157aa203 100644 --- a/packages/babel-cli/test/fixtures/babel/stdin --out-file/options.json +++ b/packages/babel-cli/test/fixtures/babel/stdin --out-file/options.json @@ -1,3 +1,3 @@ { - "args": ["--out-file", "script.js"] + "args": ["--out-file", "script.js", "-f", "file.js"] } diff --git a/packages/babel-cli/test/fixtures/babel/stdin/options.json b/packages/babel-cli/test/fixtures/babel/stdin/options.json new file mode 100644 index 0000000000..a9f1532c71 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/stdin/options.json @@ -0,0 +1,3 @@ +{ + "args": ["-f", "file.js"] +}