-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve source map resolution efficiency
- Loading branch information
Showing
7 changed files
with
187 additions
and
15 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
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,14 @@ | ||
/* eslint-disable promise/prefer-await-to-callbacks */ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable import/unambiguous */ | ||
/* eslint-disable import/no-commonjs */ | ||
const benchmark = require('nodemark'); | ||
const {getStackTrace} = require('../dist'); | ||
|
||
(async () => { | ||
const result = await benchmark(async (callback) => { | ||
await getStackTrace(); | ||
callback(); | ||
}); | ||
console.log(result); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import {promisify} from 'util'; | ||
import mockfs from 'mock-fs'; | ||
import test from 'ava'; | ||
import resolveCallSiteSourceCodeLocation from '../src/resolveCallSiteSourceCodeLocation'; | ||
|
||
const deleteFile = promisify(fs.unlink); | ||
const writeFile = promisify(fs.writeFile); | ||
|
||
const testSourceMap = { | ||
file: 'min.js', | ||
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA', | ||
names: [ | ||
'bar', | ||
'baz', | ||
'n', | ||
], | ||
sourceRoot: 'http://example.com/www/js/', | ||
sources: [ | ||
'one.js', | ||
'two.js', | ||
], | ||
version: 3, | ||
}; | ||
|
||
mockfs({ | ||
node_modules: | ||
mockfs.load('node_modules'), | ||
'testsource.map': JSON.stringify(testSourceMap), | ||
}); | ||
|
||
test('caches original line results', async (t) => { | ||
const callSite = { | ||
getColumnNumber: () => { | ||
return 28; | ||
}, | ||
getFileName: () => { | ||
return 'testsource'; | ||
}, | ||
getLineNumber: () => { | ||
return 2; | ||
}, | ||
}; | ||
const originalCallsite1 = await resolveCallSiteSourceCodeLocation(callSite); | ||
|
||
t.deepEqual(originalCallsite1, {columnNumber: 10, | ||
fileName: `${path.resolve(path.join(__dirname, '../'))}/http:/example.com/www/js/two.js`, | ||
lineNumber: 2}); | ||
|
||
// // When we delete the map, we still expect the in memory map to be used | ||
await deleteFile('testsource.map'); | ||
|
||
const originalCallsite2 = await resolveCallSiteSourceCodeLocation(callSite); | ||
t.deepEqual(originalCallsite2, originalCallsite1); | ||
}); | ||
|
||
test('only attempts to access maps once', async (t) => { | ||
const callSite1 = await resolveCallSiteSourceCodeLocation({ | ||
getColumnNumber: () => { | ||
return 28; | ||
}, | ||
getFileName: () => { | ||
return 'somesource'; | ||
}, | ||
getLineNumber: () => { | ||
return 2; | ||
}, | ||
}); | ||
t.deepEqual(callSite1, {columnNumber: 28, | ||
fileName: 'somesource', | ||
lineNumber: 2}); | ||
|
||
await writeFile('sourcesource', JSON.stringify(testSourceMap)); | ||
|
||
// We don't expect it to attempt to read this source map again | ||
const callSite2 = await resolveCallSiteSourceCodeLocation({ | ||
getColumnNumber: () => { | ||
return 28; | ||
}, | ||
getFileName: () => { | ||
return 'somesource'; | ||
}, | ||
getLineNumber: () => { | ||
return 2; | ||
}, | ||
}); | ||
t.deepEqual(callSite2, {columnNumber: 28, | ||
fileName: 'somesource', | ||
lineNumber: 2}); | ||
}); |