eslint / espree

An Esprima-compatible JavaScript parser
BSD 2-Clause "Simplified" License
2.26k stars 189 forks source link

SyntaxError: Invalid regular expression: /(?<=A).*?(?=B)/: Invalid group #496

Closed Awen-hub closed 3 years ago

Awen-hub commented 3 years ago

` const espree = require("espree");

console.log(espree.parse("const reg = /(?<=A).*?(?=B)/g", { ecmaVersion: 6 }))`

When I run the code with nodeJS, it throws an error "SyntaxError: Invalid regular expression: /(?<=A).?(?=B)/: Invalid group". However the regular expression "/(?<=A).?(?=B)/g" can be used in Chrome so I think it it not an invalid regular expression.

aladdin-add commented 3 years ago

this is working as expected. to support lookbehind assertions, you need to set ecmaVersion >= 2018

refs: https://github.com/tc39/proposals/blob/master/finished-proposals.md

Awen-hub commented 3 years ago

this is working as expected. to support lookbehind assertions, you need to set ecmaVersion >= 2018

refs: https://github.com/tc39/proposals/blob/master/finished-proposals.md

Thanks very much. I have solved the problem when setting { ecmaVersion: 2020 }.