Socket
Socket
Sign inDemoInstall

inline-source-map

Package Overview
Dependencies
2
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.2 to 0.1.3

8

index.js

@@ -8,7 +8,7 @@ 'use strict';

function linesIn(src) {
function newlinesIn(src) {
if (!src) return 0;
var newLines = src.match(/\n/g);
var newlines = src.match(/\n/g);
return newLines ? newLines.length : 0;
return newlines ? newlines.length : 0;
}

@@ -61,3 +61,3 @@

for (var line = 1; line <= linesIn(source); line++) {
for (var line = 1; line <= newlinesIn(source) + 1; line++) {
var location = { line: line, column: 0 };

@@ -64,0 +64,0 @@ mappings.push({ original: location, generated: location });

{
"name": "inline-source-map",
"version": "0.1.2",
"version": "0.1.3",
"description": "Adds source mappings and base64 encodes them, so they can be inlined in your generated file.",

@@ -5,0 +5,0 @@ "main": "inline-source-map.js",

@@ -22,5 +22,46 @@ 'use strict';

test('generated mappings', function (t) {
t.test('no offset', function (t) {
t.test('one file no offset', function (t) {
var gen = generator()
.addGeneratedMappings('foo.js', foo)
t.deepEqual(
gen._mappings()
, [ { generated: { line: 1, column: 0 },
original: { line: 1, column: 0 },
source: 'foo.js',
name: null },
{ generated: { line: 2, column: 0 },
original: { line: 2, column: 0 },
source: 'foo.js',
name: null },
{ generated: { line: 3, column: 0 },
original: { line: 3, column: 0 },
source: 'foo.js',
name: null },
{ generated: { line: 4, column: 0 },
original: { line: 4, column: 0 },
source: 'foo.js',
name: null },
{ generated: { line: 5, column: 0 },
original: { line: 5, column: 0 },
source: 'foo.js',
name: null } ]
, 'generates correct mappings'
)
t.deepEqual(
decode(gen.base64Encode())
, '{"version":3,"file":"","sources":["foo.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA"}'
, 'encodes generated mappings'
)
t.equal(
gen.inlineMappingUrl()
, '//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmb28uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQSJ9'
, 'returns correct inline mapping url'
)
})
t.test('two files no offset', function (t) {
var gen = generator()
.addGeneratedMappings('foo.js', foo)
.addGeneratedMappings('bar.js', bar)

@@ -46,2 +87,6 @@

name: null },
{ generated: { line: 5, column: 0 },
original: { line: 5, column: 0 },
source: 'foo.js',
name: null },
{ generated: { line: 1, column: 0 },

@@ -54,2 +99,6 @@ original: { line: 1, column: 0 },

source: 'bar.js',
name: null },
{ generated: { line: 3, column: 0 },
original: { line: 3, column: 0 },
source: 'bar.js',
name: null } ]

@@ -60,3 +109,3 @@ , 'generates correct mappings'

decode(gen.base64Encode())
, '{"version":3,"file":"","sources":["foo.js","bar.js"],"names":[],"mappings":"AAAA,ACAA;ADCA,ACAA;ADCA;AACA"}'
, '{"version":3,"file":"","sources":["foo.js","bar.js"],"names":[],"mappings":"AAAA,ACAA;ADCA,ACAA;ADCA,ACAA;ADCA;AACA"}'
, 'encodes generated mappings'

@@ -66,3 +115,3 @@ )

gen.inlineMappingUrl()
, '//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmb28uanMiLCJiYXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsQUNBQTtBRENBLEFDQUE7QURDQTtBQUNBIn0='
, '//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmb28uanMiLCJiYXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsQUNBQTtBRENBLEFDQUE7QURDQSxBQ0FBO0FEQ0E7QUFDQSJ9'
, 'returns correct inline mapping url'

@@ -72,2 +121,14 @@ )

t.test('one line source', function (t) {
var gen = generator().addGeneratedMappings('one-liner.js', 'console.log("line one");')
t.deepEqual(
gen._mappings()
, [ { generated: { line: 1, column: 0 },
original: { line: 1, column: 0 },
source: 'one-liner.js',
name: null } ]
, 'generates correct mappings'
)
})
t.test('with offset', function (t) {

@@ -96,2 +157,6 @@ var gen = generator()

name: null },
{ generated: { line: 25, column: 0 },
original: { line: 5, column: 0 },
source: 'foo.js',
name: null },
{ generated: { line: 24, column: 22 },

@@ -104,2 +169,6 @@ original: { line: 1, column: 0 },

source: 'bar.js',
name: null },
{ generated: { line: 26, column: 22 },
original: { line: 3, column: 0 },
source: 'bar.js',
name: null } ]

@@ -110,3 +179,3 @@ , 'generates correct mappings'

decode(gen.base64Encode())
, '{\"version\":3,\"file\":\"\",\"sources\":[\"foo.js\",\"bar.js\"],\"names\":[],\"mappings\":\";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA,sBCHA;sBACA\"}'
, '{"version":3,"file":"","sources":["foo.js","bar.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA,sBCHA;ADIA,sBCHA;sBACA"}'
, 'encodes generated mappings with offset'

@@ -113,0 +182,0 @@ )

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc