# 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
没有合适的资源?快使用搜索试试~ 我知道了~
Visual Studio Code
共1267个文件
json:499个
js:216个
svg:135个
需积分: 31 12 下载量 164 浏览量
2019-03-06
09:04:24
上传
评论 3
收藏 56.55MB RAR 举报
温馨提示
Visual Studio Code (简称 VS Code / VSC) 是一款免费开源的现代化轻量级代码编辑器,支持几乎所有主流的开发语言的语法高亮、智能代码补全、自定义热键、括号匹配、代码片段、代码对比 Diff、GIT 等特性,支持插件扩展,并针对网页开发和云端应用开发做了优化。软件跨平台支持 Win、Mac 以及 Linux
资源推荐
资源详情
资源评论
收起资源包目录
Visual Studio Code (1267个子文件)
node_modules.asar 10.74MB
electron.asar 265KB
v8_context_snapshot.bin 1.66MB
natives_blob.bin 171KB
code.cmd 137B
code 1KB
workbench.main.css 553KB
issueReporterMain.css 15KB
octicons.css 9KB
base.css 5KB
markdown.css 5KB
highlight.css 3KB
markdown.css 3KB
processExplorerMain.css 2KB
markdown.css 2KB
prettify.css 676B
octicons-animations.css 118B
icudtl.dat 9.7MB
unins000.dat 466KB
node.dll 17.86MB
d3dcompiler_47.dll 3.99MB
libGLESv2.dll 3.71MB
ffmpeg.dll 1.26MB
ucrtbase.dll 1002KB
msvcp140.dll 622KB
winpty.dll 230KB
vcruntime140.dll 92KB
vcruntime140.dll 91KB
api-ms-win-crt-private-l1-1-0.dll 79KB
api-ms-win-crt-math-l1-1-0.dll 36KB
api-ms-win-crt-multibyte-l1-1-0.dll 35KB
api-ms-win-crt-string-l1-1-0.dll 33KB
api-ms-win-crt-stdio-l1-1-0.dll 33KB
api-ms-win-crt-runtime-l1-1-0.dll 32KB
api-ms-win-crt-convert-l1-1-0.dll 31KB
api-ms-win-core-file-l1-1-0.dll 31KB
api-ms-win-crt-time-l1-1-0.dll 30KB
api-ms-win-core-localization-l1-2-0.dll 30KB
api-ms-win-crt-filesystem-l1-1-0.dll 29KB
api-ms-win-core-processthreads-l1-1-0.dll 29KB
api-ms-win-core-synch-l1-1-0.dll 29KB
api-ms-win-core-sysinfo-l1-1-0.dll 28KB
api-ms-win-core-processenvironment-l1-1-0.dll 28KB
api-ms-win-crt-process-l1-1-0.dll 28KB
api-ms-win-crt-heap-l1-1-0.dll 28KB
api-ms-win-core-libraryloader-l1-1-0.dll 28KB
api-ms-win-crt-conio-l1-1-0.dll 28KB
api-ms-win-core-rtlsupport-l1-1-0.dll 28KB
api-ms-win-core-heap-l1-1-0.dll 28KB
api-ms-win-crt-environment-l1-1-0.dll 28KB
api-ms-win-core-synch-l1-2-0.dll 28KB
api-ms-win-core-timezone-l1-1-0.dll 28KB
api-ms-win-core-console-l1-1-0.dll 28KB
api-ms-win-core-memory-l1-1-0.dll 28KB
api-ms-win-crt-utility-l1-1-0.dll 28KB
api-ms-win-core-processthreads-l1-1-1.dll 28KB
api-ms-win-crt-locale-l1-1-0.dll 28KB
api-ms-win-core-interlocked-l1-1-0.dll 27KB
api-ms-win-core-datetime-l1-1-0.dll 27KB
api-ms-win-core-util-l1-1-0.dll 27KB
api-ms-win-core-debug-l1-1-0.dll 27KB
api-ms-win-core-errorhandling-l1-1-0.dll 27KB
api-ms-win-core-handle-l1-1-0.dll 27KB
api-ms-win-core-file-l2-1-0.dll 27KB
api-ms-win-core-file-l1-2-0.dll 27KB
api-ms-win-core-string-l1-1-0.dll 27KB
api-ms-win-core-namedpipe-l1-1-0.dll 27KB
api-ms-win-core-profile-l1-1-0.dll 27KB
libEGL.dll 26KB
Code.exe 69.69MB
rg.exe 4.65MB
unins000.exe 1.17MB
inno_updater.exe 386KB
winpty-agent.exe 283KB
CodeHelper.exe 65KB
LICENSES.chromium.html 1.78MB
index.js.html 6KB
index.html 3KB
index.html 3KB
auth.html 3KB
processExplorer.html 568B
workbench.html 566B
issueReporter.html 553B
sharedProcess.html 403B
webview.html 207B
react.ico 151KB
bower.ico 150KB
java.ico 149KB
sass.ico 149KB
xml.ico 148KB
config.ico 148KB
php.ico 148KB
csharp.ico 148KB
go.ico 148KB
jade.ico 148KB
vue.ico 148KB
less.ico 148KB
html.ico 148KB
cpp.ico 148KB
javascript.ico 148KB
共 1267 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论
鬼刀之恋
- 粉丝: 6
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功