source: trip-planner-front/node_modules/merge-source-map/README.md@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1# merge-source-map
2
3[![npm-version](https://img.shields.io/npm/v/merge-source-map.svg?style=flat-square)](https://npmjs.org/package/merge-source-map)
4[![downloads](http://img.shields.io/npm/dm/merge-source-map.svg?style=flat-square)](https://npmjs.org/package/merge-source-map)
5[![travis-ci](https://img.shields.io/travis/keik/merge-source-map.svg?style=flat-square)](https://travis-ci.org/keik/merge-source-map)
6[![Coverage Status](https://img.shields.io/coveralls/keik/merge-source-map.svg?style=flat-square)](https://coveralls.io/github/keik/merge-source-map)
7
8Merge old source map and new source map in multi-transform flow
9
10
11# API
12
13```javascript
14var merge = require('merge-source-map')
15```
16
17
18## `merge(oldMap, newMap)`
19
20Merge old source map and new source map and return merged.
21If old or new source map value is falsy, return another one as it is.
22
23<dl>
24 <dt>
25 <code>oldMap</code> : <code>object|undefined</code>
26 </dt>
27 <dd>
28 old source map object
29 </dd>
30
31 <dt>
32 <code>newmap</code> : <code>object|undefined</code>
33 </dt>
34 <dd>
35 new source map object
36 </dd>
37</dl>
38
39
40# Example
41
42```javascript
43var esprima = require('esprima'),
44 estraverse = require('estraverse'),
45 escodegen = require('escodegen'),
46 convert = require('convert-source-map'),
47 merge = require('merge-source-map')
48
49const CODE = 'a = 1',
50 FILEPATH = 'a.js'
51
52// create AST of original code
53var ast = esprima.parse(CODE, {sourceType: 'module', loc: true})
54
55// transform AST of original code
56estraverse.replace(ast, {
57 enter: function(node, parent) { /* change AST */ },
58 leave: function(node, parent) { /* change AST */ }
59})
60
61// generate code and source map from transformed AST
62var gen = escodegen.generate(ast, {
63 sourceMap: FILEPATH,
64 sourceMapWithCode: true,
65 sourceContent: CODE
66})
67
68// merge old source map and new source map
69var oldMap = convert.fromSource(CODE) && convert.fromSource(CODE).toObject(),
70 newMap = JSON.parse(gen.map.toString()),
71 mergedMap = merge(oldMap, newMap),
72 mapComment = convert.fromObject(mergedMap).toComment()
73
74// attach merge source map to transformed code
75var transformed = gen.code + '\n' + mapComment
76
77console.log(transformed);
78```
79
80
81# Test
82
83```
84% npm install
85% npm test
86```
87
88
89# License
90
91MIT (c) keik
Note: See TracBrowser for help on using the repository browser.