Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Mar 3, 2022
1 parent c87ffbe commit 4041d4c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/utils/collapseSourcemaps.ts
Expand Up @@ -58,7 +58,7 @@ class Link {
const tracedLine: SourceMapSegment[] = [];

for (const segment of line) {
if (segment.length == 1) continue;
if (segment.length === 1) continue;
const source = this.sources[segment[1]];
if (!source) continue;

Expand Down Expand Up @@ -130,9 +130,7 @@ class Link {
if (segment[0] === column || searchStart === searchEnd) {
if (segment.length == 1) return null;
const source = this.sources[segment[1]];
if (!source) {
return null;
}
if (!source) return null;

return source.traceSegment(
segment[2],
Expand Down
18 changes: 9 additions & 9 deletions src/utils/getOriginalLocation.ts
Expand Up @@ -2,24 +2,24 @@ import type { DecodedSourceMapOrMissing, ExistingDecodedSourceMap } from '../rol

export function getOriginalLocation(
sourcemapChain: readonly DecodedSourceMapOrMissing[],
location: { column: number; line: number; name?: string; source?: string }
location: { column: number; line: number }
): { column: number; line: number } {
const filteredSourcemapChain = sourcemapChain.filter(
(sourcemap): sourcemap is ExistingDecodedSourceMap => !!sourcemap.mappings
);
traceSourcemap: while (filteredSourcemapChain.length > 0) {
const sourcemap = filteredSourcemapChain.pop()!;
const line = sourcemap.mappings[location.line - 1];

if (line?.length) {
for (const segment of line) {
if (segment[0] >= location.column || line.length === 1) {
if (segment.length === 1) break;
if (line) {
const filteredLine = line.filter(
(segment): segment is [number, number, number, number] => segment.length > 1
);
const lastSegment = filteredLine[filteredLine.length - 1];
for (const segment of filteredLine) {
if (segment[0] >= location.column || segment === lastSegment) {
location = {
column: segment[3],
line: segment[2] + 1,
name: segment.length === 5 ? sourcemap.names[segment[4]] : undefined,
source: sourcemap.sources[segment[1]]
line: segment[2] + 1
};
continue traceSourcemap;
}
Expand Down
Expand Up @@ -7,7 +7,7 @@ module.exports = {
plugins: {
name: 'test-plugin',
transform() {
return { code: 'export default this', map: { mappings: 'X' } };
return { code: 'export default this', map: { mappings: '' } };
}
}
},
Expand Down
Expand Up @@ -11,7 +11,7 @@ module.exports = {
// each entry of each line consist of
// [generatedColumn, sourceIndex, sourceLine, sourceColumn];
// this mapping only maps the first line to itself
const decodedMap = [[[0, 0, 0, 0]]];
const decodedMap = [[[0], [0, 0, 0, 0], [1]]];
return { code: 'export default this', map: { mappings: encode(decodedMap), sources: [] } };
}
}
Expand Down

0 comments on commit 4041d4c

Please sign in to comment.