-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Named capture groups - groups array not correct when using literal expressions #9722
Comments
Hey @kurt-genus! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
What is your Babel config and what is the generated output? |
.babelrc {
"presets": ["@babel/env", "@babel/react"],
"plugins": ["@babel/plugin-proposal-class-properties"]
} The generated output contains more than just this issue, I'll see if I can't get a complete working version. But here is what I think is the relevant portion : var regex1 = _wrapRegExp(/(\w+):(\d+)/, {
alpha: 1,
bravo: 2
});
var regex2 = _wrapRegExp(/(\w+):([a-z]+):(\w+)/, {
alpha: 1,
bravo: 2,
charlie: 3
});
var foo = 'foo:abc:bar';
var result;
if (result = regex1.exec(foo)) {
console.log(result);
} else if (result = regex2.exec(foo)) {
console.log(result);
} |
Bug Report
Current Behavior
If I have mutliple literal regex's, it seems to interfere with the groups array on the exec results.
Input Code
Expected behavior/code
If you look at the code above, what I expect in the log is for the groups array to contain an entry for "charlie" because that is the expression which matched. However, this is what I see instead:
(4) ["foo:abc:bar", "foo", "abc", "bar", index: 0, input: "foo:abc:bar", groups: {…}]
0: "foo:abc:bar"
1: "foo"
2: "abc"
3: "bar"
groups: {alpha: "foo", bravo: "abc"}
index: 0
input: "foo:abc:bar"
length: 4
proto: Array(0)
result.groups.charlie is undefined even though result[3] is set to "bar".
Babel Configuration (.babelrc, package.json, cli command)
Environment
cli
,register
,loader
]Possible Solution
Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.
The text was updated successfully, but these errors were encountered: