Add location data to tokens generated by the rewriter.

This commit is contained in:
Jason Walton
2012-11-19 11:34:09 -05:00
parent bb94e02fad
commit 12625cc00c
2 changed files with 47 additions and 1 deletions

View File

@@ -18,6 +18,7 @@
this.tagPostfixConditionals();
this.addImplicitBraces();
this.addImplicitParentheses();
this.addLocationDataToGeneratedTokens();
return this.tokens;
};
@@ -221,6 +222,31 @@
});
};
Rewriter.prototype.addLocationDataToGeneratedTokens = function() {
return this.scanTokens(function(token, i, tokens) {
var prevToken;
if (token.generated && !token.locationData) {
if (i > 0) {
prevToken = tokens[i - 1];
token.locationData = {
first_line: prevToken.locationData.last_line,
first_column: prevToken.locationData.last_column,
last_line: prevToken.locationData.last_line,
last_column: prevToken.locationData.last_column
};
} else {
token.locationData = {
first_line: 0,
first_column: 0,
last_line: 0,
last_column: 0
};
}
}
return 1;
});
};
Rewriter.prototype.addImplicitIndentation = function() {
var action, condition, indent, outdent, starter;
starter = indent = outdent = null;