update coffee script fixes #1568
This commit is contained in:
parent
330b8a4a8e
commit
27b91b44e0
5 changed files with 358 additions and 226 deletions
|
|
@ -27,7 +27,7 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
// Generated by CoffeeScript 1.6.3
|
// 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) {
|
exports.starts = function(string, literal, start) {
|
||||||
return literal === string.substr(start, literal.length);
|
return literal === string.substr(start, literal.length);
|
||||||
|
|
@ -223,30 +223,48 @@ define(function(require, exports, module) {
|
||||||
}
|
}
|
||||||
error = new SyntaxError(message);
|
error = new SyntaxError(message);
|
||||||
error.location = location;
|
error.location = location;
|
||||||
|
error.toString = syntaxErrorToString;
|
||||||
|
error.stack = error.toString();
|
||||||
throw error;
|
throw error;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.prettyErrorMessage = function(error, filename, code, useColors) {
|
exports.updateSyntaxError = function(error, code, filename) {
|
||||||
var codeLine, colorize, end, first_column, first_line, last_column, last_line, marker, message, start, _ref1;
|
if (error.toString === syntaxErrorToString) {
|
||||||
if (!error.location) {
|
error.code || (error.code = code);
|
||||||
return error.stack || ("" + error);
|
error.filename || (error.filename = filename);
|
||||||
|
error.stack = error.toString();
|
||||||
}
|
}
|
||||||
filename = error.filename || filename;
|
return error;
|
||||||
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];
|
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;
|
start = first_column;
|
||||||
end = first_line === last_line ? last_column + 1 : codeLine.length;
|
end = first_line === last_line ? last_column + 1 : codeLine.length;
|
||||||
marker = repeat(' ', start) + repeat('^', end - start);
|
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) {
|
colorize = function(str) {
|
||||||
return "\x1B[1;31m" + str + "\x1B[0m";
|
return "\x1B[1;31m" + str + "\x1B[0m";
|
||||||
};
|
};
|
||||||
codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);
|
codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);
|
||||||
marker = colorize(marker);
|
marker = colorize(marker);
|
||||||
}
|
}
|
||||||
message = "" + filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + error.message + "\n" + codeLine + "\n" + marker;
|
return "" + filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + this.message + "\n" + codeLine + "\n" + marker;
|
||||||
return message;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ define(function(require, exports, module) {
|
||||||
}
|
}
|
||||||
this.literate = opts.literate;
|
this.literate = opts.literate;
|
||||||
this.indent = 0;
|
this.indent = 0;
|
||||||
|
this.baseIndent = 0;
|
||||||
this.indebt = 0;
|
this.indebt = 0;
|
||||||
this.outdebt = 0;
|
this.outdebt = 0;
|
||||||
this.indents = [];
|
this.indents = [];
|
||||||
|
|
@ -373,11 +374,17 @@ define(function(require, exports, module) {
|
||||||
this.suppressNewlines();
|
this.suppressNewlines();
|
||||||
return indent.length;
|
return indent.length;
|
||||||
}
|
}
|
||||||
|
if (!this.tokens.length) {
|
||||||
|
this.baseIndent = this.indent = size;
|
||||||
|
return indent.length;
|
||||||
|
}
|
||||||
diff = size - this.indent + this.outdebt;
|
diff = size - this.indent + this.outdebt;
|
||||||
this.token('INDENT', diff, indent.length - size, size);
|
this.token('INDENT', diff, indent.length - size, size);
|
||||||
this.indents.push(diff);
|
this.indents.push(diff);
|
||||||
this.ends.push('OUTDENT');
|
this.ends.push('OUTDENT');
|
||||||
this.outdebt = this.indebt = 0;
|
this.outdebt = this.indebt = 0;
|
||||||
|
} else if (size < this.baseIndent) {
|
||||||
|
this.error('missing indentation', indent.length);
|
||||||
} else {
|
} else {
|
||||||
this.indebt = 0;
|
this.indebt = 0;
|
||||||
this.outdentToken(this.indent - size, noNewlines, indent.length);
|
this.outdentToken(this.indent - size, noNewlines, indent.length);
|
||||||
|
|
@ -801,10 +808,15 @@ define(function(require, exports, module) {
|
||||||
return quote + this.escapeLines(body, heredoc) + quote;
|
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, {
|
return throwSyntaxError(message, {
|
||||||
first_line: this.chunkLine,
|
first_line: first_line,
|
||||||
first_column: this.chunkColumn
|
first_column: first_column
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,10 @@ define(function(require, exports, module) {
|
||||||
Base.prototype.assigns = NO;
|
Base.prototype.assigns = NO;
|
||||||
|
|
||||||
Base.prototype.updateLocationDataIfMissing = function(locationData) {
|
Base.prototype.updateLocationDataIfMissing = function(locationData) {
|
||||||
this.locationData || (this.locationData = locationData);
|
if (this.locationData) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
this.locationData = locationData;
|
||||||
return this.eachChild(function(child) {
|
return this.eachChild(function(child) {
|
||||||
return child.updateLocationDataIfMissing(locationData);
|
return child.updateLocationDataIfMissing(locationData);
|
||||||
});
|
});
|
||||||
|
|
@ -849,11 +852,11 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
Comment.prototype.compileNode = function(o, level) {
|
Comment.prototype.compileNode = function(o, level) {
|
||||||
var code;
|
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) {
|
if ((level || o.level) === LEVEL_TOP) {
|
||||||
code = o.indent + code;
|
code = o.indent + code;
|
||||||
}
|
}
|
||||||
return [this.makeCode(code)];
|
return [this.makeCode("\n"), this.makeCode(code)];
|
||||||
};
|
};
|
||||||
|
|
||||||
return Comment;
|
return Comment;
|
||||||
|
|
@ -2879,6 +2882,7 @@ define(function(require, exports, module) {
|
||||||
} else {
|
} else {
|
||||||
this.isChain = elseBody instanceof If;
|
this.isChain = elseBody instanceof If;
|
||||||
this.elseBody = this.ensureBlock(elseBody);
|
this.elseBody = this.ensureBlock(elseBody);
|
||||||
|
this.elseBody.updateLocationDataIfMissing(elseBody.locationData);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -72,7 +72,7 @@ module.exports = {
|
||||||
"test unexpected indent": function() {
|
"test unexpected indent": function() {
|
||||||
var e = parse("a\n a\n");
|
var e = parse("a\n a\n");
|
||||||
assert.equal(e.message, "Unexpected 'INDENT'");
|
assert.equal(e.message, "Unexpected 'INDENT'");
|
||||||
assertLocation(e, 0, 0, 0, 0);
|
assertLocation(e, 1, 0, 1, 1);
|
||||||
},
|
},
|
||||||
"test invalid destructuring": function() {
|
"test invalid destructuring": function() {
|
||||||
var e = parse("\n{b: 5} = {}");
|
var e = parse("\n{b: 5} = {}");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue