-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: represent regular expressions as a
Regex
node
BREAKING CHANGE: Previously, regular expressions were represented as `Identifier` nodes, which hasn't been a problem for decaffeinate because all we wanted to do was pass them through anyway. Now, however, we want to do some processing on them and so need to identify them separately. Not to mention the fact that they are not identifiers!
- Loading branch information
1 parent
362a790
commit ddabbca
Showing
5 changed files
with
83 additions
and
1 deletion.
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
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,8 @@ | ||
import { parse } from 'babylon'; | ||
|
||
/** | ||
* Parses JavaScript source representing a regular expression. | ||
*/ | ||
export default function parseRegExp(string: string): { pattern: string, flags: string } { | ||
return parse(`(${string})`).program.body[0].expression; | ||
} |
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 @@ | ||
/a/ |
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,43 @@ | ||
{ | ||
"type": "Program", | ||
"line": 1, | ||
"column": 1, | ||
"range": [ | ||
0, | ||
4 | ||
], | ||
"raw": "/a/\n", | ||
"body": { | ||
"type": "Block", | ||
"line": 1, | ||
"column": 1, | ||
"range": [ | ||
0, | ||
3 | ||
], | ||
"statements": [ | ||
{ | ||
"type": "Regex", | ||
"line": 1, | ||
"column": 1, | ||
"range": [ | ||
0, | ||
3 | ||
], | ||
"raw": "/a/", | ||
"pattern": "a", | ||
"flags": { | ||
"global": false, | ||
"ignoreCase": false, | ||
"multiline": false, | ||
"sticky": false, | ||
"g": false, | ||
"i": false, | ||
"m": false, | ||
"y": false | ||
} | ||
} | ||
], | ||
"raw": "/a/" | ||
} | ||
} |