The JavaScript lexer in Babel is far from perfect, unfortunately...
If you feel like trying to hack at the lexer to fix this, by all means please do!
It might be a good idea for a future version to use e.g. https://github.com/Kronuz/esprima-python when it's available (i.e. an optional dependency) for more robust parsing.
I don't see how to fix this. The tokenizer can't possibly tell if /> is the start of a regexp or the end of a JSX tag, they are the same tokens. The Javascript grammar is too ambiguous for this to be decided at the tokenizer level.
A parser would be able to tell if it's currently in a JSX tag or not and resolve the ambiguity, but there is no such parsing being done in Babel. Simply keeping track of JSX open/close tokens wouldn't be enough because regexps can appear inside JSX tags (<hr class={ /\w+/.exec(var)[0] }/>).
Activity
Work around Babel bug
akx commented on May 27, 2019
The JavaScript lexer in Babel is far from perfect, unfortunately...
If you feel like trying to hack at the lexer to fix this, by all means please do!
It might be a good idea for a future version to use e.g. https://github.com/Kronuz/esprima-python when it's available (i.e. an optional dependency) for more robust parsing.
remram44 commented on May 29, 2019
Thanks, I might take a look. I am low on time unfortunately right now.
For reference, lexer is jslexer.py
remram44 commented on Jun 15, 2019
Seems that /> gets recognized as a JSX tag.
remram44 commented on Jun 15, 2019
I don't see how to fix this. The tokenizer can't possibly tell if /> is the start of a regexp or the end of a JSX tag, they are the same tokens. The Javascript grammar is too ambiguous for this to be decided at the tokenizer level.
A parser would be able to tell if it's currently in a JSX tag or not and resolve the ambiguity, but there is no such parsing being done in Babel. Simply keeping track of JSX open/close tokens wouldn't be enough because regexps can appear inside JSX tags (<hr class={ /\w+/.exec(var)[0] }/>).
I think I'll have to leave that alone, sorry!
Wrote a test:Work around Babel bug
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex
[FIX] xml: escape chars in regex