Socket
Socket
Sign inDemoInstall

source-map-support

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

source-map-support - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

4

package.json
{
"name": "source-map-support",
"description": "Fixes stack traces for files with source maps",
"version": "0.1.7",
"version": "0.1.8",
"main": "./source-map-support.js",

@@ -10,3 +10,3 @@ "scripts": {

"dependencies": {
"source-map": "0.1.8"
"source-map": "0.1.24"
},

@@ -13,0 +13,0 @@ "devDependencies": {

@@ -43,7 +43,15 @@ var SourceMapConsumer = require('source-map').SourceMapConsumer;

var originalPosition = sourceMap.map.originalPositionFor(position);
originalPosition.source = path.resolve(path.dirname(sourceMap.url), originalPosition.source);
return originalPosition;
} else {
return position;
// Only return the original position if a matching line was found. If no
// matching line is found then we return position instead, which will cause
// the stack trace to print the path and line for the compiled file. It is
// better to give a precise location in the compiled file than a vague
// location in the original file.
if (originalPosition.source !== null) {
originalPosition.source = path.resolve(path.dirname(sourceMap.url), originalPosition.source);
return originalPosition;
}
}
return position;
}

@@ -50,0 +58,0 @@

@@ -20,7 +20,31 @@ require('./source-map-support').install();

function compareStackTrace(source, expected) {
var sourceMap = new SourceMapGenerator({
function createEmptySourceMap() {
return new SourceMapGenerator({
file: '.generated.js',
sourceRoot: '.'
});
}
function createSourceMapWithGap() {
var sourceMap = createEmptySourceMap();
sourceMap.addMapping({
generated: { line: 100, column: 1 },
original: { line: 100, column: 1 },
source: '.original.js'
});
return sourceMap;
}
function createSingleLineSourceMap() {
var sourceMap = createEmptySourceMap();
sourceMap.addMapping({
generated: { line: 1, column: 1 },
original: { line: 1, column: 1 },
source: '.original.js'
});
return sourceMap;
}
function createMultiLineSourceMap() {
var sourceMap = createEmptySourceMap();
for (var i = 1; i <= 100; i++) {

@@ -33,3 +57,6 @@ sourceMap.addMapping({

}
return sourceMap;
}
function compareStackTrace(sourceMap, source, expected) {
// Check once with a separate source map

@@ -61,12 +88,3 @@ fs.writeFileSync('.generated.js.map', sourceMap);

function compareStdout(done, source, expected) {
var sourceMap = new SourceMapGenerator({
file: '.generated.js',
sourceRoot: '.'
});
sourceMap.addMapping({
generated: { line: 1, column: 1 },
original: { line: 1, column: 1 },
source: '.original.js'
});
function compareStdout(done, sourceMap, source, expected) {
fs.writeFileSync('.original.js', 'this is the original code');

@@ -90,3 +108,3 @@ fs.writeFileSync('.generated.js.map', sourceMap);

it('normal throw', function() {
compareStackTrace([
compareStackTrace(createMultiLineSourceMap(), [
'throw new Error("test");'

@@ -100,3 +118,3 @@ ], [

it('throw inside function', function() {
compareStackTrace([
compareStackTrace(createMultiLineSourceMap(), [
'function foo() {',

@@ -114,3 +132,3 @@ ' throw new Error("test");',

it('throw inside function inside function', function() {
compareStackTrace([
compareStackTrace(createMultiLineSourceMap(), [
'function foo() {',

@@ -132,3 +150,3 @@ ' function bar() {',

it('eval', function() {
compareStackTrace([
compareStackTrace(createMultiLineSourceMap(), [
'eval("throw new Error(\'test\')");'

@@ -143,3 +161,3 @@ ], [

it('eval inside eval', function() {
compareStackTrace([
compareStackTrace(createMultiLineSourceMap(), [
'eval("eval(\'throw new Error(\\"test\\")\')");'

@@ -155,3 +173,3 @@ ], [

it('eval inside function', function() {
compareStackTrace([
compareStackTrace(createMultiLineSourceMap(), [
'function foo() {',

@@ -170,3 +188,3 @@ ' eval("throw new Error(\'test\')");',

it('eval with sourceURL', function() {
compareStackTrace([
compareStackTrace(createMultiLineSourceMap(), [
'eval("throw new Error(\'test\')//@ sourceURL=sourceURL.js");'

@@ -181,3 +199,3 @@ ], [

it('eval with sourceURL inside eval', function() {
compareStackTrace([
compareStackTrace(createMultiLineSourceMap(), [
'eval("eval(\'throw new Error(\\"test\\")//@ sourceURL=sourceURL.js\')");'

@@ -193,3 +211,3 @@ ], [

it('function constructor', function() {
compareStackTrace([
compareStackTrace(createMultiLineSourceMap(), [
'throw new Function(")");'

@@ -203,4 +221,22 @@ ], [

it('throw with empty source map', function() {
compareStackTrace(createEmptySourceMap(), [
'throw new Error("test");'
], [
'Error: test',
/^ at Object\.exports\.test \(.*\/.generated.js:1:96\)$/
]);
});
it('throw with source map with gap', function() {
compareStackTrace(createSourceMapWithGap(), [
'throw new Error("test");'
], [
'Error: test',
/^ at Object\.exports\.test \(.*\/.generated.js:1:96\)$/
]);
});
it('default options', function(done) {
compareStdout(done, [
compareStdout(done, createSingleLineSourceMap(), [
'',

@@ -221,3 +257,3 @@ 'function foo() { throw new Error("this is the error"); }',

it('handleUncaughtExceptions is true', function(done) {
compareStdout(done, [
compareStdout(done, createSingleLineSourceMap(), [
'',

@@ -237,3 +273,3 @@ 'function foo() { throw new Error("this is the error"); }',

it('handleUncaughtExceptions is false', function(done) {
compareStdout(done, [
compareStdout(done, createSingleLineSourceMap(), [
'',

@@ -251,1 +287,31 @@ 'function foo() { throw new Error("this is the error"); }',

});
it('default options with empty source map', function(done) {
compareStdout(done, createEmptySourceMap(), [
'',
'function foo() { throw new Error("this is the error"); }',
'require("./source-map-support").install();',
'process.nextTick(foo);'
], [
/\/.generated.js:2$/,
'function foo() { throw new Error("this is the error"); }',
' ^',
'Error: this is the error',
/^ at foo \(.*\/.generated.js:2:24\)$/
]);
});
it('default options with source map with gap', function(done) {
compareStdout(done, createSourceMapWithGap(), [
'',
'function foo() { throw new Error("this is the error"); }',
'require("./source-map-support").install();',
'process.nextTick(foo);'
], [
/\/.generated.js:2$/,
'function foo() { throw new Error("this is the error"); }',
' ^',
'Error: this is the error',
/^ at foo \(.*\/.generated.js:2:24\)$/
]);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc