8:03 UTC">1 год назад 16787 058f31828c first commit 1 год назад 16790 058f31828c first commit 1 год назад 16792 058f31828c first commit 1 год назад 16793 058f31828c first commit 1 год назад 16795 058f31828c first commit 1 год назад 16797 058f31828c first commit 1 год назад 16800 058f31828c first commit 1 год назад 16802 058f31828c first commit 1 год назад 16803 058f31828c first commit 1 год назад 16805 058f31828c first commit 1 год назад 16807 058f31828c first commit 1 год назад 16810 058f31828c first commit 1 год назад 16812 058f31828c first commit 1 год назад 16814 058f31828c first commit 1 год назад 16817 058f31828c first commit 1 год назад 16819 058f31828c first commit 1 год назад 16821 058f31828c first commit 1 год назад 16824 058f31828c first commit 1 год назад 16831 058f31828c first commit 1 год назад 16832 058f31828c first commit 1 год назад 16843 058f31828c first commit 1 год назад 16844 058f31828c first commit 1 год назад 16850 058f31828c first commit 1 год назад 16856 058f31828c first commit 1 год назад 16862 058f31828c first commit 1 год назад 16868 058f31828c first commit 1 год назад 16869 058f31828c first commit 1 год назад 16871 058f31828c first commit 1 год назад 16874 058f31828c first commit 1 год назад 16876 058f31828c first commit 1 год назад 16877 058f31828c first commit 1 год назад 16879 058f31828c first commit 1 год назад 16887 058f31828c first commit 1 год назад 16889 058f31828c first commit 1 год назад 16892 058f31828c first commit 1 год назад 16896 058f31828c first commit 1 год назад 16898 058f31828c first commit 1 год назад 16901 058f31828c first commit 1 год назад 16903 058f31828c first commit 1 год назад 16911 058f31828c first commit 1 год назад 16917 058f31828c first commit 1 год назад 16918 058f31828c first commit 1 год назад 16922 058f31828c first commit 1 год назад 16924 058f31828c first commit 1 год назад 16926 058f31828c first commit 1 год назад 16927 058f31828c first commit 1 год назад 16928 058f31828c first commit 1 год назад 16929 058f31828c first commit 1 год назад 16932 058f31828c first commit 1 год назад 16934 058f31828c first commit 1 год назад 16941 058f31828c first commit 1 год назад 16942 058f31828c first commit 1 год назад 16944 058f31828c first commit 1 год назад 16947 058f31828c first commit 1 год назад 16949 058f31828c first commit 1 год назад 16951 058f31828c first commit 1 год назад 16952 058f31828c first commit 1 год назад 16962 058f31828c first commit 1 год назад 16964 058f31828c first commit 1 год назад 16967 058f31828c first commit 1 год назад 16969 058f31828c first commit 1 год назад 16971 058f31828c first commit 1 год назад 16974 058f31828c first commit 1 год назад 16976 058f31828c first commit 1 год назад 16978 058f31828c first commit 1 год назад 16981 058f31828c first commit 1 год назад 16983 058f31828c first commit 1 год назад 16984 058f31828c first commit 1 год назад 16986 058f31828c first commit 1 год назад 16996 058f31828c first commit 1 год назад 17008 058f31828c first commit 1 год назад 17009 058f31828c first commit 1 год назад 17020 058f31828c first commit 1 год назад 17021 058f31828c first commit 1 год назад 17022 058f31828c first commit 1 год назад 17024 058f31828c first commit 1 год назад 17034 058f31828c first commit 1 год назад 17037 058f31828c first commit 1 год назад 17039 058f31828c first commit 1 год назад 17040 058f31828c first commit 1 год назад 17041 058f31828c first commit 1 год назад 17042 058f31828c first commit 1 год назад 174 058f31828c first commit 1 год назад 175 058f31828c first commit 1 год назад 2187 058f31828c first commit 1 год назад 2224 058f31828c first commit 1 год назад 2328 058f31828c first commit 1 год назад 2336 058f31828c first commit 1 год назад 2337 058f31828c first commit 1 год назад 2579 058f31828c first commit 1 год назад 2600 058f31828c first commit 1 год назад 2600_fsm 058f31828c first commit 1 год назад 2600_vm 058f31828c first commit 1 год назад 2601 058f31828c first commit 1 год назад 2601_fsm 058f31828c first commit 1 год назад 2601_vm 058f31828c first commit 1 год назад 2602 058f31828c first commit 1 год назад 2602_fsm 058f31828c first commit 1 год назад 2602_vm 058f31828c first commit 1 год назад 2603 058f31828c first commit 1 год назад 2603_fsm 058f31828c first commit 1 год назад 2603_vm 058f31828c first commit 1 год назад 2604 058f31828c first commit 1 год назад 2605 058f31828c first commit 1 год назад 2605_fsm 058f31828c first commit 1 год назад 2605_vm 058f31828c first commit 1 год назад 2606 058f31828c first commit 1 год назад 2606_fsm 058f31828c first commit 1 год назад 2606_vm 058f31828c first commit 1 год назад 2607 058f31828c first commit 1 год назад 2607_fsm 058f31828c first commit 1 год назад 2607_vm 058f31828c first commit 1 год назад 2608 058f31828c first commit 1 год назад 2608_fsm 058f31828c first commit 1 год назад 2608_vm 058f31828c first commit 1 год назад 2609 058f31828c first commit 1 год назад 2609_fsm 058f31828c first commit 1 год назад 2609_vm 058f31828c first commit 1 год назад 2610 058f31828c first commit 1 год назад 2610_fsm 058f31828c first commit 1 год назад 2610_vm 058f31828c first commit 1 год назад 2611 058f31828c first commit 1 год назад 2612 058f31828c first commit 1 год назад 2612_fsm 058f31828c first commit 1 год назад 2612_vm 058f31828c first commit 1 год назад 2613 058f31828c first commit 1 год назад 2615 058f31828c first commit 1 год назад 2615_fsm 058f31828c first commit 1 год назад 2615_vm 058f31828c first commit 1 год назад 2616 058f31828c first commit 1 год назад 2616_fsm 058f31828c first commit 1 год назад 2616_vm 058f31828c first commit 1 год назад 2617 058f31828c first commit 1 год назад 2617_fsm 058f31828c first commit 1 год назад 2617_vm 058f31828c first commit 1 год назад 2618 058f31828c first commit 1 год назад 2618_fsm 058f31828c first commit 1 год назад 2618_vm 058f31828c first commit 1 год назад 2619 058f31828c first commit 1 год назад 2619_fsm 058f31828c first commit 1 год назад 2619_vm 058f31828c first commit 1 год назад 2620 058f31828c first commit 1 год назад 2620_fsm 058f31828c first commit 1 год назад 2650 058f31828c first commit 1 год назад 2651 058f31828c first commit 1 год назад 2652 058f31828c first commit 1 год назад 2653 058f31828c first commit 1 год назад 2654 058f31828c first commit 1 год назад 2655 058f31828c first commit 1 год назад 2656 058f31828c first commit 1 год назад 2657 058f31828c first commit 1 год назад 2658 058f31828c first commit 1 год назад 2659 058f31828c first commit 1 год назад 2660 058f31828c first commit 1 год назад 2661 058f31828c first commit 1 год назад 2662 058f31828c first commit 1 год назад 2663 058f31828c first commit 1 год назад 2664 058f31828c first commit 1 год назад 2665 058f31828c first commit 1 год назад 2666 058f31828c first commit 1 год назад 2667 058f31828c first commit 1 год назад 2668 058f31828c first commit 1 год назад 2669 058f31828c first commit 1 год назад 2670 058f31828c first commit 1 год назад 2673 058f31828c first commit 1 год назад 2674 058f31828c first commit 1 год назад 2675 058f31828c first commit 1 год назад 2678 058f31828c first commit 1 год назад 2679 058f31828c first commit 1 год назад 2680 058f31828c first commit 1 год назад 2681 058f31828c first commit 1 год назад 2682 058f31828c first commit 1 год назад 2683 058f31828c first commit 1 год назад 2684 058f31828c first commit 1 год назад 2685 058f31828c first commit 1 год назад 2686 058f31828c first commit 1 год назад 2687 058f31828c first commit 1 год назад 2688 058f31828c first commit 1 год назад 2689 058f31828c first commit 1 год назад 2690 058f31828c first commit 1 год назад 2691 058f31828c first commit 1 год назад 2692 058f31828c first commit 1 год назад 2693 058f31828c first commit 1 год назад 2696 058f31828c first commit 1 год назад 2699 058f31828c first commit 1 год назад 2701 058f31828c first commit 1 год назад 2702 058f31828c first commit 1 год назад 2703 058f31828c first commit 1 год назад 2704 058f31828c first commit 1 год назад 2753 058f31828c first commit 1 год назад 2753_fsm 058f31828c first commit 1 год назад 2753_vm 058f31828c first commit 1 год назад 2754 058f31828c first commit 1 год назад 2755 058f31828c first commit 1 год назад 2756 058f31828c first commit 1 год назад 2757 058f31828c first commit 1 год назад 2830 058f31828c first commit 1 год назад 2831 058f31828c first commit 1 год назад 2832 058f31828c first commit 1 год назад 2833 058f31828c first commit 1 год назад 2834 058f31828c first commit 1 год назад 2835 058f31828c first commit 1 год назад 2836 058f31828c first commit 1 год назад 2837 058f31828c first commit 1 год назад 2838 058f31828c first commit 1 год назад 2838_fsm 058f31828c first commit 1 год назад 2838_vm 058f31828c first commit 1 год назад 2839 058f31828c first commit 1 год назад 2840 058f31828c first commit 1 год назад 2840_fsm 058f31828c first commit 1 год назад 2840_vm 058f31828c first commit 1 год назад 2841 058f31828c first commit 1 год назад 2995 058f31828c first commit 1 год назад 2996 058f31828c first commit 1 год назад 3079 058f31828c first commit 1 год назад 3079_fsm 058f31828c first commit 1 год назад 3079_vm 058f31828c first commit 1 год назад 3080 058f31828c first commit 1 год назад 3081 058f31828c first commit 1 год назад 3085 058f31828c first commit 1 год назад 3118 058f31828c first commit 1 год назад 3119 058f31828c first commit 1 год назад 3164 058f31828c first commit 1 год назад 3256 058f31828c first commit 1 год назад 3257 058f31828c first commit 1 год назад 3258 058f31828c first commit 1 год назад 3350 058f31828c first commit 1 год назад 3351 058f31828c first commit 1 год назад 3379 058f31828c first commit 1 год назад 3380 058f31828c first commit 1 год назад 3381 058f31828c first commit 1 год назад 3394 058f31828c first commit 1 год назад 3394_fsm 058f31828c first commit 1 год назад 3394_vm 058f31828c first commit 1 год назад 3395 058f31828c first commit 1 год назад 3429 058f31828c first commit 1 год назад 3430 058f31828c first commit 1 год назад 3431 058f31828c first commit 1 год назад 3433 058f31828c first commit 1 год назад 3439 058f31828c first commit 1 год назад 3440 058f31828c first commit 1 год назад 3455 058f31828c first commit 1 год назад 3456 058f31828c first commit 1 год назад 3456_fsm 058f31828c first commit 1 год назад 3456_vm 058f31828c first commit 1 год назад 3466 058f31828c first commit 1 год назад 3467 058f31828c first commit 1 год назад 3468 058f31828c first commit 1 год назад 3501 058f31828c first commit 1 год назад 3502 058f31828c first commit 1 год назад 3503 058f31828c first commit 1 год назад 3534 058f31828c first commit 1 год назад 3541 058f31828c first commit 1 год назад 3541_fsm 058f31828c first commit 1 год назад 3541_vm 058f31828c first commit 1 год назад 3542 058f31828c first commit 1 год назад 3574 058f31828c first commit 1 год назад 3575 058f31828c first commit 1 год назад 3576 058f31828c first commit 1 год назад 3596 058f31828c first commit 1 год назад 3597 058f31828c first commit 1 год назад 3598 058f31828c first commit 1 год назад 3599 058f31828c first commit 1 год назад 3600 058f31828c first commit 1 год назад 3600_fsm 058f31828c first commit 1 год назад 3600_vm 058f31828c first commit 1 год назад 3601 058f31828c first commit 1 год назад 3601_fsm 058f31828c first commit 1 год назад 3601_vm 058f31828c first commit 1 год назад 3602 058f31828c first commit 1 год назад 3602_fsm 058f31828c first commit 1 год назад 3602_vm 058f31828c first commit 1 год назад 3603 058f31828c first commit 1 год назад 3603_fsm 058f31828c first commit 1 год назад 3603_vm 058f31828c first commit 1 год назад 3604 058f31828c first commit 1 год назад 3605 058f31828c first commit 1 год назад 3606 058f31828c first commit 1 год назад 3607 058f31828c first commit 1 год назад 3608 058f31828c first commit 1 год назад 3609 058f31828c first commit 1 год назад 3712 058f31828c first commit 1 год назад 3764 058f31828c first commit 1 год назад 3764_fsm 058f31828c first commit 1 год назад 3764_vm 058f31828c first commit 1 год назад 3766 058f31828c first commit 1 год назад 3767 058f31828c first commit 1 год назад 3997 058f31828c first commit 1 год назад 4143 058f31828c first commit 1 год назад 4144 058f31828c first commit 1 год назад 4145 058f31828c first commit 1 год назад 4146 058f31828c first commit 1 год назад 4147 058f31828c first commit 1 год назад 4148 058f31828c first commit 1 год назад 4149 058f31828c first commit 1 год назад 4150 058f31828c first commit 1 год назад 4151 058f31828c first commit 1 год назад 4152 058f31828c first commit 1 год назад 4153 058f31828c first commit 1 год назад 4154 058f31828c first commit 1 год назад 4155 058f31828c first commit 1 год назад 4156 058f31828c first commit 1 год назад 4157 058f31828c first commit 1 год назад 4158 058f31828c first commit 1 год назад 4159 058f31828c first commit 1 год назад 4160 058f31828c first commit 1 год назад 4161 058f31828c first commit 1 год назад 4162 058f31828c first commit 1 год назад 4163 058f31828c first commit 1 год назад 4164 058f31828c first commit 1 год назад 4165 058f31828c first commit 1 год назад 4166 058f31828c first commit 1 год назад 4167 058f31828c first commit 1 год назад 4168 058f31828c first commit 1 год назад 4169 058f31828c first commit 1 год назад 4170 058f31828c first commit 1 год назад 4171 058f31828c first commit 1 год назад 4172 058f31828c first commit 1 год назад 4173 058f31828c first commit 1 год назад 4174 058f31828c first commit 1 год назад 5002 058f31828c first commit 1 год назад 548 058f31828c first commit 1 год назад 549 058f31828c first commit 1 год назад 6102 058f31828c first commit 1 год назад 6104 058f31828c first commit 1 год назад 6106 058f31828c first commit 1 год назад 6110 058f31828c first commit 1 год назад 6111 058f31828c first commit 1 год назад 6112 058f31828c first commit 1 год назад 6113 058f31828c first commit 1 год назад 6117 058f31828c first commit 1 год назад 826 058f31828c first commit 1 год назад 827 058f31828c first commit 1 год назад 828 058f31828c first commit 1 год назад PG_VERSION 058f31828c first commit 1 год назад pg_filenode.map 058f31828c first commit 1 год назад pg_internal.init 058f31828c first commit 1 год назад tum/tmt_learning - Gogs: Simplico Git Service

