Run prettier
This commit is contained in:
@@ -54,7 +54,7 @@ export default class Buffer {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return this.map = map.get();
|
||||
return (this.map = map.get());
|
||||
},
|
||||
set(value) {
|
||||
Object.defineProperty(this, "map", { value, writable: true });
|
||||
@@ -81,7 +81,11 @@ export default class Buffer {
|
||||
|
||||
queue(str: string): void {
|
||||
// Drop trailing spaces when a newline is inserted.
|
||||
if (str === "\n") while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) this._queue.shift();
|
||||
if (str === "\n") {
|
||||
while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) {
|
||||
this._queue.shift();
|
||||
}
|
||||
}
|
||||
|
||||
const { line, column, filename, identifierName } = this._sourcePosition;
|
||||
this._queue.unshift([str, line, column, identifierName, filename]);
|
||||
@@ -89,13 +93,26 @@ export default class Buffer {
|
||||
|
||||
_flush(): void {
|
||||
let item;
|
||||
while (item = this._queue.pop()) this._append(...item);
|
||||
while ((item = this._queue.pop())) this._append(...item);
|
||||
}
|
||||
|
||||
_append(str: string, line: number, column: number, identifierName: ?string, filename: ?string): void {
|
||||
_append(
|
||||
str: string,
|
||||
line: number,
|
||||
column: number,
|
||||
identifierName: ?string,
|
||||
filename: ?string,
|
||||
): void {
|
||||
// If there the line is ending, adding a new mapping marker is redundant
|
||||
if (this._map && str[0] !== "\n") {
|
||||
this._map.mark(this._position.line, this._position.column, line, column, identifierName, filename);
|
||||
this._map.mark(
|
||||
this._position.line,
|
||||
this._position.column,
|
||||
line,
|
||||
column,
|
||||
identifierName,
|
||||
filename,
|
||||
);
|
||||
}
|
||||
|
||||
this._buf.push(str);
|
||||
@@ -112,11 +129,15 @@ export default class Buffer {
|
||||
}
|
||||
|
||||
removeTrailingNewline(): void {
|
||||
if (this._queue.length > 0 && this._queue[0][0] === "\n") this._queue.shift();
|
||||
if (this._queue.length > 0 && this._queue[0][0] === "\n") {
|
||||
this._queue.shift();
|
||||
}
|
||||
}
|
||||
|
||||
removeLastSemicolon(): void {
|
||||
if (this._queue.length > 0 && this._queue[0][0] === ";") this._queue.shift();
|
||||
if (this._queue.length > 0 && this._queue[0][0] === ";") {
|
||||
this._queue.shift();
|
||||
}
|
||||
}
|
||||
|
||||
endsWith(suffix: string): boolean {
|
||||
@@ -133,7 +154,8 @@ export default class Buffer {
|
||||
return last === suffix;
|
||||
}
|
||||
|
||||
const end = this._last + this._queue.reduce((acc, item) => item[0] + acc, "");
|
||||
const end =
|
||||
this._last + this._queue.reduce((acc, item) => item[0] + acc, "");
|
||||
if (suffix.length <= end.length) {
|
||||
return end.slice(-suffix.length) === suffix;
|
||||
}
|
||||
@@ -157,10 +179,10 @@ export default class Buffer {
|
||||
|
||||
const pos = loc ? loc[prop] : null;
|
||||
|
||||
this._sourcePosition.identifierName = loc && loc.identifierName || null;
|
||||
this._sourcePosition.identifierName = (loc && loc.identifierName) || null;
|
||||
this._sourcePosition.line = pos ? pos.line : null;
|
||||
this._sourcePosition.column = pos ? pos.column : null;
|
||||
this._sourcePosition.filename = loc && loc.filename || null;
|
||||
this._sourcePosition.filename = (loc && loc.filename) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +212,9 @@ export default class Buffer {
|
||||
const extra = this._queue.reduce((acc, item) => item[0] + acc, "");
|
||||
const lastIndex = extra.lastIndexOf("\n");
|
||||
|
||||
return lastIndex === -1 ? this._position.column + extra.length : (extra.length - 1 - lastIndex);
|
||||
return lastIndex === -1
|
||||
? this._position.column + extra.length
|
||||
: extra.length - 1 - lastIndex;
|
||||
}
|
||||
|
||||
getCurrentLine(): number {
|
||||
|
||||
Reference in New Issue
Block a user