How to use vlq - 10 common examples

To help you get started, we’ve selected a few vlq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dbfannin / ngx-logger / src / lib / mapper.service.ts View on Github external
// => ',' separates mappings in a line
    // decoded mapping => [ generatedCodeColumn, sourceFileIndex, sourceCodeLine, sourceCodeColumn, nameIndex ]
    let sourceFileIndex = 0,   // second field
      sourceCodeLine = 0,    // third field
      sourceCodeColumn = 0;  // fourth field

    const lines = sourceMap.mappings.split(';');

    for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
      // reset column position to 0 after each line
      let generatedCodeColumn = 0;
      // decode sections in line
      const columns = lines[lineIndex].split(',');

      for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
        const decodedSection = vlq.decode(columns[columnIndex]);
        if (decodedSection.length >= 4) {
          // update relative positions
          generatedCodeColumn += decodedSection[0];
          sourceFileIndex += decodedSection[1];
          sourceCodeLine += decodedSection[2];
          sourceCodeColumn += decodedSection[3];
        }

        // check if matching map
        if (lineIndex === position.lineNumber) {
          if (generatedCodeColumn === position.columnNumber) {
            // matching column and line found
            return new LogPosition(sourceMap.sources[sourceFileIndex], sourceCodeLine, sourceCodeColumn);
          } else if (columnIndex + 1 === columns.length) {
            // matching column not found, but line is correct
            return new LogPosition(sourceMap.sources[sourceFileIndex], sourceCodeLine, 0);
github vicwang163 / sourcemap-stack / src / mappingRealPath.js View on Github external
let sourceRow = 1
  // 文件列
  let sourceColumn = 1
  // 字段名
  let sourceNameIndex = 0
  
  for (let i = 0, len = lines.length; i < len; i++) {
    let line = lines[i]
    if (!line) {
      continue
    }
    tempResult = result[i + 1] = {}
    transformedColumn = 1
    let arr = line.split(',')
    for (let j = 0, len1 = arr.length; j < len1; j++) {
      let ret = vlq.decode(arr[j])
      let info = {}
      transformedColumn += ret[0]
      if (ret[1] !== undefined) {
        sourceIndex += ret[1]
        sourceRow += ret[2]
        sourceColumn += ret[3]
        info.sourceIndex = sourceIndex
        info.row = sourceRow
        info.column = sourceColumn
        if (ret[4] !== undefined) {
          sourceNameIndex += ret[4]
          info.name = object.names[sourceNameIndex]
        }
        // assign info
        tempResult[transformedColumn] = info
      }
github angular / angular / tools / source-map-test / parseMap.js View on Github external
      line => { return line.split(',').map(seg => vlq.decode(seg)); });
}
github alan-ai / alan-sdk-reactnative / testtools / node_modules / metro-symbolicate / src.real / SourceMetadataMapConsumer.js View on Github external
function decodeFunctionMap(
  functionMap: ?FBSourceFunctionMap,
): $ReadOnlyArray {
  if (!functionMap) {
    return [];
  }
  const parsed = [];
  let line = 1;
  let nameIndex = 0;
  for (const lineMappings of functionMap.mappings.split(';')) {
    let column = 0;
    for (const mapping of lineMappings.split(',')) {
      const [columnDelta, nameDelta, lineDelta = 0] = vlq.decode(mapping);
      line += lineDelta;
      nameIndex += nameDelta;
      column += columnDelta;
      parsed.push({line, column, name: functionMap.names[nameIndex]});
    }
  }
  return parsed;
}
github facebook / metro / packages / metro-symbolicate / src / SourceMetadataMapConsumer.js View on Github external
function decodeFunctionMap(
  functionMap: ?FBSourceFunctionMap,
): $ReadOnlyArray {
  if (!functionMap) {
    return [];
  }
  const parsed = [];
  let line = 1;
  let nameIndex = 0;
  for (const lineMappings of functionMap.mappings.split(';')) {
    let column = 0;
    for (const mapping of lineMappings.split(',')) {
      const [columnDelta, nameDelta, lineDelta = 0] = vlq.decode(mapping);
      line += lineDelta;
      nameIndex += nameDelta;
      column += columnDelta;
      parsed.push({line, column, name: functionMap.names[nameIndex]});
    }
  }
  return parsed;
}
github daviddbarrero / Ionic-4-firebase / node_modules / magic-string / dist / magic-string.es.js View on Github external
segment[1] - offsets.sourceIndex,
					segment[2] - offsets.sourceCodeLine,
					segment[3] - offsets.sourceCodeColumn
				];

				generatedCodeColumn = segment[0];
				offsets.sourceIndex = segment[1];
				offsets.sourceCodeLine = segment[2];
				offsets.sourceCodeColumn = segment[3];

				if ( ~segment[4] ) {
					arr.push( segment[4] - offsets.sourceCodeName );
					offsets.sourceCodeName = segment[4];
				}

				return encode( arr );
			}).join( ',' );
		}).join( ';' );
