summaryrefslogtreecommitdiff
path: root/node_modules/@babel/generator/lib/buffer.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-12-21 22:46:53 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-12-21 22:46:53 +0800
commitf06956efd2dc4bf77244a9fcce2b883a00b925af (patch)
tree0123cb73ce67f1f4b17e1d6cbabff076ee44e31b /node_modules/@babel/generator/lib/buffer.js
parent8d980c13970c15b6d2312b6fc4ac51698dd0d220 (diff)
updated node modules
Diffstat (limited to 'node_modules/@babel/generator/lib/buffer.js')
-rw-r--r--node_modules/@babel/generator/lib/buffer.js26
1 files changed, 21 insertions, 5 deletions
diff --git a/node_modules/@babel/generator/lib/buffer.js b/node_modules/@babel/generator/lib/buffer.js
index b9574f87..aad6c0bf 100644
--- a/node_modules/@babel/generator/lib/buffer.js
+++ b/node_modules/@babel/generator/lib/buffer.js
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = void 0;
class Buffer {
- constructor(map) {
+ constructor(map, indentChar) {
this._map = null;
this._buf = "";
this._str = "";
@@ -14,6 +14,8 @@ class Buffer {
this._queue = [];
this._queueCursor = 0;
this._canMarkIdName = true;
+ this._indentChar = "";
+ this._fastIndentations = [];
this._position = {
line: 1,
column: 0
@@ -26,6 +28,10 @@ class Buffer {
filename: undefined
};
this._map = map;
+ this._indentChar = indentChar;
+ for (let i = 0; i < 64; i++) {
+ this._fastIndentations.push(indentChar.repeat(i));
+ }
this._allocQueue();
}
_allocQueue() {
@@ -116,8 +122,9 @@ class Buffer {
const sourcePosition = this._sourcePosition;
this._pushQueue(char, 1, sourcePosition.line, sourcePosition.column, sourcePosition.filename);
}
- queueIndentation(char, repeat) {
- this._pushQueue(char, repeat, undefined, undefined, undefined);
+ queueIndentation(repeat) {
+ if (repeat === 0) return;
+ this._pushQueue(-1, repeat, undefined, undefined, undefined);
}
_flush() {
const queueCursor = this._queueCursor;
@@ -130,7 +137,16 @@ class Buffer {
}
_appendChar(char, repeat, sourcePos) {
this._last = char;
- this._str += repeat > 1 ? String.fromCharCode(char).repeat(repeat) : String.fromCharCode(char);
+ if (char === -1) {
+ const fastIndentation = this._fastIndentations[repeat];
+ if (fastIndentation !== undefined) {
+ this._str += fastIndentation;
+ } else {
+ this._str += repeat > 1 ? this._indentChar.repeat(repeat) : this._indentChar;
+ }
+ } else {
+ this._str += repeat > 1 ? String.fromCharCode(char).repeat(repeat) : String.fromCharCode(char);
+ }
if (char !== 10) {
this._mark(sourcePos.line, sourcePos.column, sourcePos.identifierName, sourcePos.identifierNamePos, sourcePos.filename);
this._position.column += repeat;
@@ -188,7 +204,7 @@ class Buffer {
}
_mark(line, column, identifierName, identifierNamePos, filename) {
var _this$_map;
- (_this$_map = this._map) == null ? void 0 : _this$_map.mark(this._position, line, column, identifierName, identifierNamePos, filename);
+ (_this$_map = this._map) == null || _this$_map.mark(this._position, line, column, identifierName, identifierNamePos, filename);
}
removeTrailingNewline() {
const queueCursor = this._queueCursor;