Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd property "original" to RegExp since property "source" is not clearly specified #577
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
May 19, 2016
Contributor
(1) ECMAScript to specify a new property
originalthat would return the original string given tonew RegExp(). That way,sourcecan keep returning whatever it wants to, which, currently, is an arbitrarily formatted string, provided that it behaves the same way as the original string when given tonew RegExp(), andoriginalwould return the string originally given tonew RegExp().
See https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#feature-requests
(2)
sourcecould revert to the older v8 behavior, be specified to return the original string as given onew RegExp(), and a newcanonicalproperty could be added that clearly specifies how aRegExpshould be formatted in a standard way.
The change of behaviour of RegExp('/test').source in v8 was needed in order to conform to the spec since ES6 ES5. In previous versions, it was less tightly specified. See RegExp.prototype.source last step and EscapeRegExpPattern step 2.
See https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#feature-requests
The change of behaviour of |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
May 19, 2016
Contributor
in order to conform to the spec since ES6
In fact, that behaviour (escaping /) was already required in ES5.1.
In fact, that behaviour (escaping |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bterlson
Sep 12, 2016
Member
Closing this. If there's still an issue here please see CONTRIBUTING.md.
|
Closing this. If there's still an issue here please see CONTRIBUTING.md. |
matthewadams commentedMay 19, 2016
The output of
RegExp.sourcechanged on us.When node@0.12.14 with v8@3.28.71.19 upgraded to node@4.0.0 with v8@4.5.103.30, the output of
RegExp.sourcechanged. The data below from my tests show it clearly, which usesnew RegExp('/test').source.Beginning with node@4.0.0/v8@4.5.103.30,
RegExp.sourcenow escapes forward slashes, which broke one of our scripts. With this change, there is no way to get the original stringsgiven innew RegExp(s). This strikes me as a deficiency, for which I have two suggestions.(1) ECMAScript to specify a new property
originalthat would return the original string given tonew RegExp(). That way,sourcecan keep returning whatever it wants to, which, currently, is an arbitrarily formatted string, provided that it behaves the same way as the original string when given tonew RegExp(), andoriginalwould return the string originally given tonew RegExp().(2)
sourcecould revert to the older v8 behavior, be specified to return the original string as given tonew RegExp(), and a newcanonicalproperty could be added that clearly specifies how aRegExpshould be formatted in a standard way.I imagine it might be too late for (2), but, in either case, it would be nice if ECMAScript at least standardized
sourceto return predictable values across implementations, as discussed previously.