ecma262 icon indicating copy to clipboard operation
ecma262 copied to clipboard

RegExp CharacterRange early error

Open Jack-Works opened this issue 7 months ago • 5 comments
trafficstars

eshost -s -e '/[\d-\D]/.test("1")'
#### engine262

SyntaxError: Invalid class range

#### javascriptcore, spidermonkey, v8
true

#### xs

SyntaxError: [\d-\D] invalid range

Per spec, it should be an Early Error:

Image

Jack-Works avatar Apr 10 '25 11:04 Jack-Works

So what are you asking of us here? Are you trying to say this is a web reality issue that we should address with a spec change? If you think it's not relied upon on the web, you should report issues to each of the nonconforming engines.

michaelficarra avatar Apr 10 '25 13:04 michaelficarra

See Annex B https://tc39.es/ecma262/#sec-patterns-static-semantics-early-errors-annexb for why /[\d-\D]/ doesn't throw a SyntaxError in browsers.

anba avatar Apr 10 '25 13:04 anba

ok... I don't know this is an annex b thing before, I thought spec is wrong

Jack-Works avatar Apr 10 '25 15:04 Jack-Works

I'm going to re-open this. I don't think the Annex B reference at the top of this section is sufficient for readers. We should add Annex B references in each early error that is augmented by Annex B.

michaelficarra avatar Apr 10 '25 16:04 michaelficarra

Plan of action from today's editor call is to pursue https://github.com/tc39/ecma262/pull/2445 (or something similar) and eventually merge the Annex B Pattern grammar into the main spec body.

michaelficarra avatar May 08 '25 00:05 michaelficarra