-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for unicode regexes - closes #11
- Loading branch information
Showing
6 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ It's as easy as: | |
- [Rest parameters](FEATURES.md#rest-parameters) | ||
- [Spread](FEATURES.md#spread) | ||
- [Template literals](FEATURES.md#template-literals) | ||
- [Unicode Regex](FEATURES.md#unicode-regex) | ||
|
||
To be implemented: | ||
|
||
|
@@ -243,6 +244,7 @@ limitations in ES5 implementations. | |
| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | ||
| Spread | ✓ | ✓ | ✓ | ✓ | ✓ | | | ||
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | ||
| Unicode regex | ✓ | ✓ | | ✓ | ✓ | | | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
zenparsing
Contributor
|
||
|
||
#### Performance | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var regexpu = require("regexpu"); | ||
var b = require("ast-types").builders; | ||
var _ = require("lodash"); | ||
|
||
exports.Literal = function (node) { | ||
var regex = node.regex; | ||
if (!regex) return; | ||
|
||
var flags = regex.flags.split("") | ||
if (!_.contains(regex.flags, "u")) return; | ||
_.pull(flags, "u"); | ||
|
||
var pattern = regexpu.rewritePattern(regex.pattern, regex.flags); | ||
return b.literal(new RegExp(pattern, flags.join(""))); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
var string = 'foo💩bar'; | ||
var match = string.match(/foo(.)bar/u); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
var string = 'foo\uD83D\uDCA9bar'; | ||
var match = string.match(/foo((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uDC00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF]))bar/); |
Does es6now really support this? It doesn’t seem to:
cc @zenparsing