Skip to content

Commit

Permalink
work on evanw#184
Browse files Browse the repository at this point in the history
  • Loading branch information
stoand committed Mar 13, 2023
1 parent c525039 commit 514b771
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 12 additions & 4 deletions internal/js_printer/js_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,15 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla

// findme
// instrument
p.print(fmt.Sprintf("__INST(%d, null, ", expr.Loc.Start))
// 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)

p.print(fmt.Sprintf("__INST(%d,%d, %s, ", p.builder.GetPrevGeneratedLine(),
p.builder.GetPrevGeneratedColumn(), p.builder.GetPrevOriginalName()))

// If syntax compression is enabled, do a pre-pass over unary and binary
// operators to inline bitwise operations of cross-module inlined constants.
Expand Down Expand Up @@ -3372,7 +3380,7 @@ func (p *printer) printBlock(loc logger.Loc, block js_ast.SBlock) {
p.printNewline()

// instrument
p.print(fmt.Sprintf("__INST(%d, %d);", loc.Start, block.CloseBraceLoc.Start))
// p.print(fmt.Sprintf("__INST(%d, %d);", loc.Start, block.CloseBraceLoc.Start))
p.printNewline()

p.options.Indent++
Expand Down Expand Up @@ -3707,9 +3715,9 @@ func (p *printer) printStmt(stmt js_ast.Stmt, flags printStmtFlags) {

// findme
// p.print(fmt.Sprintf("/**(start-st-%d)*/", stmt.Loc.Start))

// instrument
p.print(fmt.Sprintf("__INST(%d, null);", stmt.Loc.Start))
// p.print(fmt.Sprintf("__INST(%d, null);", stmt.Loc.Start))

switch s := stmt.Data.(type) {
case *js_ast.SComment:
Expand Down
13 changes: 13 additions & 0 deletions internal/sourcemap/sourcemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,19 @@ func (b *ChunkBuilder) GenerateChunk(output []byte) Chunk {
}
}

func (b *ChunkBuilder) GetPrevGeneratedLine() int {
return b.prevState.GeneratedLine
}

func (b *ChunkBuilder) GetPrevGeneratedColumn() int {
return b.prevState.GeneratedColumn
}

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) {
Expand Down

0 comments on commit 514b771

Please sign in to comment.