Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/snippets.js

Issue 29927555: Issue 6812 - Implement parsing of named arguments to snippets Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Oct. 28, 2018, 11:11 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/snippets.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/snippets.js
===================================================================
--- a/lib/snippets.js
+++ b/lib/snippets.js
@@ -109,16 +109,17 @@
let withinQuotes = false;
let unicodeEscape = null;
let quotesClosed = false;
let call = [];
let argument = "";
+ let name = null;
for (let character of script.trim() + ";")
{
let afterQuotesClosed = quotesClosed;
quotesClosed = false;
if (unicodeEscape != null)
{
@@ -150,23 +151,36 @@
{
withinQuotes = !withinQuotes;
if (!withinQuotes)
quotesClosed = true;
}
else if (withinQuotes || character != ";" && !/\s/.test(character))
{
- argument += character;
+ if (!withinQuotes && character == "=" && name == null && call.length > 0)
+ {
+ name = argument;
+ argument = "";
+ }
+ else
+ {
+ argument += character;
+ }
}
else
{
- if (argument || afterQuotesClosed)
+ if (name || argument || afterQuotesClosed)
{
- call.push(argument);
+ if (name != null)
+ call[name] = argument;
+ else
+ call.push(argument);
+
+ name = null;
argument = "";
}
if (character == ";" && call.length > 0)
{
tree.push(call);
call = [];
}
« no previous file with comments | « no previous file | test/snippets.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld