Skip to content
This repository has been archived by the owner on Dec 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #75 from Havunen/master
Browse files Browse the repository at this point in the history
Increased segment value range from Int8 to Int16 to fit all characters
  • Loading branch information
Rich-Harris authored Sep 20, 2018
2 parents 29f15ee + 7c9b368 commit 9824935
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/sourcemap-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export function decode(mappings: string): SourceMapMappings {
const c = mappings.charCodeAt(i);

if (c === 44) { // ","
if (segment.length) line.push(new Int8Array(segment) as any);
if (segment.length) line.push(new Int16Array(segment) as any);
segment = [];
j = 0;

} else if (c === 59) { // ";"
if (segment.length) line.push(new Int8Array(segment) as any);
if (segment.length) line.push(new Int16Array(segment) as any);
segment = [];
j = 0;
decoded.push(line);
Expand Down Expand Up @@ -85,7 +85,7 @@ export function decode(mappings: string): SourceMapMappings {
}
}

if (segment.length) line.push(new Int8Array(segment) as any);
if (segment.length) line.push(new Int16Array(segment) as any);
decoded.push(line);

return decoded;
Expand Down
141 changes: 120 additions & 21 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
var decode = require( '../' ).decode;
var encode = require( '../' ).encode;
var assert = require( 'assert' );
const decode = require('../').decode;
const encode = require('../').encode;
const assert = require('assert');

require( 'console-group' ).install();
require('console-group').install();

describe( 'sourcemap-codec', function () {
describe('sourcemap-codec', () => {
// TODO more tests
var tests = [
let tests = [
{
encoded: 'AAAA',
decoded: [ [ [ 0, 0, 0, 0 ] ] ]
decoded: [[[0, 0, 0, 0]]]
},
{
encoded: ';;;',
decoded: [ [], [], [], [] ]
decoded: [[], [], [], []]
},
{
encoded: 'A,AAAA;;AACDE;',
decoded: [
[ [ 0 ], [ 0, 0, 0, 0 ] ],
[[0], [0, 0, 0, 0]],
[],
[ [ 0, 0, 1, -1, 2 ] ],
[[0, 0, 1, -1, 2]],
[]
]
},
Expand All @@ -31,30 +31,129 @@ describe( 'sourcemap-codec', function () {
[],
[],
[],
[ [ 2, 0, 2, 2, 0 ], [ 4, 0, 2, 4 ], [ 6, 0, 2, 5 ], [ 7, 0, 2, 7 ] ],
[ [ 2, 1, 10, 19 ], [ 12, 1, 11, 20 ] ]
[[2, 0, 2, 2, 0], [4, 0, 2, 4], [6, 0, 2, 5], [7, 0, 2, 7]],
[[2, 1, 10, 19], [12, 1, 11, 20]]
]
},
{
encoded: "aAAA,IAAIA,eAAW,oCAAoCC,cACpC,aACdC,OAAOC,MAAOH,eAAU,GCFzB,5PAAIA,iBAAW,sBAAsBC,cACtB,aACdC,OAAOC,MAAOH,iBAAU,GCCzBI,IACAC",
decoded: [
[
[13, 0, 0, 0],
[17, 0, 0, 4, 0],
[32, 0, 0, 15],
[68, 0, 0, 51, 1],
[82, 0, 1, 15],
[95, 0, 2, 1, 2],
[102, 0, 2, 8, 3],
[108, 0, 2, 15, 0],
[123, 0, 2, 25],
[126, 1, 0, 0],
[-126, 1, 0, 4, 0],
[-109, 1, 0, 15],
[-87, 1, 0, 37, 1],
[-73, 1, 1, 15],
[-60, 1, 2, 1, 2],
[-53, 1, 2, 8, 3],
[-47, 1, 2, 15, 0],
[-30, 1, 2, 25],
[-27, 2, 3, 0, 4],
[-23, 2, 4, 0, 5]
]
]
},
{
encoded: "AAAA,aAEA,IAAIA,eAAiB,oCAAoCC,cACzD,SAASC,IACRC,OAAOC,MAAOJ,eAAgB,GAG/B,IAAIK,iBAAmB,sBAAsBJ,cAC7C,SAASK,IACRH,OAAOC,MAAOC,iBAAkB,GAGjCH,IACAI",
decoded: [
[
[0, 0, 0, 0],
[13, 0, 2, 0],
[17, 0, 2, 4, 0],
[32, 0, 2, 21],
[68, 0, 2, 57, 1],
[82, 0, 3, 0],
[91, 0, 3, 9, 2],
[95, 0, 4, 1, 3],
[102, 0, 4, 8, 4],
[108, 0, 4, 15, 0],
[123, 0, 4, 31],
[126, 0, 7, 0],
[130, 0, 7, 4, 5],
[147, 0, 7, 23],
[169, 0, 7, 45, 1],
[183, 0, 8, 0],
[192, 0, 8, 9, 6],
[196, 0, 9, 1, 3],
[203, 0, 9, 8, 4],
[209, 0, 9, 15, 5],
[226, 0, 9, 33],
[229, 0, 12, 0, 2],
[233, 0, 13, 0, 6]
]
]
},
{
encoded: "CAAC,SAAUA,EAAQC,GACC,iBAAZC,SAA0C,oBAAXC,OAAyBF,IAC7C,mBAAXG,QAAyBA,OAAOC,IAAMD,OAAOH,GACnDA,IAHF,CAIEK,EAAM,WAAe,aAEtB,IAAIC,EAAiB,oCAAoCC,cAKzD,IAAIC,EAAmB,sBAAsBD,cAH5CE,OAAOC,MAAOJ,EAAgB,GAK9BG,OAAOC,MAAOF,EAAkB",
decoded: [
[
[1, 0, 0, 1],
[10, 0, 0, 11, 0],
[12, 0, 0, 19, 1],
[15, 0, 1, 20],
[32, 0, 1, 8, 2],
[41, 0, 1, 50],
[61, 0, 1, 39, 3],
[68, 0, 1, 64, 1],
[72, 0, 2, 19],
[91, 0, 2, 8, 4],
[99, 0, 2, 33, 4],
[106, 0, 2, 40, 5],
[110, 0, 2, 46, 4],
[117, 0, 2, 53, 1],
[120, 0, 3, 2, 1],
[124, 0, 0, 0],
[125, 0, 4, 2, 6],
[127, 0, 4, 8],
[138, 0, 4, 23],
[151, 0, 6, 1],
[155, 0, 6, 5, 7],
[157, 0, 6, 22],
[193, 0, 6, 58, 8],
[207, 0, 11, 1],
[211, 0, 11, 5, 9],
[213, 0, 11, 24],
[235, 0, 11, 46, 8],
[249, 0, 8, 2, 10],
[256, 0, 8, 9, 11],
[262, 0, 8, 16, 7],
[264, 0, 8, 32],
[267, 0, 13, 2, 10],
[274, 0, 13, 9, 11],
[280, 0, 13, 16, 9],
[282, 0, 13, 34]
]
]
}
];

var filtered = tests.filter( function ( test ) {
const filtered = tests.filter((test) => {
return test.solo;
});

tests = filtered.length ? filtered : tests;

describe( 'decode()', function () {
tests.forEach( function ( test, i ) {
it( 'decodes sample ' + i, function () {
assert.deepEqual( decode( test.encoded ), test.decoded );
describe('decode()', () => {
tests.forEach((test, i) => {
it('decodes sample ' + i, () => {
assert.deepEqual(decode(test.encoded), test.decoded);
});
});
});

describe( 'encode()', function () {
tests.forEach( function ( test, i ) {
it( 'encodes sample ' + i, function () {
assert.deepEqual( encode( test.decoded ), test.encoded );
describe('encode()', () => {
tests.forEach((test, i) => {
it('encodes sample ' + i, () => {
assert.deepEqual(encode(test.decoded), test.encoded);
});
});
});
Expand Down

0 comments on commit 9824935

Please sign in to comment.