Skip to content

Commit abaa556

Browse files
authored
chore: show enhanced syntax error for all syntax errors (#10749)
1 parent 3a8eeb9 commit abaa556

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Fixes
66

7+
- `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749))
8+
79
### Chore & Maintenance
810

911
### Performance

packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ export default function handlePotentialSyntaxError(
2323
if (
2424
// `instanceof` might come from the wrong context
2525
e.name === 'SyntaxError' &&
26-
(e.message.includes('Unexpected token') ||
27-
e.message.includes('Cannot use import')) &&
2826
!e.message.includes(' expected')
2927
) {
3028
throw enhanceUnexpectedTokenMessage(e);
@@ -37,9 +35,11 @@ export function enhanceUnexpectedTokenMessage(e: Error): Error {
3735
e.stack =
3836
`${chalk.bold.red('Jest encountered an unexpected token')}
3937
40-
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
38+
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.
4139
42-
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
40+
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
41+
42+
By default "node_modules" folder is ignored by transformers.
4343
4444
Here's what you can do:
4545
${DOT}If you are trying to use ECMAScript Modules, see ${chalk.underline(

0 commit comments

Comments
 (0)