merge-source-map

WebJar for merge-source-map

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

merge-source-map
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

merge-source-map
WebJar for merge-source-map
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/keik/merge-source-map

Download merge-source-map

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/merge-source-map/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>merge-source-map</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/merge-source-map/
implementation 'org.webjars.npm:merge-source-map:1.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/merge-source-map/
implementation ("org.webjars.npm:merge-source-map:1.1.0")
'org.webjars.npm:merge-source-map:jar:1.1.0'
<dependency org="org.webjars.npm" name="merge-source-map" rev="1.1.0">
  <artifact name="merge-source-map" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='merge-source-map', version='1.1.0')
)
libraryDependencies += "org.webjars.npm" % "merge-source-map" % "1.1.0"
[org.webjars.npm/merge-source-map "1.1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : source-map jar [0.6.1,0.7)

Project Modules

There are no modules declared in this project.

merge-source-map

npm-version downloads travis-ci Coverage Status

Merge old source map and new source map in multi-transform flow

API

var merge = require('merge-source-map')

merge(oldMap, newMap)

Merge old source map and new source map and return merged. If old or new source map value is falsy, return another one as it is.

oldMap : object|undefined
old source map object
newmap : object|undefined
new source map object

Example

var esprima    = require('esprima'),
    estraverse = require('estraverse'),
    escodegen  = require('escodegen'),
    convert    = require('convert-source-map'),
    merge      = require('merge-source-map')

const CODE = 'a = 1',
      FILEPATH = 'a.js'

// create AST of original code
var ast = esprima.parse(CODE, {sourceType: 'module', loc: true})

// transform AST of original code
estraverse.replace(ast, {
  enter: function(node, parent) { /* change AST */ },
  leave: function(node, parent) { /* change AST */ }
})

// generate code and source map from transformed AST
var gen = escodegen.generate(ast, {
  sourceMap: FILEPATH,
  sourceMapWithCode: true,
  sourceContent: CODE
})

// merge old source map and new source map
var oldMap = convert.fromSource(CODE) && convert.fromSource(CODE).toObject(),
    newMap = JSON.parse(gen.map.toString()),
    mergedMap = merge(oldMap, newMap),
    mapComment = convert.fromObject(mergedMap).toComment()

// attach merge source map to transformed code
var transformed = gen.code + '\n' + mapComment

console.log(transformed);

Test

% npm install
% npm test

License

MIT (c) keik

Versions

Version
1.1.0
1.0.4