Giter Club home page Giter Club logo

Comments (7)

svaarala avatar svaarala commented on May 28, 2024

This is probably caused by the dollar escape $ inside the brackets. Ecmascript E5/E5.1 IdentityEscape production (which is the only applicable one AFAIK) is:

IdentityEscape ::
  SourceCharacter but not IdentifierPart
  <ZWJ>
  <ZWNJ>

Because "$" is a valid IdentifierPart, the escape $ is not valid as far as I understand, and \u0024 should be instead:

var a = /[\\\^\u0024\*\+\?\|\[\]\(\)\.\{\}]/g;

There are other non-standard regexp forms that nevertheless appear in existing code. A $ escape is already accepted outside a CharacterClass but not inside it. There's an ongoing task item to allow more non-standard regexps either by default or through a feature option.

from duktape.

remoe avatar remoe commented on May 28, 2024

Thanks for this detailed explanation. I agreed, but this runs nevertheless on Chrome, Firefox and v8 command line without any configuration parameters.

from duktape.

svaarala avatar svaarala commented on May 28, 2024

I know - there are actually a lot of behaviors that are not standard but still work in various other engines. Being fully compatible with other engines is not a practical goal because the non-standard features of other engines are not even compatible with each other (for instance function statements, a non-standard feature, have two competing semantics; Duktape adopts the V8 semantics here).

The approach with Duktape is that the standard behavior is implemented first, and non-standard behaviors are adopted when they either fulfill an important role (like the .stack property of errors) or are crucial to compatibility. Non-standard regexp syntax is one of the latter, and it's on the work list for future releases.

from duktape.

remoe avatar remoe commented on May 28, 2024

Ok, thanks!

from duktape.

svaarala avatar svaarala commented on May 28, 2024

I'll add dollar escape support inside character classes into the next release as it is an easy change (and dollar escape outside is already supported). There will still unfortunately be some real world regexps that won't parse - e.g. something similar to this came up with recent Emscripten (and also the test262 test suite I think):

/^function \(\) {.*}$/

Adding support to these requires a bit more work because backtracking is needed to handle the ambiguous unquoted braces. This change will be done at some point, because these regexps do crop up with existing code bases.

from duktape.

svaarala avatar svaarala commented on May 28, 2024

Ok, the "dollar escape inside character class" is now in the master branch, so your original regexp should now work :-)

from duktape.

remoe avatar remoe commented on May 28, 2024

Thanks!

from duktape.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.