diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:38:50 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:40:43 +0200 |
commit | 7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch) | |
tree | 6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/merge-source-map | |
parent | 963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff) | |
download | wallet-core-7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027.tar.xz |
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/merge-source-map')
-rw-r--r-- | node_modules/merge-source-map/LICENSE | 21 | ||||
-rw-r--r-- | node_modules/merge-source-map/README.md | 90 | ||||
-rw-r--r-- | node_modules/merge-source-map/index.js | 58 | ||||
-rw-r--r-- | node_modules/merge-source-map/package.json | 40 |
4 files changed, 209 insertions, 0 deletions
diff --git a/node_modules/merge-source-map/LICENSE b/node_modules/merge-source-map/LICENSE new file mode 100644 index 000000000..39bac6311 --- /dev/null +++ b/node_modules/merge-source-map/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) keik <k4t0.kei@gmail.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/node_modules/merge-source-map/README.md b/node_modules/merge-source-map/README.md new file mode 100644 index 000000000..26d677631 --- /dev/null +++ b/node_modules/merge-source-map/README.md @@ -0,0 +1,90 @@ +# merge-source-map + +[![npm-version](https://img.shields.io/npm/v/merge-source-map.svg?style=flat-square)](https://npmjs.org/package/merge-source-map) +[![travis-ci](https://img.shields.io/travis/keik/merge-source-map.svg?style=flat-square)](https://travis-ci.org/keik/merge-source-map) +[![Coverage Status](https://img.shields.io/coveralls/keik/merge-source-map.svg?style=flat-square)](https://coveralls.io/github/keik/merge-source-map) + +Merge old source map and new source map in multi-transform flow + + +# API + +```javascript +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. + +<dl> + <dt> + <code>oldMap</code> : <code>object|undefined</code> + </dt> + <dd> + old source map object + </dd> + + <dt> + <code>newmap</code> : <code>object|undefined</code> + </dt> + <dd> + new source map object + </dd> +</dl> + + +# Example + +```javascript +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 diff --git a/node_modules/merge-source-map/index.js b/node_modules/merge-source-map/index.js new file mode 100644 index 000000000..d15871c1d --- /dev/null +++ b/node_modules/merge-source-map/index.js @@ -0,0 +1,58 @@ +var sourceMap = require('source-map'), + SourceMapConsumer = sourceMap.SourceMapConsumer, + SourceMapGenerator = sourceMap.SourceMapGenerator + +module.exports = merge + +/** + * 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. + * + * @param {object|undefined} oldMap old source map object + * @param {object|undefined} newmap new source map object + * @return {object|undefined} merged source map object, or undefined when both old and new source map are undefined + */ +function merge(oldMap, newMap) { + + if (!oldMap) + return newMap + if (!newMap) + return oldMap + + var oldMapConsumer = new SourceMapConsumer(oldMap), + newMapConsumer = new SourceMapConsumer(newMap), + mergedMapGenerator = new SourceMapGenerator() + + // iterate on new map and overwrite original position of new map with one of old map + newMapConsumer.eachMapping(function(m) { + + // pass when `originalLine` is null. + // It occurs in case that the node does not have origin in original code. + if (m.originalLine == null) + return + + var origPosInOldMap = oldMapConsumer.originalPositionFor({line: m.originalLine, column: m.originalColumn}) + if (origPosInOldMap.source == null) + return + + mergedMapGenerator.addMapping({ + original: { + line: origPosInOldMap.line, + column: origPosInOldMap.column + }, + generated: { + line: m.generatedLine, + column: m.generatedColumn + }, + source: m.source, + name: m.name + }) + }) + + var mergedMap = JSON.parse(mergedMapGenerator.toString()) + mergedMap.sources = oldMap.sources + mergedMap.sourcesContent = oldMap.sourcesContent + mergedMap.sourceRoot = oldMap.sourceRoot + + return mergedMap +} diff --git a/node_modules/merge-source-map/package.json b/node_modules/merge-source-map/package.json new file mode 100644 index 000000000..d927b7a3e --- /dev/null +++ b/node_modules/merge-source-map/package.json @@ -0,0 +1,40 @@ +{ + "name": "merge-source-map", + "version": "1.0.3", + "description": "Merge old source map and new source map in multi-transform flow", + "main": "index.js", + "scripts": { + "test": "nyc tape test/*.js", + "lint": "eslint index.js 'test/**/*.js'", + "version": "npm run lint && npm run test" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/keik/merge-source-map.git" + }, + "author": "keik <k4t0.kei@gmail.com>", + "license": "MIT", + "bugs": { + "url": "https://github.com/keik/merge-source-map/issues" + }, + "keywords": [ + "sourcemap", + "source-map" + ], + "dependencies": { + "source-map": "^0.5.3" + }, + "devDependencies": { + "babel-core": "^6.14.0", + "babel-preset-es2015": "^6.14.0", + "coffee-script": "^1.10.0", + "convert-source-map": "^1.3.0", + "escodegen": "^1.8.1", + "eslint": "^3.5.0", + "esprima": "^3.0.0", + "estraverse": "^4.1.1", + "nyc": "^8.3.0", + "tape": "^4.5.1" + }, + "files": [] +} |