UNPKG

grunt-zuckrig-closure

Version:

Reduce a verbose syntax for Google Closure Compiler to be more Pythonic/Rubistic.

96 lines (87 loc) 2.04 kB
var Extractor; Extractor = (function() { function Extractor() {} Extractor._extend_seq = [ { k: 2, v: ';' }, { k: 3, v: '}' }, { k: 4, v: ')' }, { k: 5, v: '(' } ]; Extractor.prototype.class_name = function(i, tokens, back) { var class_name, next; if (back == null) { back = false; } class_name = []; while (true) { next = tokens[i]; if (!next) { break; } if (!(next.type === 'Identifier' || next.value === '.')) { break; } class_name.push(next.value); if (back) { i--; } else { i++; } } if (back) { class_name.reverse(); } return class_name.join(''); }; Extractor.prototype.parse_super_class = function(i, tokens) { var len, seq, skip, super_class, tok, _i, _len, _ref; len = tokens.length; super_class = null; while (i < len) { tok = tokens[i]; if ((tok != null) && (tok.type !== 'Keyword' || tok.value !== 'return')) { i += 1; continue; } skip = false; _ref = Extractor._extend_seq; for (_i = 0, _len = _ref.length; _i < _len; _i++) { seq = _ref[_i]; if ((tokens[i + seq.k] != null) && tokens[i + seq.k].value !== seq.v) { i += seq.k; skip = true; break; } } if (skip) { continue; } if (tokens[i + 6].type !== 'Identifier') { i += 6; continue; } super_class = this.class_name(i + 6, tokens); break; } return super_class; }; Extractor.prototype.parse_class_from_def = function(i, tokens) { var class_name; class_name = null; if (tokens[i].value === '=' && tokens[i + 1].value === '(' && tokens[i + 2].value === 'function' && tokens[i + 3].value === '(') { class_name = this.class_name(i - 1, tokens, true); } return class_name; }; return Extractor; })(); module.exports = Extractor;