SyntaxError: Expected atom at position 2 \p{Script_Ex
See original GitHub issueBug Report
Current Behavior
> babel . --out-dir dist
SyntaxError: Expected atom at position 2
\p{Script_Ex
^
at bail (/home/shm/dpp-query-ws/node_modules/regjsparser/parser.js:1093:13)
at parseTerm (/home/shm/dpp-query-ws/node_modules/regjsparser/parser.js:486:9)
at parseAlternative (/home/shm/dpp-query-ws/node_modules/regjsparser/parser.js:457:21)
at parseDisjunction (/home/shm/dpp-query-ws/node_modules/regjsparser/parser.js:437:16)
at parse (/home/shm/dpp-query-ws/node_modules/regjsparser/parser.js:1108:18)
at rewritePattern (/home/shm/dpp-query-ws/node_modules/regexpu-core/rewrite-pattern.js:324:15)
at PluginPass.RegExpLiteral (/home/shm/dpp-query-ws/node_modules/@babel/plugin-transform-unicode-regex/lib/index.js:50:51)
at newFn (/home/shm/dpp-query-ws/node_modules/@babel/traverse/lib/visitors.js:193:21)
at NodePath._call (/home/shm/dpp-query-ws/node_modules/@babel/traverse/lib/path/context.js:53:20)
at NodePath.call (/home/shm/dpp-query-ws/node_modules/@babel/traverse/lib/path/context.js:40:17)
Input Code
- REPL or Repo link if applicable:
var your => (code) => here;
Expected behavior/code Successful transpiled code
Babel Configuration (.babelrc, package.json, cli command) package.json
"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/node": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-flow": "^7.0.0",
"nodemon": "^1.18.4"
}
babel.config.js
module.exports = {
"presets": ["@babel/preset-env","@babel/preset-flow"],
"plugins": [
"@babel/plugin-proposal-object-rest-spread"
]
}
Environment
- Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34]
- Node/npm version: Node 8.12.0/npm 6.4.1
- OS: Ubuntu 16.04.4 LTS
- Monorepo
- How you are using Babel: [e.g.
cli
,register
,loader
] cli"build": "babel . --out-dir dist"
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Mathias Bynens on Twitter: "@FakeUnicode @AKermodeBear ...
SyntaxError: Expected atom at position 2 \p{Script_Ex · Issue #8951 · babel/babel. Bug Report Current Behavior > babel .
Read more >Facing Expected atom at position error in regular expression
Expected atom at position 37 A-Za-z]*\p{L}. I tried using npm install --save-dev @babel/plugin-proposal-unicode-property-regex and
Read more >Facing Expected atom at position error in regular expression ...
Coding example for the question Facing Expected atom at position error in regular expression-babel.js.
Read more >Angular 13: running Storybook 6.4 fails with ModuleBuildError
I use Storybook with Compodoc and have Eslint for TypeScript in place. ... /Users/xxx/node_modules/prettier/standalone.js: Expected atom at position 0 ERR!
Read more >CoffeeScript
Major new features in CoffeeScript 2 include async functions and JSX. ... and a .babelrc file (or other equivalent) in place, you can...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So I’ve managed to narrow this down. I’m not certain what the “real” fix for it is, but I have some ideas, (and a workaround that is working for me )…
TL;DR - Workaround:
When it fails for me there are two unicode regex related plugins that have been enabled by preset-env:
transform-unicode-regex
andproposal-unicode-property-regex
. They are both doing effectively the exact same thing, usingrewritePattern
fromregexpu-core
to transform the regex into an equivalent ES5 regex.However, only proposal-unicode-property-regex is passing the option
unicodePropertyEscape: true
when it callsrewritePattern
, transform-unicode-regex is not, which causes regjsparser to choke on\p{...}
and\P{...}
patterns.Unfortunately I don’t understand the Babel internals well enough to determine:
\p
/\P
and the other doesn’t.proposal-unicode-property-regex
were applied first, since it would transform the problematic escapes into something thattransform-unicode-regex
wouldn’t have issues with.If it helps, here is my
preset-env
debug output:Just enabling the
preset-es2015
causes it… Try checking/unchecking the box in https://babeljs.io/repl/build/master#?babili=false&browsers=Safari >%3D 8&build=&builtIns=false&spec=false&loose=false&code_lz=EQMwlgNgpgcghgWysAdAJygBwnAxlACgHoCAdTAbwBkIBfASjMqoFcGiWBzAGgAIByACQBGXoIBM_ekA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=true&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015&prettier=false&targets=&version=7.3.4