update coffee script fixes #1568

This commit is contained in:
nightwing 2013-08-26 17:44:57 +04:00
commit 27b91b44e0
5 changed files with 358 additions and 226 deletions

View file

@ -27,7 +27,7 @@
define(function(require, exports, module) {
// Generated by CoffeeScript 1.6.3
var buildLocationData, extend, flatten, last, repeat, _ref;
var buildLocationData, extend, flatten, last, repeat, syntaxErrorToString, _ref;
exports.starts = function(string, literal, start) {
return literal === string.substr(start, literal.length);
@ -223,30 +223,48 @@ define(function(require, exports, module) {
}
error = new SyntaxError(message);
error.location = location;
error.toString = syntaxErrorToString;
error.stack = error.toString();
throw error;
};
exports.prettyErrorMessage = function(error, filename, code, useColors) {
var codeLine, colorize, end, first_column, first_line, last_column, last_line, marker, message, start, _ref1;
if (!error.location) {
return error.stack || ("" + 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();
}
filename = error.filename || filename;
code = error.code || code;
_ref1 = error.location, first_line = _ref1.first_line, first_column = _ref1.first_column, last_line = _ref1.last_line, last_column = _ref1.last_column;
codeLine = code.split('\n')[first_line];
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 = repeat(' ', start) + repeat('^', end - start);
if (useColors) {
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);
}
message = "" + filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + error.message + "\n" + codeLine + "\n" + marker;
return message;
return "" + filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + this.message + "\n" + codeLine + "\n" + marker;
};

View file

@ -44,6 +44,7 @@ define(function(require, exports, module) {
}
this.literate = opts.literate;
this.indent = 0;
this.baseIndent = 0;
this.indebt = 0;
this.outdebt = 0;
this.indents = [];
@ -373,11 +374,17 @@ define(function(require, exports, module) {
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, indent.length - size, size);
this.indents.push(diff);
this.ends.push('OUTDENT');
this.outdebt = this.indebt = 0;
} else if (size < this.baseIndent) {
this.error('missing indentation', indent.length);
} else {
this.indebt = 0;
this.outdentToken(this.indent - size, noNewlines, indent.length);
@ -801,10 +808,15 @@ define(function(require, exports, module) {
return quote + this.escapeLines(body, heredoc) + quote;
};
Lexer.prototype.error = function(message) {
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: this.chunkLine,
first_column: this.chunkColumn
first_line: first_line,
first_column: first_column
});
};

View file

@ -256,7 +256,10 @@ define(function(require, exports, module) {
Base.prototype.assigns = NO;
Base.prototype.updateLocationDataIfMissing = function(locationData) {
this.locationData || (this.locationData = locationData);
if (this.locationData) {
return this;
}
this.locationData = locationData;
return this.eachChild(function(child) {
return child.updateLocationDataIfMissing(locationData);
});
@ -849,11 +852,11 @@ define(function(require, exports, module) {
Comment.prototype.compileNode = function(o, level) {
var code;
code = "/*" + (multident(this.comment, this.tab)) + (__indexOf.call(this.comment, '\n') >= 0 ? "\n" + this.tab : '') + "*/\n";
code = "/*" + (multident(this.comment, this.tab)) + (__indexOf.call(this.comment, '\n') >= 0 ? "\n" + this.tab : '') + "*/";
if ((level || o.level) === LEVEL_TOP) {
code = o.indent + code;
}
return [this.makeCode(code)];
return [this.makeCode("\n"), this.makeCode(code)];
};
return Comment;
@ -2879,6 +2882,7 @@ define(function(require, exports, module) {
} else {
this.isChain = elseBody instanceof If;
this.elseBody = this.ensureBlock(elseBody);
this.elseBody.updateLocationDataIfMissing(elseBody.locationData);
}
return this;
};

File diff suppressed because one or more lines are too long

View file

@ -72,7 +72,7 @@ module.exports = {
"test unexpected indent": function() {
var e = parse("a\n a\n");
assert.equal(e.message, "Unexpected 'INDENT'");
assertLocation(e, 0, 0, 0, 0);
assertLocation(e, 1, 0, 1, 1);
},
"test invalid destructuring": function() {
var e = parse("\n{b: 5} = {}");