github sohelamin / vue-example / vue-rollup-simple / node_modules / magic-string / dist / magic-string.cjs.js View on Github external
segment.sourceIndex - offsets.sourceIndex,
				segment.sourceCodeLine - offsets.sourceCodeLine,
				segment.sourceCodeColumn - offsets.sourceCodeColumn
			];

			generatedCodeColumn = segment.generatedCodeColumn;
			offsets.sourceIndex = segment.sourceIndex;
			offsets.sourceCodeLine = segment.sourceCodeLine;
			offsets.sourceCodeColumn = segment.sourceCodeColumn;

			if ( ~segment.sourceCodeName ) {
				arr.push( segment.sourceCodeName - offsets.sourceCodeName );
				offsets.sourceCodeName = segment.sourceCodeName;
			}

			return vlq.encode( arr );
		}).join( ',' );
	}).join( ';' );
github facebookarchive / flow-remove-types / index.js View on Github external
var columnDiff = start.column - end.column;
    if (lineDiff) {
      for (var l = 0; l !== lineDiff; l++) {
        mappings += ';';
      }
      mappings += vlq.encode([ start.column, 0, lineDiff, columnDiff ]);
    } else if (columnDiff) {
      if (i) {
        mappings += ',';
      }
      mappings += vlq.encode([ columnDiff, 0, lineDiff, columnDiff ]);
    }

    end = removedNodes[i].loc.end;
    mappings += ',';
    mappings += vlq.encode([ 0, 0, end.line - start.line, end.column - start.column ]);
  }

  return mappings;
}
github blackgate / ractive-componentify / lib / transformSourceMap.js View on Github external
return i.map(function(j) {
        return vlq.encode(j);
      }).join(',');
    }).join(';')
github facebookarchive / flow-remove-types / index.js View on Github external
var mappings = '';
  if (!removedNodes || removedNodes.length === '') {
    return mappings;
  }

  var end = { line: 1, column: 0 };

  for (var i = 0; i < removedNodes.length; i++) {
    var start = removedNodes[i].loc.start;
    var lineDiff = start.line - end.line;
    var columnDiff = start.column - end.column;
    if (lineDiff) {
      for (var l = 0; l !== lineDiff; l++) {
        mappings += ';';
      }
      mappings += vlq.encode([ start.column, 0, lineDiff, columnDiff ]);
    } else if (columnDiff) {
      if (i) {
        mappings += ',';
      }
      mappings += vlq.encode([ columnDiff, 0, lineDiff, columnDiff ]);
    }

    end = removedNodes[i].loc.end;
    mappings += ',';
    mappings += vlq.encode([ 0, 0, end.line - start.line, end.column - start.column ]);
  }

  return mappings;
}

vlq

Generate, and decode, base64 VLQ mappings for source maps and other uses

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis

Popular vlq functions