# Source Map
[![Build Status](https://travis-ci.org/mozilla/source-map.png?branch=master)](https://travis-ci.org/mozilla/source-map)
[![Coverage Status](https://coveralls.io/repos/github/mozilla/source-map/badge.svg)](https://coveralls.io/github/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://unpkg.com/source-map@0.7.3/dist/source-map.js"></script>
<script>
sourceMap.SourceMapConsumer.initialize({
"lib/mappings.wasm": "https://unpkg.com/source-map@0.7.3/lib/mappings.wasm"
});
</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)
- [SourceMapConsumer.initialize(options)](#sourcemapconsumerinitializeoptions)
- [new SourceMapConsumer(rawSourceMap)](#new-sourcemapconsumerrawsourcemap)
- [SourceMapConsumer.with](#sourcemapconsumerwith)
- [SourceMapConsumer.prototype.destroy()](#sourcemapconsumerprototypedestroy)
- [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
const 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'
};
const whatever = await SourceMapConsumer.with(rawSourceMap, null, consumer => {
console.log(consumer.sources);
// [ 'http://example.com/www/js/one.js',
// 'http://example.com/www/js/two.js' ]
console.log(consumer.originalPositionFor({
line: 2,
column: 28
}));
// { source: 'http://example.com/www/js/two.js',
// line: 2,
// column: 10,
// name: 'n' }
console.log(consumer.generatedPositionFor({
source: 'http://example.com/www/js/two.js',
line: 2,
column: 10
}));
// { line: 2, column: 28 }
consumer.eachMapping(function (m) {
// ...
});
return computeWhatever();
});
```
### 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.
#### SourceMapConsumer.initialize(options)
When using `SourceMapConsumer` outside of node.js, for example on the Web, it
needs to know from what URL to load `lib/mappings.wasm`. You must inform it by
calling `initialize` before constructing any `SourceMapConsumer`s.
The options object has the following properties:
* `"lib/mappings.wasm"`: A `String` containing the URL of the
`lib/mappings.wasm` file, or an `ArrayBuffer` with the contents of `lib/mappings.wasm`.
```js
sourceMap.SourceMapConsumer.initializ
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
uni-app 是一个使用 Vue.js 开发小程序、H5、App的统一前端框架。官网地址:https://uniapp.dcloud.io开发者使用 Vue 语法编写代码,uni-app 框架将其编译到 小程序(微信/支付宝/百度/字节跳动/QQ/快手/钉钉/小红书)、App(iOS/Android)、H5等多个平台,保证其正确运行并达到优秀体验。uni-app的特点:开发者和案例更多:HBuilder装机量800万台,开发者社区月活百万,70多个QQ微信群承载10万人。案例众多,uni统计月活超10亿(详见)性能更高(见评测)更丰富的周边生态,插件市场数千款插件提供比小程序原生开发更好的开发体验、更高的工程化效率跨端抹平度更完善,且各端特色发挥更灵活,可真正实现一套代码多端覆盖,无需各端多头维护升级权威认可:阿里小程序官方工具内置uni-app(详见)、腾讯课堂官方自制uni-app培训视频(详见)。快速开始:uni-app支持通过vue-cli命令行、HBuilderX可视化界面两种方式快速创建项目HBuilderX可视化界面:专用IDE,内置相关环境,开箱即用,开发效率更高。
资源推荐
资源详情
资源评论
收起资源包目录
uni-app 是一个使用 Vue.js 开发小程序、H5、App的统一前端框架 (1989个子文件)
.babelrc 26B
generate-components-wxml.bak 5KB
index.bak 3KB
compile-to-template.bak 1KB
generate-pages-wxml.bak 940B
range.bnf 619B
index.css 94KB
view.css 59KB
index.css 51KB
index.css 15KB
index.css 15KB
index.css 14KB
editor.css 9KB
wxParse.css 4KB
index.dark.css 4KB
polyfill.css 36B
.editorconfig 269B
.eslintignore 2KB
.gitignore 178B
.gitignore 11B
.gitkeep 0B
__uniapppicker.html 134KB
__uniapppicker.html 134KB
__uniappchooselocation.html 29KB
__uniappchooselocation.html 29KB
__uniappopenlocation.html 13KB
__uniappopenlocation.html 13KB
__uniappscan.html 7KB
__uniappscan.html 7KB
__uniappview.html 811B
__uniappview.html 811B
demo.html 166B
view.umd.js 813KB
index.v3.js 699KB
index.umd.min.js 521KB
view.umd.min.js 391KB
vue.js 343KB
vue.esm.js 327KB
vue.common.dev.js 321KB
vue.esm.browser.js 316KB
vue.common.js 285KB
vue.esm.js 285KB
vue.js 282KB
vue.esm.browser.js 272KB
source-map.debug.js 266KB
browser.js 251KB
vue.runtime.js 241KB
index.js 231KB
vue.runtime.esm.js 229KB
vue.runtime.common.dev.js 225KB
view.runtime.esm.js 223KB
__uniappquill.js 212KB
quill.min.js 211KB
__uniappquill.js 211KB
index.umd.min.js 208KB
vue.runtime.common.js 207KB
vue.runtime.esm.js 207KB
vue.runtime.js 205KB
service.runtime.esm.dev.js 191KB
uni-push.es.js 190KB
index.js 187KB
vue-i18n.global.js 182KB
megalo.mp.esm.js 179KB
vue.runtime.esm.js 176KB
vue-i18n.esm-browser.js 172KB
service.runtime.esm.prod.js 167KB
mp.runtime.esm.js 157KB
build.js 157KB
build.js 145KB
build.js 144KB
index.js 139KB
vue-i18n.runtime.global.js 132KB
build.js 129KB
vue-i18n.runtime.esm-browser.js 124KB
vue.dev.js 123KB
uni-stacktracey.cjs.js 120KB
uni-stacktracey.es.js 120KB
vue.prod.js 111KB
source-map.js 104KB
core-base.global.js 103KB
core-base.esm-browser.js 97KB
vue.min.js 95KB
vue.common.prod.js 95KB
vue.esm.browser.min.js 94KB
index.js 88KB
vue.min.js 84KB
vue-composition-api.js 81KB
vue.dev.js 77KB
index.js 76KB
index.js 76KB
vue-i18n.esm-bundler.js 76KB
vue-i18n.runtime.esm-bundler.js 76KB
vue-composition-api.esm.js 73KB
vue-composition-api.common.js 72KB
vue-router.common.js 71KB
vue-router.esm.js 71KB
vue-router.js 71KB
index.js 69KB
index.js 68KB
index.js 67KB
共 1989 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
传奇开心果编程
- 粉丝: 8085
- 资源: 335
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功