# Source Map JS
[![NPM](https://nodei.co/npm/source-map-js.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/source-map-js)
Difference between original [source-map](https://github.com/mozilla/source-map):
> TL,DR: it's fork of original [email protected], but with perfomance optimizations.
This journey starts from [[email protected]](https://github.com/mozilla/source-map/blob/master/CHANGELOG.md#070). 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](media/downloads.png)
More important that WASM version has some optimizations in JS code too. This is why [community asked to create branch for 0.6 version](https://github.com/mozilla/source-map/issues/324) and port these optimizations but, sadly, the answer was «no». A bit later I discovered [the issue](https://github.com/mozilla/source-map/issues/370) created by [Ben Rothman (@benthemonkey)](https://github.com/benthemonkey) with no response at all.
[Roman Dvornov (@lahmatiy)](https://github.com/lahmatiy) wrote a [serveral posts](https://t.me/gorshochekvarit/76) (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»](https://mrale.ph/blog/2018/02/03/maybe-you-dont-need-rust-to-speed-up-your-js.html) written by [Vyacheslav Egorov (@mraleph)](https://github.com/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][format].
[format]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
## Use with Node
$ npm install source-map-js
<!-- ## 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"
没有合适的资源?快使用搜索试试~ 我知道了~
vue3工程化开发,各组件拼凑,实现增加,删除
共538个文件
js:246个
ts:65个
json:61个
需积分: 0 1 下载量 87 浏览量
2023-04-09
14:25:45
上传
评论
收藏 8.59MB ZIP 举报
温馨提示
vue3工程化开发,各组件拼凑,实现增加,删除
资源推荐
资源详情
资源评论
收起资源包目录
vue3工程化开发,各组件拼凑,实现增加,删除 (538个子文件)
openChrome.applescript 3KB
publicUtils.cjs 113KB
index.cjs 78KB
index.cjs 1KB
nanoid.cjs 1KB
index.browser.cjs 1KB
index.cjs 1018B
index.cjs 993B
index.browser.cjs 983B
index.cjs 499B
index.cjs 120B
index.cjs 111B
parser.cmd 232B
parser.cmd 232B
parser.cmd 232B
parser.cmd 214B
rollup.cmd 204B
nanoid.cmd 202B
resolve.cmd 198B
esbuild.cmd 198B
vite.cmd 198B
rollup.cmd 192B
nanoid.cmd 190B
resolve.cmd 186B
esbuild.cmd 186B
vite.cmd 180B
cup.coffee 1B
mug.coffee 0B
style.css 1KB
index-fc5f319f.css 1KB
.editorconfig 605B
.editorconfig 286B
esbuild 9KB
esbuild 321B
esbuild 309B
.eslintrc 2KB
.eslintrc 339B
.eslintrc 231B
.eslintrc 176B
.eslintrc 132B
esbuild.exe 8.82MB
index.js.flow 282KB
.gitignore 253B
.gitkeep 0B
index.html 449B
index.html 362B
dep-79892de8.js 2.01MB
compiler-sfc.esm-browser.js 1.48MB
rollup.js 962KB
node-entry.js 959KB
vue.global.js 628KB
vue.esm-browser.js 598KB
compiler-sfc.cjs.js 512KB
index.js 476KB
vue.runtime.global.js 425KB
runtime-dom.global.js 424KB
vue.runtime.esm-browser.js 400KB
runtime-dom.esm-browser.js 399KB
dep-98d07f71.js 330KB
runtime-core.esm-bundler.js 309KB
runtime-core.cjs.js 302KB
server-renderer.esm-browser.js 293KB
source-map.debug.js 266KB
runtime-core.cjs.prod.js 237KB
compiler-dom.global.js 231KB
compiler-core.cjs.js 228KB
dep-f63b56ae.js 223KB
compiler-core.cjs.prod.js 221KB
compiler-dom.esm-browser.js 216KB
compiler-core.esm-bundler.js 195KB
vue.esm-browser.prod.js 129KB
watch.js 128KB
vue.global.prod.js 126KB
index.js 119KB
source-map.js 104KB
main.js 85KB
vue.runtime.esm-browser.prod.js 83KB
runtime-dom.esm-browser.prod.js 83KB
vue.runtime.global.prod.js 82KB
runtime-dom.global.prod.js 82KB
compiler-dom.cjs.js 77KB
compiler-dom.cjs.prod.js 74KB
runtime-dom.esm-bundler.js 59KB
server-renderer.esm-browser.prod.js 58KB
runtime-dom.cjs.js 57KB
compiler-dom.esm-browser.prod.js 56KB
compiler-dom.global.prod.js 56KB
compiler-ssr.cjs.js 55KB
index-5ac61b88.js 53KB
runtime-dom.cjs.prod.js 53KB
reactivity.global.js 46KB
reactivity.esm-browser.js 42KB
reactivity.esm-bundler.js 42KB
reactivity.cjs.js 42KB
source-map-consumer.js 41KB
source-map-consumer.js 40KB
reactivity.cjs.prod.js 39KB
server-renderer.cjs.js 38KB
magic-string.umd.js 36KB
server-renderer.esm-bundler.js 35KB
共 538 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
是星星就该闪烁
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功