| | |
| | | value: true |
| | | }); |
| | | exports.default = void 0; |
| | | |
| | | function SourcePos() { |
| | | return { |
| | | identifierName: undefined, |
| | | line: undefined, |
| | | column: undefined, |
| | | filename: undefined |
| | | }; |
| | | } |
| | | |
| | | const SPACES_RE = /^[ \t]+$/; |
| | | |
| | | class Buffer { |
| | |
| | | line: 1, |
| | | column: 0 |
| | | }; |
| | | this._sourcePosition = { |
| | | identifierName: null, |
| | | line: null, |
| | | column: null, |
| | | filename: null |
| | | }; |
| | | this._sourcePosition = SourcePos(); |
| | | this._disallowedPop = null; |
| | | this._map = map; |
| | | } |
| | |
| | | const map = this._map; |
| | | const result = { |
| | | code: this._buf.trimRight(), |
| | | map: null, |
| | | rawMappings: map == null ? void 0 : map.getRawMappings() |
| | | decodedMap: map == null ? void 0 : map.getDecoded(), |
| | | |
| | | get map() { |
| | | return result.map = map ? map.get() : null; |
| | | }, |
| | | |
| | | set map(value) { |
| | | Object.defineProperty(result, "map", { |
| | | value, |
| | | writable: true |
| | | }); |
| | | }, |
| | | |
| | | get rawMappings() { |
| | | return result.rawMappings = map == null ? void 0 : map.getRawMappings(); |
| | | }, |
| | | |
| | | set rawMappings(value) { |
| | | Object.defineProperty(result, "rawMappings", { |
| | | value, |
| | | writable: true |
| | | }); |
| | | } |
| | | |
| | | }; |
| | | |
| | | if (map) { |
| | | Object.defineProperty(result, "map", { |
| | | configurable: true, |
| | | enumerable: true, |
| | | |
| | | get() { |
| | | return this.map = map.get(); |
| | | }, |
| | | |
| | | set(value) { |
| | | Object.defineProperty(this, "map", { |
| | | value, |
| | | writable: true |
| | | }); |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | |
| | | line, |
| | | column, |
| | | filename, |
| | | identifierName, |
| | | force |
| | | identifierName |
| | | } = this._sourcePosition; |
| | | |
| | | this._append(str, line, column, identifierName, filename, force); |
| | | this._append(str, line, column, identifierName, filename); |
| | | } |
| | | |
| | | queue(str) { |
| | |
| | | line, |
| | | column, |
| | | filename, |
| | | identifierName, |
| | | force |
| | | identifierName |
| | | } = this._sourcePosition; |
| | | |
| | | this._queue.unshift([str, line, column, identifierName, filename, force]); |
| | | this._queue.unshift([str, line, column, identifierName, filename]); |
| | | } |
| | | |
| | | queueIndentation(str) { |
| | | this._queue.unshift([str, undefined, undefined, undefined, undefined]); |
| | | } |
| | | |
| | | _flush() { |
| | |
| | | } |
| | | } |
| | | |
| | | _append(str, line, column, identifierName, filename, force) { |
| | | _append(str, line, column, identifierName, filename) { |
| | | this._buf += str; |
| | | this._last = str.charCodeAt(str.length - 1); |
| | | let i = str.indexOf("\n"); |
| | | let last = 0; |
| | | |
| | | if (i !== 0) { |
| | | this._mark(line, column, identifierName, filename, force); |
| | | this._mark(line, column, identifierName, filename); |
| | | } |
| | | |
| | | while (i !== -1) { |
| | |
| | | last = i + 1; |
| | | |
| | | if (last < str.length) { |
| | | this._mark(++line, 0, identifierName, filename, force); |
| | | this._mark(++line, 0, identifierName, filename); |
| | | } |
| | | |
| | | i = str.indexOf("\n", last); |
| | |
| | | this._position.column += str.length - last; |
| | | } |
| | | |
| | | _mark(line, column, identifierName, filename, force) { |
| | | _mark(line, column, identifierName, filename) { |
| | | var _this$_map; |
| | | |
| | | (_this$_map = this._map) == null ? void 0 : _this$_map.mark(this._position.line, this._position.column, line, column, identifierName, filename, force); |
| | | (_this$_map = this._map) == null ? void 0 : _this$_map.mark(this._position, line, column, identifierName, filename); |
| | | } |
| | | |
| | | removeTrailingNewline() { |
| | |
| | | } |
| | | |
| | | exactSource(loc, cb) { |
| | | this.source("start", loc, true); |
| | | this.source("start", loc); |
| | | cb(); |
| | | this.source("end", loc); |
| | | |
| | | this._disallowPop("start", loc); |
| | | } |
| | | |
| | | source(prop, loc, force) { |
| | | source(prop, loc) { |
| | | if (prop && !loc) return; |
| | | |
| | | this._normalizePosition(prop, loc, this._sourcePosition, force); |
| | | this._normalizePosition(prop, loc, this._sourcePosition); |
| | | } |
| | | |
| | | withSource(prop, loc, cb) { |
| | |
| | | this.source(prop, loc); |
| | | cb(); |
| | | |
| | | if ((!this._sourcePosition.force || this._sourcePosition.line !== originalLine || this._sourcePosition.column !== originalColumn || this._sourcePosition.filename !== originalFilename) && (!this._disallowedPop || this._disallowedPop.line !== originalLine || this._disallowedPop.column !== originalColumn || this._disallowedPop.filename !== originalFilename)) { |
| | | if (!this._disallowedPop || this._disallowedPop.line !== originalLine || this._disallowedPop.column !== originalColumn || this._disallowedPop.filename !== originalFilename) { |
| | | this._sourcePosition.line = originalLine; |
| | | this._sourcePosition.column = originalColumn; |
| | | this._sourcePosition.filename = originalFilename; |
| | | this._sourcePosition.identifierName = originalIdentifierName; |
| | | this._sourcePosition.force = false; |
| | | this._disallowedPop = null; |
| | | } |
| | | } |
| | | |
| | | _disallowPop(prop, loc) { |
| | | if (prop && !loc) return; |
| | | this._disallowedPop = this._normalizePosition(prop, loc); |
| | | this._disallowedPop = this._normalizePosition(prop, loc, SourcePos()); |
| | | } |
| | | |
| | | _normalizePosition(prop, loc, targetObj, force) { |
| | | _normalizePosition(prop, loc, targetObj) { |
| | | const pos = loc ? loc[prop] : null; |
| | | |
| | | if (targetObj === undefined) { |
| | | targetObj = { |
| | | identifierName: null, |
| | | line: null, |
| | | column: null, |
| | | filename: null, |
| | | force: false |
| | | }; |
| | | } |
| | | |
| | | const origLine = targetObj.line; |
| | | const origColumn = targetObj.column; |
| | | const origFilename = targetObj.filename; |
| | | targetObj.identifierName = prop === "start" && (loc == null ? void 0 : loc.identifierName) || null; |
| | | targetObj.identifierName = prop === "start" && (loc == null ? void 0 : loc.identifierName) || undefined; |
| | | targetObj.line = pos == null ? void 0 : pos.line; |
| | | targetObj.column = pos == null ? void 0 : pos.column; |
| | | targetObj.filename = loc == null ? void 0 : loc.filename; |
| | | |
| | | if (force || targetObj.line !== origLine || targetObj.column !== origColumn || targetObj.filename !== origFilename) { |
| | | targetObj.force = force; |
| | | } |
| | | |
| | | return targetObj; |
| | | } |
| | | |