Brak opisu

Prach Pongpanich 6f337d0a21 install tailwind alpine daisyui 2 lat temu
..
CHANGELOG.md 6f337d0a21 install tailwind alpine daisyui 2 lat temu
LICENSE 6f337d0a21 install tailwind alpine daisyui 2 lat temu
README.md 6f337d0a21 install tailwind alpine daisyui 2 lat temu
package.json 6f337d0a21 install tailwind alpine daisyui 2 lat temu
source-map.d.ts 6f337d0a21 install tailwind alpine daisyui 2 lat temu
source-map.js 6f337d0a21 install tailwind alpine daisyui 2 lat temu

README.md

Source Map JS

NPM

Difference between original source-map:

TL,DR: it's fork of original source-map@0.6, but with perfomance optimizations.

This journey starts from source-map@0.7.0. Some part of it was rewritten to Rust and WASM and API became async.

It's still a major block for many libraries like PostCSS or Sass for example because they need to migrate the whole API to the async way. This is the reason why 0.6.1 has 2x more downloads than 0.7.3 while it's faster several times.

Downloads count

More important that WASM version has some optimizations in JS code too. This is why community asked to create branch for 0.6 version and port these optimizations but, sadly, the answer was «no». A bit later I discovered the issue created by Ben Rothman (@benthemonkey) with no response at all.

Roman Dvornov (@lahmatiy) wrote a serveral posts (russian, only, sorry) about source-map library in his own Telegram channel. He mentioned the article «Maybe you don't need Rust and WASM to speed up your JS» written by Vyacheslav Egorov (@mraleph). This article contains optimizations and hacks that lead to almost the same performance compare to WASM implementation.

I decided to fork the original source-map and port these optimizations from the article and several others PR from the original source-map.


This is a library to generate and consume the source map format described here.

Use with Node

$ npm install source-map-js

Table of Contents

Examples

Consuming a source map

var rawSourceMap = {
  version: 3,
  file: 'min.js',
  names: ['bar', 'baz', 'n'],
  sources: ['one.js', 'two.js'],
  sourceRoot: 'http://example.com/www/js/',
  mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
};

var smc = new SourceMapConsumer(rawSourceMap);

console.log(smc.sources);
// [ 'http://example.com/www/js/one.js',
//   'http://example.com/www/js/two.js' ]

console.log(smc.originalPositionFor({
  line: 2,
  column: 28
}));
// { source: 'http://example.com/www/js/two.js',
//   line: 2,
//   column: 10,
//   name: 'n' }

console.log(smc.generatedPositionFor({
  source: 'http://example.com/www/js/two.js',
  line: 2,
  column: 10
}));
// { line: 2, column: 28 }

