Re: why is regexp /\-/u a syntax-error?

2019-09-20 Thread kai zhu
fyi, googling "tc39 regexp unicode" led to web-compat reasoning (learned
something new) @
https://github.com/tc39/proposal-regexp-unicode-property-escapes#what-about-backwards-compatibility

What about backwards compatibility?
In regular expressions without the u flag, the pattern \p is an
(unnecessary) escape sequence for p. Patterns of the form \p{Letter} might
already be present in existing regular expressions without the u flag, and
therefore we cannot assign new meaning to such patterns without breaking
backwards compatibility.

For this reason, ECMAScript 2015 made unnecessary escape sequences like \p
and \P throw an exception when the u flag is set. This enables us to change
the meaning of \p{…} and \P{…} in regular expressions with the u flag
without breaking backwards compatibility.



On Fri, Sep 20, 2019 at 9:13 AM Mathias Bynens  wrote:

> Think of the `u` flag as a strict mode for regular expressions.
>
> `/\a/u` throws, because there is no reason to escape `a` as `\a` --
> therefore, if such an escape sequence is present, it's likely a user error.
> The same goes for `/\-/u`. `-` only has special meaning within character
> classes, not outside of them.
>
> On Fri, Sep 20, 2019 at 11:22 AM kai zhu  wrote:
>
>> jslint previously warned against unescaped literal "-" in regexp.
>>
>> however, escaping "-" together with unicode flag "u", causes syntax error
>> in chrome/firefox/edge (and jslint has since removed warning):
>>
>> ```javascript
>> let rgx = /\-/u
>> VM21:1 Uncaught SyntaxError: Invalid regular expression: /\-/: Invalid
>> escape
>> at :1:10
>> ```
>>
>> just, curious on reason why above edge-case is a syntax-error?
>> ___
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: why is regexp /\-/u a syntax-error?

2019-09-20 Thread Mathias Bynens
Think of the `u` flag as a strict mode for regular expressions.

`/\a/u` throws, because there is no reason to escape `a` as `\a` --
therefore, if such an escape sequence is present, it's likely a user error.
The same goes for `/\-/u`. `-` only has special meaning within character
classes, not outside of them.

On Fri, Sep 20, 2019 at 11:22 AM kai zhu  wrote:

> jslint previously warned against unescaped literal "-" in regexp.
>
> however, escaping "-" together with unicode flag "u", causes syntax error
> in chrome/firefox/edge (and jslint has since removed warning):
>
> ```javascript
> let rgx = /\-/u
> VM21:1 Uncaught SyntaxError: Invalid regular expression: /\-/: Invalid
> escape
> at :1:10
> ```
>
> just, curious on reason why above edge-case is a syntax-error?
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


why is regexp /\-/u a syntax-error?

2019-09-20 Thread kai zhu
jslint previously warned against unescaped literal "-" in regexp.

however, escaping "-" together with unicode flag "u", causes syntax error
in chrome/firefox/edge (and jslint has since removed warning):

```javascript
let rgx = /\-/u
VM21:1 Uncaught SyntaxError: Invalid regular expression: /\-/: Invalid
escape
at :1:10
```

just, curious on reason why above edge-case is a syntax-error?
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss