mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Improve locationData of implicit object braces.
Set location of generated left brace to start of content, so the corresponding AST nodes don't span preceding spaces, blank lines or comments.
This commit is contained in:
@@ -331,22 +331,25 @@
|
||||
|
||||
Rewriter.prototype.addLocationDataToGeneratedTokens = function() {
|
||||
return this.scanTokens(function(token, i, tokens) {
|
||||
var last_column, last_line, _ref, _ref1, _ref2;
|
||||
var column, line, nextLocation, prevLocation, _ref, _ref1;
|
||||
if (token[2]) {
|
||||
return 1;
|
||||
}
|
||||
if (!(token.generated || token.explicit)) {
|
||||
return 1;
|
||||
}
|
||||
_ref2 = (_ref = (_ref1 = tokens[i - 1]) != null ? _ref1[2] : void 0) != null ? _ref : {
|
||||
last_line: 0,
|
||||
last_column: 0
|
||||
}, last_line = _ref2.last_line, last_column = _ref2.last_column;
|
||||
if (token[0] === '{' && (nextLocation = (_ref = tokens[i + 1]) != null ? _ref[2] : void 0)) {
|
||||
line = nextLocation.first_line, column = nextLocation.first_column;
|
||||
} else if (prevLocation = (_ref1 = tokens[i - 1]) != null ? _ref1[2] : void 0) {
|
||||
line = prevLocation.last_line, column = prevLocation.last_column;
|
||||
} else {
|
||||
line = column = 0;
|
||||
}
|
||||
token[2] = {
|
||||
first_line: last_line,
|
||||
first_column: last_column,
|
||||
last_line: last_line,
|
||||
last_column: last_column
|
||||
first_line: line,
|
||||
first_column: column,
|
||||
last_line: line,
|
||||
last_column: column
|
||||
};
|
||||
return 1;
|
||||
});
|
||||
|
||||
@@ -325,12 +325,17 @@ class exports.Rewriter
|
||||
@scanTokens (token, i, tokens) ->
|
||||
return 1 if token[2]
|
||||
return 1 unless token.generated or token.explicit
|
||||
{last_line, last_column} = tokens[i - 1]?[2] ? last_line: 0, last_column: 0
|
||||
if token[0] is '{' and nextLocation=tokens[i + 1]?[2]
|
||||
{first_line: line, first_column: column} = nextLocation
|
||||
else if prevLocation = tokens[i - 1]?[2]
|
||||
{last_line: line, last_column: column} = prevLocation
|
||||
else
|
||||
line = column = 0
|
||||
token[2] =
|
||||
first_line: last_line
|
||||
first_column: last_column
|
||||
last_line: last_line
|
||||
last_column: last_column
|
||||
first_line: line
|
||||
first_column: column
|
||||
last_line: line
|
||||
last_column: column
|
||||
1
|
||||
|
||||
# Because our grammar is LALR(1), it can't handle some single-line
|
||||
|
||||
Reference in New Issue
Block a user