Suggestion to improve the view parser
See original GitHub issueThe way you parse the views currently is quite buggy, it can fail if comments or parens are present in strings.
A better strategy would be to use a single regex that matches strings, comments and the /l\s*(/, and ignore the strings/comment matches.
Something like this would do:
L_MATCHER = /((?:^|[^\w\d$])l\s*\()|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/|\/\/.*?\n/g
function findL(str, i) {
var match;
L_MATCHER.lastIndex = i;
while (match = L_MATCHER.exec(str)) if(match[1] != null) {
return match.index + match[1].length;
}
}
You could also use a similar strategy to match parentheses.
PAREN_MATCHER = /[()]|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/|\/\/.*?\n/g
then ignore cases where match[0] is not a parenthesis.
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Optimizing Parser Performance – TypeFox Blog
In this article we showcased 3 ways of improving parsing performance. These are general tips that should be applicable to most top-down parsing...
Read more >Improving the performance of an ANTLR parser - Strumenta
In this article we offer some suggestions on improving the performance of your ANTLR parser. ... You can also look at the ANTLR...
Read more >Develop Advanced Security Information Model (ASIM) parsers ...
This article explains how to develop, test, and deploy Microsoft Sentinel Advanced Security Information Model (ASIM) parsers.
Read more >5 Ways Email Parsing Improves Lead Workflow - LinkedIn
An email parser, together with a webhook, is a great way to improve your workflow for entering leads into your CRM or marketing...
Read more >In-depth: The Parser Context
Overview. The parser's context is yet another concept. An instance (object) of the context class is created before a non-terminal starts parsing and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m not sure this approach is worth pursuing further at all. The function call regex/replace will break non-local variable references. Here’s a simple test case:
So if
lis renamed (which may happen, for example, if a bundler or a minifier renames it), things break.Using any library in a view function will also break:
My recommendation would be to do the replacements with a custom babel transformation instead of doing it at runtime. Doing it at the JSX level might allow you to drop the
l()call altogether if an assumption is made that an interpolation is reactive, but it could just be a macro onl()as well.With merging refactor into master, this is no longer relevant