diff --git a/internal/js_printer/js_printer.go b/internal/js_printer/js_printer.go index a5b59cf1ff8..8ab2d833812 100644 --- a/internal/js_printer/js_printer.go +++ b/internal/js_printer/js_printer.go @@ -329,6 +329,7 @@ func (p *printer) printJSXTag(tagOrNil js_ast.Expr) { } type printer struct { + file string symbols js_ast.SymbolMap isUnbound func(js_ast.Ref) bool renamer renamer.Renamer @@ -1759,17 +1760,9 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla // findme // instrument - // p.print(fmt.Sprintf("__INST(%d, null, ", int(expr.Loc.Start))) - - // p.print(fmt.Sprintf("__INST(%07d, null, ", int(expr.Loc.Start)+4*len(p.js)+22-12)) - p.addSourceMapping(expr.Loc) - // p.builder.UpdateGeneratedLineAndColumn(p.js) - - var fileName = strings.Split(string(p.js), "\n")[0] - - p.print(fmt.Sprintf("__INST(%d,%d, %s, ", p.builder.GetPrevGeneratedLine(), - p.builder.GetPrevGeneratedColumn(), fileName)) + p.print(fmt.Sprintf("__INST(%d,%d,null,null,'%s',", p.builder.GetOriginalLine(), + p.builder.GetOriginalColumn(), p.file)) // If syntax compression is enabled, do a pre-pass over unary and binary // operators to inline bitwise operations of cross-module inlined constants. @@ -4548,8 +4541,10 @@ type PrintResult struct { SourceMapChunk sourcemap.Chunk } -func Print(tree js_ast.AST, symbols js_ast.SymbolMap, r renamer.Renamer, options Options) PrintResult { +// findme print +func Print(tree js_ast.AST, symbols js_ast.SymbolMap, r renamer.Renamer, options Options, file string) PrintResult { p := &printer{ + file: file, symbols: symbols, renamer: r, importRecords: tree.ImportRecords, diff --git a/internal/linker/linker.go b/internal/linker/linker.go index 86d85ad6d97..8ec93cd2075 100644 --- a/internal/linker/linker.go +++ b/internal/linker/linker.go @@ -4118,7 +4118,7 @@ func (c *linkerContext) generateCodeForFileInChunkJS( tree.Directive = "" // This is handled elsewhere tree.Parts = []js_ast.Part{{Stmts: stmts}} *result = compileResultJS{ - PrintResult: js_printer.Print(tree, c.graph.Symbols, r, printOptions), + PrintResult: js_printer.Print(tree, c.graph.Symbols, r, printOptions, file.InputFile.Source.PrettyPath), sourceIndex: partRange.sourceIndex, } @@ -4435,7 +4435,7 @@ func (c *linkerContext) generateEntryPointTailJS( RequireOrImportMetaForSource: c.requireOrImportMetaForSource, MangledProps: c.mangledProps, } - result.PrintResult = js_printer.Print(tree, c.graph.Symbols, r, printOptions) + result.PrintResult = js_printer.Print(tree, c.graph.Symbols, r, printOptions, file.InputFile.Source.PrettyPath) return } @@ -4761,12 +4761,12 @@ func (c *linkerContext) generateChunkJS(chunkIndex int, chunkWaitGroup *sync.Wai crossChunkResult := js_printer.Print(js_ast.AST{ ImportRecords: crossChunkImportRecords, Parts: []js_ast.Part{{Stmts: chunkRepr.crossChunkPrefixStmts}}, - }, c.graph.Symbols, r, printOptions) + }, c.graph.Symbols, r, printOptions, "") crossChunkPrefix = crossChunkResult.JS jsonMetadataImports = crossChunkResult.JSONMetadataImports crossChunkSuffix = js_printer.Print(js_ast.AST{ Parts: []js_ast.Part{{Stmts: chunkRepr.crossChunkSuffixStmts}}, - }, c.graph.Symbols, r, printOptions).JS + }, c.graph.Symbols, r, printOptions, "").JS } // Generate the exports for the entry point, if there are any diff --git a/internal/sourcemap/sourcemap.go b/internal/sourcemap/sourcemap.go index 88bad0d1bba..8fb8598cb29 100644 --- a/internal/sourcemap/sourcemap.go +++ b/internal/sourcemap/sourcemap.go @@ -726,19 +726,14 @@ func (b *ChunkBuilder) GenerateChunk(output []byte) Chunk { } } -func (b *ChunkBuilder) GetPrevGeneratedLine() int { - return b.prevState.GeneratedLine +func (b *ChunkBuilder) GetOriginalLine() int { + return int(b.prevState.OriginalLine) } -func (b *ChunkBuilder) GetPrevGeneratedColumn() int { - return b.prevState.GeneratedColumn +func (b *ChunkBuilder) GetOriginalColumn() int { + return int(b.prevState.OriginalColumn) } -func (b *ChunkBuilder) GetPrevOriginalName() string { - return b.prevOriginalName -} - - // Scan over the printed text since the last source mapping and update the // generated line and column numbers func (b *ChunkBuilder) updateGeneratedLineAndColumn(output []byte) {