1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/@babel/generator/lib/buffer.js

217 lines
5.4 KiB
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _trimRight() {
2024-01-16 21:26:16 +08:00
var data = _interopRequireDefault(require("trim-right"));
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_trimRight = function _trimRight() {
2023-12-18 13:12:25 +08:00
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2024-01-16 21:26:16 +08:00
var SPACES_RE = /^[ \t]+$/;
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
var Buffer = function () {
function Buffer(map) {
2023-12-18 13:12:25 +08:00
this._map = null;
this._buf = [];
this._last = "";
this._queue = [];
this._position = {
line: 1,
column: 0
};
this._sourcePosition = {
identifierName: null,
line: null,
column: null,
filename: null
};
this._map = map;
}
2024-01-16 21:26:16 +08:00
var _proto = Buffer.prototype;
_proto.get = function get() {
2023-12-18 13:12:25 +08:00
this._flush();
2024-01-16 21:26:16 +08:00
var map = this._map;
var result = {
2023-12-18 13:12:25 +08:00
code: (0, _trimRight().default)(this._buf.join("")),
map: null,
rawMappings: map && map.getRawMappings()
};
if (map) {
Object.defineProperty(result, "map", {
configurable: true,
enumerable: true,
2024-01-16 21:26:16 +08:00
get: function get() {
2023-12-18 13:12:25 +08:00
return this.map = map.get();
},
2024-01-16 21:26:16 +08:00
set: function set(value) {
2023-12-18 13:12:25 +08:00
Object.defineProperty(this, "map", {
2024-01-16 21:26:16 +08:00
value: value,
2023-12-18 13:12:25 +08:00
writable: true
});
}
});
}
return result;
2024-01-16 21:26:16 +08:00
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto.append = function append(str) {
2023-12-18 13:12:25 +08:00
this._flush();
2024-01-16 21:26:16 +08:00
var _sourcePosition = this._sourcePosition,
line = _sourcePosition.line,
column = _sourcePosition.column,
filename = _sourcePosition.filename,
identifierName = _sourcePosition.identifierName;
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
this._append(str, line, column, identifierName, filename);
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto.queue = function queue(str) {
2023-12-18 13:12:25 +08:00
if (str === "\n") {
while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) {
this._queue.shift();
}
}
2024-01-16 21:26:16 +08:00
var _sourcePosition2 = this._sourcePosition,
line = _sourcePosition2.line,
column = _sourcePosition2.column,
filename = _sourcePosition2.filename,
identifierName = _sourcePosition2.identifierName;
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
this._queue.unshift([str, line, column, identifierName, filename]);
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto._flush = function _flush() {
var item;
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
while (item = this._queue.pop()) {
this._append.apply(this, item);
}
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto._append = function _append(str, line, column, identifierName, filename) {
2023-12-18 13:12:25 +08:00
if (this._map && str[0] !== "\n") {
2024-01-16 21:26:16 +08:00
this._map.mark(this._position.line, this._position.column, line, column, identifierName, filename);
2023-12-18 13:12:25 +08:00
}
this._buf.push(str);
this._last = str[str.length - 1];
2024-01-16 21:26:16 +08:00
for (var i = 0; i < str.length; i++) {
2023-12-18 13:12:25 +08:00
if (str[i] === "\n") {
this._position.line++;
this._position.column = 0;
} else {
this._position.column++;
}
}
2024-01-16 21:26:16 +08:00
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto.removeTrailingNewline = function removeTrailingNewline() {
2023-12-18 13:12:25 +08:00
if (this._queue.length > 0 && this._queue[0][0] === "\n") {
this._queue.shift();
}
2024-01-16 21:26:16 +08:00
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto.removeLastSemicolon = function removeLastSemicolon() {
2023-12-18 13:12:25 +08:00
if (this._queue.length > 0 && this._queue[0][0] === ";") {
this._queue.shift();
}
2024-01-16 21:26:16 +08:00
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto.endsWith = function endsWith(suffix) {
2023-12-18 13:12:25 +08:00
if (suffix.length === 1) {
2024-01-16 21:26:16 +08:00
var last;
2023-12-18 13:12:25 +08:00
if (this._queue.length > 0) {
2024-01-16 21:26:16 +08:00
var str = this._queue[0][0];
2023-12-18 13:12:25 +08:00
last = str[str.length - 1];
} else {
last = this._last;
}
return last === suffix;
}
2024-01-16 21:26:16 +08:00
var end = this._last + this._queue.reduce(function (acc, item) {
return item[0] + acc;
}, "");
2023-12-18 13:12:25 +08:00
if (suffix.length <= end.length) {
return end.slice(-suffix.length) === suffix;
}
return false;
2024-01-16 21:26:16 +08:00
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto.hasContent = function hasContent() {
2023-12-18 13:12:25 +08:00
return this._queue.length > 0 || !!this._last;
2024-01-16 21:26:16 +08:00
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto.source = function source(prop, loc) {
2023-12-18 13:12:25 +08:00
if (prop && !loc) return;
2024-01-16 21:26:16 +08:00
var pos = loc ? loc[prop] : 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;
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto.withSource = function withSource(prop, loc, cb) {
2023-12-18 13:12:25 +08:00
if (!this._map) return cb();
2024-01-16 21:26:16 +08:00
var originalLine = this._sourcePosition.line;
var originalColumn = this._sourcePosition.column;
var originalFilename = this._sourcePosition.filename;
var originalIdentifierName = this._sourcePosition.identifierName;
2023-12-18 13:12:25 +08:00
this.source(prop, loc);
cb();
2024-01-16 21:26:16 +08:00
this._sourcePosition.line = originalLine;
this._sourcePosition.column = originalColumn;
this._sourcePosition.filename = originalFilename;
this._sourcePosition.identifierName = originalIdentifierName;
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto.getCurrentColumn = function getCurrentColumn() {
var extra = this._queue.reduce(function (acc, item) {
return item[0] + acc;
}, "");
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
var lastIndex = extra.lastIndexOf("\n");
2023-12-18 13:12:25 +08:00
return lastIndex === -1 ? this._position.column + extra.length : extra.length - 1 - lastIndex;
2024-01-16 21:26:16 +08:00
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
_proto.getCurrentLine = function getCurrentLine() {
var extra = this._queue.reduce(function (acc, item) {
return item[0] + acc;
}, "");
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
var count = 0;
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
for (var i = 0; i < extra.length; i++) {
2023-12-18 13:12:25 +08:00
if (extra[i] === "\n") count++;
}
return this._position.line + count;
2024-01-16 21:26:16 +08:00
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
return Buffer;
}();
2023-12-18 13:12:25 +08:00
exports.default = Buffer;