-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix map resolution You prefix `source` with `sourceRoot`, then resolve it relative to the map URL. Before we incorrectly allowed a map's source to be absolute after the `sourceRoot` was specified. This matches `source-map` and Chrome's behaviors. * Eliminate arrow fn
- Loading branch information
1 parent
f8a42eb
commit 99b6a47
Showing
5 changed files
with
40 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
import resolveUri from '@jridgewell/resolve-uri'; | ||
import stripFilename from './strip-filename'; | ||
|
||
export default function resolve(input: string, base: string | undefined): string { | ||
// The base is always treated as a directory, if it's not empty. | ||
type Resolve = (source: string | null) => string; | ||
export default function resolver( | ||
mapUrl: string | null | undefined, | ||
sourceRoot: string | undefined, | ||
): Resolve { | ||
const from = stripFilename(mapUrl); | ||
// The sourceRoot is always treated as a directory, if it's not empty. | ||
// https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327 | ||
// https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401 | ||
if (base && !base.endsWith('/')) base += '/'; | ||
const prefix = sourceRoot ? sourceRoot + '/' : ''; | ||
|
||
return resolveUri(input, base); | ||
return (source) => resolveUri(prefix + (source || ''), from); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
import { strict as assert } from 'assert'; | ||
import resolve from '../src/resolve'; | ||
import resolver from '../src/resolve'; | ||
|
||
describe('resolve', () => { | ||
it('resolves input relative to base', () => { | ||
const base = 'bar/'; | ||
const input = 'foo'; | ||
it('unresolved without sourceRoot', () => { | ||
const resolve = resolver(undefined, undefined); | ||
assert.equal(resolve('input.js'), 'input.js'); | ||
}); | ||
|
||
it('relative to mapUrl', () => { | ||
const resolve = resolver('foo/script.js.map', undefined); | ||
assert.equal(resolve('input.js'), 'foo/input.js'); | ||
}); | ||
|
||
assert.equal(resolve(input, base), 'bar/foo'); | ||
it('relative to sourceRoot', () => { | ||
const resolve = resolver(undefined, 'foo'); | ||
assert.equal(resolve('input.js'), 'foo/input.js'); | ||
}); | ||
|
||
it('treats base as a directory regardless of slash', () => { | ||
const base = 'bar'; | ||
const input = 'foo'; | ||
it('relative to mapUrl then sourceRoot', () => { | ||
const resolve = resolver('foo/script.js.map', 'bar'); | ||
assert.equal(resolve('input.js'), 'foo/bar/input.js'); | ||
}); | ||
|
||
it('prepends sourceRoot to source before resolving', () => { | ||
const resolve = resolver('foo/script.js.map', 'bar'); | ||
assert.equal(resolve('/input.js'), 'foo/bar/input.js'); | ||
}); | ||
|
||
assert.equal(resolve(input, base), 'bar/foo'); | ||
it('skips undefined sourceRoot before resolving', () => { | ||
const resolve = resolver('foo/script.js.map', undefined); | ||
assert.equal(resolve('/input.js'), '/input.js'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters