# Source Map
[![Build Status](https://travis-ci.org/mozilla/source-map.png?branch=master)](https://travis-ci.org/mozilla/source-map)
[![NPM](https://nodei.co/npm/source-map.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/source-map)
This is a library to generate and consume the source map format
[described here][format].
[format]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
## Use with Node
$ npm install source-map
## Use on the Web
<script src="https://raw.githubusercontent.com/mozilla/source-map/master/dist/source-map.min.js" defer></script>
--------------------------------------------------------------------------------
<!-- `npm run toc` to regenerate the Table of Contents -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of Contents
- [Examples](#examples)
- [Consuming a source map](#consuming-a-source-map)
- [Generating a source map](#generating-a-source-map)
- [With SourceNode (high level API)](#with-sourcenode-high-level-api)
- [With SourceMapGenerator (low level API)](#with-sourcemapgenerator-low-level-api)
- [API](#api)
- [SourceMapConsumer](#sourcemapconsumer)
- [new SourceMapConsumer(rawSourceMap)](#new-sourcemapconsumerrawsourcemap)
- [SourceMapConsumer.prototype.computeColumnSpans()](#sourcemapconsumerprototypecomputecolumnspans)
- [SourceMapConsumer.prototype.originalPositionFor(generatedPosition)](#sourcemapconsumerprototypeoriginalpositionforgeneratedposition)
- [SourceMapConsumer.prototype.generatedPositionFor(originalPosition)](#sourcemapconsumerprototypegeneratedpositionfororiginalposition)
- [SourceMapConsumer.prototype.allGeneratedPositionsFor(originalPosition)](#sourcemapconsumerprototypeallgeneratedpositionsfororiginalposition)
- [SourceMapConsumer.prototype.hasContentsOfAllSources()](#sourcemapconsumerprototypehascontentsofallsources)
- [SourceMapConsumer.prototype.sourceContentFor(source[, returnNullOnMissing])](#sourcemapconsumerprototypesourcecontentforsource-returnnullonmissing)
- [SourceMapConsumer.prototype.eachMapping(callback, context, order)](#sourcemapconsumerprototypeeachmappingcallback-context-order)
- [SourceMapGenerator](#sourcemapgenerator)
- [new SourceMapGenerator([startOfSourceMap])](#new-sourcemapgeneratorstartofsourcemap)
- [SourceMapGenerator.fromSourceMap(sourceMapConsumer)](#sourcemapgeneratorfromsourcemapsourcemapconsumer)
- [SourceMapGenerator.prototype.addMapping(mapping)](#sourcemapgeneratorprototypeaddmappingmapping)
- [SourceMapGenerator.prototype.setSourceContent(sourceFile, sourceContent)](#sourcemapgeneratorprototypesetsourcecontentsourcefile-sourcecontent)
- [SourceMapGenerator.prototype.applySourceMap(sourceMapConsumer[, sourceFile[, sourceMapPath]])](#sourcemapgeneratorprototypeapplysourcemapsourcemapconsumer-sourcefile-sourcemappath)
- [SourceMapGenerator.prototype.toString()](#sourcemapgeneratorprototypetostring)
- [SourceNode](#sourcenode)
- [new SourceNode([line, column, source[, chunk[, name]]])](#new-sourcenodeline-column-source-chunk-name)
- [SourceNode.fromStringWithSourceMap(code, sourceMapConsumer[, relativePath])](#sourcenodefromstringwithsourcemapcode-sourcemapconsumer-relativepath)
- [SourceNode.prototype.add(chunk)](#sourcenodeprototypeaddchunk)
- [SourceNode.prototype.prepend(chunk)](#sourcenodeprototypeprependchunk)
- [SourceNode.prototype.setSourceContent(sourceFile, sourceContent)](#sourcenodeprototypesetsourcecontentsourcefile-sourcecontent)
- [SourceNode.prototype.walk(fn)](#sourcenodeprototypewalkfn)
- [SourceNode.prototype.walkSourceContents(fn)](#sourcenodeprototypewalksourcecontentsfn)
- [SourceNode.prototype.join(sep)](#sourcenodeprototypejoinsep)
- [SourceNode.prototype.replaceRight(pattern, replacement)](#sourcenodeprototypereplacerightpattern-replacement)
- [SourceNode.prototype.toString()](#sourcenodeprototypetostring)
- [SourceNode.prototype.toStringWithSourceMap([startOfSourceMap])](#sourcenodeprototypetostringwithsourcemapstartofsourcemap)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## Examples
### Consuming a source map
```js
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**](https://hacks.mozilla.org/2013/05/compiling-to-javascript-and-debugging-with-source-maps/)
#### With SourceNode (high level API)
```js
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)
```js
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:
```js
// 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.
```js
var consumer = new sourceMap.SourceMapConsumer(rawSourceMapJsonData);
```
#### SourceMapConsumer.prototype.computeColumnSpans()
Compute the last column for each generated mapping. The last column is
inclusive.
```js
// Before:
consumer.allGeneratedPositionsFor({ line: 2, source: "foo.coffee" })
// [ { line: 2,
// column: 1 },
// { line: 2,
// column: 10 },
// { line: 2
没有合适的资源?快使用搜索试试~ 我知道了~
vsCode-win32-x64.zip压缩包
共1453个文件
json:539个
js:324个
svg:115个
需积分: 49 24 下载量 8 浏览量
2018-12-26
16:59:13
上传
评论
收藏 64.32MB ZIP 举报
温馨提示
vsCode-win32-x64.zip压缩包vsCode-win32-x64.zip压缩包
资源推荐
资源详情
资源评论
收起资源包目录
vsCode-win32-x64.zip压缩包 (1453个子文件)
node_modules.asar 11.3MB
electron.asar 263KB
snapshot_blob.bin 1.46MB
natives_blob.bin 217KB
code.cmd 137B
code 1KB
workbench.main.css 551KB
issueReporterMain.css 13KB
octicons.css 8KB
base.css 5KB
markdown.css 5KB
highlight.css 3KB
markdown.css 3KB
markdown.css 2KB
processExplorerMain.css 872B
prettify.css 676B
octicons-animations.css 118B
icudtl.dat 9.72MB
node.dll 17.05MB
d3dcompiler_47.dll 3.98MB
libGLESv2.dll 3.53MB
ucrtbase.dll 979KB
msvcp140.dll 618KB
ffmpeg.dll 580KB
winpty.dll 239KB
vcruntime140.dll 86KB
vcruntime140.dll 82KB
api-ms-win-crt-private-l1-1-0.dll 70KB
libEGL.dll 33KB
api-ms-win-crt-math-l1-1-0.dll 28KB
api-ms-win-crt-multibyte-l1-1-0.dll 27KB
api-ms-win-crt-string-l1-1-0.dll 25KB
api-ms-win-crt-stdio-l1-1-0.dll 25KB
api-ms-win-crt-runtime-l1-1-0.dll 23KB
api-ms-win-crt-convert-l1-1-0.dll 23KB
api-ms-win-core-file-l1-1-0.dll 22KB
api-ms-win-crt-time-l1-1-0.dll 21KB
api-ms-win-core-localization-l1-2-0.dll 21KB
api-ms-win-core-synch-l1-1-0.dll 21KB
api-ms-win-core-processthreads-l1-1-0.dll 21KB
api-ms-win-crt-filesystem-l1-1-0.dll 21KB
api-ms-win-core-sysinfo-l1-1-0.dll 20KB
api-ms-win-crt-conio-l1-1-0.dll 20KB
api-ms-win-core-processenvironment-l1-1-0.dll 20KB
api-ms-win-crt-process-l1-1-0.dll 20KB
api-ms-win-crt-heap-l1-1-0.dll 20KB
api-ms-win-core-heap-l1-1-0.dll 19KB
api-ms-win-core-rtlsupport-l1-1-0.dll 19KB
api-ms-win-crt-environment-l1-1-0.dll 19KB
api-ms-win-crt-locale-l1-1-0.dll 19KB
api-ms-win-core-synch-l1-2-0.dll 19KB
api-ms-win-core-memory-l1-1-0.dll 19KB
api-ms-win-crt-utility-l1-1-0.dll 19KB
api-ms-win-core-libraryloader-l1-1-0.dll 19KB
api-ms-win-core-processthreads-l1-1-1.dll 19KB
api-ms-win-core-console-l1-1-0.dll 19KB
api-ms-win-core-debug-l1-1-0.dll 19KB
api-ms-win-core-handle-l1-1-0.dll 19KB
api-ms-win-core-datetime-l1-1-0.dll 19KB
api-ms-win-core-errorhandling-l1-1-0.dll 19KB
api-ms-win-core-file-l1-2-0.dll 19KB
api-ms-win-core-timezone-l1-1-0.dll 19KB
api-ms-win-core-string-l1-1-0.dll 19KB
api-ms-win-core-util-l1-1-0.dll 19KB
api-ms-win-core-namedpipe-l1-1-0.dll 19KB
api-ms-win-core-interlocked-l1-1-0.dll 19KB
api-ms-win-core-file-l2-1-0.dll 19KB
api-ms-win-core-profile-l1-1-0.dll 18KB
octicons.eot 28KB
Code.exe 64.53MB
rg.exe 3.34MB
rg.exe 3.34MB
inno_updater.exe 393KB
winpty-agent.exe 297KB
CodeHelper.exe 72KB
LICENSES.chromium.html 1.72MB
index.js.html 6KB
index.html 3KB
index.html 3KB
auth.html 3KB
processExplorer.html 587B
issueReporter.html 553B
workbench.html 551B
sharedProcess.html 403B
webview.html 207B
react.ico 151KB
bower.ico 150KB
java.ico 149KB
sass.ico 148KB
xml.ico 148KB
config.ico 148KB
php.ico 148KB
csharp.ico 148KB
go.ico 148KB
jade.ico 148KB
vue.ico 148KB
html.ico 148KB
less.ico 148KB
javascript.ico 148KB
json.ico 148KB
共 1453 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
qq_43229556
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功