-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Lexer fails to parse regex literal: /\\/ #10026
Comments
I don't think it was ever the intention to parse literal regexp expressions: |
@petebacondarwin @lgalfaso @caitp what do you guys think? I would say "won't fix" and update https://docs.angularjs.org/guide/expression but yeh, wanted to check with you. |
I feel like it's a wontfix |
A more practical (albeit contrived) example, perhaps: <!-- item.color = "red orange" -->
<span ng-style="{'color': item.color.replace(/ /g, '-')}"> |
I don't think this is something that we want to support, mainly for performance reasons, but also because it's just kind of ugly instead. If someone did want something like that, it would be a great place to use a filter <span ng-style="{color: item.color | hyphenate}"> or something |
Yeh, I'm with @caitp - a filter is far more elegant (and testable!) in this case. I'm going to put together a PR with the doc update stating clearly that we don't support regexp literals in expressions - unless someone is strongly opposed. |
Seems reasonable. |
cool, lets close this then. @ComFreek does that work for you? |
@caitp Yes, using a filter seems to be a good fit for my use case (encoding a URL while replacing slashes). Thanks for the quick replies! |
Plunker: http://plnkr.co/edit/pNtjb67O8OQa2SS3P4Ed?p=preview
The following code throws a lexer error:
The lexer seems to fail at the regex literal
/\\/
.The error message:
The raw error dump from Chrome's dev tools:
Note: The bug can be easily circumvented by placing the regex literal into a controller method or the like.
The text was updated successfully, but these errors were encountered: