-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1261 from ashgti/main
Adding support for indexed source maps.
- Loading branch information
Showing
5 changed files
with
167 additions
and
24 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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
import { expect } from 'chai'; | ||
import { RawIndexMap, RawSourceMap, SourceMapConsumer } from 'source-map'; | ||
import { SourceMap } from './sourceMap'; | ||
|
||
const sampleSource = 'console.log(123)'; | ||
const basicSourceMap: RawSourceMap = { | ||
version: 3, | ||
sources: ['one.js'], | ||
sourcesContent: [sampleSource], | ||
names: [], | ||
file: '', | ||
mappings: '', | ||
}; | ||
const indexedSourceMap: RawIndexMap = { | ||
version: 3, | ||
sections: [ | ||
{ | ||
offset: { line: 0, column: 100 }, | ||
map: basicSourceMap, | ||
}, | ||
], | ||
}; | ||
|
||
describe('SourceMap', () => { | ||
it('loads basic source-maps', async () => { | ||
const map = new SourceMap( | ||
await new SourceMapConsumer(basicSourceMap), | ||
{ | ||
sourceMapUrl: JSON.stringify(basicSourceMap), | ||
compiledPath: 'one.js', | ||
}, | ||
'', | ||
['one.js'], | ||
false, | ||
); | ||
|
||
expect(map.sourceContentFor('one.js')).to.eq(sampleSource); | ||
}); | ||
|
||
it('loads indexed source-maps', async () => { | ||
const map = new SourceMap( | ||
await new SourceMapConsumer(indexedSourceMap), | ||
{ | ||
sourceMapUrl: JSON.stringify(indexedSourceMap), | ||
compiledPath: 'one.js', | ||
}, | ||
'', | ||
['one.js'], | ||
false, | ||
); | ||
|
||
expect(map.sourceContentFor('one.js')).to.eq(sampleSource); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
|
||
import { expect } from 'chai'; | ||
import dataUriToBuffer from 'data-uri-to-buffer'; | ||
import { RawIndexMap, RawSourceMap } from 'source-map'; | ||
import Dap from '../../dap/api'; | ||
import { stubbedDapApi, StubDapApi } from '../../dap/stubbedApi'; | ||
import { Logger } from '../logging/logger'; | ||
import { SourceMapFactory } from './sourceMapFactory'; | ||
|
||
const sampleSource = 'console.log(123)'; | ||
const basicSourceMap: RawSourceMap = { | ||
version: 3, | ||
sources: ['one.js'], | ||
sourcesContent: [sampleSource], | ||
names: [], | ||
file: '', | ||
mappings: '', | ||
}; | ||
const indexedSourceMap: RawIndexMap = { | ||
version: 3, | ||
sections: [ | ||
{ | ||
offset: { line: 0, column: 100 }, | ||
map: basicSourceMap, | ||
}, | ||
], | ||
}; | ||
|
||
describe('SourceMapFactory', () => { | ||
let stubDap: StubDapApi; | ||
|
||
beforeEach(() => { | ||
stubDap = stubbedDapApi(); | ||
}); | ||
|
||
it('loads source-maps', async () => { | ||
const factory = new SourceMapFactory( | ||
{ | ||
rebaseRemoteToLocal() { | ||
return '/tmp/local'; | ||
}, | ||
rebaseLocalToRemote() { | ||
return '/tmp/remote'; | ||
}, | ||
shouldResolveSourceMap() { | ||
return true; | ||
}, | ||
urlToAbsolutePath() { | ||
return Promise.resolve('/tmp/abs'); | ||
}, | ||
absolutePathToUrlRegexp() { | ||
return undefined; | ||
}, | ||
}, | ||
{ | ||
fetch(url) { | ||
return Promise.resolve({ | ||
ok: true, | ||
body: dataUriToBuffer(url).toString('utf8'), | ||
url: url, | ||
statusCode: 500, | ||
}); | ||
}, | ||
fetchJson<T>() { | ||
return Promise.resolve({ ok: true, body: {} as T, url: '', statusCode: 200 }); | ||
}, | ||
}, | ||
stubDap as unknown as Dap.Api, | ||
Logger.null, | ||
); | ||
|
||
const map = await factory.load({ | ||
sourceMapUrl: | ||
'data:application/json;base64,' + | ||
Buffer.from(JSON.stringify(indexedSourceMap)).toString('base64'), | ||
compiledPath: '/tmp/local/one.js', | ||
}); | ||
|
||
expect(map.sources).to.eql(['one.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