Skip to content

Commit

Permalink
chore: show enhanced syntax error for all syntax errors (#10749)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 4, 2020
1 parent 3a8eeb9 commit abaa556
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749))

### Chore & Maintenance

### Performance
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts
Expand Up @@ -23,8 +23,6 @@ export default function handlePotentialSyntaxError(
if (
// `instanceof` might come from the wrong context
e.name === 'SyntaxError' &&
(e.message.includes('Unexpected token') ||
e.message.includes('Cannot use import')) &&
!e.message.includes(' expected')
) {
throw enhanceUnexpectedTokenMessage(e);
Expand All @@ -37,9 +35,11 @@ export function enhanceUnexpectedTokenMessage(e: Error): Error {
e.stack =
`${chalk.bold.red('Jest encountered an unexpected token')}
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
${DOT}If you are trying to use ECMAScript Modules, see ${chalk.underline(
Expand Down

0 comments on commit abaa556

Please sign in to comment.