smc.eachMapping(function (m) {
  // ...
});

Generating a source map

In depth guide: Compiling to JavaScript, and Debugging with Source Maps

With SourceNode (high level API)

function compile(ast) {
  switch (ast.type) {
  case 'BinaryExpression':
    return new SourceNode(
      ast.location.line,
      ast.location.column,
      ast.location.source,
      [compile(ast.left), " + ", compile(ast.right)]
    );
  case 'Literal':
    return new SourceNode(
      ast.location.line,
      ast.location.column,
      ast.location.source,
      String(ast.value)
    );
  // ...
  default:
    throw new Error("Bad AST");
  }
}

var ast = parse("40 + 2", "add.js");
console.log(compile(ast).toStringWithSourceMap({
  file: 'add.js'
}));
// { code: '40 + 2',
//   map: [object SourceMapGenerator] }

With SourceMapGenerator (low level API)

var map = new SourceMapGenerator({
  file: "source-mapped.js"
});

map.addMapping({
  generated: {
    line: 10,
    column: 35
  },
  source: "foo.js",
  original: {
    line: 33,
    column: 2
  },
  name: "christopher"
});

console.log(map.toString());
// '{"version":3,"file":"source-mapped.js","sources":["foo.js"],"names":["christopher"],"mappings":";;;;;;;;;mCAgCEA"}'

