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

Add support for the /u flag (RegExp.prototype.unicode) #9

Closed
mathiasbynens opened this issue Nov 13, 2013 · 6 comments
Closed

Add support for the /u flag (RegExp.prototype.unicode) #9

mathiasbynens opened this issue Nov 13, 2013 · 6 comments
Labels

Comments

@mathiasbynens
Copy link
Collaborator

https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-regexp.prototype.unicode

Contrary to #8, this does affect parsing; based on whether or not the u flag was set, different parsing logic applies.

@mathiasbynens
Copy link
Collaborator Author

Note: the current support for Unicode code point escapes should only be enabled when the u flag is set, as per the spec.

@mathiasbynens
Copy link
Collaborator Author

Bug: regjsparser.parse('\uD834\uDF06', 'u') says type: escape but it should be type: character.

@jviereck
Copy link
Owner

Just tried with the current version and now get this output:

{
    "type": "alternative",
    "body": [
        {
            "type": "value",
            "kind": "unicode",
            "codePoint": 119558,
            "range": [
                0,
                12
            ],
            "raw": "\\uD834\\uDF06"
        }
    ],
    "range": [
        0,
        12
    ],
    "raw": "\\uD834\\uDF06",
    "lastMatchIdx": 0
}

Therefore, closing this issue.

@mathiasbynens
Copy link
Collaborator Author

"kind": "unicode"

Wait, what? I thought we renamed that?

@jviereck
Copy link
Owner

You are right, I and it is renamed - I was not on the master branch when testing this. From master, the output looks (correctly) like this:

{
    "type": "alternative",
    "body": [
        {
            "type": "value",
            "kind": "unicodeCodePointEscape",
            "codePoint": 119558,
            "range": [
                0,
                12
            ],
            "raw": "\\uD834\\uDF06"
        }
    ],
    "range": [
        0,
        12
    ],
    "raw": "\\uD834\\uDF06",
    "lastMatchIdx": 0
}

@mathiasbynens
Copy link
Collaborator Author

Your example still says it’s an escape sequence (because the CLI is used and it considers the \ as a string containing a slash, i.e. \\) but you’re right in that the output is now correct in this case:

> regjsparser.parse('\uD834\uDF06', 'u')
{ type: 'alternative',
  body:
   [ { type: 'value',
       kind: 'symbol',
       codePoint: 119558,
       range: [Object],
       raw: '\uD834\uDF06' } ],
  range: [ 0, 2 ],
  raw: '\uD834\uDF06',
  lastMatchIdx: 0 }

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

No branches or pull requests

2 participants