Skip to content
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

downlevel regexp named capture groups #31241

Closed
5 tasks done
jaredh159 opened this issue May 3, 2019 · 3 comments
Closed
5 tasks done

downlevel regexp named capture groups #31241

jaredh159 opened this issue May 3, 2019 · 3 comments

Comments

@jaredh159
Copy link

Search Terms

"named capture"
regexp named capture groups

Suggestion

Regexp named capture groups have been added to the ECMA spec. It would be great if typescript could compile these down based on the desired target. Babel already has a plugin to do so:

babel/proposals#35
babel/babel#9345
tc39/ecma262#1027

Use Cases

Writing next-level javascript regular expressions! 😎

And because it's a great feature for readable, maintainable code, and is in the spec.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@jaredh159
Copy link
Author

Argh, my bad. It looks like you already do this. I had an error I thought was failure to downlevel these named capture groups, but I was wrong. Sorry! 😬

@cascornelissen
Copy link

@jaredh159, do you, by any chance, remember what issue caused this for you back then?

I'm working on a project which has es2018 in the compilerOptions.libs array in tsconfig.js and es5 as compilerOptions.target but the compiled files still contain named capture groups.

This is an example of the regex that shows this issue:

/^(?<name>[A-Za-z]+)/

@jaredh159
Copy link
Author

@cascornelissen I can't remember, honestly, sorry. I know I was used named capture groups and was getting an error in Safari I think, so I assumed they weren't being transpiled, but I jumped the gun and I had some mostly unrelated other problem that just happened to crop up at the same time that I started using named capture groups, IIRC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants