You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pm...@apache.org on 2014/08/30 20:42:44 UTC

[11/14] pre-compile CoffeeScript files in server

http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/coffee-script/lib/coffee-script/helpers.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/coffee-script/lib/coffee-script/helpers.js b/weinre.server/node_modules/coffee-script/lib/coffee-script/helpers.js
index b0a997b..049f757 100644
--- a/weinre.server/node_modules/coffee-script/lib/coffee-script/helpers.js
+++ b/weinre.server/node_modules/coffee-script/lib/coffee-script/helpers.js
@@ -1,6 +1,6 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.8.0
 (function() {
-  var extend, flatten;
+  var buildLocationData, extend, flatten, last, repeat, syntaxErrorToString, _ref;
 
   exports.starts = function(string, literal, start) {
     return literal === string.substr(start, literal.length);
@@ -12,6 +12,19 @@
     return literal === string.substr(string.length - len - (back || 0), len);
   };
 
+  exports.repeat = repeat = function(str, n) {
+    var res;
+    res = '';
+    while (n > 0) {
+      if (n & 1) {
+        res += str;
+      }
+      n >>>= 1;
+      str += str;
+    }
+    return res;
+  };
+
   exports.compact = function(array) {
     var item, _i, _len, _results;
     _results = [];
@@ -70,8 +83,170 @@
     return val;
   };
 
-  exports.last = function(array, back) {
+  exports.last = last = function(array, back) {
     return array[array.length - (back || 0) - 1];
   };
 
+  exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
+    var e, _i, _len;
+    for (_i = 0, _len = this.length; _i < _len; _i++) {
+      e = this[_i];
+      if (fn(e)) {
+        return true;
+      }
+    }
+    return false;
+  };
+
+  exports.invertLiterate = function(code) {
+    var line, lines, maybe_code;
+    maybe_code = true;
+    lines = (function() {
+      var _i, _len, _ref1, _results;
+      _ref1 = code.split('\n');
+      _results = [];
+      for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+        line = _ref1[_i];
+        if (maybe_code && /^([ ]{4}|[ ]{0,3}\t)/.test(line)) {
+          _results.push(line);
+        } else if (maybe_code = /^\s*$/.test(line)) {
+          _results.push(line);
+        } else {
+          _results.push('# ' + line);
+        }
+      }
+      return _results;
+    })();
+    return lines.join('\n');
+  };
+
+  buildLocationData = function(first, last) {
+    if (!last) {
+      return first;
+    } else {
+      return {
+        first_line: first.first_line,
+        first_column: first.first_column,
+        last_line: last.last_line,
+        last_column: last.last_column
+      };
+    }
+  };
+
+  exports.addLocationDataFn = function(first, last) {
+    return function(obj) {
+      if (((typeof obj) === 'object') && (!!obj['updateLocationDataIfMissing'])) {
+        obj.updateLocationDataIfMissing(buildLocationData(first, last));
+      }
+      return obj;
+    };
+  };
+
+  exports.locationDataToString = function(obj) {
+    var locationData;
+    if (("2" in obj) && ("first_line" in obj[2])) {
+      locationData = obj[2];
+    } else if ("first_line" in obj) {
+      locationData = obj;
+    }
+    if (locationData) {
+      return ("" + (locationData.first_line + 1) + ":" + (locationData.first_column + 1) + "-") + ("" + (locationData.last_line + 1) + ":" + (locationData.last_column + 1));
+    } else {
+      return "No location data";
+    }
+  };
+
+  exports.baseFileName = function(file, stripExt, useWinPathSep) {
+    var parts, pathSep;
+    if (stripExt == null) {
+      stripExt = false;
+    }
+    if (useWinPathSep == null) {
+      useWinPathSep = false;
+    }
+    pathSep = useWinPathSep ? /\\|\// : /\//;
+    parts = file.split(pathSep);
+    file = parts[parts.length - 1];
+    if (!(stripExt && file.indexOf('.') >= 0)) {
+      return file;
+    }
+    parts = file.split('.');
+    parts.pop();
+    if (parts[parts.length - 1] === 'coffee' && parts.length > 1) {
+      parts.pop();
+    }
+    return parts.join('.');
+  };
+
+  exports.isCoffee = function(file) {
+    return /\.((lit)?coffee|coffee\.md)$/.test(file);
+  };
+
+  exports.isLiterate = function(file) {
+    return /\.(litcoffee|coffee\.md)$/.test(file);
+  };
+
+  exports.throwSyntaxError = function(message, location) {
+    var error;
+    error = new SyntaxError(message);
+    error.location = location;
+    error.toString = syntaxErrorToString;
+    error.stack = error.toString();
+    throw error;
+  };
+
+  exports.updateSyntaxError = function(error, code, filename) {
+    if (error.toString === syntaxErrorToString) {
+      error.code || (error.code = code);
+      error.filename || (error.filename = filename);
+      error.stack = error.toString();
+    }
+    return error;
+  };
+
+  syntaxErrorToString = function() {
+    var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, start, _ref1, _ref2;
+    if (!(this.code && this.location)) {
+      return Error.prototype.toString.call(this);
+    }
+    _ref1 = this.location, first_line = _ref1.first_line, first_column = _ref1.first_column, last_line = _ref1.last_line, last_column = _ref1.last_column;
+    if (last_line == null) {
+      last_line = first_line;
+    }
+    if (last_column == null) {
+      last_column = first_column;
+    }
+    filename = this.filename || '[stdin]';
+    codeLine = this.code.split('\n')[first_line];
+    start = first_column;
+    end = first_line === last_line ? last_column + 1 : codeLine.length;
+    marker = codeLine.slice(0, start).replace(/[^\s]/g, ' ') + repeat('^', end - start);
+    if (typeof process !== "undefined" && process !== null) {
+      colorsEnabled = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS;
+    }
+    if ((_ref2 = this.colorful) != null ? _ref2 : colorsEnabled) {
+      colorize = function(str) {
+        return "\x1B[1;31m" + str + "\x1B[0m";
+      };
+      codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);
+      marker = colorize(marker);
+    }
+    return "" + filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + this.message + "\n" + codeLine + "\n" + marker;
+  };
+
+  exports.nameWhitespaceCharacter = function(string) {
+    switch (string) {
+      case ' ':
+        return 'space';
+      case '\n':
+        return 'newline';
+      case '\r':
+        return 'carriage return';
+      case '\t':
+        return 'tab';
+      default:
+        return string;
+    }
+  };
+
 }).call(this);

http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/coffee-script/lib/coffee-script/index.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/coffee-script/lib/coffee-script/index.js b/weinre.server/node_modules/coffee-script/lib/coffee-script/index.js
index d344c41..46c97ea 100644
--- a/weinre.server/node_modules/coffee-script/lib/coffee-script/index.js
+++ b/weinre.server/node_modules/coffee-script/lib/coffee-script/index.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.8.0
 (function() {
   var key, val, _ref;
 

http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/coffee-script/lib/coffee-script/lexer.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/coffee-script/lib/coffee-script/lexer.js b/weinre.server/node_modules/coffee-script/lib/coffee-script/lexer.js
index f80a443..0f3cef8 100644
--- a/weinre.server/node_modules/coffee-script/lib/coffee-script/lexer.js
+++ b/weinre.server/node_modules/coffee-script/lib/coffee-script/lexer.js
@@ -1,36 +1,36 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.8.0
 (function() {
-  var BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, starts, _ref, _ref1,
+  var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, UNARY_MATH, WHITESPACE, compact, count, invertLiterate, key, last, locationDataToString, repeat, starts, throwSyntaxError, _ref, _ref1,
     __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
 
   _ref = require('./rewriter'), Rewriter = _ref.Rewriter, INVERSES = _ref.INVERSES;
 
-  _ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last;
+  _ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last, repeat = _ref1.repeat, invertLiterate = _ref1.invertLiterate, locationDataToString = _ref1.locationDataToString, throwSyntaxError = _ref1.throwSyntaxError;
 
   exports.Lexer = Lexer = (function() {
-
     function Lexer() {}
 
     Lexer.prototype.tokenize = function(code, opts) {
-      var i, tag;
+      var consumed, i, tag, _ref2;
       if (opts == null) {
         opts = {};
       }
-      if (WHITESPACE.test(code)) {
-        code = "\n" + code;
-      }
-      code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
-      this.code = code;
-      this.line = opts.line || 0;
+      this.literate = opts.literate;
       this.indent = 0;
+      this.baseIndent = 0;
       this.indebt = 0;
       this.outdebt = 0;
       this.indents = [];
       this.ends = [];
       this.tokens = [];
+      this.chunkLine = opts.line || 0;
+      this.chunkColumn = opts.column || 0;
+      code = this.clean(code);
       i = 0;
       while (this.chunk = code.slice(i)) {
-        i += this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
+        consumed = this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
+        _ref2 = this.getLineAndColumnFromChunk(consumed), this.chunkLine = _ref2[0], this.chunkColumn = _ref2[1];
+        i += consumed;
       }
       this.closeIndentation();
       if (tag = this.ends.pop()) {
@@ -42,17 +42,34 @@
       return (new Rewriter).rewrite(this.tokens);
     };
 
+    Lexer.prototype.clean = function(code) {
+      if (code.charCodeAt(0) === BOM) {
+        code = code.slice(1);
+      }
+      code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
+      if (WHITESPACE.test(code)) {
+        code = "\n" + code;
+        this.chunkLine--;
+      }
+      if (this.literate) {
+        code = invertLiterate(code);
+      }
+      return code;
+    };
+
     Lexer.prototype.identifierToken = function() {
-      var colon, forcedIdentifier, id, input, match, prev, tag, _ref2, _ref3;
+      var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, tag, tagToken, _ref2, _ref3, _ref4;
       if (!(match = IDENTIFIER.exec(this.chunk))) {
         return 0;
       }
       input = match[0], id = match[1], colon = match[2];
+      idLength = id.length;
+      poppedToken = void 0;
       if (id === 'own' && this.tag() === 'FOR') {
         this.token('OWN', id);
         return id.length;
       }
-      forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::') || !prev.spaced && prev[0] === '@');
+      forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::' || _ref2 === '?::') || !prev.spaced && prev[0] === '@');
       tag = 'IDENTIFIER';
       if (!forcedIdentifier && (__indexOf.call(JS_KEYWORDS, id) >= 0 || __indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
         tag = id.toUpperCase();
@@ -71,7 +88,7 @@
           } else {
             tag = 'RELATION';
             if (this.value() === '!') {
-              this.tokens.pop();
+              poppedToken = this.tokens.pop();
               id = '!' + id;
             }
           }
@@ -111,9 +128,13 @@
           }
         })();
       }
-      this.token(tag, id);
+      tagToken = this.token(tag, id, 0, idLength);
+      if (poppedToken) {
+        _ref4 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = _ref4[0], tagToken[2].first_column = _ref4[1];
+      }
       if (colon) {
-        this.token(':', ':');
+        colonOffset = input.lastIndexOf(':');
+        this.token(':', ':', colonOffset, colon.length);
       }
       return input.length;
     };
@@ -135,46 +156,50 @@
       }
       lexedLength = number.length;
       if (octalLiteral = /^0o([0-7]+)/.exec(number)) {
-        number = '0x' + (parseInt(octalLiteral[1], 8)).toString(16);
+        number = '0x' + parseInt(octalLiteral[1], 8).toString(16);
       }
       if (binaryLiteral = /^0b([01]+)/.exec(number)) {
-        number = '0x' + (parseInt(binaryLiteral[1], 2)).toString(16);
+        number = '0x' + parseInt(binaryLiteral[1], 2).toString(16);
       }
-      this.token('NUMBER', number);
+      this.token('NUMBER', number, 0, lexedLength);
       return lexedLength;
     };
 
     Lexer.prototype.stringToken = function() {
-      var match, octalEsc, string;
-      switch (this.chunk.charAt(0)) {
+      var inner, innerLen, numBreak, octalEsc, pos, quote, string, trimmed;
+      switch (quote = this.chunk.charAt(0)) {
         case "'":
-          if (!(match = SIMPLESTR.exec(this.chunk))) {
-            return 0;
-          }
-          this.token('STRING', (string = match[0]).replace(MULTILINER, '\\\n'));
+          string = (SIMPLESTR.exec(this.chunk) || [])[0];
           break;
         case '"':
-          if (!(string = this.balancedString(this.chunk, '"'))) {
-            return 0;
-          }
-          if (0 < string.indexOf('#{', 1)) {
-            this.interpolateString(string.slice(1, -1));
-          } else {
-            this.token('STRING', this.escapeLines(string));
-          }
-          break;
-        default:
-          return 0;
+          string = this.balancedString(this.chunk, '"');
+      }
+      if (!string) {
+        return 0;
+      }
+      inner = string.slice(1, -1);
+      trimmed = this.removeNewlines(inner);
+      if (quote === '"' && 0 < string.indexOf('#{', 1)) {
+        numBreak = pos = 0;
+        innerLen = inner.length;
+        while (inner.charAt(pos++) === '\n' && pos < innerLen) {
+          numBreak++;
+        }
+        this.interpolateString(trimmed, {
+          strOffset: 1 + numBreak,
+          lexedLength: string.length
+        });
+      } else {
+        this.token('STRING', quote + this.escapeLines(trimmed) + quote, 0, string.length);
       }
       if (octalEsc = /^(?:\\.|[^\\])*\\(?:0[0-7]|[1-7])/.test(string)) {
         this.error("octal escape sequences " + string + " are not allowed");
       }
-      this.line += count(string, '\n');
       return string.length;
     };
 
     Lexer.prototype.heredocToken = function() {
-      var doc, heredoc, match, quote;
+      var doc, heredoc, match, quote, strOffset;
       if (!(match = HEREDOC.exec(this.chunk))) {
         return 0;
       }
@@ -185,13 +210,15 @@
         indent: null
       });
       if (quote === '"' && 0 <= doc.indexOf('#{')) {
+        strOffset = match[2].charAt(0) === '\n' ? 4 : 3;
         this.interpolateString(doc, {
-          heredoc: true
+          heredoc: true,
+          strOffset: strOffset,
+          lexedLength: heredoc.length
         });
       } else {
-        this.token('STRING', this.makeString(doc, quote, true));
+        this.token('STRING', this.makeString(doc, quote, true), 0, heredoc.length);
       }
-      this.line += count(heredoc, '\n');
       return heredoc.length;
     };
 
@@ -204,10 +231,9 @@
       if (here) {
         this.token('HERECOMMENT', this.sanitizeHeredoc(here, {
           herecomment: true,
-          indent: Array(this.indent + 1).join(' ')
-        }));
+          indent: repeat(' ', this.indent)
+        }), 0, comment.length);
       }
-      this.line += count(comment, '\n');
       return comment.length;
     };
 
@@ -216,7 +242,7 @@
       if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
         return 0;
       }
-      this.token('JS', (script = match[0]).slice(1, -1));
+      this.token('JS', (script = match[0]).slice(1, -1), 0, script.length);
       return script.length;
     };
 
@@ -225,9 +251,7 @@
       if (this.chunk.charAt(0) !== '/') {
         return 0;
       }
-      if (match = HEREGEX.exec(this.chunk)) {
-        length = this.heregexToken(match);
-        this.line += count(match[0], '\n');
+      if (length = this.heregexToken()) {
         return length;
       }
       prev = last(this.tokens);
@@ -238,74 +262,87 @@
         return 0;
       }
       _ref3 = match, match = _ref3[0], regex = _ref3[1], flags = _ref3[2];
+      if (regex === '//') {
+        return 0;
+      }
       if (regex.slice(0, 2) === '/*') {
         this.error('regular expressions cannot begin with `*`');
       }
-      if (regex === '//') {
-        regex = '/(?:)/';
-      }
-      this.token('REGEX', "" + regex + flags);
+      this.token('REGEX', "" + regex + flags, 0, match.length);
       return match.length;
     };
 
-    Lexer.prototype.heregexToken = function(match) {
-      var body, flags, heregex, re, tag, tokens, value, _i, _len, _ref2, _ref3, _ref4, _ref5;
+    Lexer.prototype.heregexToken = function() {
+      var body, flags, flagsOffset, heregex, match, plusToken, prev, re, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;
+      if (!(match = HEREGEX.exec(this.chunk))) {
+        return 0;
+      }
       heregex = match[0], body = match[1], flags = match[2];
       if (0 > body.indexOf('#{')) {
-        re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');
+        re = this.escapeLines(body.replace(HEREGEX_OMIT, '$1$2').replace(/\//g, '\\/'), true);
         if (re.match(/^\*/)) {
           this.error('regular expressions cannot begin with `*`');
         }
-        this.token('REGEX', "/" + (re || '(?:)') + "/" + flags);
+        this.token('REGEX', "/" + (re || '(?:)') + "/" + flags, 0, heregex.length);
         return heregex.length;
       }
-      this.token('IDENTIFIER', 'RegExp');
-      this.tokens.push(['CALL_START', '(']);
+      this.token('IDENTIFIER', 'RegExp', 0, 0);
+      this.token('CALL_START', '(', 0, 0);
       tokens = [];
       _ref2 = this.interpolateString(body, {
-        regex: true
+        regex: true,
+        strOffset: 3
       });
       for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
-        _ref3 = _ref2[_i], tag = _ref3[0], value = _ref3[1];
+        token = _ref2[_i];
+        tag = token[0], value = token[1];
         if (tag === 'TOKENS') {
           tokens.push.apply(tokens, value);
-        } else {
-          if (!(value = value.replace(HEREGEX_OMIT, ''))) {
+        } else if (tag === 'NEOSTRING') {
+          if (!(value = value.replace(HEREGEX_OMIT, '$1$2'))) {
             continue;
           }
           value = value.replace(/\\/g, '\\\\');
-          tokens.push(['STRING', this.makeString(value, '"', true)]);
+          token[0] = 'STRING';
+          token[1] = this.makeString(value, '"', true);
+          tokens.push(token);
+        } else {
+          this.error("Unexpected " + tag);
         }
-        tokens.push(['+', '+']);
+        prev = last(this.tokens);
+        plusToken = ['+', '+'];
+        plusToken[2] = prev[2];
+        tokens.push(plusToken);
       }
       tokens.pop();
-      if (((_ref4 = tokens[0]) != null ? _ref4[0] : void 0) !== 'STRING') {
-        this.tokens.push(['STRING', '""'], ['+', '+']);
+      if (((_ref3 = tokens[0]) != null ? _ref3[0] : void 0) !== 'STRING') {
+        this.token('STRING', '""', 0, 0);
+        this.token('+', '+', 0, 0);
       }
-      (_ref5 = this.tokens).push.apply(_ref5, tokens);
+      (_ref4 = this.tokens).push.apply(_ref4, tokens);
       if (flags) {
-        this.tokens.push([',', ','], ['STRING', '"' + flags + '"']);
+        flagsOffset = heregex.lastIndexOf(flags);
+        this.token(',', ',', flagsOffset, 0);
+        this.token('STRING', '"' + flags + '"', flagsOffset, flags.length);
       }
-      this.token(')', ')');
+      this.token(')', ')', heregex.length - 1, 0);
       return heregex.length;
     };
 
     Lexer.prototype.lineToken = function() {
-      var diff, indent, match, noNewlines, prev, size;
+      var diff, indent, match, noNewlines, size;
       if (!(match = MULTI_DENT.exec(this.chunk))) {
         return 0;
       }
       indent = match[0];
-      this.line += count(indent, '\n');
       this.seenFor = false;
-      prev = last(this.tokens, 1);
       size = indent.length - 1 - indent.lastIndexOf('\n');
       noNewlines = this.unfinished();
       if (size - this.indebt === this.indent) {
         if (noNewlines) {
           this.suppressNewlines();
         } else {
-          this.newlineToken();
+          this.newlineToken(0);
         }
         return indent.length;
       }
@@ -315,37 +352,48 @@
           this.suppressNewlines();
           return indent.length;
         }
+        if (!this.tokens.length) {
+          this.baseIndent = this.indent = size;
+          return indent.length;
+        }
         diff = size - this.indent + this.outdebt;
-        this.token('INDENT', diff);
+        this.token('INDENT', diff, indent.length - size, size);
         this.indents.push(diff);
         this.ends.push('OUTDENT');
         this.outdebt = this.indebt = 0;
+        this.indent = size;
+      } else if (size < this.baseIndent) {
+        this.error('missing indentation', indent.length);
       } else {
         this.indebt = 0;
-        this.outdentToken(this.indent - size, noNewlines);
+        this.outdentToken(this.indent - size, noNewlines, indent.length);
       }
-      this.indent = size;
       return indent.length;
     };
 
-    Lexer.prototype.outdentToken = function(moveOut, noNewlines) {
-      var dent, len;
+    Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) {
+      var decreasedIndent, dent, lastIndent, _ref2;
+      decreasedIndent = this.indent - moveOut;
       while (moveOut > 0) {
-        len = this.indents.length - 1;
-        if (this.indents[len] === void 0) {
+        lastIndent = this.indents[this.indents.length - 1];
+        if (!lastIndent) {
           moveOut = 0;
-        } else if (this.indents[len] === this.outdebt) {
+        } else if (lastIndent === this.outdebt) {
           moveOut -= this.outdebt;
           this.outdebt = 0;
-        } else if (this.indents[len] < this.outdebt) {
-          this.outdebt -= this.indents[len];
-          moveOut -= this.indents[len];
+        } else if (lastIndent < this.outdebt) {
+          this.outdebt -= lastIndent;
+          moveOut -= lastIndent;
         } else {
-          dent = this.indents.pop() - this.outdebt;
-          moveOut -= dent;
+          dent = this.indents.pop() + this.outdebt;
+          if (outdentLength && (_ref2 = this.chunk[outdentLength], __indexOf.call(INDENTABLE_CLOSERS, _ref2) >= 0)) {
+            decreasedIndent -= dent - moveOut;
+            moveOut = dent;
+          }
           this.outdebt = 0;
           this.pair('OUTDENT');
-          this.token('OUTDENT', dent);
+          this.token('OUTDENT', moveOut, 0, outdentLength);
+          moveOut -= dent;
         }
       }
       if (dent) {
@@ -355,8 +403,9 @@
         this.tokens.pop();
       }
       if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
-        this.token('TERMINATOR', '\n');
+        this.token('TERMINATOR', '\n', outdentLength, 0);
       }
+      this.indent = decreasedIndent;
       return this;
     };
 
@@ -376,12 +425,12 @@
       }
     };
 
