|
168 | 168 | _parseMethod: function(expression) {
|
169 | 169 | var m = expression.match(/(\w*)\((.*)\)/);
|
170 | 170 | if (m) {
|
171 |
| - return this._parseArgs({ |
172 |
| - method: m[1], |
173 |
| - static: true |
174 |
| - }, m[2].split(',')); |
| 171 | + // replace escaped commas with comma entity, split on un-escaped commas |
| 172 | + var args = m[2].replace(/\\,/g, ',').split(','); |
| 173 | + return this._parseArgs(args, { method: m[1], static: true }); |
175 | 174 | }
|
176 | 175 | },
|
177 | 176 |
|
178 |
| - _parseArgs: function(effect, argList) { |
| 177 | + _parseArgs: function(argList, effect) { |
179 | 178 | effect.args = argList.map(function(rawArg) {
|
180 | 179 | var arg = this._parseArg(rawArg);
|
181 | 180 | if (!arg.literal) {
|
|
187 | 186 | },
|
188 | 187 |
|
189 | 188 | _parseArg: function(rawArg) {
|
190 |
| - // clean up string |
191 |
| - var arg = String(rawArg).trim(); |
| 189 | + // clean up whitespace |
| 190 | + var arg = String(rawArg).trim() |
| 191 | + // replace comma entity with comma |
| 192 | + .replace(/,/g, ',') |
| 193 | + // repair escape sequences |
| 194 | + .replace(/\\(.)/g, '\$1') |
| 195 | + ; |
192 | 196 | // basic argument descriptor
|
193 | 197 | var a = {
|
194 | 198 | name: arg,
|
195 | 199 | model: this._modelForPath(arg)
|
196 | 200 | };
|
197 |
| - // detect structured path (has dots) |
198 |
| - a.structured = arg.indexOf('.') > 0; |
199 |
| - if (a.structured) { |
200 |
| - a.wildcard = (arg.slice(-2) == '.*'); |
201 |
| - if (a.wildcard) { |
202 |
| - a.name = arg.slice(0, -2); |
203 |
| - } |
204 |
| - } else { |
205 |
| - // detect literal value (must be JSON) |
206 |
| - var fc = arg[0]; |
207 |
| - if (fc >= '0' && fc <= '9') { |
208 |
| - fc = '#'; |
209 |
| - } |
210 |
| - switch(fc) { |
211 |
| - // TODO(sjmiles): single-quote is invalid JSON |
212 |
| - //case "'": |
213 |
| - case '"': |
214 |
| - case '{': |
215 |
| - case '[': |
216 |
| - case '#': |
217 |
| - try { |
218 |
| - a.value = JSON.parse(arg); |
219 |
| - a.literal = true; |
220 |
| - } catch(x) { |
221 |
| - // warn? |
222 |
| - } |
223 |
| - break; |
| 201 | + // detect literal value (must be String or Number) |
| 202 | + var fc = arg[0]; |
| 203 | + if (fc >= '0' && fc <= '9') { |
| 204 | + fc = '#'; |
| 205 | + } |
| 206 | + switch(fc) { |
| 207 | + case "'": |
| 208 | + case '"': |
| 209 | + a.value = arg.slice(1, -1); |
| 210 | + a.literal = true; |
| 211 | + break; |
| 212 | + case '#': |
| 213 | + a.value = Number(arg); |
| 214 | + a.literal = true; |
| 215 | + break; |
| 216 | + } |
| 217 | + // if not literal, look for structured path |
| 218 | + if (!a.literal) { |
| 219 | + // detect structured path (has dots) |
| 220 | + a.structured = arg.indexOf('.') > 0; |
| 221 | + if (a.structured) { |
| 222 | + a.wildcard = (arg.slice(-2) == '.*'); |
| 223 | + if (a.wildcard) { |
| 224 | + a.name = arg.slice(0, -2); |
| 225 | + } |
224 | 226 | }
|
225 | 227 | }
|
226 | 228 | return a;
|
|
0 commit comments