# 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
mrcrowl.easy-less-1.7.3
需积分: 0 154 浏览量
更新于2022-12-07
收藏 1.97MB ZIP 举报
《深入浅出:mrcrowl.easy-less-1.7.3——简化LESS CSS编程的艺术》
在Web前端开发领域,CSS(层叠样式表)是不可或缺的一部分,它赋予网页丰富的样式与布局。然而,随着网页设计的复杂度不断提升,CSS代码的维护和管理变得越来越困难。为了解决这一问题,CSS预处理器应运而生,LESS便是其中的代表之一。今天我们要探讨的是一个名为“mrcrowl.easy-less”的扩展插件,版本号为1.7.3,它旨在使LESS的使用更加便捷,从而提升开发效率。
LESS是一种CSS预处理器,它引入了变量、嵌套规则、混合、函数等概念,使得CSS代码更易于组织和维护。mrcrowl.easy-less-1.7.3是这个预处理器的一个轻量级扩展,它的主要目标就是为开发者提供一个更简洁、更高效的LESS编程环境。
我们来看一下mrcrowl.easy-less-1.7.3的主要特性:
1. **自动编译**:该插件能实时监控LESS文件的改动,并自动将其编译成可被浏览器识别的CSS,大大减少了手动编译的繁琐步骤。
2. **智能提示**:在编写LESS代码时,插件提供代码补全功能,帮助开发者快速定位和选择所需样式,提高编码速度。
3. **错误检测**:在编译过程中,如果出现语法错误或警告,插件会立即提醒,避免了在运行时才发现问题的尴尬。
4. **简洁界面**:mrcrowl.easy-less-1.7.3拥有直观的操作界面,使开发者能更专注于代码本身,而不是工具的使用。
5. **兼容性**:该插件与多种IDE和文本编辑器兼容,包括但不限于Visual Studio Code、Sublime Text等,适应不同开发者的习惯。
6. **版本控制**:1.7.3版本修复了一些已知问题,提升了整体稳定性,确保在各种项目中的稳定使用。
在实际应用中,mrcrowl.easy-less-1.7.3可以帮助开发者更好地利用LESS的强大功能,如:
- **变量**:使用变量存储颜色、尺寸等常量,减少重复代码,提高代码一致性。
- **嵌套规则**:通过嵌套选择器,使得代码结构更清晰,易于理解。
- **混合(Mixins)**:定义可复用的样式块,实现代码复用,降低维护成本。
- **函数**:内置和自定义函数可以进行复杂的计算和转换,如单位转换、颜色操作等。
在项目中采用mrcrowl.easy-less-1.7.3,可以显著提升CSS的编写体验,使团队协作更加顺畅,同时提高代码质量。为了更好地利用这个工具,开发者需要对LESS的基本语法有深入理解,并熟悉插件的各项功能。通过实践和探索,可以逐步发掘出mrcrowl.easy-less-1.7.3在CSS开发中的无穷潜力。
mrcrowl.easy-less-1.7.3作为一款LESS扩展插件,不仅简化了LESS的使用,还极大地优化了开发流程,是CSS开发者值得拥有的强大助手。对于想要提升CSS编写效率,同时保持代码整洁的开发者来说,这是一个不容忽视的选择。
jimi3322
- 粉丝: 20
- 资源: 1
最新资源
- libnma-devel-1.8.6-2.el7.x64-86.rpm.tar.gz
- libnotify-0.7.7-1.el7.x64-86.rpm.tar.gz
- TrieTree-字典树
- libnotify-devel-0.7.7-1.el7.x64-86.rpm.tar.gz
- libntlm-1.3-6.el7.x64-86.rpm.tar.gz
- image_2019-灵敏度分析
- CurriculumDesign-字典树
- libntlm-devel-1.3-6.el7.x64-86.rpm.tar.gz
- 三菱FX3U PLC与三台台达VFD-E变频器功能块通讯教程:实现正反转、频率设定与状态监控,三菱FX3U FB功能块方式通讯三台VFD-E变频器示例 所需硬件:三菱FX3U PLC,fx3u 485
- liboauth-0.9.7-4.el7.x64-86.rpm.tar.gz
- ollama-ollama
- liboauth-devel-0.9.7-4.el7.x64-86.rpm.tar.gz
- 基于遗传算法与粒子群优化的BP神经网络预测模型-利用MATLAB实现预测分析,遗传算法、粒子群算法优化BP神经网络 #预测#机器学习#MATLAB# 我这是关于预测的 ,核心关键词:遗传算法; 粒子
- Awesome-LLM-deepseek部署
- libobjc-4.8.5-44.el7.x64-86.rpm.tar.gz
- ollama-ollama