1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.vash = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2 | var debug = require('debug')
|
3 | var lg = debug('vash:main');
|
4 |
|
5 | var Lexer = require('./lib/lexer');
|
6 | var Parser = require('./lib/parser');
|
7 | var codegen = require('./lib/codegen');
|
8 | var runtime = require('./runtime');
|
9 | var helperbatch = require('./lib/helperbatch');
|
10 | var copyrtl = require('./lib/util/copyrtl');
|
11 |
|
12 |
|
13 |
|
14 | require('./lib/helpers');
|
15 | copyrtl(exports, runtime);
|
16 |
|
17 | exports.config = {
|
18 |
|
19 |
|
20 | favorText: false,
|
21 |
|
22 | saveAT: false,
|
23 | saveTextTag: false,
|
24 |
|
25 |
|
26 | useWith: false,
|
27 | htmlEscape: true,
|
28 | helpersName: 'html',
|
29 | modelName: 'model',
|
30 | debug: true,
|
31 | source: null,
|
32 | simple: false,
|
33 |
|
34 |
|
35 | asHelper: false,
|
36 | args: null
|
37 | }
|
38 |
|
39 | exports.version = require('./package.json').version;
|
40 |
|
41 | exports.compileStream = function() {
|
42 |
|
43 |
|
44 | throw new Error('NotImplemented');
|
45 | }
|
46 |
|
47 | exports.compile = function(markup, options) {
|
48 |
|
49 | if(markup === '' || typeof markup !== 'string') {
|
50 | throw new Error('Empty or non-string cannot be compiled');
|
51 | }
|
52 |
|
53 | var opts = copyrtl({}, exports.config, options || {});
|
54 |
|
55 | var l = new Lexer();
|
56 |
|
57 | l.write(markup);
|
58 | var tokens = l.read();
|
59 |
|
60 | var p = new Parser(opts);
|
61 | p.write(tokens);
|
62 | var more = true;
|
63 | while(more !== null) more = p.read();
|
64 |
|
65 | p.checkStack();
|
66 |
|
67 |
|
68 | opts.source = l.originalInput;
|
69 |
|
70 | p.lg(p.dumpAST());
|
71 |
|
72 | var compiled = codegen(p.stack[0], opts);
|
73 | lg(compiled);
|
74 | var tpl = runtime.link(compiled, opts);
|
75 |
|
76 | return tpl;
|
77 | }
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | exports['compileHelper'] = helperbatch.bind(null, 'helper', exports.compile);
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | exports['compileBatch'] = exports['batch'] = helperbatch.bind(null, 'batch', exports.compile);
|
118 | },{"./lib/codegen":2,"./lib/helperbatch":4,"./lib/helpers":6,"./lib/lexer":9,"./lib/parser":24,"./lib/util/copyrtl":26,"./package.json":34,"./runtime":35,"debug":29}],2:[function(require,module,exports){
|
119 |
|
120 | var debug = require('debug');
|
121 | var lg = debug('vash:codegen');
|
122 |
|
123 | var gens = {}
|
124 |
|
125 | gens.VashProgram = function(node, opts, generate) {
|
126 | return node.body.map(generate).join('');
|
127 | }
|
128 |
|
129 | gens.VashExplicitExpression = function(node, opts, generate) {
|
130 | var str = node.values.map(generate).join('');
|
131 | str = '(' + maybeHTMLEscape(node, opts, str) + ')';
|
132 | if (parentIsContent(node)) {
|
133 | str = bewrap(str);
|
134 | }
|
135 | return str;
|
136 | }
|
137 |
|
138 | gens.VashExpression = function(node, opts, generate) {
|
139 | var str = node.values.map(generate).join('');
|
140 | str = bewrap(maybeHTMLEscape(node, opts, str));
|
141 | return str;
|
142 | }
|
143 |
|
144 | gens.VashRegex = function(node, opts, generate) {
|
145 | var str = node.values.map(generate).join('');
|
146 | str = maybeHTMLEscape(node, opts, str);
|
147 | if (parentIsContent(node)) {
|
148 | str = bewrap(str);
|
149 | }
|
150 | return str;
|
151 | }
|
152 |
|
153 | gens.VashMarkup = function(node, opts, generate) {
|
154 | var isText = node.name === 'text';
|
155 | var name = node.name ? bcwrap(node.name) : '';
|
156 | var tagNameValue = name
|
157 | + (node.expression ? generate(node.expression) : '');
|
158 |
|
159 | var tagOpen = ''
|
160 | + bcwrap('<')
|
161 | + tagNameValue
|
162 | + bcwrap(node.attributes.length ? ' ' : '')
|
163 | + node.attributes.map(generate).join(bcwrap(' '))
|
164 |
|
165 | var values;
|
166 | var tagClose;
|
167 |
|
168 | if (node.isVoid) {
|
169 | tagOpen += bcwrap(node.voidClosed ? ' />' : '>');
|
170 | values = '';
|
171 | tagClose = '';
|
172 | } else {
|
173 | tagOpen += bcwrap('>');
|
174 | values = node.values.map(generate).join('');
|
175 | tagClose = node.isClosed ? bcwrap('</') + tagNameValue + bcwrap('>') : '';
|
176 | }
|
177 |
|
178 | if (isText) {
|
179 | tagOpen = tagClose = '';
|
180 | }
|
181 |
|
182 | return ''
|
183 | + (parentIsExpression(node) ? '(function () {' : '')
|
184 | + dbgstart(node, opts)
|
185 | + tagOpen
|
186 | + values
|
187 | + tagClose
|
188 | + dbgend(node, opts)
|
189 | + (parentIsExpression(node) ? '}())' : '')
|
190 | }
|
191 |
|
192 | gens.VashMarkupAttribute = function(node, opts, generate) {
|
193 | var quote = node.rightIsQuoted || '';
|
194 | quote = escapeMarkupContent(quote);
|
195 | return ''
|
196 | + dbgstart(node, opts)
|
197 | + node.left.map(generate).join('')
|
198 | + (node.right.length || node.rightIsQuoted
|
199 | ? bcwrap('=' + quote)
|
200 | + node.right.map(generate).join('')
|
201 | + bcwrap(quote)
|
202 | : '')
|
203 | + dbgend(node, opts);
|
204 | }
|
205 |
|
206 | gens.VashMarkupContent = function(node, opts, generate) {
|
207 | return ''
|
208 | + dbgstart(node, opts)
|
209 | + node.values.map(generate).join('')
|
210 | + dbgend(node, opts);
|
211 | }
|
212 |
|
213 | gens.VashMarkupComment = function(node, opts, generate) {
|
214 | return ''
|
215 | + bcwrap('<!--')
|
216 | + dbgstart(node, opts)
|
217 | + node.values.map(generate).join('')
|
218 | + dbgend(node, opts)
|
219 | + bcwrap('-->');
|
220 | }
|
221 |
|
222 | gens.VashBlock = function(node, opts, generate) {
|
223 | var hasValues = node.values.length > 0;
|
224 | var unsafeForDbg = node.keyword === 'switch'
|
225 | || !node.name
|
226 | || !hasValues;
|
227 | var openBrace = hasValues || node.hasBraces
|
228 | ? '{' + (unsafeForDbg ? '' : dbgstart(node, opts))
|
229 | : '';
|
230 | var closeBrace = hasValues || node.hasBraces
|
231 | ? (unsafeForDbg ? '' : dbgend(node, opts)) + '}'
|
232 | : '';
|
233 | return ''
|
234 | + (node.keyword ? node.keyword : '')
|
235 | + node.head.map(generate).join('')
|
236 | + openBrace
|
237 | + node.values.map(generate).join('')
|
238 | + closeBrace
|
239 | + node.tail.map(generate).join('');
|
240 | }
|
241 |
|
242 | gens.VashIndexExpression = function(node, opts, generate) {
|
243 | var str = node.values.map(generate).join('');
|
244 | return '[' + str + ']';
|
245 | }
|
246 |
|
247 | gens.VashText = function(node, opts, generate) {
|
248 | if (!node.value.length) return '';
|
249 | return parentIsContent(node)
|
250 | ? ''
|
251 | + dbgstart(node, opts)
|
252 | + bcwrap(escapeMarkupContent(node.value))
|
253 | + dbgend(node, opts)
|
254 | : node.value;
|
255 | }
|
256 |
|
257 | gens.VashComment = function(node, opts, generate) {
|
258 | return '';
|
259 | }
|
260 |
|
261 | var reQuote = /(['"])/g;
|
262 | var reEscapedQuote = /\\+(["'])/g;
|
263 | var reLineBreak = /\n/g;
|
264 | var reHelpersName = /HELPERSNAME/g;
|
265 | var reModelName = /MODELNAME/g;
|
266 | var reOriginalMarkup = /ORIGINALMARKUP/g;
|
267 |
|
268 | function escapeMarkupContent(str) {
|
269 | return str
|
270 | .replace(/\\/g, '\\\\')
|
271 | .replace(reQuote, '\\$1')
|
272 | .replace(reLineBreak, '\\n');
|
273 | }
|
274 |
|
275 | var BUFFER_HEAD = '\n__vbuffer.push(';
|
276 | var BUFFER_TAIL = ');\n';
|
277 |
|
278 |
|
279 | function bcwrap(str) {
|
280 | return BUFFER_HEAD + '\'' + str.replace(/\n/, '\\n') + '\'' + BUFFER_TAIL;
|
281 | }
|
282 |
|
283 |
|
284 | function bewrap(str) {
|
285 | return BUFFER_HEAD + str + BUFFER_TAIL;
|
286 | }
|
287 |
|
288 | function parentIsContent(node) {
|
289 | return node.parent.type === 'VashMarkup'
|
290 | || node.parent.type === 'VashMarkupContent'
|
291 | || node.parent.type === 'VashMarkupComment'
|
292 | || node.parent.type === 'VashMarkupAttribute'
|
293 | || node.parent.type === 'VashProgram';
|
294 | }
|
295 |
|
296 | function parentIsExpression(node) {
|
297 | return node.parent.type === 'VashExpression'
|
298 | || node.parent.type === 'VashExplicitExpression'
|
299 | || node.parent.type === 'VashIndexExpression';
|
300 | }
|
301 |
|
302 | function dbgstart(node, opts) {
|
303 | return opts.debug
|
304 | ? ''
|
305 | + opts.helpersName + '.vl = ' + node.startloc.line + ', '
|
306 | + opts.helpersName + '.vc = ' + node.startloc.column + '; \n'
|
307 | : '';
|
308 | }
|
309 |
|
310 | function dbgend(node, opts) {
|
311 | return opts.debug
|
312 | ? ''
|
313 | + opts.helpersName + '.vl = ' + node.endloc.line + ', '
|
314 | + opts.helpersName + '.vc = ' + node.endloc.column + '; \n'
|
315 | : '';
|
316 | }
|
317 |
|
318 | function maybeHTMLEscape(node, opts, str) {
|
319 | if (parentIsContent(node) && opts.htmlEscape) {
|
320 | return opts.helpersName + '.escape(' + str + ').toHtmlString()';
|
321 | } else {
|
322 | return str;
|
323 | }
|
324 | }
|
325 |
|
326 | function replaceDevTokens(str, opts){
|
327 | return str
|
328 | .replace( reHelpersName, opts.helpersName )
|
329 | .replace( reModelName, opts.modelName );
|
330 | }
|
331 |
|
332 | function head(opts){
|
333 | var str = ''
|
334 | + (opts.debug ? 'try { \n' : '')
|
335 | + 'var __vbuffer = HELPERSNAME.buffer; \n'
|
336 | + 'HELPERSNAME.options = __vopts; \n'
|
337 | + 'MODELNAME = MODELNAME || {}; \n'
|
338 | + (opts.useWith ? 'with( MODELNAME ){ \n' : '');
|
339 |
|
340 | str = replaceDevTokens(str, opts);
|
341 | return str;
|
342 | }
|
343 |
|
344 | function helperHead(opts){
|
345 | var str = ''
|
346 | + (opts.debug ? 'try { \n' : '')
|
347 | + 'var __vbuffer = this.buffer; \n'
|
348 | + 'var MODELNAME = this.model; \n'
|
349 | + 'var HELPERSNAME = this; \n';
|
350 |
|
351 | str = replaceDevTokens(str, opts);
|
352 | return str;
|
353 | }
|
354 |
|
355 | function tail(opts){
|
356 | var str = ''
|
357 | + (opts.simple
|
358 | ? 'return HELPERSNAME.buffer.join(""); \n'
|
359 | : ';(__vopts && __vopts.onRenderEnd && __vopts.onRenderEnd(null, HELPERSNAME)); \n'
|
360 | + 'return (__vopts && __vopts.asContext) \n'
|
361 | + ' ? HELPERSNAME \n'
|
362 | + ' : HELPERSNAME.toString(); \n' )
|
363 | + (opts.useWith ? '} \n' : '')
|
364 | + (opts.debug ? '} catch( e ){ \n'
|
365 | + ' HELPERSNAME.reportError( e, HELPERSNAME.vl, HELPERSNAME.vc, "ORIGINALMARKUP", "!LB!", true ); \n'
|
366 | + '} \n' : '');
|
367 |
|
368 | str = replaceDevTokens(str, opts)
|
369 | .replace(reOriginalMarkup, escapeForDebug(opts.source));
|
370 |
|
371 | return str;
|
372 | }
|
373 |
|
374 | function helperTail(opts){
|
375 | var str = ''
|
376 | + (opts.debug ? '} catch( e ){ \n'
|
377 | + ' HELPERSNAME.reportError( e, HELPERSNAME.vl, HELPERSNAME.vc, "ORIGINALMARKUP", "!LB!", true ); \n'
|
378 | + '} \n' : '');
|
379 |
|
380 | str = replaceDevTokens(str, opts)
|
381 | .replace(reOriginalMarkup, escapeForDebug(opts.source));
|
382 |
|
383 | return str;
|
384 | }
|
385 |
|
386 | function escapeForDebug( str ){
|
387 | return str
|
388 | .replace(reLineBreak, '!LB!')
|
389 | .replace(reQuote, '\\$1')
|
390 | .replace(reEscapedQuote, '\\$1')
|
391 | }
|
392 |
|
393 |
|
394 |
|
395 | function condenseContent(str) {
|
396 | return str
|
397 | .replace(/'\);\n+__vbuffer.push\('/g, '')
|
398 | .replace(/\n+/g, '\n');
|
399 | }
|
400 |
|
401 | function generate(node, opts) {
|
402 |
|
403 | function gen(opts, node) {
|
404 | lg('Entering ' + node.type);
|
405 | var str = gens[node.type](node, opts, genChild);
|
406 | lg('Leaving ' + node.type);
|
407 | return str;
|
408 |
|
409 | function genChild(child) {
|
410 | if (!child.parent) child.parent = node;
|
411 | lg('Generating child type %s of parent type %s', child.type, node.type)
|
412 | return gen(opts, child);
|
413 | }
|
414 | }
|
415 |
|
416 | var generated = gen(opts, node);
|
417 |
|
418 | var body;
|
419 | if(!opts.asHelper){
|
420 | body = head(opts) + generated + tail(opts);
|
421 | } else {
|
422 | body = helperHead(opts) + generated + helperTail(opts);
|
423 | }
|
424 |
|
425 | return opts.debug
|
426 | ? body
|
427 | : condenseContent(body);
|
428 | }
|
429 |
|
430 | module.exports = generate;
|
431 |
|
432 | },{"debug":29}],3:[function(require,module,exports){
|
433 |
|
434 | exports.context = function(input, lineno, columnno, linebreak) {
|
435 | linebreak = linebreak || '!LB!';
|
436 |
|
437 | var lines = input.split(linebreak)
|
438 | , contextSize = lineno === 0 && columnno === 0 ? lines.length - 1 : 3
|
439 | , start = Math.max(0, lineno - contextSize)
|
440 | , end = Math.min(lines.length, lineno + contextSize);
|
441 |
|
442 | return lines
|
443 | .slice(start, end)
|
444 | .map(function(line, i, all){
|
445 | var curr = i + start + 1;
|
446 |
|
447 | return (curr === lineno ? ' > ' : ' ')
|
448 | + (curr < 10 ? ' ' : '')
|
449 | + curr
|
450 | + ' | '
|
451 | + line;
|
452 | }).join('\n');
|
453 | }
|
454 | },{}],4:[function(require,module,exports){
|
455 |
|
456 | var slice = Array.prototype.slice
|
457 |
|
458 | , reHelperFuncHead = /vash\.helpers\.([^= ]+?)\s*=\s*function([^(]*?)\(([^)]*?)\)\s*{/
|
459 | , reHelperFuncTail = /\}$/
|
460 |
|
461 | , reBatchSeparator = /^\/\/\s*@\s*batch\s*=\s*(.*?)$/
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 | module.exports = function compile(type, compile, str, options){
|
469 |
|
470 | var separator = type === 'helper'
|
471 | ? reHelperFuncHead
|
472 | : reBatchSeparator;
|
473 |
|
474 | var tpls = splitByNamedTpl(separator, str, function(ma, name){
|
475 | return name.replace(/^\s+|\s+$/, '');
|
476 | }, type === 'helper' ? true : false);
|
477 |
|
478 | if(tpls){
|
479 | Object.keys(tpls).forEach(function(path){
|
480 | tpls[path] = type === 'helper'
|
481 | ? compileSingleHelper(compile, tpls[path], options)
|
482 | : compile('@{' + tpls[path] + '}', options);
|
483 | });
|
484 |
|
485 | tpls.toClientString = function(){
|
486 | return Object.keys(tpls).reduce(function(prev, curr){
|
487 | if(curr === 'toClientString'){
|
488 | return prev;
|
489 | }
|
490 | return prev + tpls[curr].toClientString() + '\n';
|
491 | }, '')
|
492 | }
|
493 | }
|
494 |
|
495 | return tpls;
|
496 | }
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 | var splitByNamedTpl = function(reSeparator, markup, resultHandler, keepSeparator){
|
517 |
|
518 | var lines = markup.split(/[\n\r]/g)
|
519 | ,tpls = {}
|
520 | ,paths = []
|
521 | ,currentPath = ''
|
522 |
|
523 | lines.forEach(function(line, i){
|
524 |
|
525 | var pathResult = reSeparator.exec(line)
|
526 | ,handlerResult = pathResult ? resultHandler.apply(pathResult, pathResult) : null
|
527 |
|
528 | if(handlerResult){
|
529 | currentPath = handlerResult;
|
530 | tpls[currentPath] = [];
|
531 | }
|
532 |
|
533 | if((!handlerResult || keepSeparator) && line){
|
534 | tpls[currentPath].push(line);
|
535 | }
|
536 | });
|
537 |
|
538 | Object.keys(tpls).forEach(function(key){
|
539 | tpls[key] = tpls[key].join('\n');
|
540 | })
|
541 |
|
542 | return tpls;
|
543 | }
|
544 |
|
545 | var compileSingleHelper = function(compile, str, options){
|
546 |
|
547 | options = options || {};
|
548 |
|
549 |
|
550 | var def = str.replace(/^[\s\n\r]+|[\s\n\r]+$/, '').match(reHelperFuncHead)
|
551 |
|
552 | ,args = def[3].split(',').map(function(arg){ return arg.replace(' ', '') })
|
553 | ,name = def[1]
|
554 | ,body = str
|
555 | .replace( reHelperFuncHead, '' )
|
556 | .replace( reHelperFuncTail, '' )
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 | body = '@{' + body + '}';
|
563 |
|
564 |
|
565 | options.args = args;
|
566 | options.asHelper = name;
|
567 | return compile(body, options);
|
568 | }
|
569 |
|
570 | },{}],5:[function(require,module,exports){
|
571 | var helpers = require('../../runtime').helpers;
|
572 |
|
573 |
|
574 |
|
575 |
|
576 | helpers.config.highlighter = null;
|
577 |
|
578 | helpers.highlight = function(lang, cb){
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 | var startMark = this.buffer.mark();
|
585 |
|
586 |
|
587 |
|
588 | cb( this.model );
|
589 |
|
590 |
|
591 | var cbOutLines = this.buffer.fromMark(startMark);
|
592 |
|
593 |
|
594 |
|
595 |
|
596 | this.buffer.push( '<pre><code>' );
|
597 |
|
598 | if( helpers.config.highlighter ){
|
599 | this.buffer.push( helpers.config.highlighter(lang, cbOutLines.join('')).value );
|
600 | } else {
|
601 | this.buffer.push( cbOutLines );
|
602 | }
|
603 |
|
604 | this.buffer.push( '</code></pre>' );
|
605 |
|
606 |
|
607 |
|
608 | }
|
609 |
|
610 | },{"../../runtime":35}],6:[function(require,module,exports){
|
611 | require('./trim');
|
612 | require('./highlight');
|
613 | require('./layout');
|
614 | module.exports = require('../../runtime');
|
615 | },{"../../runtime":35,"./highlight":5,"./layout":7,"./trim":8}],7:[function(require,module,exports){
|
616 | var helpers = require('../../runtime').helpers;
|
617 | var copyrtl = require('../util/copyrtl');
|
618 |
|
619 |
|
620 | var vash = require('../../index');
|
621 | module.exports = vash;
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 | if( typeof window === 'undefined' ){
|
628 | var fs = require('fs')
|
629 | ,path = require('path')
|
630 | }
|
631 |
|
632 |
|
633 | helpers.config.browser = false;
|
634 |
|
635 | vash.loadFile = function(filepath, options, cb){
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 | options = copyrtl({}, vash.config, options || {});
|
658 |
|
659 | var browser = helpers.config.browser
|
660 | ,tpl
|
661 |
|
662 | if( !browser && options.settings && options.settings.views ){
|
663 |
|
664 | filepath = path.normalize( filepath );
|
665 |
|
666 | if( filepath.indexOf( path.normalize( options.settings.views ) ) === -1 ){
|
667 |
|
668 | filepath = path.join( options.settings.views, filepath );
|
669 | }
|
670 |
|
671 | if( !path.extname( filepath ) ){
|
672 | filepath += '.' + ( options.settings['view engine'] || 'vash' )
|
673 | }
|
674 | }
|
675 |
|
676 |
|
677 | try {
|
678 |
|
679 | tpl = options.cache || browser
|
680 | ? helpers.tplcache[filepath] || ( helpers.tplcache[filepath] = vash.compile(fs.readFileSync(filepath, 'utf8')) )
|
681 | : vash.compile( fs.readFileSync(filepath, 'utf8') )
|
682 |
|
683 | cb && cb(null, tpl);
|
684 | } catch(e) {
|
685 | cb && cb(e, null);
|
686 | }
|
687 | }
|
688 |
|
689 | vash.renderFile = vash.__express = function(filepath, options, cb){
|
690 |
|
691 | vash.loadFile(filepath, options, function(err, tpl){
|
692 |
|
693 | var prevORE = options.onRenderEnd;
|
694 |
|
695 | cb( err, !err && tpl(options, function(err, ctx){
|
696 | ctx.finishLayout()
|
697 | if( prevORE ) prevORE(err, ctx);
|
698 | }) );
|
699 | })
|
700 | }
|
701 |
|
702 | helpers._ensureLayoutProps = function(){
|
703 | this.appends = this.appends || {};
|
704 | this.prepends = this.prepends || {};
|
705 | this.blocks = this.blocks || {};
|
706 |
|
707 | this.blockMarks = this.blockMarks || {};
|
708 | }
|
709 |
|
710 | helpers.finishLayout = function(){
|
711 | this._ensureLayoutProps();
|
712 |
|
713 | var self = this, name, marks, blocks, prepends, appends, injectMark, m, content, block
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 | for( name in this.blockMarks ){
|
721 |
|
722 | marks = this.blockMarks[name];
|
723 |
|
724 | prepends = this.prepends[name];
|
725 | blocks = this.blocks[name];
|
726 | appends = this.appends[name];
|
727 |
|
728 | injectMark = marks.pop();
|
729 |
|
730 |
|
731 | m = this.buffer.mark();
|
732 |
|
733 | prepends && prepends.forEach(function(p){ self.buffer.pushConcat( p ); });
|
734 |
|
735 |
|
736 |
|
737 | block = blocks.pop();
|
738 | block && this.buffer.pushConcat( block );
|
739 |
|
740 | appends && appends.forEach(function(a){ self.buffer.pushConcat( a ); });
|
741 |
|
742 |
|
743 | content = this.buffer.fromMark( m )
|
744 |
|
745 |
|
746 |
|
747 |
|
748 | content = compactContent(content);
|
749 |
|
750 |
|
751 | content.unshift( injectMark, 0 );
|
752 | this.buffer.spliceMark.apply( this.buffer, content );
|
753 | }
|
754 |
|
755 | for( name in this.blockMarks ){
|
756 |
|
757 |
|
758 | this.blockMarks[name].forEach(function(m){ m.destroy(); });
|
759 | }
|
760 |
|
761 |
|
762 | delete this.blockMarks;
|
763 | delete this.prepends;
|
764 | delete this.blocks;
|
765 | delete this.appends;
|
766 |
|
767 |
|
768 | return this.toString();
|
769 | }
|
770 |
|
771 |
|
772 |
|
773 | function compactContent(content) {
|
774 | var re = vash.Mark.re;
|
775 | var parts = [];
|
776 | var str = '';
|
777 |
|
778 | content.forEach(function(part) {
|
779 | if (re.exec(part)) {
|
780 | parts.push(str, part);
|
781 | str = '';
|
782 | } else {
|
783 |
|
784 | str += (part || '');
|
785 | }
|
786 | });
|
787 |
|
788 |
|
789 | parts.push(str);
|
790 |
|
791 | return parts;
|
792 | }
|
793 |
|
794 | helpers.extend = function(path, ctn){
|
795 | var self = this
|
796 | ,buffer = this.buffer
|
797 | ,origModel = this.model
|
798 | ,layoutCtx;
|
799 |
|
800 | this._ensureLayoutProps();
|
801 |
|
802 |
|
803 | vash.loadFile(path, this.model, function(err, tpl){
|
804 |
|
805 | if (err) throw err;
|
806 |
|
807 |
|
808 |
|
809 |
|
810 | var start = self.buffer.mark();
|
811 |
|
812 | ctn(self.model);
|
813 |
|
814 |
|
815 | var content = self.buffer.fromMark( start )
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 | self.isExtending = true;
|
828 | tpl( self.model, { context: self } );
|
829 | self.isExtending = false;
|
830 | });
|
831 |
|
832 | this.model = origModel;
|
833 | }
|
834 |
|
835 | helpers.include = function(name, model){
|
836 |
|
837 | var self = this
|
838 | ,buffer = this.buffer
|
839 | ,origModel = this.model;
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 | vash.loadFile(name, this.model, function(err, tpl){
|
846 | if (err) throw err;
|
847 | tpl( model || self.model, { context: self } );
|
848 | });
|
849 |
|
850 | this.model = origModel;
|
851 | }
|
852 |
|
853 | helpers.block = function(name, ctn){
|
854 | this._ensureLayoutProps();
|
855 |
|
856 | var self = this
|
857 |
|
858 | ,marks = this.blockMarks[name] || ( this.blockMarks[name] = [] )
|
859 |
|
860 | ,blocks = this.blocks[name] || ( this.blocks[name] = [] )
|
861 | ,start
|
862 | ,content;
|
863 |
|
864 |
|
865 |
|
866 | if( ctn ){
|
867 | start = this.buffer.mark();
|
868 | ctn( this.model );
|
869 | content = this.buffer.fromMark( start );
|
870 |
|
871 |
|
872 | if( content.length && !this.isExtending ){
|
873 | blocks.push( content );
|
874 | }
|
875 |
|
876 |
|
877 | if( content.length && this.isExtending ){
|
878 | blocks.unshift( content );
|
879 | }
|
880 | }
|
881 |
|
882 |
|
883 | marks.push( this.buffer.mark( 'block-' + name ) );
|
884 | }
|
885 |
|
886 | helpers._handlePrependAppend = function( type, name, ctn ){
|
887 | this._ensureLayoutProps();
|
888 |
|
889 | var start = this.buffer.mark()
|
890 | ,content
|
891 | ,stack = this[type]
|
892 | ,namedStack = stack[name] || ( stack[name] = [] )
|
893 |
|
894 | ctn( this.model );
|
895 | content = this.buffer.fromMark( start );
|
896 |
|
897 | namedStack.push( content );
|
898 | }
|
899 |
|
900 | helpers.append = function(name, ctn){
|
901 | this._handlePrependAppend( 'appends', name, ctn );
|
902 | }
|
903 |
|
904 | helpers.prepend = function(name, ctn){
|
905 | this._handlePrependAppend( 'prepends', name, ctn );
|
906 | }
|
907 |
|
908 | },{"../../index":1,"../../runtime":35,"../util/copyrtl":26,"fs":28,"path":32}],8:[function(require,module,exports){
|
909 | var helpers = require('../../runtime').helpers;
|
910 |
|
911 |
|
912 | helpers.trim = function(val){
|
913 | return val.replace(/^\s*|\s*$/g, '');
|
914 | }
|
915 | },{"../../runtime":35}],9:[function(require,module,exports){
|
916 | var debug = require('debug');
|
917 | var tokens = require('./tokens');
|
918 |
|
919 |
|
920 |
|
921 |
|
922 |
|
923 | function VLexer(){
|
924 | this.lg = debug('vash:lexer');
|
925 | this.input = '';
|
926 | this.originalInput = '';
|
927 | this.lineno = 1;
|
928 | this.charno = 0;
|
929 | }
|
930 |
|
931 | module.exports = VLexer;
|
932 |
|
933 | VLexer.prototype = {
|
934 |
|
935 | write: function(input) {
|
936 | var normalized = input.replace(/\r\n|\r/g, '\n');
|
937 |
|
938 |
|
939 | if (this.originalInput.length == 0) {
|
940 | normalized = normalized.replace(/^\uFEFF/, '');
|
941 | }
|
942 |
|
943 | this.input += normalized;
|
944 | this.originalInput += normalized;
|
945 | return true;
|
946 | },
|
947 |
|
948 | read: function() {
|
949 | var out = []
|
950 | , result;
|
951 | while(this.input.length) {
|
952 | result = this.advance();
|
953 | if (result) {
|
954 | out.push(result);
|
955 | this.lg('Read %s at line %d, column %d with content %s',
|
956 | result.type, result.line, result.chr, result.val.replace(/(\n)/, '\\n'));
|
957 | }
|
958 | }
|
959 | return out;
|
960 | },
|
961 |
|
962 | scan: function(regexp, type){
|
963 | var captures, token;
|
964 | if (captures = regexp.exec(this.input)) {
|
965 | this.input = this.input.substr((captures[1].length));
|
966 |
|
967 | token = {
|
968 | type: type
|
969 | ,line: this.lineno
|
970 | ,chr: this.charno
|
971 | ,val: captures[1] || ''
|
972 | ,toString: function(){
|
973 | return '[' + this.type
|
974 | + ' (' + this.line + ',' + this.chr + '): '
|
975 | + this.val.replace(/(\n)/, '\\n') + ']';
|
976 | }
|
977 | };
|
978 |
|
979 | this.charno += captures[0].length;
|
980 | return token;
|
981 | }
|
982 | }
|
983 |
|
984 | ,advance: function() {
|
985 |
|
986 | var i, name, test, result;
|
987 |
|
988 | for(i = 0; i < tokens.tests.length; i += 2){
|
989 | test = tokens.tests[i+1];
|
990 | test.displayName = tokens.tests[i];
|
991 |
|
992 | if(typeof test === 'function'){
|
993 |
|
994 | result = test.call(this);
|
995 | }
|
996 |
|
997 | if(typeof test.exec === 'function'){
|
998 |
|
999 | result = this.scan(test, tokens.tests[i]);
|
1000 | }
|
1001 |
|
1002 | if( result ){
|
1003 | return result;
|
1004 | }
|
1005 | }
|
1006 | }
|
1007 | }
|
1008 |
|
1009 | },{"./tokens":25,"debug":29}],10:[function(require,module,exports){
|
1010 | var Node = module.exports = function BlockNode() {
|
1011 | this.type = 'VashBlock';
|
1012 | this.keyword = null;
|
1013 | this.head = [];
|
1014 | this.values = [];
|
1015 | this.tail = [];
|
1016 | this.hasBraces = null;
|
1017 | this.startloc = null;
|
1018 | this.endloc = null;
|
1019 |
|
1020 | this._reachedOpenBrace = false;
|
1021 | this._reachedCloseBrace = false;
|
1022 | this._withinCommentLine = false;
|
1023 | this._waitingForEndQuote = null;
|
1024 | }
|
1025 |
|
1026 | Node.prototype.endOk = function() {
|
1027 | var gradeSchool = this.hasBraces
|
1028 | && (!this._reachedOpenBrace || !this._reachedCloseBrace);
|
1029 |
|
1030 | return (gradeSchool || this._withinCommentLine || this._waitingForEndQuote)
|
1031 | ? false
|
1032 | : true;
|
1033 | }
|
1034 | },{}],11:[function(require,module,exports){
|
1035 | var Node = module.exports = function CommentNode() {
|
1036 | this.type = 'VashComment';
|
1037 | this.values = [];
|
1038 | this.startloc = null;
|
1039 | this.endloc = null;
|
1040 |
|
1041 | this._waitingForClose = null;
|
1042 | }
|
1043 |
|
1044 | Node.prototype.endOk = function() {
|
1045 | return this._waitingForClose
|
1046 | ? false
|
1047 | : true;
|
1048 | }
|
1049 | },{}],12:[function(require,module,exports){
|
1050 | var Node = module.exports = function ExplicitExpressionNode() {
|
1051 | this.type = 'VashExplicitExpression';
|
1052 | this.values = [];
|
1053 | this.startloc = null;
|
1054 | this.endloc = null;
|
1055 |
|
1056 | this._waitingForParenClose = null;
|
1057 | this._waitingForEndQuote = null;
|
1058 | }
|
1059 |
|
1060 | Node.prototype.endOk = function() {
|
1061 | return this._waitingForEndQuote || this._waitingForParenClose
|
1062 | ? false
|
1063 | : true;
|
1064 | }
|
1065 | },{}],13:[function(require,module,exports){
|
1066 | var Node = module.exports = function ExpressionNode() {
|
1067 | this.type = 'VashExpression';
|
1068 | this.values = [];
|
1069 | this.startloc = null;
|
1070 | this.endloc = null;
|
1071 | }
|
1072 | },{}],14:[function(require,module,exports){
|
1073 | var Node = module.exports = function IndexExpressionNode() {
|
1074 | this.type = 'VashIndexExpression';
|
1075 | this.values = [];
|
1076 | this.startloc = null;
|
1077 | this.endloc = null;
|
1078 |
|
1079 | this._waitingForEndQuote = null;
|
1080 | this._waitingForHardParenClose = null;
|
1081 | }
|
1082 |
|
1083 | Node.prototype.endOk = function() {
|
1084 | return (this._waitingForEndQuote || this._waitingForHardParenClose)
|
1085 | ? false
|
1086 | : true;
|
1087 | }
|
1088 | },{}],15:[function(require,module,exports){
|
1089 | module.exports = function LocationNode() {
|
1090 | this.line = 1;
|
1091 | this.column = 0;
|
1092 | }
|
1093 | },{}],16:[function(require,module,exports){
|
1094 | var Node = module.exports = function MarkupNode() {
|
1095 | this.type = 'VashMarkup';
|
1096 | this.name = null;
|
1097 | this.expression = null;
|
1098 | this.attributes = [];
|
1099 | this.values = [];
|
1100 | this.isVoid = false;
|
1101 | this.voidClosed = false;
|
1102 | this.isClosed = false;
|
1103 | this.startloc = null;
|
1104 | this.endloc = null;
|
1105 |
|
1106 | this._finishedOpen = false;
|
1107 |
|
1108 | this._waitingForFinishedClose = false;
|
1109 | }
|
1110 |
|
1111 | var voids = module.exports.voids = [
|
1112 |
|
1113 |
|
1114 | '!DOCTYPE', '!doctype', 'doctype',
|
1115 |
|
1116 |
|
1117 | 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
|
1118 | 'link', 'meta', 'param', 'source', 'track', 'wbr'
|
1119 | ];
|
1120 |
|
1121 | Node.isVoid = function(name) {
|
1122 | return voids.indexOf(name) > -1;
|
1123 | }
|
1124 |
|
1125 |
|
1126 |
|
1127 | var implieds = [
|
1128 | 'dd', 'dt', 'li', 'option', 'optgroup', 'p', 'rp', 'rt'
|
1129 | ]
|
1130 |
|
1131 | Node.isImplied = function(name) {
|
1132 | return implieds.indexOf(name) > -1;
|
1133 | }
|
1134 |
|
1135 | Node.prototype.endOk = function() {
|
1136 |
|
1137 | if (
|
1138 | this._finishedOpen
|
1139 | && (this.isClosed || this.voidClosed)
|
1140 | ) {
|
1141 | return true;
|
1142 | }
|
1143 |
|
1144 | return false;
|
1145 | }
|
1146 | },{}],17:[function(require,module,exports){
|
1147 | var Node = module.exports = function MarkupAttributeNode() {
|
1148 | this.type = 'VashMarkupAttribute';
|
1149 | this.left = [];
|
1150 | this.right = [];
|
1151 | this.rightIsQuoted = false;
|
1152 | this.startloc = null;
|
1153 | this.endloc = null;
|
1154 |
|
1155 | this._finishedLeft = false;
|
1156 | this._expectRight = false;
|
1157 | }
|
1158 |
|
1159 | Node.prototype.endOk = function() {
|
1160 |
|
1161 | return this._finishedLeft
|
1162 | ? true
|
1163 | : false;
|
1164 | }
|
1165 | },{}],18:[function(require,module,exports){
|
1166 | var Node = module.exports = function MarkupCommentNode() {
|
1167 | this.type = 'VashMarkupComment';
|
1168 | this.values = [];
|
1169 | this.startloc = null;
|
1170 | this.endloc = null;
|
1171 |
|
1172 | this._finishedOpen = false
|
1173 | this._waitingForClose = null;
|
1174 | }
|
1175 |
|
1176 | Node.prototype.endOk = function() {
|
1177 | return this._waitingForClose || this._finishedOpen
|
1178 | ? false
|
1179 | : true;
|
1180 | }
|
1181 | },{}],19:[function(require,module,exports){
|
1182 | var Node = module.exports = function MarkupContentNode() {
|
1183 | this.type = 'VashMarkupContent';
|
1184 | this.values = [];
|
1185 | this.startloc = null;
|
1186 | this.endloc = null;
|
1187 |
|
1188 | this._waitingForNewline = null;
|
1189 | }
|
1190 |
|
1191 | Node.prototype.endOk = function() {
|
1192 | return this._waitingForNewline
|
1193 | ? false
|
1194 | : true;
|
1195 | }
|
1196 | },{}],20:[function(require,module,exports){
|
1197 | module.exports = function ProgramNode() {
|
1198 | this.type = 'VashProgram';
|
1199 | this.body = [];
|
1200 | }
|
1201 | },{}],21:[function(require,module,exports){
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 | var Node = module.exports = function RegexNode() {
|
1212 | this.type = 'VashRegex';
|
1213 | this.values = [];
|
1214 | this.startloc = null;
|
1215 | this.endloc = null;
|
1216 |
|
1217 | this._waitingForForwardSlash = null;
|
1218 | this._waitingForFlags = null;
|
1219 | }
|
1220 |
|
1221 | Node.prototype.endOk = function() {
|
1222 | return this._waitingForForwardSlash || this._waitingForFlags
|
1223 | ? false
|
1224 | : true;
|
1225 | }
|
1226 | },{}],22:[function(require,module,exports){
|
1227 | module.exports = function TextNode() {
|
1228 | this.type = 'VashText';
|
1229 | this.value = '';
|
1230 | this.startloc = null;
|
1231 | this.endloc = null;
|
1232 | }
|
1233 | },{}],23:[function(require,module,exports){
|
1234 | function clean(node) {
|
1235 | return Object.keys(node).reduce(function(out, key) {
|
1236 | var value = node[key];
|
1237 | if (key[0] !== '_' && typeof value !== 'function') {
|
1238 | if (Array.isArray(value)) {
|
1239 | out[key] = value.map(clean);
|
1240 | } else {
|
1241 | out[key] = value;
|
1242 | }
|
1243 | }
|
1244 | return out;
|
1245 | }, {});
|
1246 | }
|
1247 |
|
1248 | exports.clean = clean;
|
1249 |
|
1250 | },{}],24:[function(require,module,exports){
|
1251 |
|
1252 | var debug = require('debug');
|
1253 |
|
1254 | var tks = require('./tokens');
|
1255 | var nodestuff = require('./nodestuff');
|
1256 | var error = require('./error');
|
1257 | var namer = require('./util/fn-namer');
|
1258 |
|
1259 | var ProgramNode = namer(require('./nodes/program'));
|
1260 | var TextNode = namer(require('./nodes/text'));
|
1261 | var MarkupNode = namer(require('./nodes/markup'));
|
1262 | var MarkupCommentNode = namer(require('./nodes/markupcomment'));
|
1263 | var MarkupContentNode = namer(require('./nodes/markupcontent'));
|
1264 | var MarkupAttributeNode = namer(require('./nodes/markupattribute'));
|
1265 | var ExpressionNode = namer(require('./nodes/expression'));
|
1266 | var ExplicitExpressionNode = namer(require('./nodes/explicitexpression'));
|
1267 | var IndexExpressionNode = namer(require('./nodes/indexexpression'));
|
1268 | var LocationNode = namer(require('./nodes/location'));
|
1269 | var BlockNode = namer(require('./nodes/block'));
|
1270 | var CommentNode = namer(require('./nodes/comment'));
|
1271 | var RegexNode = namer(require('./nodes/regex'));
|
1272 |
|
1273 | function Parser(opts) {
|
1274 | this.lg = debug('vash:parser');
|
1275 | this.tokens = [];
|
1276 | this.deferredTokens = [];
|
1277 | this.node = null;
|
1278 | this.stack = [];
|
1279 | this.inputText = '';
|
1280 | this.opts = opts || {};
|
1281 | this.previousNonWhitespace = null
|
1282 | }
|
1283 |
|
1284 | module.exports = Parser;
|
1285 |
|
1286 | Parser.prototype.decorateError = function(err, line, column) {
|
1287 | err.message = ''
|
1288 | + err.message
|
1289 | + ' at template line ' + line
|
1290 | + ', column ' + column + '\n\n'
|
1291 | + 'Context: \n'
|
1292 | + error.context(this.inputText, line, column, '\n')
|
1293 | + '\n';
|
1294 |
|
1295 | return err;
|
1296 | }
|
1297 |
|
1298 | Parser.prototype.write = function(tokens) {
|
1299 | if (!Array.isArray(tokens)) tokens = [tokens];
|
1300 | this.inputText += tokens.map(function(tok) { return tok.val; }).join('');
|
1301 | this.tokens.unshift.apply(this.tokens, tokens.reverse());
|
1302 | }
|
1303 |
|
1304 | Parser.prototype.read = function() {
|
1305 | if (!this.tokens.length && !this.deferredTokens.length) return null;
|
1306 |
|
1307 | if (!this.node) {
|
1308 | this.openNode(new ProgramNode());
|
1309 | this.openNode(new MarkupNode(), this.node.body);
|
1310 | this.node._finishedOpen = true;
|
1311 | this.node.name = 'text';
|
1312 | updateLoc(this.node, { line: 0, chr: 0 })
|
1313 | this.openNode(new MarkupContentNode(), this.node.values);
|
1314 | updateLoc(this.node, { line: 0, chr: 0 })
|
1315 | }
|
1316 |
|
1317 | var curr = this.deferredTokens.pop() || this.tokens.pop();
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 | var nnwon = null;
|
1324 |
|
1325 | for (var i = this.deferredTokens.length-1; i >= 0; i--) {
|
1326 | if (
|
1327 | nnwon
|
1328 | && nnwon.type !== tks.WHITESPACE
|
1329 | && nnwon.type !== tks.NEWLINE
|
1330 | ) break;
|
1331 | nnwon = this.deferredTokens[i];
|
1332 | }
|
1333 |
|
1334 | for (var i = this.tokens.length-1; i >= 0; i--) {
|
1335 | if (
|
1336 | nnwon
|
1337 | && nnwon.type !== tks.WHITESPACE
|
1338 | && nnwon.type !== tks.NEWLINE
|
1339 | ) break;
|
1340 | nnwon = this.tokens[i];
|
1341 | }
|
1342 |
|
1343 | var next = this.deferredTokens.pop() || this.tokens.pop();
|
1344 | var ahead = this.deferredTokens.pop() || this.tokens.pop();
|
1345 |
|
1346 | var dispatch = 'continue' + this.node.constructor.name;
|
1347 |
|
1348 | this.lg('Read: %s', dispatch);
|
1349 | this.lg(' curr %s', curr);
|
1350 | this.lg(' next %s', next);
|
1351 | this.lg(' ahead %s', ahead);
|
1352 | this.lg(' nnwon %s', nnwon);
|
1353 |
|
1354 | if (curr._considerEscaped) {
|
1355 | this.lg(' Previous token was marked as escaping');
|
1356 | }
|
1357 |
|
1358 | var consumed = this[dispatch](this.node, curr, next, ahead, nnwon);
|
1359 |
|
1360 | if (ahead) {
|
1361 |
|
1362 | this.deferredTokens.push(ahead);
|
1363 | }
|
1364 |
|
1365 | if (next) {
|
1366 |
|
1367 | this.deferredTokens.push(next);
|
1368 | }
|
1369 |
|
1370 | if (!consumed) {
|
1371 | this.lg('Deferring curr %s', curr);
|
1372 | this.deferredTokens.push(curr);
|
1373 | } else {
|
1374 |
|
1375 | if (curr.type !== tks.WHITESPACE) {
|
1376 | this.lg('set previousNonWhitespace %s', curr);
|
1377 | this.previousNonWhitespace = curr;
|
1378 | }
|
1379 |
|
1380 |
|
1381 | if (curr.type === tks.NEWLINE) {
|
1382 | this.lg('set previousNonWhitespace %s', null);
|
1383 | this.previousNonWhitespace = null;
|
1384 | }
|
1385 |
|
1386 | if (!curr._considerEscaped && curr.type === tks.BACKSLASH) {
|
1387 | next._considerEscaped = true;
|
1388 | }
|
1389 | }
|
1390 | }
|
1391 |
|
1392 | Parser.prototype.checkStack = function() {
|
1393 |
|
1394 | var i = this.stack.length-1;
|
1395 | var node;
|
1396 | var msg;
|
1397 |
|
1398 |
|
1399 | while(i >= 2) {
|
1400 | node = this.stack[i];
|
1401 | if (node.endOk && !node.endOk()) {
|
1402 |
|
1403 | delete node.values;
|
1404 | msg = 'Found unclosed ' + node.type;
|
1405 | var err = new Error(msg);
|
1406 | err.name = 'UnclosedNodeError';
|
1407 | throw this.decorateError(
|
1408 | err,
|
1409 | node.startloc.line,
|
1410 | node.startloc.column);
|
1411 | }
|
1412 | i--;
|
1413 | }
|
1414 | }
|
1415 |
|
1416 |
|
1417 |
|
1418 | Parser.prototype.flag = function(node, name, value) {
|
1419 | var printVal = (value && typeof value === 'object')
|
1420 | ? value.type
|
1421 | : value;
|
1422 | this.lg('Flag %s on node %s was %s now %s',
|
1423 | name, node.type, node[name], printVal);
|
1424 | node[name] = value;
|
1425 | }
|
1426 |
|
1427 | Parser.prototype.dumpAST = function() {
|
1428 | if (!this.stack.length) {
|
1429 | var msg = 'No AST to dump.';
|
1430 | throw new Error(msg);
|
1431 | }
|
1432 |
|
1433 | return JSON.stringify(this.stack[0], null, ' ');
|
1434 | }
|
1435 |
|
1436 | Parser.prototype.openNode = function(node, opt_insertArr) {
|
1437 | this.stack.push(node);
|
1438 | this.lg('Opened node %s from %s',
|
1439 | node.type, (this.node ? this.node.type : null));
|
1440 | this.node = node;
|
1441 |
|
1442 | if (opt_insertArr) {
|
1443 | opt_insertArr.push(node);
|
1444 | }
|
1445 |
|
1446 | return node;
|
1447 | }
|
1448 |
|
1449 | Parser.prototype.closeNode = function(node) {
|
1450 | var toClose = this.stack[this.stack.length-1];
|
1451 | if (node !== toClose) {
|
1452 | var msg = 'InvalidCloseAction: '
|
1453 | + 'Expected ' + node.type + ' in stack, instead found '
|
1454 | + toClose.type;
|
1455 | throw new Error(msg);
|
1456 | }
|
1457 |
|
1458 | this.stack.pop();
|
1459 | var last = this.stack[this.stack.length-1];
|
1460 |
|
1461 | this.lg('Closing node %s (%s), returning to node %s',
|
1462 | node.type, node.name, last.type)
|
1463 |
|
1464 | this.node = last;
|
1465 | }
|
1466 |
|
1467 | Parser.prototype.continueCommentNode = function(node, curr, next) {
|
1468 | var valueNode = ensureTextNode(node.values);
|
1469 |
|
1470 | if (curr.type === tks.AT_STAR_OPEN && !node._waitingForClose) {
|
1471 | this.flag(node, '_waitingForClose', tks.AT_STAR_CLOSE)
|
1472 | updateLoc(node, curr);
|
1473 | return true;
|
1474 | }
|
1475 |
|
1476 | if (curr.type === node._waitingForClose) {
|
1477 | this.flag(node, '_waitingForClose', null)
|
1478 | updateLoc(node, curr);
|
1479 | this.closeNode(node);
|
1480 | return true;
|
1481 | }
|
1482 |
|
1483 | if (curr.type === tks.DOUBLE_FORWARD_SLASH && !node._waitingForClose){
|
1484 | this.flag(node, '_waitingForClose', tks.NEWLINE);
|
1485 | updateLoc(node, curr);
|
1486 | return true;
|
1487 | }
|
1488 |
|
1489 | appendTextValue(valueNode, curr);
|
1490 | return true;
|
1491 | }
|
1492 |
|
1493 | Parser.prototype.continueMarkupNode = function(node, curr, next) {
|
1494 | var valueNode = node.values[node.values.length-1];
|
1495 |
|
1496 | if (curr.type === tks.LT_SIGN && !node._finishedOpen) {
|
1497 | updateLoc(node, curr);
|
1498 | return true;
|
1499 | }
|
1500 |
|
1501 | if (
|
1502 | !node._finishedOpen
|
1503 | && curr.type !== tks.GT_SIGN
|
1504 | && curr.type !== tks.LT_SIGN
|
1505 | && curr.type !== tks.WHITESPACE
|
1506 | && curr.type !== tks.NEWLINE
|
1507 | && curr.type !== tks.HTML_TAG_VOID_CLOSE
|
1508 | ) {
|
1509 |
|
1510 |
|
1511 |
|
1512 | if (
|
1513 | curr.type === tks.AT
|
1514 | && !curr._considerEscaped
|
1515 | && next
|
1516 | && next.type === tks.AT
|
1517 | ) {
|
1518 | next._considerEscaped = true;
|
1519 | return true;
|
1520 | }
|
1521 |
|
1522 | if (curr.type === tks.AT && !curr._considerEscaped) {
|
1523 | this.flag(node, 'expression', this.openNode(new ExpressionNode()));
|
1524 | updateLoc(node.expression, curr);
|
1525 | return true;
|
1526 | }
|
1527 |
|
1528 | node.name = node.name
|
1529 | ? node.name + curr.val
|
1530 | : curr.val;
|
1531 | updateLoc(node, curr);
|
1532 | return true;
|
1533 | }
|
1534 |
|
1535 | if (curr.type === tks.GT_SIGN && !node._waitingForFinishedClose) {
|
1536 | this.flag(node, '_finishedOpen', true);
|
1537 |
|
1538 | if (MarkupNode.isVoid(node.name)) {
|
1539 | this.flag(node, 'isVoid', true);
|
1540 | this.closeNode(node);
|
1541 | updateLoc(node, curr);
|
1542 | } else {
|
1543 | valueNode = this.openNode(new MarkupContentNode(), node.values);
|
1544 | updateLoc(valueNode, curr);
|
1545 | }
|
1546 |
|
1547 | return true;
|
1548 | }
|
1549 |
|
1550 | if (curr.type === tks.GT_SIGN && node._waitingForFinishedClose) {
|
1551 | this.flag(node, '_waitingForFinishedClose', false);
|
1552 | this.closeNode(node);
|
1553 | updateLoc(node, curr);
|
1554 | return true;
|
1555 | }
|
1556 |
|
1557 |
|
1558 | if (
|
1559 | curr.type === tks.HTML_TAG_CLOSE
|
1560 | && next
|
1561 | && next.type === tks.IDENTIFIER
|
1562 | && MarkupNode.isVoid(next.val)
|
1563 | ) {
|
1564 | throw newUnexpectedClosingTagError(this, curr, curr.val + next.val);
|
1565 | }
|
1566 |
|
1567 |
|
1568 | if (curr.type === tks.HTML_TAG_CLOSE) {
|
1569 | this.flag(node, '_waitingForFinishedClose', true);
|
1570 | this.flag(node, 'isClosed', true);
|
1571 | return true;
|
1572 | }
|
1573 |
|
1574 |
|
1575 | if (curr.type === tks.HTML_COMMENT_CLOSE) {
|
1576 | this.flag(node, '_waitingForFinishedClose', false);
|
1577 | this.closeNode(node);
|
1578 | return false;
|
1579 | }
|
1580 |
|
1581 | if (curr.type === tks.HTML_TAG_VOID_CLOSE) {
|
1582 | this.closeNode(node);
|
1583 | this.flag(node, 'isVoid', true);
|
1584 | this.flag(node, 'voidClosed', true);
|
1585 | this.flag(node, 'isClosed', true);
|
1586 | updateLoc(node, curr);
|
1587 | return true;
|
1588 | }
|
1589 |
|
1590 | if (node._waitingForFinishedClose) {
|
1591 | this.lg('Ignoring %s while waiting for closing GT_SIGN',
|
1592 | curr);
|
1593 | return true;
|
1594 | }
|
1595 |
|
1596 | if (
|
1597 | (curr.type === tks.WHITESPACE || curr.type === tks.NEWLINE)
|
1598 | && !node._finishedOpen
|
1599 | && next.type !== tks.HTML_TAG_VOID_CLOSE
|
1600 | && next.type !== tks.GT_SIGN
|
1601 | && next.type !== tks.NEWLINE
|
1602 | && next.type !== tks.WHITESPACE
|
1603 | ) {
|
1604 |
|
1605 | valueNode = this.openNode(new MarkupAttributeNode(), node.attributes);
|
1606 | updateLoc(valueNode, curr);
|
1607 | return true;
|
1608 | }
|
1609 |
|
1610 |
|
1611 | if (
|
1612 | (curr.type === tks.WHITESPACE || curr.type === tks.NEWLINE)
|
1613 | && !node._finishedOpen
|
1614 | ) {
|
1615 | updateLoc(node, curr);
|
1616 | return true;
|
1617 | }
|
1618 |
|
1619 |
|
1620 |
|
1621 | if (node._finishedOpen) {
|
1622 | valueNode = this.openNode(new MarkupContentNode(), this.node.values);
|
1623 | updateLoc(valueNode, curr);
|
1624 | return false;
|
1625 | }
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 |
|
1632 | }
|
1633 |
|
1634 | Parser.prototype.continueMarkupAttributeNode = function(node, curr, next) {
|
1635 |
|
1636 | var valueNode;
|
1637 |
|
1638 | if (
|
1639 | curr.type === tks.AT
|
1640 | && !curr._considerEscaped
|
1641 | && next
|
1642 | && next.type === tks.AT
|
1643 | ) {
|
1644 | next._considerEscaped = true;
|
1645 | return true;
|
1646 | }
|
1647 |
|
1648 | if (curr.type === tks.AT && !curr._considerEscaped) {
|
1649 |
|
1650 |
|
1651 | valueNode = this.openNode(new ExpressionNode(), !node._finishedLeft
|
1652 | ? node.left
|
1653 | : node.right);
|
1654 |
|
1655 | updateLoc(valueNode, curr);
|
1656 | return true;
|
1657 | }
|
1658 |
|
1659 |
|
1660 | if (
|
1661 | !node._expectRight
|
1662 | && (curr.type === tks.WHITESPACE
|
1663 | || curr.type === tks.GT_SIGN
|
1664 | || curr.type === tks.HTML_TAG_VOID_CLOSE)
|
1665 | ) {
|
1666 | this.flag(node, '_finishedLeft', true);
|
1667 | updateLoc(node, curr);
|
1668 | this.closeNode(node);
|
1669 | return false;
|
1670 | }
|
1671 |
|
1672 |
|
1673 | if (curr.type === tks.EQUAL_SIGN && !node._finishedLeft) {
|
1674 | this.flag(node, '_finishedLeft', true);
|
1675 | this.flag(node, '_expectRight', true);
|
1676 | return true;
|
1677 | }
|
1678 |
|
1679 |
|
1680 | if (
|
1681 | node._expectRight
|
1682 | && !node.rightIsQuoted
|
1683 | && (curr.type === tks.DOUBLE_QUOTE
|
1684 | || curr.type === tks.SINGLE_QUOTE)
|
1685 | ) {
|
1686 | this.flag(node, 'rightIsQuoted', curr.val);
|
1687 | return true;
|
1688 | }
|
1689 |
|
1690 |
|
1691 | if (node.rightIsQuoted === curr.val) {
|
1692 | updateLoc(node, curr);
|
1693 | this.closeNode(node);
|
1694 | return true;
|
1695 | }
|
1696 |
|
1697 |
|
1698 |
|
1699 | if (!node._finishedLeft) {
|
1700 | valueNode = ensureTextNode(node.left);
|
1701 | } else {
|
1702 | valueNode = ensureTextNode(node.right);
|
1703 | }
|
1704 |
|
1705 | appendTextValue(valueNode, curr);
|
1706 | return true;
|
1707 | }
|
1708 |
|
1709 | Parser.prototype.continueMarkupContentNode = function(node, curr, next, ahead) {
|
1710 | var valueNode = ensureTextNode(node.values);
|
1711 |
|
1712 | if (curr.type === tks.HTML_COMMENT_OPEN) {
|
1713 | valueNode = this.openNode(new MarkupCommentNode(), node.values);
|
1714 | updateLoc(valueNode, curr);
|
1715 | return false;
|
1716 | }
|
1717 |
|
1718 | if (curr.type === tks.HTML_COMMENT_CLOSE) {
|
1719 | updateLoc(node, curr);
|
1720 | this.closeNode(node);
|
1721 | return false;
|
1722 | }
|
1723 |
|
1724 | if (curr.type === tks.AT_COLON && !curr._considerEscaped) {
|
1725 | this.flag(node, '_waitingForNewline', true);
|
1726 | updateLoc(valueNode, curr);
|
1727 | return true;
|
1728 | }
|
1729 |
|
1730 | if (curr.type === tks.NEWLINE && node._waitingForNewline === true) {
|
1731 | this.flag(node, '_waitingForNewline', false);
|
1732 | appendTextValue(valueNode, curr);
|
1733 | updateLoc(node, curr);
|
1734 | this.closeNode(node);
|
1735 | return true;
|
1736 | }
|
1737 |
|
1738 | if (
|
1739 | curr.type === tks.AT
|
1740 | && !curr._considerEscaped
|
1741 | && next.type === tks.BRACE_OPEN
|
1742 | ) {
|
1743 | valueNode = this.openNode(new BlockNode(), node.values);
|
1744 | updateLoc(valueNode, curr);
|
1745 | return true;
|
1746 | }
|
1747 |
|
1748 | if (
|
1749 | curr.type === tks.AT
|
1750 | && !curr._considerEscaped
|
1751 | && (next.type === tks.BLOCK_KEYWORD
|
1752 | || next.type === tks.FUNCTION)
|
1753 | ) {
|
1754 | valueNode = this.openNode(new BlockNode(), node.values);
|
1755 | updateLoc(valueNode, curr);
|
1756 | return true;
|
1757 | }
|
1758 |
|
1759 |
|
1760 | if (
|
1761 | curr.type === tks.AT
|
1762 | && !curr._considerEscaped
|
1763 | && next
|
1764 | && (
|
1765 | next.type === tks.AT_COLON
|
1766 | || next.type === tks.AT
|
1767 | || next.type === tks.AT_STAR_OPEN
|
1768 | )
|
1769 | ) {
|
1770 | next._considerEscaped = true;
|
1771 | return true;
|
1772 | }
|
1773 |
|
1774 |
|
1775 | if (curr.type === tks.AT && !curr._considerEscaped) {
|
1776 | valueNode = this.openNode(new ExpressionNode(), node.values);
|
1777 | updateLoc(valueNode, curr);
|
1778 | return true;
|
1779 | }
|
1780 |
|
1781 | if (curr.type === tks.AT_STAR_OPEN && !curr._considerEscaped) {
|
1782 | this.openNode(new CommentNode(), node.values);
|
1783 | return false;
|
1784 | }
|
1785 |
|
1786 | var parent = this.stack[this.stack.length-2];
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 | if (
|
1792 | curr.type === tks.HTML_TAG_CLOSE
|
1793 | || (curr.type === tks.BRACE_CLOSE
|
1794 | && parent && parent.type === 'VashBlock')
|
1795 | ) {
|
1796 | this.closeNode(node);
|
1797 | updateLoc(node, curr);
|
1798 | return false;
|
1799 | }
|
1800 |
|
1801 | if (
|
1802 | curr.type === tks.LT_SIGN
|
1803 | && next
|
1804 | && (
|
1805 |
|
1806 |
|
1807 |
|
1808 |
|
1809 |
|
1810 |
|
1811 |
|
1812 |
|
1813 | (next.type === tks.IDENTIFIER
|
1814 | && ahead
|
1815 | && (
|
1816 | ahead.type === tks.GT_SIGN
|
1817 | || ahead.type === tks.WHITESPACE
|
1818 | || ahead.type === tks.NEWLINE
|
1819 | || ahead.type === tks.AT
|
1820 | || ahead.type === tks.UNARY_OPERATOR
|
1821 | || ahead.type === tks.COLON
|
1822 | )
|
1823 | )
|
1824 | || next.type === tks.AT)
|
1825 | ) {
|
1826 |
|
1827 |
|
1828 | valueNode = this.openNode(new MarkupNode(), node.values);
|
1829 | updateLoc(valueNode, curr);
|
1830 | return false;
|
1831 | }
|
1832 |
|
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 | if (
|
1838 | curr.type === tks.WHITESPACE
|
1839 | && !node._waitingForNewline
|
1840 | && !this.opts.favorText
|
1841 | && parent
|
1842 | && parent.type === 'VashBlock'
|
1843 | ) {
|
1844 | return true;
|
1845 | }
|
1846 |
|
1847 | appendTextValue(valueNode, curr);
|
1848 | return true;
|
1849 | }
|
1850 |
|
1851 | Parser.prototype.continueMarkupCommentNode = function(node, curr, next) {
|
1852 | var valueNode = node.values[node.values.length-1];
|
1853 |
|
1854 | if (curr.type === tks.HTML_COMMENT_OPEN) {
|
1855 | this.flag(node, '_finishedOpen', true);
|
1856 | this.flag(node, '_waitingForClose', tks.HTML_COMMENT_CLOSE);
|
1857 | updateLoc(node, curr);
|
1858 | valueNode = this.openNode(new MarkupContentNode(), node.values);
|
1859 | return true;
|
1860 | }
|
1861 |
|
1862 | if (curr.type === tks.HTML_COMMENT_CLOSE && node._finishedOpen) {
|
1863 | this.flag(node, '_waitingForClose', null);
|
1864 | updateLoc(node, curr);
|
1865 | this.closeNode(node);
|
1866 | return true;
|
1867 | }
|
1868 |
|
1869 | valueNode = ensureTextNode(node.values);
|
1870 | appendTextValue(valueNode, curr);
|
1871 | return true;
|
1872 | }
|
1873 |
|
1874 | Parser.prototype.continueExpressionNode = function(node, curr, next) {
|
1875 | var valueNode = node.values[node.values.length-1];
|
1876 | var pnw = this.previousNonWhitespace;
|
1877 |
|
1878 | if (
|
1879 | curr.type === tks.AT
|
1880 | && next.type === tks.HARD_PAREN_OPEN
|
1881 | ) {
|
1882 |
|
1883 | updateLoc(node, curr);
|
1884 | this.closeNode(node);
|
1885 | return true;
|
1886 | }
|
1887 |
|
1888 | if (curr.type === tks.PAREN_OPEN) {
|
1889 | this.openNode(new ExplicitExpressionNode(), node.values);
|
1890 | return false;
|
1891 | }
|
1892 |
|
1893 | if (
|
1894 | curr.type === tks.HARD_PAREN_OPEN
|
1895 | && node.values[0]
|
1896 | && node.values[0].type === 'VashExplicitExpression'
|
1897 | ) {
|
1898 |
|
1899 | updateLoc(node, curr);
|
1900 | this.closeNode(node);
|
1901 | return false;
|
1902 | }
|
1903 |
|
1904 | if (
|
1905 | curr.type === tks.HARD_PAREN_OPEN
|
1906 | && next.type === tks.HARD_PAREN_CLOSE
|
1907 | ) {
|
1908 |
|
1909 | updateLoc(node, curr);
|
1910 | this.closeNode(node);
|
1911 | return false;
|
1912 | }
|
1913 |
|
1914 | if (curr.type === tks.HARD_PAREN_OPEN) {
|
1915 | this.openNode(new IndexExpressionNode(), node.values);
|
1916 | return false;
|
1917 | }
|
1918 |
|
1919 | if (
|
1920 | curr.type === tks.FORWARD_SLASH
|
1921 | && pnw
|
1922 | && pnw.type === tks.AT
|
1923 | ) {
|
1924 | this.openNode(new RegexNode(), node.values)
|
1925 | return false;
|
1926 | }
|
1927 |
|
1928 |
|
1929 |
|
1930 |
|
1931 | if (curr.type === tks.PERIOD && next && next.type === tks.IDENTIFIER) {
|
1932 | valueNode = ensureTextNode(node.values);
|
1933 | appendTextValue(valueNode, curr);
|
1934 | return true;
|
1935 | }
|
1936 |
|
1937 | if (curr.type === tks.IDENTIFIER) {
|
1938 |
|
1939 | if (node.values.length > 0 && valueNode && valueNode.type !== 'VashText') {
|
1940 |
|
1941 | this.closeNode(node);
|
1942 | return false;
|
1943 | }
|
1944 |
|
1945 | valueNode = ensureTextNode(node.values);
|
1946 | appendTextValue(valueNode, curr);
|
1947 | return true;
|
1948 | } else {
|
1949 | this.closeNode(node);
|
1950 | return false;
|
1951 | }
|
1952 | }
|
1953 |
|
1954 | Parser.prototype.continueExplicitExpressionNode = function(node, curr, next) {
|
1955 |
|
1956 | var valueNode = node.values[node.values.length-1];
|
1957 |
|
1958 | if (
|
1959 | node.values.length === 0
|
1960 | && (curr.type === tks.AT || curr.type === tks.PAREN_OPEN)
|
1961 | ) {
|
1962 |
|
1963 | this.flag(node, '_waitingForParenClose', true);
|
1964 | updateLoc(node, curr);
|
1965 | return true;
|
1966 | }
|
1967 |
|
1968 | if (curr.type === tks.PAREN_OPEN && !node._waitingForEndQuote) {
|
1969 |
|
1970 | valueNode = this.openNode(new ExplicitExpressionNode(), node.values);
|
1971 | updateLoc(valueNode, curr);
|
1972 |
|
1973 | return true;
|
1974 | }
|
1975 |
|
1976 | if (curr.type === tks.PAREN_CLOSE && !node._waitingForEndQuote) {
|
1977 |
|
1978 | this.flag(node, '_waitingForParenClose', false);
|
1979 | updateLoc(node, curr);
|
1980 | this.closeNode(node);
|
1981 |
|
1982 | return true;
|
1983 | }
|
1984 |
|
1985 | if (curr.type === tks.FUNCTION && !node._waitingForEndQuote) {
|
1986 | valueNode = this.openNode(new BlockNode(), node.values);
|
1987 | updateLoc(valueNode, curr);
|
1988 | return false;
|
1989 | }
|
1990 |
|
1991 | if (
|
1992 | curr.type === tks.LT_SIGN
|
1993 | && next.type === tks.IDENTIFIER
|
1994 | && !node._waitingForEndQuote
|
1995 | ) {
|
1996 |
|
1997 | valueNode = this.openNode(new MarkupNode(), node.values);
|
1998 | updateLoc(valueNode, curr);
|
1999 | return false;
|
2000 | }
|
2001 |
|
2002 | var pnw = this.previousNonWhitespace;
|
2003 |
|
2004 | if (
|
2005 | curr.type === tks.FORWARD_SLASH
|
2006 | && !node._waitingForEndQuote
|
2007 | && pnw
|
2008 | && pnw.type !== tks.IDENTIFIER
|
2009 | && pnw.type !== tks.NUMERAL
|
2010 | && pnw.type !== tks.PAREN_CLOSE
|
2011 | ) {
|
2012 | valueNode = this.openNode(new RegexNode(), node.values);
|
2013 | updateLoc(valueNode, curr);
|
2014 | return false;
|
2015 | }
|
2016 |
|
2017 |
|
2018 | valueNode = ensureTextNode(node.values);
|
2019 |
|
2020 | if (
|
2021 | !node._waitingForEndQuote
|
2022 | && (curr.type === tks.SINGLE_QUOTE || curr.type === tks.DOUBLE_QUOTE)
|
2023 | ) {
|
2024 | this.flag(node, '_waitingForEndQuote', curr.val);
|
2025 | appendTextValue(valueNode, curr);
|
2026 | return true;
|
2027 | }
|
2028 |
|
2029 | if (
|
2030 | curr.val === node._waitingForEndQuote
|
2031 | && !curr._considerEscaped
|
2032 | ) {
|
2033 | this.flag(node, '_waitingForEndQuote', null);
|
2034 | appendTextValue(valueNode, curr);
|
2035 | return true;
|
2036 | }
|
2037 |
|
2038 | appendTextValue(valueNode, curr);
|
2039 | return true;
|
2040 | }
|
2041 |
|
2042 | Parser.prototype.continueRegexNode = function(node, curr, next) {
|
2043 | var valueNode = ensureTextNode(node.values);
|
2044 |
|
2045 | if (
|
2046 | curr.type === tks.FORWARD_SLASH
|
2047 | && !node._waitingForForwardSlash
|
2048 | && !curr._considerEscaped
|
2049 | ) {
|
2050 |
|
2051 | this.flag(node, '_waitingForForwardSlash', true);
|
2052 | appendTextValue(valueNode, curr);
|
2053 | return true;
|
2054 | }
|
2055 |
|
2056 | if (
|
2057 | curr.type === tks.FORWARD_SLASH
|
2058 | && node._waitingForForwardSlash
|
2059 | && !curr._considerEscaped
|
2060 | ) {
|
2061 |
|
2062 | this.flag(node, '_waitingForForwardSlash', null);
|
2063 | this.flag(node, '_waitingForFlags', true);
|
2064 | appendTextValue(valueNode, curr);
|
2065 | return true;
|
2066 | }
|
2067 |
|
2068 | if (node._waitingForFlags) {
|
2069 | this.flag(node, '_waitingForFlags', null);
|
2070 | this.closeNode(node);
|
2071 |
|
2072 | if (curr.type === tks.IDENTIFIER) {
|
2073 | appendTextValue(valueNode, curr);
|
2074 | return true;
|
2075 | } else {
|
2076 | return false;
|
2077 | }
|
2078 | }
|
2079 |
|
2080 | if (
|
2081 | curr.type === tks.BACKSLASH
|
2082 | && !curr._considerEscaped
|
2083 | ) {
|
2084 | next._considerEscaped = true;
|
2085 | }
|
2086 |
|
2087 | appendTextValue(valueNode, curr);
|
2088 | return true;
|
2089 | }
|
2090 |
|
2091 | Parser.prototype.continueBlockNode = function(node, curr, next, ahead, nnwon) {
|
2092 |
|
2093 | var valueNode = node.values[node.values.length-1];
|
2094 |
|
2095 | if (curr.type === tks.AT_STAR_OPEN) {
|
2096 | this.openNode(new CommentNode(), node.body);
|
2097 | return false;
|
2098 | }
|
2099 |
|
2100 | if (curr.type === tks.DOUBLE_FORWARD_SLASH && !node._waitingForEndQuote) {
|
2101 | this.openNode(new CommentNode(), node.body);
|
2102 | return false;
|
2103 | }
|
2104 |
|
2105 | if (
|
2106 | curr.type === tks.AT_COLON
|
2107 | && (!node.hasBraces || node._reachedOpenBrace)
|
2108 | ) {
|
2109 | valueNode = this.openNode(new MarkupContentNode(), node.values);
|
2110 | return false;
|
2111 | }
|
2112 |
|
2113 | if (
|
2114 | (curr.type === tks.BLOCK_KEYWORD || curr.type === tks.FUNCTION)
|
2115 | && !node._reachedOpenBrace
|
2116 | && !node.keyword
|
2117 | ) {
|
2118 | this.flag(node, 'keyword', curr.val);
|
2119 | return true;
|
2120 | }
|
2121 |
|
2122 | if (
|
2123 | (curr.type === tks.BLOCK_KEYWORD || curr.type === tks.FUNCTION)
|
2124 | && !node._reachedOpenBrace
|
2125 | ) {
|
2126 |
|
2127 | this.flag(node, 'hasBraces', false);
|
2128 | valueNode = this.openNode(new BlockNode(), node.values);
|
2129 | updateLoc(valueNode, curr);
|
2130 | return false;
|
2131 | }
|
2132 |
|
2133 | if (
|
2134 | (curr.type === tks.BLOCK_KEYWORD || curr.type === tks.FUNCTION)
|
2135 | && !node._reachedCloseBrace
|
2136 | && node.hasBraces
|
2137 | && !node._waitingForEndQuote
|
2138 | ) {
|
2139 | valueNode = this.openNode(new BlockNode(), node.values);
|
2140 | updateLoc(valueNode, curr);
|
2141 | return false;
|
2142 | }
|
2143 |
|
2144 | if (
|
2145 | (curr.type === tks.BLOCK_KEYWORD || curr.type === tks.FUNCTION)
|
2146 | && node._reachedCloseBrace
|
2147 | && !node._waitingForEndQuote
|
2148 | ) {
|
2149 | valueNode = this.openNode(new BlockNode(), node.tail);
|
2150 | updateLoc(valueNode, curr);
|
2151 | return false;
|
2152 | }
|
2153 |
|
2154 | if (
|
2155 | curr.type === tks.BRACE_OPEN
|
2156 | && !node._reachedOpenBrace
|
2157 | && !node._waitingForEndQuote
|
2158 | ) {
|
2159 | this.flag(node, '_reachedOpenBrace', true);
|
2160 | this.flag(node, 'hasBraces', true);
|
2161 | if (this.opts.favorText) {
|
2162 | valueNode = this.openNode(new MarkupContentNode(), node.values);
|
2163 | updateLoc(valueNode, curr);
|
2164 | }
|
2165 | return true;
|
2166 | }
|
2167 |
|
2168 | if (
|
2169 | curr.type === tks.BRACE_OPEN
|
2170 | && !node._waitingForEndQuote
|
2171 | ) {
|
2172 | valueNode = this.openNode(new BlockNode(), node.values);
|
2173 | updateLoc(valueNode, curr);
|
2174 | return false;
|
2175 | }
|
2176 |
|
2177 | if (
|
2178 | curr.type === tks.BRACE_CLOSE
|
2179 | && node.hasBraces
|
2180 | && !node._reachedCloseBrace
|
2181 | && !node._waitingForEndQuote
|
2182 | ) {
|
2183 | updateLoc(node, curr);
|
2184 | this.flag(node, '_reachedCloseBrace', true);
|
2185 |
|
2186 |
|
2187 |
|
2188 | if (
|
2189 | nnwon
|
2190 | && nnwon.type !== tks.BLOCK_KEYWORD
|
2191 | ) {
|
2192 | this.closeNode(node);
|
2193 | }
|
2194 |
|
2195 | return true;
|
2196 | }
|
2197 |
|
2198 | if (
|
2199 | curr.type === tks.BRACE_CLOSE
|
2200 | && !node.hasBraces
|
2201 | ) {
|
2202 |
|
2203 |
|
2204 | this.closeNode(node);
|
2205 | updateLoc(node, curr);
|
2206 | return false;
|
2207 | }
|
2208 |
|
2209 | if (
|
2210 | curr.type === tks.LT_SIGN
|
2211 | && (next.type === tks.AT || next.type === tks.IDENTIFIER)
|
2212 | && !node._waitingForEndQuote
|
2213 | && node._reachedCloseBrace
|
2214 | ) {
|
2215 | this.closeNode(node);
|
2216 | updateLoc(node, curr);
|
2217 | return false;
|
2218 | }
|
2219 |
|
2220 | if (
|
2221 | curr.type === tks.LT_SIGN
|
2222 | && (next.type === tks.AT || next.type === tks.IDENTIFIER)
|
2223 | && !node._waitingForEndQuote
|
2224 | && !node._reachedCloseBrace
|
2225 | ) {
|
2226 | valueNode = this.openNode(new MarkupNode(), node.values);
|
2227 | updateLoc(valueNode, curr);
|
2228 | return false;
|
2229 | }
|
2230 |
|
2231 | if (curr.type === tks.HTML_TAG_CLOSE) {
|
2232 | if (
|
2233 | (node.hasBraces && node._reachedCloseBrace)
|
2234 | || !node._reachedOpenBrace
|
2235 | ) {
|
2236 | updateLoc(node, curr);
|
2237 | this.closeNode(node);
|
2238 | return false;
|
2239 | }
|
2240 |
|
2241 |
|
2242 |
|
2243 |
|
2244 |
|
2245 | if (
|
2246 | next
|
2247 | && next.type === tks.IDENTIFIER
|
2248 | && MarkupNode.isVoid(next.val)
|
2249 | ){
|
2250 | throw newUnexpectedClosingTagError(this, curr, curr.val + next.val);
|
2251 | }
|
2252 | }
|
2253 |
|
2254 | if (
|
2255 | curr.type === tks.AT
|
2256 | && (next.type === tks.BLOCK_KEYWORD
|
2257 | || next.type === tks.BRACE_OPEN
|
2258 | || next.type === tks.FUNCTION)
|
2259 | ) {
|
2260 |
|
2261 | valueNode = this.openNode(new BlockNode(), node.values);
|
2262 | updateLoc(valueNode, curr);
|
2263 |
|
2264 | return true;
|
2265 | }
|
2266 |
|
2267 | if (
|
2268 | curr.type === tks.AT && next.type === tks.PAREN_OPEN
|
2269 | ) {
|
2270 |
|
2271 | valueNode = this.openNode(new ExpressionNode(), node.values);
|
2272 | updateLoc(valueNode, curr);
|
2273 | return true;
|
2274 | }
|
2275 |
|
2276 | var attachmentNode;
|
2277 |
|
2278 | if (node._reachedOpenBrace && node._reachedCloseBrace) {
|
2279 | attachmentNode = node.tail;
|
2280 | } else if (!node._reachedOpenBrace) {
|
2281 | attachmentNode = node.head;
|
2282 | } else {
|
2283 | attachmentNode = node.values;
|
2284 | }
|
2285 |
|
2286 | valueNode = attachmentNode[attachmentNode.length-1];
|
2287 |
|
2288 | if (
|
2289 | curr.type === tks.AT
|
2290 | && next.type === tks.IDENTIFIER
|
2291 | && !node._waitingForEndQuote
|
2292 | ) {
|
2293 |
|
2294 | if (node._reachedCloseBrace) {
|
2295 | this.closeNode(node);
|
2296 | return false;
|
2297 | } else {
|
2298 |
|
2299 | valueNode = this.openNode(new MarkupContentNode(), attachmentNode);
|
2300 | updateLoc(valueNode, curr);
|
2301 | return false;
|
2302 | }
|
2303 | }
|
2304 |
|
2305 | if (
|
2306 | curr.type !== tks.BLOCK_KEYWORD
|
2307 | && curr.type !== tks.PAREN_OPEN
|
2308 | && curr.type !== tks.WHITESPACE
|
2309 | && curr.type !== tks.NEWLINE
|
2310 | && node.hasBraces
|
2311 | && node._reachedCloseBrace
|
2312 | ) {
|
2313 |
|
2314 | updateLoc(node, curr);
|
2315 | this.closeNode(node);
|
2316 | return false;
|
2317 | }
|
2318 |
|
2319 | if (curr.type === tks.PAREN_OPEN) {
|
2320 | valueNode = this.openNode(new ExplicitExpressionNode(), attachmentNode);
|
2321 | updateLoc(valueNode, curr);
|
2322 | return false;
|
2323 | }
|
2324 |
|
2325 | valueNode = ensureTextNode(attachmentNode);
|
2326 |
|
2327 | if (
|
2328 | curr.val === node._waitingForEndQuote
|
2329 | && !curr._considerEscaped
|
2330 | ) {
|
2331 | this.flag(node, '_waitingForEndQuote', null);
|
2332 | appendTextValue(valueNode, curr);
|
2333 | return true;
|
2334 | }
|
2335 |
|
2336 | if (
|
2337 | !node._waitingForEndQuote
|
2338 | && (curr.type === tks.DOUBLE_QUOTE || curr.type === tks.SINGLE_QUOTE)
|
2339 | ) {
|
2340 | this.flag(node, '_waitingForEndQuote', curr.val);
|
2341 | appendTextValue(valueNode, curr);
|
2342 | return true;
|
2343 | }
|
2344 |
|
2345 | var pnw = this.previousNonWhitespace;
|
2346 |
|
2347 | if (
|
2348 | curr.type === tks.FORWARD_SLASH
|
2349 | && !node._waitingForEndQuote
|
2350 | && pnw
|
2351 | && pnw.type !== tks.IDENTIFIER
|
2352 | && pnw.type !== tks.NUMERAL
|
2353 | ) {
|
2354 |
|
2355 | valueNode = this.openNode(new RegexNode(), attachmentNode);
|
2356 | updateLoc(valueNode, curr);
|
2357 | return false;
|
2358 | }
|
2359 |
|
2360 | appendTextValue(valueNode, curr);
|
2361 | return true;
|
2362 | }
|
2363 |
|
2364 |
|
2365 |
|
2366 |
|
2367 | Parser.prototype.continueIndexExpressionNode = function(node, curr, next) {
|
2368 | var valueNode = node.values[node.values.length-1];
|
2369 |
|
2370 | if (node._waitingForEndQuote) {
|
2371 | if (curr.val === node._waitingForEndQuote) {
|
2372 | this.flag(node, '_waitingForEndQuote', null);
|
2373 | }
|
2374 |
|
2375 | appendTextValue(valueNode, curr);
|
2376 | return true;
|
2377 | }
|
2378 |
|
2379 | if (
|
2380 | curr.type === tks.HARD_PAREN_OPEN
|
2381 | && !valueNode
|
2382 | ) {
|
2383 | this.flag(node, '_waitingForHardParenClose', true);
|
2384 | updateLoc(node, curr);
|
2385 | return true;
|
2386 | }
|
2387 |
|
2388 | if (curr.type === tks.HARD_PAREN_CLOSE) {
|
2389 | this.flag(node, '_waitingForHardParenClose', false);
|
2390 | this.closeNode(node);
|
2391 | updateLoc(node, curr);
|
2392 | return true;
|
2393 | }
|
2394 |
|
2395 | if (curr.type === tks.PAREN_OPEN) {
|
2396 | valueNode = this.openNode(new ExplicitExpressionNode(), node.values);
|
2397 | updateLoc(valueNode, curr);
|
2398 | return false;
|
2399 | }
|
2400 |
|
2401 | valueNode = ensureTextNode(node.values);
|
2402 |
|
2403 | if (!node._waitingForEndQuote
|
2404 | && (curr.type === tks.DOUBLE_QUOTE
|
2405 | || curr.type === tks.SINGLE_QUOTE)
|
2406 | ) {
|
2407 | this.flag(node, '_waitingForEndQuote', curr.val);
|
2408 | appendTextValue(valueNode, curr);
|
2409 | return true;
|
2410 | }
|
2411 |
|
2412 |
|
2413 |
|
2414 | appendTextValue(valueNode, curr);
|
2415 | return true;
|
2416 | }
|
2417 |
|
2418 | function updateLoc(node, token) {
|
2419 | var loc;
|
2420 | loc = new LocationNode();
|
2421 | loc.line = token.line;
|
2422 | loc.column = token.chr;
|
2423 |
|
2424 | if (node.startloc === null) {
|
2425 | node.startloc = loc;
|
2426 | }
|
2427 |
|
2428 | node.endloc = loc;
|
2429 | }
|
2430 |
|
2431 | function ensureTextNode(valueList) {
|
2432 | var valueNode = valueList[valueList.length-1];
|
2433 |
|
2434 | if (!valueNode || valueNode.type !== 'VashText') {
|
2435 | valueNode = new TextNode();
|
2436 | valueList.push(valueNode);
|
2437 | }
|
2438 |
|
2439 | return valueNode;
|
2440 | }
|
2441 |
|
2442 | function appendTextValue(textNode, token) {
|
2443 | if (!('value' in textNode)) {
|
2444 | var msg = 'Expected TextNode but found ' + textNode.type
|
2445 | + ' when appending token ' + token;
|
2446 | throw new Error(msg);
|
2447 | }
|
2448 |
|
2449 | textNode.value += token.val;
|
2450 | updateLoc(textNode, token);
|
2451 | }
|
2452 |
|
2453 | function newUnexpectedClosingTagError(parser, tok, tagName) {
|
2454 | var err = new Error(''
|
2455 | + 'Found a closing tag for a known void HTML element: '
|
2456 | + tagName + '.');
|
2457 | err.name = 'UnexpectedClosingTagError';
|
2458 | return parser.decorateError(
|
2459 | err,
|
2460 | tok.line,
|
2461 | tok.chr);
|
2462 | }
|
2463 |
|
2464 |
|
2465 | },{"./error":3,"./nodes/block":10,"./nodes/comment":11,"./nodes/explicitexpression":12,"./nodes/expression":13,"./nodes/indexexpression":14,"./nodes/location":15,"./nodes/markup":16,"./nodes/markupattribute":17,"./nodes/markupcomment":18,"./nodes/markupcontent":19,"./nodes/program":20,"./nodes/regex":21,"./nodes/text":22,"./nodestuff":23,"./tokens":25,"./util/fn-namer":27,"debug":29}],25:[function(require,module,exports){
|
2466 |
|
2467 |
|
2468 |
|
2469 |
|
2470 |
|
2471 |
|
2472 |
|
2473 |
|
2474 |
|
2475 |
|
2476 |
|
2477 |
|
2478 | var TESTS = [
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 | 'EMAIL', (/^([a-zA-Z0-9.%]+@[a-zA-Z0-9.\-]+\.(?:[a-z]{2}|co\.uk|com|edu|net|org))\b/)
|
2491 |
|
2492 | , 'AT_STAR_OPEN', (/^(@\*)/)
|
2493 | , 'AT_STAR_CLOSE', (/^(\*@)/)
|
2494 |
|
2495 |
|
2496 | , 'AT_COLON', (/^(@\:)/)
|
2497 | , 'AT', (/^(@)/)
|
2498 |
|
2499 |
|
2500 | , 'PAREN_OPEN', (/^(\()/)
|
2501 | , 'PAREN_CLOSE', (/^(\))/)
|
2502 |
|
2503 |
|
2504 | , 'HARD_PAREN_OPEN', (/^(\[)/)
|
2505 | , 'HARD_PAREN_CLOSE', (/^(\])/)
|
2506 |
|
2507 |
|
2508 | , 'BRACE_OPEN', (/^(\{)/)
|
2509 | , 'BRACE_CLOSE', (/^(\})/)
|
2510 |
|
2511 |
|
2512 | , 'HTML_TAG_VOID_CLOSE', (/^(\/>)/)
|
2513 | , 'HTML_TAG_CLOSE', (/^(<\/)/)
|
2514 | , 'HTML_COMMENT_OPEN', (/^(<!--+)/)
|
2515 | , 'HTML_COMMENT_CLOSE', (/^(--+>)/)
|
2516 | , 'LT_SIGN', (/^(<)/)
|
2517 | , 'GT_SIGN', (/^(>)/)
|
2518 |
|
2519 | , 'ASSIGNMENT_OPERATOR', (/^(\|=|\^=|&=|>>>=|>>=|<<=|-=|\+=|%=|\/=|\*=)\b/)
|
2520 | , 'EQUALITY_OPERATOR', (/^(===|==|!==|!=)\b/)
|
2521 | , 'BITWISE_SHIFT_OPERATOR', (/^(<<|>>>|>>)/)
|
2522 | , 'UNARY_OPERATOR', (/^(delete\b|typeof\b|void|\+\+|--|\+|-|~|!)/)
|
2523 | , 'RELATIONAL_OPERATOR', (/^(<=|>=|instanceof|in)\b/)
|
2524 | , 'BINARY_LOGICAL_OPERATOR', (/^(&&|\|\|)\b/)
|
2525 | , 'BINARY_BITWISE_OPERATOR', (/^(&|\^|\|)\b/)
|
2526 | , 'NEW_OPERATOR', (/^(new)\b/)
|
2527 | , 'COMMA_OPERATOR', (/^(,)/)
|
2528 |
|
2529 | , 'EQUAL_SIGN', (/^(=)/)
|
2530 | , 'COLON', (/^(:)/)
|
2531 | , 'PERIOD', (/^(\.)/)
|
2532 | , 'NEWLINE', function(){
|
2533 | var token = this.scan(/^(\n)/, exports.NEWLINE);
|
2534 | if(token){
|
2535 | this.lineno++;
|
2536 | this.charno = 0;
|
2537 | }
|
2538 | return token;
|
2539 | }
|
2540 | , 'WHITESPACE', (/^([^\S\n]+)/)
|
2541 | , 'FUNCTION', (/^(function)(?![\d\w])/)
|
2542 | , 'BLOCK_KEYWORD', (/^(catch|do|else if|else|finally|for|function|goto|if|switch|try|while|with)(?![\d\w])/)
|
2543 | , 'KEYWORD', (/^(break|case|continue|instanceof|return|var)(?![\d\w])/)
|
2544 | , 'IDENTIFIER', (/^([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)/)
|
2545 |
|
2546 | , 'DOUBLE_FORWARD_SLASH', (/^(\/\/)/)
|
2547 |
|
2548 | , 'FORWARD_SLASH', (/^(\/)/)
|
2549 |
|
2550 | , 'BACKSLASH', (/^(\\)/)
|
2551 | , 'EXCLAMATION_POINT', (/^(!)/)
|
2552 | , 'DOUBLE_QUOTE', (/^(\")/)
|
2553 | , 'SINGLE_QUOTE', (/^(\')/)
|
2554 |
|
2555 | , 'NUMERAL', (/^([0-9])/)
|
2556 | , 'CONTENT', (/^([^\s])/)
|
2557 |
|
2558 | ];
|
2559 |
|
2560 | exports.tests = TESTS;
|
2561 |
|
2562 |
|
2563 | for(var i = 0; i < TESTS.length; i += 2) {
|
2564 | exports[TESTS[i]] = TESTS[i];
|
2565 | }
|
2566 | },{}],26:[function(require,module,exports){
|
2567 | module.exports = function(obj) {
|
2568 |
|
2569 | var next, i, p;
|
2570 |
|
2571 | for(i = 1; i < arguments.length; i++){
|
2572 | next = arguments[i];
|
2573 |
|
2574 | for(p in next){
|
2575 | obj[p] = next[p];
|
2576 | }
|
2577 | }
|
2578 |
|
2579 | return obj;
|
2580 | }
|
2581 | },{}],27:[function(require,module,exports){
|
2582 | var lg = require('debug')('vash:fn-namer');
|
2583 | var reName = /^function\s+([A-Za-z0-9_]+)\s*\(/;
|
2584 |
|
2585 | module.exports = function(fn) {
|
2586 | if (fn.name) {
|
2587 | lg('bailing, found .name %s', fn.name);
|
2588 | return fn;
|
2589 | }
|
2590 | var fnstr = fn.toString();
|
2591 | var match = reName.exec(fnstr);
|
2592 | if (!match) {
|
2593 | lg('bailing, could not match within %s', fnstr);
|
2594 | return fn;
|
2595 | }
|
2596 | fn.name = match[1];
|
2597 | lg('set .name as %s', fn.name);
|
2598 | return fn;
|
2599 | }
|
2600 | },{"debug":29}],28:[function(require,module,exports){
|
2601 |
|
2602 | },{}],29:[function(require,module,exports){
|
2603 |
|
2604 |
|
2605 |
|
2606 |
|
2607 |
|
2608 |
|
2609 |
|
2610 | exports = module.exports = require('./debug');
|
2611 | exports.log = log;
|
2612 | exports.formatArgs = formatArgs;
|
2613 | exports.save = save;
|
2614 | exports.load = load;
|
2615 | exports.useColors = useColors;
|
2616 | exports.storage = 'undefined' != typeof chrome
|
2617 | && 'undefined' != typeof chrome.storage
|
2618 | ? chrome.storage.local
|
2619 | : localstorage();
|
2620 |
|
2621 |
|
2622 |
|
2623 |
|
2624 |
|
2625 | exports.colors = [
|
2626 | 'lightseagreen',
|
2627 | 'forestgreen',
|
2628 | 'goldenrod',
|
2629 | 'dodgerblue',
|
2630 | 'darkorchid',
|
2631 | 'crimson'
|
2632 | ];
|
2633 |
|
2634 |
|
2635 |
|
2636 |
|
2637 |
|
2638 |
|
2639 |
|
2640 |
|
2641 |
|
2642 | function useColors() {
|
2643 |
|
2644 | return ('WebkitAppearance' in document.documentElement.style) ||
|
2645 |
|
2646 | (window.console && (console.firebug || (console.exception && console.table))) ||
|
2647 |
|
2648 |
|
2649 | (navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31);
|
2650 | }
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 | exports.formatters.j = function(v) {
|
2657 | return JSON.stringify(v);
|
2658 | };
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 | function formatArgs() {
|
2668 | var args = arguments;
|
2669 | var useColors = this.useColors;
|
2670 |
|
2671 | args[0] = (useColors ? '%c' : '')
|
2672 | + this.namespace
|
2673 | + (useColors ? ' %c' : ' ')
|
2674 | + args[0]
|
2675 | + (useColors ? '%c ' : ' ')
|
2676 | + '+' + exports.humanize(this.diff);
|
2677 |
|
2678 | if (!useColors) return args;
|
2679 |
|
2680 | var c = 'color: ' + this.color;
|
2681 | args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1));
|
2682 |
|
2683 |
|
2684 |
|
2685 |
|
2686 | var index = 0;
|
2687 | var lastC = 0;
|
2688 | args[0].replace(/%[a-z%]/g, function(match) {
|
2689 | if ('%%' === match) return;
|
2690 | index++;
|
2691 | if ('%c' === match) {
|
2692 |
|
2693 |
|
2694 | lastC = index;
|
2695 | }
|
2696 | });
|
2697 |
|
2698 | args.splice(lastC, 0, c);
|
2699 | return args;
|
2700 | }
|
2701 |
|
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 |
|
2708 |
|
2709 | function log() {
|
2710 |
|
2711 |
|
2712 | return 'object' === typeof console
|
2713 | && console.log
|
2714 | && Function.prototype.apply.call(console.log, console, arguments);
|
2715 | }
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 |
|
2723 |
|
2724 | function save(namespaces) {
|
2725 | try {
|
2726 | if (null == namespaces) {
|
2727 | exports.storage.removeItem('debug');
|
2728 | } else {
|
2729 | exports.storage.debug = namespaces;
|
2730 | }
|
2731 | } catch(e) {}
|
2732 | }
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 |
|
2740 |
|
2741 | function load() {
|
2742 | var r;
|
2743 | try {
|
2744 | r = exports.storage.debug;
|
2745 | } catch(e) {}
|
2746 | return r;
|
2747 | }
|
2748 |
|
2749 |
|
2750 |
|
2751 |
|
2752 |
|
2753 | exports.enable(load());
|
2754 |
|
2755 |
|
2756 |
|
2757 |
|
2758 |
|
2759 |
|
2760 |
|
2761 |
|
2762 |
|
2763 |
|
2764 |
|
2765 |
|
2766 | function localstorage(){
|
2767 | try {
|
2768 | return window.localStorage;
|
2769 | } catch (e) {}
|
2770 | }
|
2771 |
|
2772 | },{"./debug":30}],30:[function(require,module,exports){
|
2773 |
|
2774 |
|
2775 |
|
2776 |
|
2777 |
|
2778 |
|
2779 |
|
2780 |
|
2781 | exports = module.exports = debug;
|
2782 | exports.coerce = coerce;
|
2783 | exports.disable = disable;
|
2784 | exports.enable = enable;
|
2785 | exports.enabled = enabled;
|
2786 | exports.humanize = require('ms');
|
2787 |
|
2788 |
|
2789 |
|
2790 |
|
2791 |
|
2792 | exports.names = [];
|
2793 | exports.skips = [];
|
2794 |
|
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 | exports.formatters = {};
|
2802 |
|
2803 |
|
2804 |
|
2805 |
|
2806 |
|
2807 | var prevColor = 0;
|
2808 |
|
2809 |
|
2810 |
|
2811 |
|
2812 |
|
2813 | var prevTime;
|
2814 |
|
2815 |
|
2816 |
|
2817 |
|
2818 |
|
2819 |
|
2820 |
|
2821 |
|
2822 | function selectColor() {
|
2823 | return exports.colors[prevColor++ % exports.colors.length];
|
2824 | }
|
2825 |
|
2826 |
|
2827 |
|
2828 |
|
2829 |
|
2830 |
|
2831 |
|
2832 |
|
2833 |
|
2834 | function debug(namespace) {
|
2835 |
|
2836 |
|
2837 | function disabled() {
|
2838 | }
|
2839 | disabled.enabled = false;
|
2840 |
|
2841 |
|
2842 | function enabled() {
|
2843 |
|
2844 | var self = enabled;
|
2845 |
|
2846 |
|
2847 | var curr = +new Date();
|
2848 | var ms = curr - (prevTime || curr);
|
2849 | self.diff = ms;
|
2850 | self.prev = prevTime;
|
2851 | self.curr = curr;
|
2852 | prevTime = curr;
|
2853 |
|
2854 |
|
2855 | if (null == self.useColors) self.useColors = exports.useColors();
|
2856 | if (null == self.color && self.useColors) self.color = selectColor();
|
2857 |
|
2858 | var args = Array.prototype.slice.call(arguments);
|
2859 |
|
2860 | args[0] = exports.coerce(args[0]);
|
2861 |
|
2862 | if ('string' !== typeof args[0]) {
|
2863 |
|
2864 | args = ['%o'].concat(args);
|
2865 | }
|
2866 |
|
2867 |
|
2868 | var index = 0;
|
2869 | args[0] = args[0].replace(/%([a-z%])/g, function(match, format) {
|
2870 |
|
2871 | if (match === '%%') return match;
|
2872 | index++;
|
2873 | var formatter = exports.formatters[format];
|
2874 | if ('function' === typeof formatter) {
|
2875 | var val = args[index];
|
2876 | match = formatter.call(self, val);
|
2877 |
|
2878 |
|
2879 | args.splice(index, 1);
|
2880 | index--;
|
2881 | }
|
2882 | return match;
|
2883 | });
|
2884 |
|
2885 | if ('function' === typeof exports.formatArgs) {
|
2886 | args = exports.formatArgs.apply(self, args);
|
2887 | }
|
2888 | var logFn = enabled.log || exports.log || console.log.bind(console);
|
2889 | logFn.apply(self, args);
|
2890 | }
|
2891 | enabled.enabled = true;
|
2892 |
|
2893 | var fn = exports.enabled(namespace) ? enabled : disabled;
|
2894 |
|
2895 | fn.namespace = namespace;
|
2896 |
|
2897 | return fn;
|
2898 | }
|
2899 |
|
2900 |
|
2901 |
|
2902 |
|
2903 |
|
2904 |
|
2905 |
|
2906 |
|
2907 |
|
2908 | function enable(namespaces) {
|
2909 | exports.save(namespaces);
|
2910 |
|
2911 | var split = (namespaces || '').split(/[\s,]+/);
|
2912 | var len = split.length;
|
2913 |
|
2914 | for (var i = 0; i < len; i++) {
|
2915 | if (!split[i]) continue;
|
2916 | namespaces = split[i].replace(/\*/g, '.*?');
|
2917 | if (namespaces[0] === '-') {
|
2918 | exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
2919 | } else {
|
2920 | exports.names.push(new RegExp('^' + namespaces + '$'));
|
2921 | }
|
2922 | }
|
2923 | }
|
2924 |
|
2925 |
|
2926 |
|
2927 |
|
2928 |
|
2929 |
|
2930 |
|
2931 | function disable() {
|
2932 | exports.enable('');
|
2933 | }
|
2934 |
|
2935 |
|
2936 |
|
2937 |
|
2938 |
|
2939 |
|
2940 |
|
2941 |
|
2942 |
|
2943 | function enabled(name) {
|
2944 | var i, len;
|
2945 | for (i = 0, len = exports.skips.length; i < len; i++) {
|
2946 | if (exports.skips[i].test(name)) {
|
2947 | return false;
|
2948 | }
|
2949 | }
|
2950 | for (i = 0, len = exports.names.length; i < len; i++) {
|
2951 | if (exports.names[i].test(name)) {
|
2952 | return true;
|
2953 | }
|
2954 | }
|
2955 | return false;
|
2956 | }
|
2957 |
|
2958 |
|
2959 |
|
2960 |
|
2961 |
|
2962 |
|
2963 |
|
2964 |
|
2965 |
|
2966 | function coerce(val) {
|
2967 | if (val instanceof Error) return val.stack || val.message;
|
2968 | return val;
|
2969 | }
|
2970 |
|
2971 | },{"ms":31}],31:[function(require,module,exports){
|
2972 |
|
2973 |
|
2974 |
|
2975 |
|
2976 | var s = 1000;
|
2977 | var m = s * 60;
|
2978 | var h = m * 60;
|
2979 | var d = h * 24;
|
2980 | var y = d * 365.25;
|
2981 |
|
2982 |
|
2983 |
|
2984 |
|
2985 |
|
2986 |
|
2987 |
|
2988 |
|
2989 |
|
2990 |
|
2991 |
|
2992 |
|
2993 |
|
2994 |
|
2995 | module.exports = function(val, options){
|
2996 | options = options || {};
|
2997 | if ('string' == typeof val) return parse(val);
|
2998 | return options.long
|
2999 | ? long(val)
|
3000 | : short(val);
|
3001 | };
|
3002 |
|
3003 |
|
3004 |
|
3005 |
|
3006 |
|
3007 |
|
3008 |
|
3009 |
|
3010 |
|
3011 | function parse(str) {
|
3012 | str = '' + str;
|
3013 | if (str.length > 10000) return;
|
3014 | var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
|
3015 | if (!match) return;
|
3016 | var n = parseFloat(match[1]);
|
3017 | var type = (match[2] || 'ms').toLowerCase();
|
3018 | switch (type) {
|
3019 | case 'years':
|
3020 | case 'year':
|
3021 | case 'yrs':
|
3022 | case 'yr':
|
3023 | case 'y':
|
3024 | return n * y;
|
3025 | case 'days':
|
3026 | case 'day':
|
3027 | case 'd':
|
3028 | return n * d;
|
3029 | case 'hours':
|
3030 | case 'hour':
|
3031 | case 'hrs':
|
3032 | case 'hr':
|
3033 | case 'h':
|
3034 | return n * h;
|
3035 | case 'minutes':
|
3036 | case 'minute':
|
3037 | case 'mins':
|
3038 | case 'min':
|
3039 | case 'm':
|
3040 | return n * m;
|
3041 | case 'seconds':
|
3042 | case 'second':
|
3043 | case 'secs':
|
3044 | case 'sec':
|
3045 | case 's':
|
3046 | return n * s;
|
3047 | case 'milliseconds':
|
3048 | case 'millisecond':
|
3049 | case 'msecs':
|
3050 | case 'msec':
|
3051 | case 'ms':
|
3052 | return n;
|
3053 | }
|
3054 | }
|
3055 |
|
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 |
|
3062 |
|
3063 |
|
3064 | function short(ms) {
|
3065 | if (ms >= d) return Math.round(ms / d) + 'd';
|
3066 | if (ms >= h) return Math.round(ms / h) + 'h';
|
3067 | if (ms >= m) return Math.round(ms / m) + 'm';
|
3068 | if (ms >= s) return Math.round(ms / s) + 's';
|
3069 | return ms + 'ms';
|
3070 | }
|
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 |
|
3077 |
|
3078 |
|
3079 |
|
3080 | function long(ms) {
|
3081 | return plural(ms, d, 'day')
|
3082 | || plural(ms, h, 'hour')
|
3083 | || plural(ms, m, 'minute')
|
3084 | || plural(ms, s, 'second')
|
3085 | || ms + ' ms';
|
3086 | }
|
3087 |
|
3088 |
|
3089 |
|
3090 |
|
3091 |
|
3092 | function plural(ms, n, name) {
|
3093 | if (ms < n) return;
|
3094 | if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
|
3095 | return Math.ceil(ms / n) + ' ' + name + 's';
|
3096 | }
|
3097 |
|
3098 | },{}],32:[function(require,module,exports){
|
3099 | (function (process){
|
3100 |
|
3101 |
|
3102 |
|
3103 |
|
3104 |
|
3105 |
|
3106 |
|
3107 |
|
3108 |
|
3109 |
|
3110 |
|
3111 |
|
3112 |
|
3113 |
|
3114 |
|
3115 |
|
3116 |
|
3117 |
|
3118 |
|
3119 |
|
3120 |
|
3121 |
|
3122 |
|
3123 |
|
3124 |
|
3125 | function normalizeArray(parts, allowAboveRoot) {
|
3126 |
|
3127 | var up = 0;
|
3128 | for (var i = parts.length - 1; i >= 0; i--) {
|
3129 | var last = parts[i];
|
3130 | if (last === '.') {
|
3131 | parts.splice(i, 1);
|
3132 | } else if (last === '..') {
|
3133 | parts.splice(i, 1);
|
3134 | up++;
|
3135 | } else if (up) {
|
3136 | parts.splice(i, 1);
|
3137 | up--;
|
3138 | }
|
3139 | }
|
3140 |
|
3141 |
|
3142 | if (allowAboveRoot) {
|
3143 | for (; up--; up) {
|
3144 | parts.unshift('..');
|
3145 | }
|
3146 | }
|
3147 |
|
3148 | return parts;
|
3149 | }
|
3150 |
|
3151 |
|
3152 |
|
3153 | var splitPathRe =
|
3154 | /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
|
3155 | var splitPath = function(filename) {
|
3156 | return splitPathRe.exec(filename).slice(1);
|
3157 | };
|
3158 |
|
3159 |
|
3160 |
|
3161 | exports.resolve = function() {
|
3162 | var resolvedPath = '',
|
3163 | resolvedAbsolute = false;
|
3164 |
|
3165 | for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
3166 | var path = (i >= 0) ? arguments[i] : process.cwd();
|
3167 |
|
3168 |
|
3169 | if (typeof path !== 'string') {
|
3170 | throw new TypeError('Arguments to path.resolve must be strings');
|
3171 | } else if (!path) {
|
3172 | continue;
|
3173 | }
|
3174 |
|
3175 | resolvedPath = path + '/' + resolvedPath;
|
3176 | resolvedAbsolute = path.charAt(0) === '/';
|
3177 | }
|
3178 |
|
3179 |
|
3180 |
|
3181 |
|
3182 |
|
3183 | resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
|
3184 | return !!p;
|
3185 | }), !resolvedAbsolute).join('/');
|
3186 |
|
3187 | return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
3188 | };
|
3189 |
|
3190 |
|
3191 |
|
3192 | exports.normalize = function(path) {
|
3193 | var isAbsolute = exports.isAbsolute(path),
|
3194 | trailingSlash = substr(path, -1) === '/';
|
3195 |
|
3196 |
|
3197 | path = normalizeArray(filter(path.split('/'), function(p) {
|
3198 | return !!p;
|
3199 | }), !isAbsolute).join('/');
|
3200 |
|
3201 | if (!path && !isAbsolute) {
|
3202 | path = '.';
|
3203 | }
|
3204 | if (path && trailingSlash) {
|
3205 | path += '/';
|
3206 | }
|
3207 |
|
3208 | return (isAbsolute ? '/' : '') + path;
|
3209 | };
|
3210 |
|
3211 |
|
3212 | exports.isAbsolute = function(path) {
|
3213 | return path.charAt(0) === '/';
|
3214 | };
|
3215 |
|
3216 |
|
3217 | exports.join = function() {
|
3218 | var paths = Array.prototype.slice.call(arguments, 0);
|
3219 | return exports.normalize(filter(paths, function(p, index) {
|
3220 | if (typeof p !== 'string') {
|
3221 | throw new TypeError('Arguments to path.join must be strings');
|
3222 | }
|
3223 | return p;
|
3224 | }).join('/'));
|
3225 | };
|
3226 |
|
3227 |
|
3228 |
|
3229 |
|
3230 | exports.relative = function(from, to) {
|
3231 | from = exports.resolve(from).substr(1);
|
3232 | to = exports.resolve(to).substr(1);
|
3233 |
|
3234 | function trim(arr) {
|
3235 | var start = 0;
|
3236 | for (; start < arr.length; start++) {
|
3237 | if (arr[start] !== '') break;
|
3238 | }
|
3239 |
|
3240 | var end = arr.length - 1;
|
3241 | for (; end >= 0; end--) {
|
3242 | if (arr[end] !== '') break;
|
3243 | }
|
3244 |
|
3245 | if (start > end) return [];
|
3246 | return arr.slice(start, end - start + 1);
|
3247 | }
|
3248 |
|
3249 | var fromParts = trim(from.split('/'));
|
3250 | var toParts = trim(to.split('/'));
|
3251 |
|
3252 | var length = Math.min(fromParts.length, toParts.length);
|
3253 | var samePartsLength = length;
|
3254 | for (var i = 0; i < length; i++) {
|
3255 | if (fromParts[i] !== toParts[i]) {
|
3256 | samePartsLength = i;
|
3257 | break;
|
3258 | }
|
3259 | }
|
3260 |
|
3261 | var outputParts = [];
|
3262 | for (var i = samePartsLength; i < fromParts.length; i++) {
|
3263 | outputParts.push('..');
|
3264 | }
|
3265 |
|
3266 | outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
3267 |
|
3268 | return outputParts.join('/');
|
3269 | };
|
3270 |
|
3271 | exports.sep = '/';
|
3272 | exports.delimiter = ':';
|
3273 |
|
3274 | exports.dirname = function(path) {
|
3275 | var result = splitPath(path),
|
3276 | root = result[0],
|
3277 | dir = result[1];
|
3278 |
|
3279 | if (!root && !dir) {
|
3280 |
|
3281 | return '.';
|
3282 | }
|
3283 |
|
3284 | if (dir) {
|
3285 |
|
3286 | dir = dir.substr(0, dir.length - 1);
|
3287 | }
|
3288 |
|
3289 | return root + dir;
|
3290 | };
|
3291 |
|
3292 |
|
3293 | exports.basename = function(path, ext) {
|
3294 | var f = splitPath(path)[2];
|
3295 |
|
3296 | if (ext && f.substr(-1 * ext.length) === ext) {
|
3297 | f = f.substr(0, f.length - ext.length);
|
3298 | }
|
3299 | return f;
|
3300 | };
|
3301 |
|
3302 |
|
3303 | exports.extname = function(path) {
|
3304 | return splitPath(path)[3];
|
3305 | };
|
3306 |
|
3307 | function filter (xs, f) {
|
3308 | if (xs.filter) return xs.filter(f);
|
3309 | var res = [];
|
3310 | for (var i = 0; i < xs.length; i++) {
|
3311 | if (f(xs[i], i, xs)) res.push(xs[i]);
|
3312 | }
|
3313 | return res;
|
3314 | }
|
3315 |
|
3316 |
|
3317 | var substr = 'ab'.substr(-1) === 'b'
|
3318 | ? function (str, start, len) { return str.substr(start, len) }
|
3319 | : function (str, start, len) {
|
3320 | if (start < 0) start = str.length + start;
|
3321 | return str.substr(start, len);
|
3322 | }
|
3323 | ;
|
3324 |
|
3325 | }).call(this,require('_process'))
|
3326 | },{"_process":33}],33:[function(require,module,exports){
|
3327 |
|
3328 |
|
3329 | var process = module.exports = {};
|
3330 | var queue = [];
|
3331 | var draining = false;
|
3332 | var currentQueue;
|
3333 | var queueIndex = -1;
|
3334 |
|
3335 | function cleanUpNextTick() {
|
3336 | draining = false;
|
3337 | if (currentQueue.length) {
|
3338 | queue = currentQueue.concat(queue);
|
3339 | } else {
|
3340 | queueIndex = -1;
|
3341 | }
|
3342 | if (queue.length) {
|
3343 | drainQueue();
|
3344 | }
|
3345 | }
|
3346 |
|
3347 | function drainQueue() {
|
3348 | if (draining) {
|
3349 | return;
|
3350 | }
|
3351 | var timeout = setTimeout(cleanUpNextTick);
|
3352 | draining = true;
|
3353 |
|
3354 | var len = queue.length;
|
3355 | while(len) {
|
3356 | currentQueue = queue;
|
3357 | queue = [];
|
3358 | while (++queueIndex < len) {
|
3359 | if (currentQueue) {
|
3360 | currentQueue[queueIndex].run();
|
3361 | }
|
3362 | }
|
3363 | queueIndex = -1;
|
3364 | len = queue.length;
|
3365 | }
|
3366 | currentQueue = null;
|
3367 | draining = false;
|
3368 | clearTimeout(timeout);
|
3369 | }
|
3370 |
|
3371 | process.nextTick = function (fun) {
|
3372 | var args = new Array(arguments.length - 1);
|
3373 | if (arguments.length > 1) {
|
3374 | for (var i = 1; i < arguments.length; i++) {
|
3375 | args[i - 1] = arguments[i];
|
3376 | }
|
3377 | }
|
3378 | queue.push(new Item(fun, args));
|
3379 | if (queue.length === 1 && !draining) {
|
3380 | setTimeout(drainQueue, 0);
|
3381 | }
|
3382 | };
|
3383 |
|
3384 |
|
3385 | function Item(fun, array) {
|
3386 | this.fun = fun;
|
3387 | this.array = array;
|
3388 | }
|
3389 | Item.prototype.run = function () {
|
3390 | this.fun.apply(null, this.array);
|
3391 | };
|
3392 | process.title = 'browser';
|
3393 | process.browser = true;
|
3394 | process.env = {};
|
3395 | process.argv = [];
|
3396 | process.version = '';
|
3397 | process.versions = {};
|
3398 |
|
3399 | function noop() {}
|
3400 |
|
3401 | process.on = noop;
|
3402 | process.addListener = noop;
|
3403 | process.once = noop;
|
3404 | process.off = noop;
|
3405 | process.removeListener = noop;
|
3406 | process.removeAllListeners = noop;
|
3407 | process.emit = noop;
|
3408 |
|
3409 | process.binding = function (name) {
|
3410 | throw new Error('process.binding is not supported');
|
3411 | };
|
3412 |
|
3413 | process.cwd = function () { return '/' };
|
3414 | process.chdir = function (dir) {
|
3415 | throw new Error('process.chdir is not supported');
|
3416 | };
|
3417 | process.umask = function() { return 0; };
|
3418 |
|
3419 | },{}],34:[function(require,module,exports){
|
3420 | module.exports={
|
3421 | "name": "vash",
|
3422 | "description": "Razor syntax for JS templating",
|
3423 | "version": "0.12.1",
|
3424 | "author": "Andrew Petersen <senofpeter@gmail.com>",
|
3425 | "homepage": "https://github.com/kirbysayshi/vash",
|
3426 | "bin": {
|
3427 | "vash": "./bin/vash"
|
3428 | },
|
3429 | "keywords": [
|
3430 | "razor",
|
3431 | "parser",
|
3432 | "template",
|
3433 | "express"
|
3434 | ],
|
3435 | "repository": {
|
3436 | "type": "git",
|
3437 | "url": "git://github.com/kirbysayshi/vash"
|
3438 | },
|
3439 | "main": "index.js",
|
3440 | "engines": {
|
3441 | "node": ">= 0.10"
|
3442 | },
|
3443 | "scripts": {
|
3444 | "prepublish": "npm run test && npm run build",
|
3445 | "coverage": "VASHPATH=../../index.js VASHRUNTIMEPATH=../../runtime.js browserify -t envify -t coverify test/vows/vash.test.js | node | coverify",
|
3446 | "build": "browserify index.js --standalone vash > build/vash.js && browserify --standalone vash runtime.js > build/vash-runtime.js && browserify --standalone vash --external fs --external path lib/helpers/index.js > build/vash-runtime-all.js",
|
3447 | "test": "VASHPATH=../../index.js VASHRUNTIMEPATH=../../runtime.js vows test/vows/vash.*.js --spec",
|
3448 | "docs": "scripts/docs.sh",
|
3449 | "docs-dev": "scripts/docs-dev.sh"
|
3450 | },
|
3451 | "dependencies": {
|
3452 | "commander": "~1.1.1",
|
3453 | "debug": "^2.2.0",
|
3454 | "uglify-js": "^2.6.2"
|
3455 | },
|
3456 | "devDependencies": {
|
3457 | "browserify": "^13.0.0",
|
3458 | "coverify": "^1.4.1",
|
3459 | "envify": "^3.4.0",
|
3460 | "jshint": "0.8.0",
|
3461 | "marked": "~0.2.8",
|
3462 | "semver": "~1",
|
3463 | "vows": "^0.8.1"
|
3464 | }
|
3465 | }
|
3466 |
|
3467 | },{}],35:[function(require,module,exports){
|
3468 |
|
3469 | var error = require('./lib/error');
|
3470 | var runtime = {
|
3471 | version: require('./package.json').version
|
3472 | };
|
3473 |
|
3474 | var helpers = runtime['helpers'];
|
3475 |
|
3476 | module.exports = runtime;
|
3477 |
|
3478 | function Helpers( model ) {
|
3479 | this.buffer = new Buffer();
|
3480 | this.model = model;
|
3481 | this.options = null;
|
3482 |
|
3483 | this.vl = 0;
|
3484 | this.vc = 0;
|
3485 | };
|
3486 |
|
3487 | runtime['helpers']
|
3488 | = helpers
|
3489 | = Helpers.prototype
|
3490 | = { constructor: Helpers, config: {}, tplcache: {} };
|
3491 |
|
3492 |
|
3493 |
|
3494 | helpers.toString = helpers.toHtmlString = function(){
|
3495 |
|
3496 | return this.buffer._vo.join('');
|
3497 | }
|
3498 |
|
3499 |
|
3500 |
|
3501 |
|
3502 | var HTML_REGEX = /[&<>"'`]/g
|
3503 | ,HTML_REPLACER = function(match) { return HTML_CHARS[match]; }
|
3504 | ,HTML_CHARS = {
|
3505 | "&": "&"
|
3506 | ,"<": "<"
|
3507 | ,">": ">"
|
3508 | ,'"': """
|
3509 | ,"'": "'"
|
3510 | ,"`": "`"
|
3511 | };
|
3512 |
|
3513 | helpers['raw'] = function( val ) {
|
3514 | var func = function() { return val; };
|
3515 |
|
3516 | val = val != null ? val : "";
|
3517 |
|
3518 | return {
|
3519 | toHtmlString: func
|
3520 | ,toString: func
|
3521 | };
|
3522 | };
|
3523 |
|
3524 | helpers['escape'] = function( val ) {
|
3525 | var func = function() { return val; };
|
3526 |
|
3527 | val = val != null ? val : "";
|
3528 |
|
3529 | if ( typeof val.toHtmlString !== "function" ) {
|
3530 |
|
3531 | val = val.toString().replace( HTML_REGEX, HTML_REPLACER );
|
3532 |
|
3533 | return {
|
3534 | toHtmlString: func
|
3535 | ,toString: func
|
3536 | };
|
3537 | }
|
3538 |
|
3539 | return val;
|
3540 | };
|
3541 |
|
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 |
|
3547 |
|
3548 |
|
3549 |
|
3550 |
|
3551 |
|
3552 | var Buffer = function() {
|
3553 | this._vo = [];
|
3554 | }
|
3555 |
|
3556 | Buffer.prototype.mark = function( debugName ) {
|
3557 | var mark = new Mark( this, debugName );
|
3558 | mark.markedIndex = this._vo.length;
|
3559 | this._vo.push( mark.uid );
|
3560 | return mark;
|
3561 | };
|
3562 |
|
3563 | Buffer.prototype.fromMark = function( mark ) {
|
3564 | var found = mark.findInBuffer();
|
3565 |
|
3566 | if( found > -1 ){
|
3567 |
|
3568 | mark.destroy();
|
3569 |
|
3570 | return this._vo.splice( found, this._vo.length );
|
3571 | }
|
3572 |
|
3573 | return [];
|
3574 | };
|
3575 |
|
3576 | Buffer.prototype.spliceMark = function( mark, numToRemove, add ){
|
3577 | var found = mark.findInBuffer();
|
3578 |
|
3579 | if( found > -1 ){
|
3580 | mark.destroy();
|
3581 | arguments[0] = found;
|
3582 | return this._vo.splice.apply( this._vo, arguments );
|
3583 | }
|
3584 |
|
3585 | return [];
|
3586 | };
|
3587 |
|
3588 | Buffer.prototype.empty = function() {
|
3589 | return this._vo.splice( 0, this._vo.length );
|
3590 | };
|
3591 |
|
3592 | Buffer.prototype.push = function( buffer ) {
|
3593 | return this._vo.push( buffer );
|
3594 | };
|
3595 |
|
3596 | Buffer.prototype.pushConcat = function( buffer ){
|
3597 | var buffers;
|
3598 | if (Array.isArray(buffer)) {
|
3599 | buffers = buffer;
|
3600 | } else if ( arguments.length > 1 ) {
|
3601 | buffers = Array.prototype.slice.call( arguments );
|
3602 | } else {
|
3603 | buffers = [buffer];
|
3604 | }
|
3605 |
|
3606 | for (var i = 0; i < buffers.length; i++) {
|
3607 | this._vo.push( buffers[i] );
|
3608 | }
|
3609 |
|
3610 | return this.__vo;
|
3611 | }
|
3612 |
|
3613 | Buffer.prototype.indexOf = function( str ){
|
3614 |
|
3615 | for( var i = 0; i < this._vo.length; i++ ){
|
3616 | if(
|
3617 | ( str.test && this._vo[i] && this._vo[i].search(str) > -1 )
|
3618 | || this._vo[i] == str
|
3619 | ){
|
3620 | return i;
|
3621 | }
|
3622 | }
|
3623 |
|
3624 | return -1;
|
3625 | }
|
3626 |
|
3627 | Buffer.prototype.lastIndexOf = function( str ){
|
3628 | var i = this._vo.length;
|
3629 |
|
3630 | while( --i >= 0 ){
|
3631 | if(
|
3632 | ( str.test && this._vo[i] && this._vo[i].search(str) > -1 )
|
3633 | || this._vo[i] == str
|
3634 | ){
|
3635 | return i;
|
3636 | }
|
3637 | }
|
3638 |
|
3639 | return -1;
|
3640 | }
|
3641 |
|
3642 | Buffer.prototype.splice = function(){
|
3643 | return this._vo.splice.apply( this._vo, arguments );
|
3644 | }
|
3645 |
|
3646 | Buffer.prototype.index = function( idx ){
|
3647 | return this._vo[ idx ];
|
3648 | }
|
3649 |
|
3650 | Buffer.prototype.flush = function() {
|
3651 | return this.empty().join( "" );
|
3652 | };
|
3653 |
|
3654 | Buffer.prototype.toString = Buffer.prototype.toHtmlString = function(){
|
3655 |
|
3656 |
|
3657 | return this._vo.join( "" );
|
3658 | }
|
3659 |
|
3660 |
|
3661 |
|
3662 |
|
3663 |
|
3664 |
|
3665 |
|
3666 |
|
3667 |
|
3668 | var Mark = runtime['Mark'] = function( buffer, debugName ){
|
3669 | this.uid = '[VASHMARK-'
|
3670 | + ~~( Math.random() * 10000000 )
|
3671 | + (debugName ? ':' + debugName : '')
|
3672 | + ']';
|
3673 | this.markedIndex = 0;
|
3674 | this.buffer = buffer;
|
3675 | this.destroyed = false;
|
3676 | }
|
3677 |
|
3678 | var reMark = Mark.re = /\[VASHMARK\-\d{1,8}(?::[\s\S]+?)?]/g
|
3679 |
|
3680 |
|
3681 | Mark.uidLike = function( str ){
|
3682 | return (str || '').search( reMark ) > -1;
|
3683 | }
|
3684 |
|
3685 | Mark.prototype.destroy = function(){
|
3686 |
|
3687 | var found = this.findInBuffer();
|
3688 |
|
3689 | if( found > -1 ){
|
3690 | this.buffer.splice( found, 1 );
|
3691 | this.markedIndex = -1;
|
3692 | }
|
3693 |
|
3694 | this.destroyed = true;
|
3695 | }
|
3696 |
|
3697 | Mark.prototype.findInBuffer = function(){
|
3698 |
|
3699 | if( this.destroyed ){
|
3700 | return -1;
|
3701 | }
|
3702 |
|
3703 | if( this.markedIndex && this.buffer.index( this.markedIndex ) === this.uid ){
|
3704 | return this.markedIndex;
|
3705 | }
|
3706 |
|
3707 |
|
3708 | var escaped = this.uid.replace(/(\[|\])/g, '\\$1');
|
3709 | var re = new RegExp(escaped);
|
3710 | return this.markedIndex = this.buffer.indexOf( re );
|
3711 | }
|
3712 |
|
3713 |
|
3714 |
|
3715 |
|
3716 |
|
3717 |
|
3718 |
|
3719 |
|
3720 | helpers.constructor.reportError = function(e, lineno, chr, orig, lb, atRenderTime){
|
3721 |
|
3722 | lb = lb || '!LB!';
|
3723 |
|
3724 | var contextStr = error.context(orig, lineno, chr, lb);
|
3725 |
|
3726 | e.vashlineno = lineno;
|
3727 | e.vashcharno = chr;
|
3728 | e.message = 'Problem while '
|
3729 | + (atRenderTime ? 'rendering' : 'compiling')
|
3730 | + ' template at line '
|
3731 | + lineno + ', character ' + chr
|
3732 | + '.\nOriginal message: ' + e.message + '.'
|
3733 | + '\nContext: \n\n' + contextStr + '\n\n';
|
3734 |
|
3735 | throw e;
|
3736 | };
|
3737 |
|
3738 | helpers['reportError'] = function() {
|
3739 | this.constructor.reportError.apply( this, arguments );
|
3740 | };
|
3741 |
|
3742 |
|
3743 |
|
3744 |
|
3745 |
|
3746 |
|
3747 |
|
3748 |
|
3749 |
|
3750 |
|
3751 |
|
3752 |
|
3753 |
|
3754 |
|
3755 | runtime['link'] = function( cmpFunc, options ){
|
3756 |
|
3757 |
|
3758 |
|
3759 | var originalFunc
|
3760 | ,cmpOpts;
|
3761 |
|
3762 | if( !options.args ){
|
3763 |
|
3764 | options.args = [options.modelName, options.helpersName, '__vopts', 'runtime'];
|
3765 | }
|
3766 |
|
3767 | if( typeof cmpFunc === 'string' ){
|
3768 | originalFunc = cmpFunc;
|
3769 |
|
3770 | try {
|
3771 |
|
3772 |
|
3773 | cmpOpts = options.args.slice();
|
3774 | cmpOpts.push(cmpFunc);
|
3775 | cmpFunc = Function.apply(null, cmpOpts);
|
3776 | } catch(e) {
|
3777 |
|
3778 | helpers.reportError(e, 0, 0, originalFunc, /\n/, false);
|
3779 | }
|
3780 | }
|
3781 |
|
3782 |
|
3783 | cmpFunc.options = {
|
3784 | simple: options.simple
|
3785 | ,modelName: options.modelName
|
3786 | ,helpersName: options.helpersName
|
3787 | }
|
3788 |
|
3789 | var linked;
|
3790 |
|
3791 | if( options.asHelper ){
|
3792 |
|
3793 | cmpFunc.options.args = options.args;
|
3794 | cmpFunc.options.asHelper = options.asHelper;
|
3795 |
|
3796 | linked = function(){
|
3797 | return cmpFunc.apply(this, slice.call(arguments));
|
3798 | }
|
3799 |
|
3800 | helpers[options.asHelper] = linked;
|
3801 |
|
3802 | } else {
|
3803 |
|
3804 | linked = function( model, opts ){
|
3805 | if( options.simple ){
|
3806 | var ctx = {
|
3807 | buffer: []
|
3808 | ,escape: Helpers.prototype.escape
|
3809 | ,raw: Helpers.prototype.raw
|
3810 | }
|
3811 | return cmpFunc( model, ctx, opts, runtime );
|
3812 | }
|
3813 |
|
3814 | opts = divineRuntimeTplOptions( model, opts );
|
3815 | return cmpFunc( model, (opts && opts.context) || new Helpers( model ), opts, runtime );
|
3816 | }
|
3817 | }
|
3818 |
|
3819 |
|
3820 | linked['toString'] = function(){ return cmpFunc.toString(); }
|
3821 |
|
3822 |
|
3823 | linked['_toString'] = function(){ return Function.prototype.toString.call(linked) }
|
3824 |
|
3825 |
|
3826 |
|
3827 | linked['toClientString'] = function(){
|
3828 | return 'vash.link( '
|
3829 | + cmpFunc.toString() + ', '
|
3830 | + JSON.stringify( cmpFunc.options ) + ' )';
|
3831 | }
|
3832 |
|
3833 | return linked;
|
3834 | }
|
3835 |
|
3836 |
|
3837 |
|
3838 |
|
3839 |
|
3840 |
|
3841 | function divineRuntimeTplOptions( model, opts ){
|
3842 |
|
3843 |
|
3844 | if( typeof opts === 'function' ) {
|
3845 | opts = { onRenderEnd: opts };
|
3846 | }
|
3847 |
|
3848 |
|
3849 | if( model && model.onRenderEnd ){
|
3850 | opts = opts || {};
|
3851 |
|
3852 | if( !opts.onRenderEnd ){
|
3853 | opts.onRenderEnd = model.onRenderEnd;
|
3854 | }
|
3855 |
|
3856 | delete model.onRenderEnd;
|
3857 | }
|
3858 |
|
3859 |
|
3860 | if( !opts ){
|
3861 | opts = {};
|
3862 | }
|
3863 |
|
3864 | return opts;
|
3865 | }
|
3866 |
|
3867 |
|
3868 | var slice = Array.prototype.slice;
|
3869 |
|
3870 |
|
3871 |
|
3872 |
|
3873 |
|
3874 |
|
3875 |
|
3876 | runtime['lookup'] = function( path, model ){
|
3877 | var tpl = runtime.helpers.tplcache[path];
|
3878 | if( !tpl ){ throw new Error('Could not find template: ' + path); }
|
3879 | if( model ){ return tpl(model); }
|
3880 | else return tpl;
|
3881 | };
|
3882 |
|
3883 | runtime['install'] = function( path, tpl ){
|
3884 | var cache = runtime.helpers.tplcache;
|
3885 | if( typeof tpl === 'string' ){
|
3886 |
|
3887 |
|
3888 |
|
3889 |
|
3890 | if ( typeof this.compile === 'function') {
|
3891 | tpl = this.compile(tpl);
|
3892 | } else {
|
3893 | throw new Error('.install(path, [string]) is not available in the standalone runtime.');
|
3894 | }
|
3895 | } else if( typeof path === 'object' ){
|
3896 | tpl = path;
|
3897 | Object.keys(tpl).forEach(function(path){
|
3898 | cache[path] = tpl[path];
|
3899 | });
|
3900 | return cache;
|
3901 | }
|
3902 | return cache[path] = tpl;
|
3903 | };
|
3904 |
|
3905 | runtime['uninstall'] = function( path ){
|
3906 | var cache = runtime.helpers.tplcache
|
3907 | ,deleted = false;
|
3908 |
|
3909 | if( typeof path === 'string' ){
|
3910 | return delete cache[path];
|
3911 | } else {
|
3912 | Object.keys(cache).forEach(function(key){
|
3913 | if( cache[key] === path ){ deleted = delete cache[key]; }
|
3914 | })
|
3915 | return deleted;
|
3916 | }
|
3917 | };
|
3918 |
|
3919 | },{"./lib/error":3,"./package.json":34}]},{},[1])(1)
|
3920 | }); |
\ | No newline at end of file |