Skip to content

Commit

Permalink
simplify encodeMappings a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Sep 2, 2015
1 parent b80a365 commit c83c017
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions src/MagicString/encodeMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,29 @@ export default function encodeMappings ( original, str, mappings, hires, sourcem
char = i + charOffset;
origin = inverseMappings[ char ];

if ( !~origin ) {
if ( !~lastOrigin ) {
// do nothing
} else {
location = getLocation( locations, lastOrigin + 1 );

segments.push({
generatedCodeColumn: i,
sourceIndex: sourceIndex,
sourceCodeLine: location.line,
sourceCodeColumn: location.column
});
}
}

else {
if ( !hires && ( origin === lastOrigin + 1 ) && !sourcemapLocations[ origin ] ) {
// do nothing
} else {
location = getLocation( locations, origin );

segments.push({
generatedCodeColumn: i,
sourceIndex: sourceIndex,
sourceCodeLine: location.line,
sourceCodeColumn: location.column
});
}
location = ( !~origin && ~lastOrigin ) ?

// if this character has no mapping, but the last one did,
// create a new segment
getLocation( locations, lastOrigin + 1 ) :

// otherwise create a new segment if this character is mapped to an origin and
// a) we're in hires mode
// b) the origin isn't just lastOrigin + 1
// c) there's a marked sourcemapLocation
( ~origin && ( hires || ( ~lastOrigin && origin !== lastOrigin + 1 ) || sourcemapLocations[ origin ] ) ) ?
getLocation( locations, origin ) :

// otherwise skip it
null;

if ( location ) {
segments.push({
generatedCodeColumn: i,
sourceIndex: sourceIndex,
sourceCodeLine: location.line,
sourceCodeColumn: location.column
});
}

lastOrigin = origin;
Expand Down

0 comments on commit c83c017

Please sign in to comment.