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

Standardize new RegExp literal AST format #27

Closed
mathiasbynens opened this issue Feb 16, 2015 · 3 comments · Fixed by #29
Closed

Standardize new RegExp literal AST format #27

mathiasbynens opened this issue Feb 16, 2015 · 3 comments · Fixed by #29

Comments

@mathiasbynens
Copy link

In Esprima, /foo/gi now gives:

{
  type: "Literal",
  value: /foo/gi,
  regex: {
    pattern: "foo",
    flags: "gi"
  }
}

The advantage of having the separate regex property is that even in environments that don’t support a given flag (e.g. the u flag) the regex can still be represented in the AST. The value property is null in such a case.

See https://code.google.com/p/esprima/issues/detail?id=557#c4.

cc @sebmck @michaelficarra

@Constellation
Copy link
Contributor

And this style can be represented as JSON.

@sebmck
Copy link

sebmck commented Feb 16, 2015

This is also the behaviour of Acorn (acornjs/acorn@f48503c).

@nzakas
Copy link
Contributor

nzakas commented Feb 18, 2015

Espree does the same

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

Successfully merging a pull request may close this issue.

4 participants