MCPcopy Create free account
hub / github.com/mozilla/source-map / originalPositionFor

Method originalPositionFor

lib/source-map-consumer.js:478–541  ·  view source on GitHub ↗

* Returns the original source, line, and column information for the generated * source's line and column positions provided. The only argument is an object * with the following properties: * * - line: The line number in the generated source. The line number * is 1-based. *

(aArgs)

Source from the content-addressed store, hash-verified

476 * - name: The original identifier, or null.
477 */
478 originalPositionFor(aArgs) {
479 const needle = {
480 generatedLine: util.getArg(aArgs, "line"),
481 generatedColumn: util.getArg(aArgs, "column"),
482 };
483
484 if (needle.generatedLine < 1) {
485 throw new Error("Line numbers must be >= 1");
486 }
487
488 if (needle.generatedColumn < 0) {
489 throw new Error("Column numbers must be >= 0");
490 }
491
492 let bias = util.getArg(
493 aArgs,
494 "bias",
495 SourceMapConsumer.GREATEST_LOWER_BOUND
496 );
497 if (bias == null) {
498 bias = SourceMapConsumer.GREATEST_LOWER_BOUND;
499 }
500
501 let mapping;
502 this._wasm.withMappingCallback(
503 m => (mapping = m),
504 () => {
505 this._wasm.exports.original_location_for(
506 this._getMappingsPtr(),
507 needle.generatedLine - 1,
508 needle.generatedColumn,
509 bias
510 );
511 }
512 );
513
514 if (mapping) {
515 if (mapping.generatedLine === needle.generatedLine) {
516 let source = util.getArg(mapping, "source", null);
517 if (source !== null) {
518 source = this._absoluteSources.at(source);
519 }
520
521 let name = util.getArg(mapping, "name", null);
522 if (name !== null) {
523 name = this._names.at(name);
524 }
525
526 return {
527 source,
528 line: util.getArg(mapping, "originalLine", null),
529 column: util.getArg(mapping, "originalColumn", null),
530 name,
531 };
532 }
533 }
534
535 return {

Callers

nothing calls this directly

Calls 2

_getMappingsPtrMethod · 0.95
atMethod · 0.80

Tested by

no test coverage detected