API

Get a reference to the module:

// Node.js
var sourceMap = require('source-map');

// Browser builds
var sourceMap = window.sourceMap;

// Inside Firefox
const sourceMap = require("devtools/toolkit/sourcemap/source-map.js");

SourceMapConsumer

A SourceMapConsumer instance represents a parsed source map which we can query for information about the original file positions by giving it a file position in the generated source.

new SourceMapConsumer(rawSourceMap)

The only parameter is the raw source map (either as a string which can be JSON.parse'd, or an object). According to the spec, source maps have the following attributes:

  • version: Which version of the source map spec this map is following.

  • sources: An array of URLs to the original source files.

  • names: An array of identifiers which can be referenced by individual mappings.

  • sourceRoot: Optional. The URL root from which all sources are relative.

  • sourcesContent: Optional. An array of contents of the original source files.

  • mappings: A string of base64 VLQs which contain the actual mappings.

  • file: Optional. The generated filename this source map is associated with.

var consumer = new sourceMap.SourceMapConsumer(rawSourceMapJsonData);

SourceMapConsumer.prototype.computeColumnSpans()

Compute the last column for each generated mapping. The last column is inclusive.

// Before:
consumer.allGeneratedPositionsFor({ line: 2, source: "foo.coffee" })
// [ { line: 2,
//     column: 1 },
//   { line: 2,
//     column: 10 },
//   { line: 2,
//     column: 20 } ]

consumer.computeColumnSpans();

// After:
consumer.allGeneratedPositionsFor({ line: 2, source: "foo.coffee" })
// [ { line: 2,
//     column: 1,
//     lastColumn: 9 },
//   { line: 2,
//     column: 10,
//     lastColumn: 19 },
//   { line: 2,
//     column: 20,
//     lastColumn: Infinity } ]

SourceMapConsumer.prototype.originalPositionFor(generatedPosition)

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. Line numbers in this library are 1-based (note that the underlying source map specification uses 0-based line numbers -- this library handles the translation).

  • column: The column number in the generated source. Column numbers in this library are 0-based.

  • bias: Either SourceMapConsumer.GREATEST_LOWER_BOUND or SourceMapConsumer.LEAST_UPPER_BOUND. Specifies whether to return the closest element that is smaller than or greater than the one we are searching for, respectively, if the exact element cannot be found. Defaults to SourceMapConsumer.GREATEST_LOWER_BOUND.

and an object is returned with the following properties:

  • source: The original source file, or null if this information is not available.

  • line: The line number in the original source, or null if this information is not available. The line number is 1-based.

  • column: The column number in the original source, or null if this information is not available. The column number is 0-based.

  • name: The original identifier, or null if this information is not available.

consumer.originalPositionFor({ line: 2, column: 10 })
// { source: 'foo.coffee',
//   line: 2,
//   column: 2,
//   name: null }

consumer.originalPositionFor({ line: 99999999999999999, column: 999999999999999 })
// { source: null,
//   line: null,
//   column: null,
//   name: null }

SourceMapConsumer.prototype.generatedPositionFor(originalPosition)

Returns the generated line and column information for the original source, line, and column positions provided. The only argument is an object with the following properties:

  • source: The filename of the original source.

  • line: The line number in the original source. The line number is 1-based.

  • column: The column number in the original source. The column number is 0-based.

and an object is returned with the following properties:

  • line: The line number in the generated source, or null. The line number is 1-based.

  • column: The column number in the generated source, or null. The column number is 0-based.

consumer.generatedPositionFor({ source: "example.js", line: 2, column: 10 })
// { line: 1,
//   column: 56 }

SourceMapConsumer.prototype.allGeneratedPositionsFor(originalPosition)

Returns all generated line and column information for the original source, line, and column provided. If no column is provided, returns all mappings corresponding to a either the line we are searching for or the next closest line that has any mappings. Otherwise, returns all mappings corresponding to the given line and either the column we are searching for or the next closest column that has any offsets.

The only argument is an object with the following properties:

  • source: The filename of the original source.

  • line: The line number in the original source. The line number is 1-based.

  • column: Optional. The column number in the original source. The column number is 0-based.

and an array of objects is returned, each with the following properties:

  • line: The line number in the generated source, or null. The line number is 1-based.

  • column: The column number in the generated source, or null. The column number is 0-based.

consumer.allGeneratedpositionsfor({ line: 2, source: "foo.coffee" })
// [ { line: 2,
//     column: 1 },
//   { line: 2,
//     column: 10 },
//   { line: 2,
//     column: 20 } ]

SourceMapConsumer.prototype.hasContentsOfAllSources()

Return true if we have the embedded source content for every source listed in the source map, false otherwise.

In other words, if this method returns true, then consumer.sourceContentFor(s) will succeed for every source s in consumer.sources.

// ...
if (consumer.hasContentsOfAllSources()) {
  consumerReadyCallback(consumer);
} else {
  fetchSources(consumer, consumerReadyCallback);
}
// ...

SourceMapConsumer.prototype.sourceContentFor(source[, returnNullOnMissing])

Returns the original source content for the source provided. The only argument is the URL of the original source file.

If the source content for the given source is not found, then an error is thrown. Optionally, pass true as the second param to have null returned instead.

consumer.sources
// [ "my-cool-lib.clj" ]

consumer.sourceContentFor("my-cool-lib.clj")
// "..."

consumer.sourceContentFor("this is not in the source map");
// Error: "this is not in the source map" is not in the source map

consumer.sourceContentFor("this is not in the source map", true);
// null

SourceMapConsumer.prototype.eachMapping(callback, context, order)

Iterate over each mapping between an original source/line/column and a generated line/column in this source map.

  • callback: The function that is called with each mapping. Mappings have the form { source, generatedLine, generatedColumn, originalLine, originalColumn, name }

  • context: Optional. If specified, this object will be the value of this every time that callback is called.

  • order: Either SourceMapConsumer.GENERATED_ORDER or SourceMapConsumer.ORIGINAL_ORDER. Specifies whether you want to iterate over the mappings sorted by the generated file's line/column order or the original's source/line/column order, respectively. Defaults to SourceMapConsumer.GENERATED_ORDER.

consumer.eachMapping(function (m) { console.log(m); })
// ...
// { source: 'illmatic.js',
//   generatedLine: 1,
//   generatedColumn: 0,
//   originalLine: 1,
//   originalColumn: 0,
//   name: null }
// { source: 'illmatic.js',
//   generatedLine: 2,
//   generatedColumn: 0,
//   originalLine: 2,
//   originalColumn: 0,
//   name: null }
// ...

SourceMapGenerator

An instance of the SourceMapGenerator represents a source map which is being built incrementally.

new SourceMapGenerator([startOfSourceMap])

You may pass an object with the following properties:

  • file: The filename of the generated source that this source map is associated with.

  • sourceRoot: A root for all relative URLs in this source map.

  • skipValidation: Optional. When true, disables validation of mappings as they are added. This can improve performance but should be used with discretion, as a last resort. Even then, one should avoid using this flag when running tests, if possible.

var generator = new sourceMap.SourceMapGenerator({
  file: "my-generated-javascript-file.js",
  sourceRoot: "http://example.com/app/js/"
});

SourceMapGenerator.fromSourceMap(sourceMapConsumer)

Creates a new SourceMapGenerator from an existing SourceMapConsumer instance.

  • sourceMapConsumer The SourceMap.
var generator = sourceMap.SourceMapGenerator.fromSourceMap(consumer);

SourceMapGenerator.prototype.addMapping(mapping)

Add a single mapping from original source line and column to the generated source's line and column for this source map being created. The mapping object should have the following properties:

  • generated: An object with the generated line and column positions.

  • original: An object with the original line and column positions.

  • source: The original source file (relative to the sourceRoot).

  • name: An optional original token name for this mapping.

generator.addMapping({
  source: "module-one.scm",
  original: { line: 128, column: 0 },
  generated: { line: 3, column: 456 }
})

SourceMapGenerator.prototype.setSourceContent(sourceFile, sourceContent)

Set the source content for an original source file.

  • sourceFile the URL of the original source file.

  • sourceContent the content of the source file.

generator.setSourceContent("module-one.scm",
                           fs.readFileSync("path/to/module-one.scm"))

SourceMapGenerator.prototype.applySourceMap(sourceMapConsumer[, sourceFile[, sourceMapPath]])

Applies a SourceMap for a source file to the SourceMap. Each mapping to the supplied source file is rewritten using the supplied SourceMap. Note: The resolution for the resulting mappings is the minimum of this map and the supplied map.

  • sourceMapConsumer: The SourceMap to be applied.

  • sourceFile: Optional. The filename of the source file. If omitted, sourceMapConsumer.file will be used, if it exists. Otherwise an error will be thrown.

  • sourceMapPath: Optional. The dirname of the path to the SourceMap to be applied. If relative, it is relative to the SourceMap.

This parameter is needed when the two SourceMaps aren't in the same directory, and the SourceMap to be applied contains relative source paths. If so, those relative source paths need to be rewritten relative to the SourceMap.

If omitted, it is assumed that both SourceMaps are in the same directory, thus not needing any rewriting. (Supplying '.' has the same effect.)

SourceMapGenerator.prototype.toString()

Renders the source map being generated to a string.

generator.toString()
// '{"version":3,"sources":["module-one.scm"],"names":[],"mappings":"...snip...","file":"my-generated-javascript-file.js","sourceRoot":"http://example.com/app/js/"}'

SourceNode

SourceNodes provide a way to abstract over interpolating and/or concatenating snippets of generated JavaScript source code, while maintaining the line and column information associated between those snippets and the original source code. This is useful as the final intermediate representation a compiler might use before outputting the generated JS and source map.

new SourceNode([line, column, source[, chunk[, name]]])

  • line: The original line number associated with this source node, or null if it isn't associated with an original line. The line number is 1-based.

  • column: The original column number associated with this source node, or null if it isn't associated with an original column. The column number is 0-based.

  • source: The original source's filename; null if no filename is provided.

  • chunk: Optional. Is immediately passed to SourceNode.prototype.add, see below.

  • name: Optional. The original identifier.

var node = new SourceNode(1, 2, "a.cpp", [
  new SourceNode(3, 4, "b.cpp", "extern int status;\n"),
  new SourceNode(5, 6, "c.cpp", "std::string* make_string(size_t n);\n"),
  new SourceNode(7, 8, "d.cpp", "int main(int argc, char** argv) {}\n"),
]);

SourceNode.fromStringWithSourceMap(code, sourceMapConsumer[, relativePath])

Creates a SourceNode from generated code and a SourceMapConsumer.

  • code: The generated code

  • sourceMapConsumer The SourceMap for the generated code

  • relativePath The optional path that relative sources in sourceMapConsumer should be relative to.

var consumer = new SourceMapConsumer(fs.readFileSync("path/to/my-file.js.map", "utf8"));
var node = SourceNode.fromStringWithSourceMap(fs.readFileSync("path/to/my-file.js"),
                                              consumer);

SourceNode.prototype.add(chunk)

Add a chunk of generated JS to this source node.

  • chunk: A string snippet of generated JS code, another instance of SourceNode, or an array where each member is one of those things.
node.add(" + ");
node.add(otherNode);
node.add([leftHandOperandNode, " + ", rightHandOperandNode]);

SourceNode.prototype.prepend(chunk)

Prepend a chunk of generated JS to this source node.

  • chunk: A string snippet of generated JS code, another instance of SourceNode, or an array where each member is one of those things.
node.prepend("/** Build Id: f783haef86324gf **/\n\n");

SourceNode.prototype.setSourceContent(sourceFile, sourceContent)

Set the source content for a source file. This will be added to the SourceMap in the sourcesContent field.

  • sourceFile: The filename of the source file

  • sourceContent: The content of the source file

node.setSourceContent("module-one.scm",
                      fs.readFileSync("path/to/module-one.scm"))

SourceNode.prototype.walk(fn)

Walk over the tree of JS snippets in this node and its children. The walking function is called once for each snippet of JS and is passed that snippet and the its original associated source's line/column location.

  • fn: The traversal function.
var node = new SourceNode(1, 2, "a.js", [
  new SourceNode(3, 4, "b.js", "uno"),
  "dos",
  [
    "tres",
    new SourceNode(5, 6, "c.js", "quatro")
  ]
]);

node.walk(function (code, loc) { console.log("WALK:", code, loc); })
// WALK: uno { source: 'b.js', line: 3, column: 4, name: null }
// WALK: dos { source: 'a.js', line: 1, column: 2, name: null }
// WALK: tres { source: 'a.js', line: 1, column: 2, name: null }
// WALK: quatro { source: 'c.js', line: 5, column: 6, name: null }

SourceNode.prototype.walkSourceContents(fn)

Walk over the tree of SourceNodes. The walking function is called for each source file content and is passed the filename and source content.

  • fn: The traversal function.
var a = new SourceNode(1, 2, "a.js", "generated from a");
a.setSourceContent("a.js", "original a");
var b = new SourceNode(1, 2, "b.js", "generated from b");
b.setSourceContent("b.js", "original b");
var c = new SourceNode(1, 2, "c.js", "generated from c");
c.setSourceContent("c.js", "original c");

var node = new SourceNode(null, null, null, [a, b, c]);
node.walkSourceContents(function (source, contents) { console.log("WALK:", source, ":", contents); })
// WALK: a.js : original a
// WALK: b.js : original b
// WALK: c.js : original c

SourceNode.prototype.join(sep)

Like Array.prototype.join except for SourceNodes. Inserts the separator between each of this source node's children.

  • sep: The separator.
var lhs = new SourceNode(1, 2, "a.rs", "my_copy");
var operand = new SourceNode(3, 4, "a.rs", "=");
var rhs = new SourceNode(5, 6, "a.rs", "orig.clone()");

var node = new SourceNode(null, null, null, [ lhs, operand, rhs ]);
var joinedNode = node.join(" ");

SourceNode.prototype.replaceRight(pattern, replacement)

Call String.prototype.replace on the very right-most source snippet. Useful for trimming white space from the end of a source node, etc.

  • pattern: The pattern to replace.

  • replacement: The thing to replace the pattern with.

// Trim trailing white space.
node.replaceRight(/\s*$/, "");

SourceNode.prototype.toString()

Return the string representation of this source node. Walks over the tree and concatenates all the various snippets together to one string.

var node = new SourceNode(1, 2, "a.js", [
  new SourceNode(3, 4, "b.js", "uno"),
  "dos",
  [
    "tres",
    new SourceNode(5, 6, "c.js", "quatro")
  ]
]);

node.toString()
// 'unodostresquatro'

SourceNode.prototype.toStringWithSourceMap([startOfSourceMap])

Returns the string representation of this tree of source nodes, plus a SourceMapGenerator which contains all the mappings between the generated and original sources.

The arguments are the same as those to new SourceMapGenerator.

var node = new SourceNode(1, 2, "a.js", [
  new SourceNode(3, 4, "b.js", "uno"),
  "dos",
  [
    "tres",
    new SourceNode(5, 6, "c.js", "quatro")
  ]
]);

node.toStringWithSourceMap({ file: "my-output-file.js" })
// { code: 'unodostresquatro',
//   map: [object SourceMapGenerator] }