| 50 | #allowRangeMappings: boolean; |
| 51 | |
| 52 | constructor( |
| 53 | opts: { |
| 54 | filename?: string; |
| 55 | sourceFileName?: string; |
| 56 | sourceRoot?: string; |
| 57 | inputSourceMap?: SourceMapInput; |
| 58 | sourceMapRanges?: boolean; |
| 59 | }, |
| 60 | code: string | Record<string, string> | null | undefined, |
| 61 | ) { |
| 62 | const map = (this._map = new GenMapping({ sourceRoot: opts.sourceRoot })); |
| 63 | this._sourceFileName = opts.sourceFileName?.replace(/\\/g, "/"); |
| 64 | this._rawMappings = undefined; |
| 65 | this.#allowRangeMappings = opts.sourceMapRanges ?? false; |
| 66 | |
| 67 | if (opts.inputSourceMap) { |
| 68 | if (this.#allowRangeMappings) { |
| 69 | this.#allowRangeMappings = false; |
| 70 | console.warn( |
| 71 | "[BABEL] Note: The code generator has disabled source map ranges " + |
| 72 | `for ${opts.filename ?? "the generated code"}, because they ` + |
| 73 | "cannot be used together with `inputSourceMap` yet.", |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | this._inputMap = new TraceMap(opts.inputSourceMap); |
| 78 | const resolvedSources = this._inputMap.resolvedSources; |
| 79 | if (resolvedSources.length) { |
| 80 | for (let i = 0; i < resolvedSources.length; i++) { |
| 81 | setSourceContent( |
| 82 | map, |
| 83 | resolvedSources[i], |
| 84 | // @ts-expect-error FIXME: this._inputMap.sourcesContent?.[i] may be undefined, which is not acceptable by setSourceContent |
| 85 | this._inputMap.sourcesContent?.[i], |
| 86 | ); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | if (typeof code === "string" && !opts.inputSourceMap) { |
| 92 | setSourceContent(map, this._sourceFileName!, code); |
| 93 | } else if (typeof code === "object") { |
| 94 | for (const sourceFileName of Object.keys(code!)) { |
| 95 | setSourceContent( |
| 96 | map, |
| 97 | sourceFileName.replace(/\\/g, "/"), |
| 98 | code![sourceFileName], |
| 99 | ); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Get the sourcemap. |