-    Lexer.prototype.newlineToken = function() {
+    Lexer.prototype.newlineToken = function(offset) {
       while (this.value() === ';') {
         this.tokens.pop();
       }
       if (this.tag() !== 'TERMINATOR') {
-        this.token('TERMINATOR', '\n');
+        this.token('TERMINATOR', '\n', offset, 0);
       }
       return this;
     };
@@ -426,6 +475,8 @@
         tag = 'COMPOUND_ASSIGN';
       } else if (__indexOf.call(UNARY, value) >= 0) {
         tag = 'UNARY';
+      } else if (__indexOf.call(UNARY_MATH, value) >= 0) {
+        tag = 'UNARY_MATH';
       } else if (__indexOf.call(SHIFT, value) >= 0) {
         tag = 'SHIFT';
       } else if (__indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {
@@ -466,7 +517,7 @@
         if (HEREDOC_ILLEGAL.test(doc)) {
           this.error("block comment cannot contain \"*/\", starting");
         }
-        if (doc.indexOf('\n') <= 0) {
+        if (doc.indexOf('\n') < 0) {
           return doc;
         }
       } else {
@@ -535,7 +586,7 @@
           case end:
             stack.pop();
             if (!stack.length) {
-              return str.slice(0, i + 1 || 9e9);
+              return str.slice(0, +i + 1 || 9e9);
             }
             end = stack[stack.length - 1];
             continue;
@@ -555,11 +606,14 @@
     };
 
     Lexer.prototype.interpolateString = function(str, options) {
-      var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _i, _len, _ref2, _ref3, _ref4;
+      var column, errorToken, expr, heredoc, i, inner, interpolated, len, letter, lexedLength, line, locationToken, nested, offsetInChunk, pi, plusToken, popped, regex, rparen, strOffset, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;
       if (options == null) {
         options = {};
       }
-      heredoc = options.heredoc, regex = options.regex;
+      heredoc = options.heredoc, regex = options.regex, offsetInChunk = options.offsetInChunk, strOffset = options.strOffset, lexedLength = options.lexedLength;
+      offsetInChunk || (offsetInChunk = 0);
+      strOffset || (strOffset = 0);
+      lexedLength || (lexedLength = str.length);
       tokens = [];
       pi = 0;
       i = -1;
@@ -572,22 +626,27 @@
           continue;
         }
         if (pi < i) {
-          tokens.push(['NEOSTRING', str.slice(pi, i)]);
+          tokens.push(this.makeToken('NEOSTRING', str.slice(pi, i), strOffset + pi));
+        }
+        if (!errorToken) {
+          errorToken = this.makeToken('', 'string interpolation', offsetInChunk + i + 1, 2);
         }
         inner = expr.slice(1, -1);
         if (inner.length) {
+          _ref2 = this.getLineAndColumnFromChunk(strOffset + i + 2), line = _ref2[0], column = _ref2[1];
           nested = new Lexer().tokenize(inner, {
-            line: this.line,
+            line: line,
+            column: column,
             rewrite: false
           });
-          nested.pop();
-          if (((_ref2 = nested[0]) != null ? _ref2[0] : void 0) === 'TERMINATOR') {
-            nested.shift();
+          popped = nested.pop();
+          if (((_ref3 = nested[0]) != null ? _ref3[0] : void 0) === 'TERMINATOR') {
+            popped = nested.shift();
           }
           if (len = nested.length) {
             if (len > 1) {
-              nested.unshift(['(', '(', this.line]);
-              nested.push([')', ')', this.line]);
+              nested.unshift(this.makeToken('(', '(', strOffset + i + 1, 0));
+              nested.push(this.makeToken(')', ')', strOffset + i + 1 + inner.length, 0));
             }
             tokens.push(['TOKENS', nested]);
           }
@@ -596,52 +655,110 @@
         pi = i + 1;
       }
       if ((i > pi && pi < str.length)) {
-        tokens.push(['NEOSTRING', str.slice(pi)]);
+        tokens.push(this.makeToken('NEOSTRING', str.slice(pi), strOffset + pi));
       }
       if (regex) {
         return tokens;
       }
       if (!tokens.length) {
-        return this.token('STRING', '""');
+        return this.token('STRING', '""', offsetInChunk, lexedLength);
       }
       if (tokens[0][0] !== 'NEOSTRING') {
-        tokens.unshift(['', '']);
+        tokens.unshift(this.makeToken('NEOSTRING', '', offsetInChunk));
       }
       if (interpolated = tokens.length > 1) {
-        this.token('(', '(');
+        this.token('(', '(', offsetInChunk, 0, errorToken);
       }
       for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
-        _ref3 = tokens[i], tag = _ref3[0], value = _ref3[1];
+        token = tokens[i];
+        tag = token[0], value = token[1];
         if (i) {
-          this.token('+', '+');
+          if (i) {
+            plusToken = this.token('+', '+');
+          }
+          locationToken = tag === 'TOKENS' ? value[0] : token;
+          plusToken[2] = {
+            first_line: locationToken[2].first_line,
+            first_column: locationToken[2].first_column,
+            last_line: locationToken[2].first_line,
+            last_column: locationToken[2].first_column
+          };
         }
         if (tag === 'TOKENS') {
           (_ref4 = this.tokens).push.apply(_ref4, value);
+        } else if (tag === 'NEOSTRING') {
+          token[0] = 'STRING';
+          token[1] = this.makeString(value, '"', heredoc);
+          this.tokens.push(token);
         } else {
-          this.token('STRING', this.makeString(value, '"', heredoc));
+          this.error("Unexpected " + tag);
         }
       }
       if (interpolated) {
-        this.token(')', ')');
+        rparen = this.makeToken(')', ')', offsetInChunk + lexedLength, 0);
+        rparen.stringEnd = true;
+        this.tokens.push(rparen);
       }
       return tokens;
     };
 
     Lexer.prototype.pair = function(tag) {
-      var size, wanted;
+      var wanted;
       if (tag !== (wanted = last(this.ends))) {
         if ('OUTDENT' !== wanted) {
           this.error("unmatched " + tag);
         }
-        this.indent -= size = last(this.indents);
-        this.outdentToken(size, true);
+        this.outdentToken(last(this.indents), true);
         return this.pair(tag);
       }
       return this.ends.pop();
     };
 
-    Lexer.prototype.token = function(tag, value) {
-      return this.tokens.push([tag, value, this.line]);
+    Lexer.prototype.getLineAndColumnFromChunk = function(offset) {
+      var column, lineCount, lines, string;
+      if (offset === 0) {
+        return [this.chunkLine, this.chunkColumn];
+      }
+      if (offset >= this.chunk.length) {
+        string = this.chunk;
+      } else {
+        string = this.chunk.slice(0, +(offset - 1) + 1 || 9e9);
+      }
+      lineCount = count(string, '\n');
+      column = this.chunkColumn;
+      if (lineCount > 0) {
+        lines = string.split('\n');
+        column = last(lines).length;
+      } else {
+        column += string.length;
+      }
+      return [this.chunkLine + lineCount, column];
+    };
+
+    Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) {
+      var lastCharacter, locationData, token, _ref2, _ref3;
+      if (offsetInChunk == null) {
+        offsetInChunk = 0;
+      }
+      if (length == null) {
+        length = value.length;
+      }
+      locationData = {};
+      _ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = _ref2[0], locationData.first_column = _ref2[1];
+      lastCharacter = Math.max(0, length - 1);
+      _ref3 = this.getLineAndColumnFromChunk(offsetInChunk + lastCharacter), locationData.last_line = _ref3[0], locationData.last_column = _ref3[1];
+      token = [tag, value, locationData];
+      return token;
+    };
+
+    Lexer.prototype.token = function(tag, value, offsetInChunk, length, origin) {
+      var token;
+      token = this.makeToken(tag, value, offsetInChunk, length);
+      if (origin) {
+        token.origin = origin;
+      }
+      this.tokens.push(token);
+      return token;
     };
 
     Lexer.prototype.tag = function(index, tag) {
@@ -656,19 +773,34 @@
 
     Lexer.prototype.unfinished = function() {
       var _ref2;
-      return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');
+      return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === '?::' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === 'UNARY_MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === '**' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');
+    };
+
+    Lexer.prototype.removeNewlines = function(str) {
+      return str.replace(/^\s*\n\s*/, '').replace(/([^\\]|\\\\)\s*\n\s*$/, '$1');
     };
 
     Lexer.prototype.escapeLines = function(str, heredoc) {
-      return str.replace(MULTILINER, heredoc ? '\\n' : '');
+      str = str.replace(/\\[^\S\n]*(\n|\\)\s*/g, function(escaped, character) {
+        if (character === '\n') {
+          return '';
+        } else {
+          return escaped;
+        }
+      });
+      if (heredoc) {
+        return str.replace(MULTILINER, '\\n');
+      } else {
+        return str.replace(/\s*\n\s*/g, ' ');
+      }
     };
 
     Lexer.prototype.makeString = function(body, quote, heredoc) {
       if (!body) {
         return quote + quote;
       }
-      body = body.replace(/\\([\s\S])/g, function(match, contents) {
-        if (contents === '\n' || contents === quote) {
+      body = body.replace(RegExp("\\\\(" + quote + "|\\\\)", "g"), function(match, contents) {
+        if (contents === quote) {
           return contents;
         } else {
           return match;
@@ -678,8 +810,16 @@
       return quote + this.escapeLines(body, heredoc) + quote;
     };
 
-    Lexer.prototype.error = function(message) {
-      throw SyntaxError("" + message + " on line " + (this.line + 1));
+    Lexer.prototype.error = function(message, offset) {
+      var first_column, first_line, _ref2;
+      if (offset == null) {
+        offset = 0;
+      }
+      _ref2 = this.getLineAndColumnFromChunk(offset), first_line = _ref2[0], first_column = _ref2[1];
+      return throwSyntaxError(message, {
+        first_line: first_line,
+        first_column: first_column
+      });
     };
 
     return Lexer;
@@ -713,7 +853,7 @@
 
   COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);
 
-  RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf', 'implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static', 'yield'];
+  RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf', 'implements', 'interface', 'package', 'private', 'protected', 'public', 'static', 'yield'];
 
   STRICT_PROSCRIBED = ['arguments', 'eval'];
 
@@ -723,31 +863,33 @@
 
   exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED;
 
+  BOM = 65279;
+
   IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/;
 
   NUMBER = /^0b[01]+|^0o[0-7]+|^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i;
 
-  HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/;
+  HEREDOC = /^("""|''')((?:\\[\s\S]|[^\\])*?)(?:\n[^\n\S]*)?\1/;
 
-  OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
+  OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>*\/%])\2=?|\?(\.|::)|\.{2,3})/;
 
   WHITESPACE = /^[^\n\S]+/;
 
-  COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/;
+  COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|###$)|^(?:\s*#(?!##[^#]).*)+/;
 
   CODE = /^[-=]>/;
 
   MULTI_DENT = /^(?:\n[^\n\S]*)+/;
 
-  SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;
+  SIMPLESTR = /^'[^\\']*(?:\\[\s\S][^\\']*)*'/;
 
   JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
 
   REGEX = /^(\/(?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/)([imgy]{0,4})(?!\w)/;
 
-  HEREGEX = /^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?!\w)/;
+  HEREGEX = /^\/{3}((?:\\?[\s\S])+?)\/{3}([imgy]{0,4})(?!\w)/;
 
-  HEREGEX_OMIT = /\s+(?:#.*)?/g;
+  HEREGEX_OMIT = /((?:\\\\)+)|\\(\s|\/)|\s+(?:#.*)?/g;
 
   MULTILINER = /\n/g;
 
@@ -759,9 +901,11 @@
 
   TRAILING_SPACES = /\s+$/;
 
-  COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];
+  COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|=', '**=', '//=', '%%='];
 
-  UNARY = ['!', '~', 'NEW', 'TYPEOF', 'DELETE', 'DO'];
+  UNARY = ['NEW', 'TYPEOF', 'DELETE', 'DO'];
+
+  UNARY_MATH = ['!', '~'];
 
   LOGIC = ['&&', '||', '&', '|', '^'];
 
@@ -769,15 +913,15 @@
 
   COMPARE = ['==', '!=', '<', '>', '<=', '>='];
 
-  MATH = ['*', '/', '%'];
+  MATH = ['*', '/', '%', '//', '%%'];
 
   RELATION = ['IN', 'OF', 'INSTANCEOF'];
 
   BOOL = ['TRUE', 'FALSE'];
 
-  NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', 'NULL', 'UNDEFINED', '++', '--', ']'];
+  NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', 'NULL', 'UNDEFINED', '++', '--'];
 
-  NOT_SPACED_REGEX = NOT_REGEX.concat(')', '}', 'THIS', 'IDENTIFIER', 'STRING');
+  NOT_SPACED_REGEX = NOT_REGEX.concat(')', '}', 'THIS', 'IDENTIFIER', 'STRING', ']');
 
   CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER'];
 
@@ -785,4 +929,6 @@
 
   LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
 
+  INDENTABLE_CLOSERS = [')', '}', ']'];
+
 }).call(this);