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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/snippets.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 let escape = false; 108 let escape = false;
109 let withinQuotes = false; 109 let withinQuotes = false;
110 110
111 let unicodeEscape = null; 111 let unicodeEscape = null;
112 112
113 let quotesClosed = false; 113 let quotesClosed = false;
114 114
115 let call = []; 115 let call = [];
116 let argument = ""; 116 let argument = "";
117 let name = null;
117 118
118 for (let character of script.trim() + ";") 119 for (let character of script.trim() + ";")
119 { 120 {
120 let afterQuotesClosed = quotesClosed; 121 let afterQuotesClosed = quotesClosed;
121 quotesClosed = false; 122 quotesClosed = false;
122 123
123 if (unicodeEscape != null) 124 if (unicodeEscape != null)
124 { 125 {
125 unicodeEscape += character; 126 unicodeEscape += character;
126 127
(...skipping 21 matching lines...) Expand all
148 } 149 }
149 else if (character == "'") 150 else if (character == "'")
150 { 151 {
151 withinQuotes = !withinQuotes; 152 withinQuotes = !withinQuotes;
152 153
153 if (!withinQuotes) 154 if (!withinQuotes)
154 quotesClosed = true; 155 quotesClosed = true;
155 } 156 }
156 else if (withinQuotes || character != ";" && !/\s/.test(character)) 157 else if (withinQuotes || character != ";" && !/\s/.test(character))
157 { 158 {
158 argument += character; 159 if (!withinQuotes && character == "=" && name == null && call.length > 0)
160 {
161 name = argument;
162 argument = "";
163 }
164 else
165 {
166 argument += character;
167 }
159 } 168 }
160 else 169 else
161 { 170 {
162 if (argument || afterQuotesClosed) 171 if (name || argument || afterQuotesClosed)
163 { 172 {
164 call.push(argument); 173 if (name != null)
174 call[name] = argument;
175 else
176 call.push(argument);
177
178 name = null;
165 argument = ""; 179 argument = "";
166 } 180 }
167 181
168 if (character == ";" && call.length > 0) 182 if (character == ";" && call.length > 0)
169 { 183 {
170 tree.push(call); 184 tree.push(call);
171 call = []; 185 call = [];
172 } 186 }
173 } 187 }
174 } 188 }
(...skipping 29 matching lines...) Expand all
204 let value = imports[name]; 218 let value = imports[name];
205 if (typeof value == "function") 219 if (typeof value == "function")
206 value(...args); 220 value(...args);
207 } 221 }
208 } 222 }
209 } 223 }
210 `; 224 `;
211 } 225 }
212 226
213 exports.compileScript = compileScript; 227 exports.compileScript = compileScript;
OLDNEW
« 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