Skip to content

Commit

Permalink
fix #289: off-by-one error with source map index
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jul 30, 2020
1 parent 272d43f commit 0bdd842
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

Care was taken to still parallelize as much as possible despite parts of the code having to block. Each input file in a chunk is still printed to a string fully in parallel. Waiting was only introduced in the chunk assembly stage where input file strings are joined together. In practice, this change doesn't appear to have slowed down esbuild by a noticeable amount.

* Fix an off-by-one error with source map generation ([#289](https://github.com/evanw/esbuild/issues/289))

The nested source map support added in version 0.6.5 contained a bug. Input files that were included in the bundle but that didn't themselves contain any generated code caused the source index to shift by one, throwing off the source names of all files after it. This could happen with files consisting only of re-export statements (e.g. `export {name} from 'path'`). This bug has been fixed and this specific scenario now has test coverage.

## 0.6.10

* Revert the binary operator chain change
Expand Down
8 changes: 4 additions & 4 deletions internal/bundler/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2959,11 +2959,11 @@ func (c *linkerContext) generateChunk(chunk *chunkMeta) func([]ast.ImportRecord)
prevOffset.advanceBytes(compileResult.JS)
} else {
prevOffset = lineColumnOffset{}
}

// Include this file in the source map
if c.options.SourceMap != config.SourceMapNone {
compileResultsForSourceMap = append(compileResultsForSourceMap, compileResult)
// Include this file in the source map
if c.options.SourceMap != config.SourceMapNone {
compileResultsForSourceMap = append(compileResultsForSourceMap, compileResult)
}
}

// Include this file in the metadata
Expand Down
30 changes: 30 additions & 0 deletions scripts/verify-source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,35 @@ const testCaseStdin = {
`,
}

const testCaseEmptyFile = {
'entry.js': `
import './before'
import {fn} from './re-export'
import './after'
fn()
`,
're-export.js': `
// This file will be empty in the generated code, which was causing
// an off-by-one error with the source index in the source map
export {default as fn} from './test'
`,
'test.js': `
export default function() {
console.log("test")
}
`,
'before.js': `
console.log("before")
`,
'after.js': `
console.log("after")
`,
}

const toSearchEmptyFile = [
'before', 'test', 'after',
]

async function check(kind, testCase, toSearch, flags) {
let failed = 0

Expand Down Expand Up @@ -230,6 +259,7 @@ async function main() {
check('es6' + suffix, testCaseES6, toSearchBundle, flags.concat('--outfile=out.js', '--bundle')),
check('ts' + suffix, testCaseTypeScriptRuntime, toSearchNoBundle, flags.concat('--outfile=out.js')),
check('stdin-stdout' + suffix, testCaseStdin, toSearchNoBundle, flags.concat('--sourcefile=<stdin>')),
check('empty' + suffix, testCaseEmptyFile, toSearchEmptyFile, flags.concat('--outfile=out.js', '--bundle')),
)
}

Expand Down

0 comments on commit 0bdd842

Please sign in to comment.