1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 | var _genMapping = require("@jridgewell/gen-mapping");
|
8 | var _traceMapping = require("@jridgewell/trace-mapping");
|
9 | class SourceMap {
|
10 | constructor(opts, code) {
|
11 | var _opts$sourceFileName;
|
12 | this._map = void 0;
|
13 | this._rawMappings = void 0;
|
14 | this._sourceFileName = void 0;
|
15 | this._lastGenLine = 0;
|
16 | this._lastSourceLine = 0;
|
17 | this._lastSourceColumn = 0;
|
18 | this._inputMap = void 0;
|
19 | const map = this._map = new _genMapping.GenMapping({
|
20 | sourceRoot: opts.sourceRoot
|
21 | });
|
22 | this._sourceFileName = (_opts$sourceFileName = opts.sourceFileName) == null ? void 0 : _opts$sourceFileName.replace(/\\/g, "/");
|
23 | this._rawMappings = undefined;
|
24 | if (opts.inputSourceMap) {
|
25 | this._inputMap = new _traceMapping.TraceMap(opts.inputSourceMap);
|
26 | const resolvedSources = this._inputMap.resolvedSources;
|
27 | if (resolvedSources.length) {
|
28 | for (let i = 0; i < resolvedSources.length; i++) {
|
29 | var _this$_inputMap$sourc;
|
30 | (0, _genMapping.setSourceContent)(map, resolvedSources[i], (_this$_inputMap$sourc = this._inputMap.sourcesContent) == null ? void 0 : _this$_inputMap$sourc[i]);
|
31 | }
|
32 | }
|
33 | }
|
34 | if (typeof code === "string" && !opts.inputSourceMap) {
|
35 | (0, _genMapping.setSourceContent)(map, this._sourceFileName, code);
|
36 | } else if (typeof code === "object") {
|
37 | for (const sourceFileName of Object.keys(code)) {
|
38 | (0, _genMapping.setSourceContent)(map, sourceFileName.replace(/\\/g, "/"), code[sourceFileName]);
|
39 | }
|
40 | }
|
41 | }
|
42 | get() {
|
43 | return (0, _genMapping.toEncodedMap)(this._map);
|
44 | }
|
45 | getDecoded() {
|
46 | return (0, _genMapping.toDecodedMap)(this._map);
|
47 | }
|
48 | getRawMappings() {
|
49 | return this._rawMappings || (this._rawMappings = (0, _genMapping.allMappings)(this._map));
|
50 | }
|
51 | mark(generated, line, column, identifierName, identifierNamePos, filename) {
|
52 | var _originalMapping;
|
53 | this._rawMappings = undefined;
|
54 | let originalMapping;
|
55 | if (line != null) {
|
56 | if (this._inputMap) {
|
57 | originalMapping = (0, _traceMapping.originalPositionFor)(this._inputMap, {
|
58 | line,
|
59 | column
|
60 | });
|
61 | if (!originalMapping.name && identifierNamePos) {
|
62 | const originalIdentifierMapping = (0, _traceMapping.originalPositionFor)(this._inputMap, identifierNamePos);
|
63 | if (originalIdentifierMapping.name) {
|
64 | identifierName = originalIdentifierMapping.name;
|
65 | }
|
66 | }
|
67 | } else {
|
68 | originalMapping = {
|
69 | source: (filename == null ? void 0 : filename.replace(/\\/g, "/")) || this._sourceFileName,
|
70 | line: line,
|
71 | column: column
|
72 | };
|
73 | }
|
74 | }
|
75 | (0, _genMapping.maybeAddMapping)(this._map, {
|
76 | name: identifierName,
|
77 | generated,
|
78 | source: (_originalMapping = originalMapping) == null ? void 0 : _originalMapping.source,
|
79 | original: originalMapping
|
80 | });
|
81 | }
|
82 | }
|
83 | exports.default = SourceMap;
|
84 |
|
85 |
|