Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(915)

Unified Diff: third_party/WebKit/Source/devtools/front_end/formatter_worker/AcornTokenizer.js

Issue 2769843003: DevTools: split text_utils out of common module (Closed)
Patch Set: rebaseline Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/formatter_worker/AcornTokenizer.js
diff --git a/third_party/WebKit/Source/devtools/front_end/formatter_worker/AcornTokenizer.js b/third_party/WebKit/Source/devtools/front_end/formatter_worker/AcornTokenizer.js
index 395c8e5400b5f2dca3ff99b186d9fce0e6774e88..e18423f8e32e70689a4cee5440adf8692217fa0c 100644
--- a/third_party/WebKit/Source/devtools/front_end/formatter_worker/AcornTokenizer.js
+++ b/third_party/WebKit/Source/devtools/front_end/formatter_worker/AcornTokenizer.js
@@ -12,8 +12,7 @@ FormatterWorker.AcornTokenizer = class {
this._content = content;
this._comments = [];
this._tokenizer = acorn.tokenizer(this._content, {ecmaVersion: 8, onComment: this._comments});
- this._lineEndings = this._content.computeLineEndings();
- this._lineNumber = 0;
+ this._textCursor = new TextUtils.TextCursor(this._content.computeLineEndings());
this._tokenLineStart = 0;
this._tokenLineEnd = 0;
this._nextTokenInternal();
@@ -78,16 +77,6 @@ FormatterWorker.AcornTokenizer = class {
}
/**
- * @param {number} position
- * @return {number}
- */
- _rollLineNumberToPosition(position) {
- while (this._lineNumber + 1 < this._lineEndings.length && position > this._lineEndings[this._lineNumber])
- ++this._lineNumber;
- return this._lineNumber;
- }
-
- /**
* @return {?Acorn.TokenOrComment}
*/
nextToken() {
@@ -95,10 +84,12 @@ FormatterWorker.AcornTokenizer = class {
if (token.type === acorn.tokTypes.eof)
return null;
- this._tokenLineStart = this._rollLineNumberToPosition(token.start);
- this._tokenLineEnd = this._rollLineNumberToPosition(token.end);
- this._tokenColumnStart =
- this._tokenLineStart > 0 ? token.start - this._lineEndings[this._tokenLineStart - 1] - 1 : token.start;
+ this._textCursor.advance(token.start);
+ this._tokenLineStart = this._textCursor.lineNumber();
+ this._tokenColumnStart = this._textCursor.columnNumber();
+
+ this._textCursor.advance(token.end);
+ this._tokenLineEnd = this._textCursor.lineNumber();
return token;
}

Powered by Google App Engine
This is Rietveld 408576698