# 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
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
sublimetext3_64 绿色版 (1861个子文件)
01524fae79697630d0454ba3fabd9414 3.14MB
AUTHORS 5KB
autoprefixer 598B
autoprefixer 32B
browserslist 22B
Startup.cache 230KB
PHP Source.sublime-syntax.cache 31KB
Matlab.sublime-syntax.cache 26KB
Objective-C.sublime-syntax.cache 25KB
CSS.sublime-syntax.cache 17KB
C#.sublime-syntax.cache 16KB
Objective-C++.sublime-syntax.cache 15KB
Python.sublime-syntax.cache 15KB
R.sublime-syntax.cache 14KB
C++.sublime-syntax.cache 14KB
JavaScript.sublime-syntax.cache 14KB
C.sublime-syntax.cache 11KB
Scala.sublime-syntax.cache 11KB
Markdown.sublime-syntax.cache 11KB
Clojure.sublime-syntax.cache 11KB
Meta Info Summary.cache 11KB
LaTeX.sublime-syntax.cache 10KB
Bash.sublime-syntax.cache 10KB
Ruby.sublime-syntax.cache 10KB
D.sublime-syntax.cache 9KB
Java.sublime-syntax.cache 9KB
AppleScript.sublime-syntax.cache 9KB
Rust.sublime-syntax.cache 8KB
commands-builtin-shell-bash.sublime-syntax.cache 7KB
Perl.sublime-syntax.cache 7KB
ASP.sublime-syntax.cache 7KB
ActionScript.sublime-syntax.cache 7KB
OCaml.sublime-syntax.cache 6KB
Erlang.sublime-syntax.cache 6KB
Groovy.sublime-syntax.cache 5KB
HTML.sublime-syntax.cache 5KB
Lisp.sublime-syntax.cache 5KB
Go.sublime-syntax.cache 5KB
Batch File.sublime-syntax.cache 5KB
Makefile.sublime-syntax.cache 5KB
Syntax Summary.cache 4KB
Tcl.sublime-syntax.cache 4KB
YAML.sublime-syntax.cache 4KB
Git Commit.sublime-syntax.cache 3KB
RegExp.sublime-syntax.cache 3KB
Haskell.sublime-syntax.cache 3KB
SQL.sublime-syntax.cache 3KB
XML.sublime-syntax.cache 2KB
Git Config.sublime-syntax.cache 2KB
TeX.sublime-syntax.cache 2KB
Textile.sublime-syntax.cache 2KB
OCamllex.sublime-syntax.cache 2KB
JavaDoc.sublime-syntax.cache 2KB
OCamlyacc.sublime-syntax.cache 2KB
reStructuredText.sublime-syntax.cache 2KB
Git Attributes.sublime-syntax.cache 2KB
Lua.sublime-syntax.cache 2KB
DOT.sublime-syntax.cache 1KB
JSON.sublime-syntax.cache 1KB
Ruby on Rails.sublime-syntax.cache 1KB
Git Rebase.sublime-syntax.cache 1KB
Git Common.sublime-syntax.cache 1KB
Regular Expressions (JavaScript).sublime-syntax.cache 1KB
Regular Expressions (PHP).sublime-syntax.cache 1KB
Rd (R Documentation).sublime-syntax.cache 1KB
Pascal.sublime-syntax.cache 1KB
Regular Expressions (Python).sublime-syntax.cache 1KB
Bibtex.sublime-syntax.cache 1KB
HTML (Tcl).sublime-syntax.cache 1010B
Ruby Haml.sublime-syntax.cache 985B
Java Server Pages (JSP).sublime-syntax.cache 909B
Diff.sublime-syntax.cache 788B
Git Link.sublime-syntax.cache 742B
LaTeX Log.sublime-syntax.cache 668B
HTML-ASP.sublime-syntax.cache 640B
Build.sublime-syntax.cache 604B
Literate Haskell.sublime-syntax.cache 588B
JavaProperties.sublime-syntax.cache 575B
Git Log.sublime-syntax.cache 473B
PHP.sublime-syntax.cache 435B
camlp4.sublime-syntax.cache 430B
HTML (Rails).sublime-syntax.cache 427B
MultiMarkdown.sublime-syntax.cache 393B
JavaScript (Rails).sublime-syntax.cache 388B
Output.tmLanguage.cache 384B
Git Ignore.sublime-syntax.cache 328B
SQL (Rails).sublime-syntax.cache 304B
HTML (Erlang).sublime-syntax.cache 257B
Make Output.sublime-syntax.cache 234B
Cargo.sublime-syntax.cache 228B
R Console.sublime-syntax.cache 219B
Shell-Unix-Generic.sublime-syntax.cache 127B
Plain text.tmLanguage.cache 92B
Ignored Packages.cache 11B
setup.cfg 99B
COPYING 3KB
COPYING 2KB
oscrypto-ca-bundle.crt 145KB
default.css 7KB
extra-d04c85ed4a.css 5KB
共 1861 条
- 1
- 2
- 3
- 4
- 5
- 6
- 19
资源评论
- 风凌~度2019-08-16和官方的一样哦,很好用的
- papima2019-10-14很不错,非常好用。
- 危机时刻2019-12-03666很不错,非常好用。
天地本宽99
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 响应式个人博客网站主题模板 zblog模板.rar
- 梯度下降算法是一种优化算法,通常用于最小化某个损失函数 它被广泛应用于机器学习和深度学习领域,用于更新模型参数以使损失函数最小化
- 1080K影视网站苹果CMSV10模版.rar
- GWO-HKELM灰狼算法优化混合核极限学习机多变量回归预测(Matlab完整源码和数据)
- 一个简单的 Python 类设计案例,实现一个简单的学生管理系统
- 健康监测的微信小程序页面源码
- 微信信息账号的微信小程序模板源码
- 停车查询费的微信小程序页面模板代码
- Python简单画出爱心给女朋友
- JEDEC JESD79-5B:2022 DDR5 SDRAM -内存标准规范.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功