├── .gitignore ├── .editorconfig ├── test ├── fixtures │ └── from-to-tests │ │ ├── hello-world2.generated.txt │ │ ├── hello-world1.generated.txt │ │ ├── hello-world3.generated.txt │ │ ├── multiple-file.generated.txt │ │ ├── null-source.generated.txt │ │ ├── file-offset.generated.txt │ │ ├── no-source-contents.generated.txt │ │ ├── empty-lines.generated.txt │ │ ├── mismatched-mappings.generated.txt │ │ ├── multiple-mappings-per-line.generated.txt │ │ ├── babel2-source.js │ │ ├── null-source.input.map │ │ ├── null-source.expected.map │ │ ├── no-source-contents.input.map │ │ ├── no-source-contents.expected.map │ │ ├── hello-world1.input.map │ │ ├── hello-world2.expected.map │ │ ├── hello-world2.input.map │ │ ├── empty-lines.input.map │ │ ├── hello-world1.expected.map │ │ ├── hello-world3.expected.map │ │ ├── hello-world3.input.map │ │ ├── empty-lines.expected.map │ │ ├── multiple-file.expected.map │ │ ├── multiple-file.input.map │ │ ├── multiple-mappings-per-line.expected.map │ │ ├── multiple-mappings-per-line.input.map │ │ ├── file-offset.input.map │ │ ├── mismatched-mappings.expected.map │ │ ├── file-offset.expected.map │ │ ├── mismatched-mappings.input.map │ │ ├── babel2.expected.map │ │ ├── babel2.input.map │ │ ├── babel-source.js │ │ ├── babel.expected.map │ │ ├── babel2.generated.js │ │ ├── babel.input.map │ │ └── babel.generated.js ├── MappingGeneration.js ├── fromStringWithSourceMapTest.js └── mapGeneratedCode.js ├── lib ├── index.js ├── helpers.js ├── MappingsContext.js ├── CodeNode.js ├── SingleLineNode.js ├── fromStringWithSourceMap.js ├── SourceListMap.js ├── SourceNode.js └── base64-vlq.js ├── .travis.yml ├── package.json ├── LICENSE ├── README.md └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /coverage 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*.js] 4 | indent_style=tab 5 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/hello-world2.generated.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | World -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/hello-world1.generated.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | World 3 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/hello-world3.generated.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | World 3 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/multiple-file.generated.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | World 3 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/null-source.generated.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | World 3 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/file-offset.generated.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | World 3 | Offset -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/no-source-contents.generated.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | World 3 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/empty-lines.generated.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | 3 | World 4 | 5 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/mismatched-mappings.generated.txt: -------------------------------------------------------------------------------- 1 | function foobar() { 2 | return; // foo 3 | } -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/multiple-mappings-per-line.generated.txt: -------------------------------------------------------------------------------- 1 | Hello World Test 2 | World Test 3 | Test 4 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/babel2-source.js: -------------------------------------------------------------------------------- 1 | class Test { 2 | foo() { 3 | console.log('bar') 4 | throw new Error('bar') 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/null-source.input.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "null-source.generated.txt", 4 | "mappings": "CAAA;CACA;" 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/null-source.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "null-source.generated.txt", 4 | "sources": [ 5 | null 6 | ], 7 | "mappings": "AAAA;AACA;" 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/no-source-contents.input.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "no-source-contents.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "mappings": "CAAA;CACA;" 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/no-source-contents.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "no-source-contents.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "mappings": "AAAA;AACA;" 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/hello-world1.input.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "hello-world1.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "Hello\nWorld\n" 9 | ], 10 | "mappings": "CAAA;CACA;" 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/hello-world2.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "hello-world2.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "Hello\nWorld" 9 | ], 10 | "mappings": "AAAA;AACA" 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/hello-world2.input.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "hello-world2.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "Hello\nWorld" 9 | ], 10 | "mappings": "CAAA;CACA" 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/empty-lines.input.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "empty-lines.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "Hello\n\nWorld\n\n" 9 | ], 10 | "mappings": "CAAA;;AAEA;;" 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/hello-world1.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "hello-world1.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "Hello\nWorld\n" 9 | ], 10 | "mappings": "AAAA;AACA;" 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/hello-world3.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "hello-world3.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "Hello\nWorld\n" 9 | ], 10 | "mappings": "AAAA;AACA;" 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/hello-world3.input.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "hello-world3.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "Hello\nWorld\n" 9 | ], 10 | "mappings": "A,CAAA;A,CACA;A" 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/empty-lines.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "empty-lines.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "Hello\n\nWorld\n\n" 9 | ], 10 | "mappings": "AAAA;AACA;AACA;AACA;" 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/multiple-file.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "multiple-file.generated.txt", 4 | "sources": [ 5 | "hello.txt", 6 | "world.txt" 7 | ], 8 | "sourcesContent": [ 9 | "Hello\n", 10 | "World\n" 11 | ], 12 | "mappings": "AAAA;ACAA;" 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/multiple-file.input.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "multiple-file.generated.txt", 4 | "sources": [ 5 | "hello.txt", 6 | "world.txt" 7 | ], 8 | "sourcesContent": [ 9 | "Hello\n", 10 | "World\n" 11 | ], 12 | "mappings": "CAAA;CCAA;" 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/multiple-mappings-per-line.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "multiple-mappings-per-line.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "Hello\nWorld\nTest\n" 9 | ], 10 | "mappings": "AAAA;AACA;AACA;" 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/multiple-mappings-per-line.input.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "multiple-mappings-per-line.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "Hello\nWorld\nTest\n" 9 | ], 10 | "mappings": "CAAA,MAC,,MAC;,CAD,MAC;CA," 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/file-offset.input.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "file-offset.generated.txt", 4 | "sources": [ 5 | "hello.txt", 6 | "world.txt" 7 | ], 8 | "sourcesContent": [ 9 | "\nHello\nWorld\nTest", 10 | "Hello\nWorld\nWith\nOffset" 11 | ], 12 | "mappings": "CACA;CCAA;CAEA" 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/mismatched-mappings.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "mismatched-mappings.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "function foobar() {\n return; // foo\n}" 9 | ], 10 | "mappings": "AAAA;AACA;AADA" 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/file-offset.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "file-offset.generated.txt", 4 | "sources": [ 5 | "hello.txt", 6 | "world.txt" 7 | ], 8 | "sourcesContent": [ 9 | "\nHello\nWorld\nTest", 10 | "Hello\nWorld\nWith\nOffset" 11 | ], 12 | "mappings": "AACA;ACAA;AAEA" 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/mismatched-mappings.input.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "mismatched-mappings.generated.txt", 4 | "sources": [ 5 | "hello-world.txt" 6 | ], 7 | "sourcesContent": [ 8 | "function foobar() {\n return; // foo\n}" 9 | ], 10 | "mappings": "AAAA,SAAS,MAAT,GAAmB;AACjB;CADF;AAAmB" 11 | } 12 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | exports.SourceListMap = require("./SourceListMap"); 2 | exports.SourceNode = require("./SourceNode"); 3 | exports.SingleLineNode = require("./SingleLineNode"); 4 | exports.CodeNode = require("./CodeNode"); 5 | exports.MappingsContext = require("./MappingsContext"); 6 | exports.fromStringWithSourceMap = require("./fromStringWithSourceMap"); 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | 4 | branches: 5 | only: 6 | - master 7 | 8 | matrix: 9 | include: 10 | - os: linux 11 | node_js: "8" 12 | - os: linux 13 | node_js: "6" 14 | - os: linux 15 | node_js: "4.3" 16 | - os: osx 17 | node_js: "8" 18 | allow_failures: 19 | - os: osx 20 | fast_finish: true 21 | -------------------------------------------------------------------------------- /lib/helpers.js: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Tobias Koppers @sokra 4 | */ 5 | "use strict"; 6 | 7 | exports.getNumberOfLines = function getNumberOfLines(str) { 8 | let nr = -1; 9 | let idx = -1; 10 | do { 11 | nr++ 12 | idx = str.indexOf("\n", idx + 1); 13 | } while(idx >= 0); 14 | return nr; 15 | }; 16 | 17 | exports.getUnfinishedLine = function getUnfinishedLine(str) { 18 | const idx = str.lastIndexOf("\n"); 19 | if(idx === -1) 20 | return str.length; 21 | else 22 | return str.length - idx - 1; 23 | }; 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "source-list-map", 3 | "version": "2.0.1", 4 | "description": "Fast line to line SourceMap generator.", 5 | "author": "Tobias Koppers @sokra", 6 | "main": "lib/index.js", 7 | "scripts": { 8 | "test": "mocha -R spec" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/webpack/source-list-map.git" 13 | }, 14 | "keywords": [ 15 | "source-map" 16 | ], 17 | "files": [ 18 | "lib" 19 | ], 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/webpack/source-list-map/issues" 23 | }, 24 | "homepage": "https://github.com/webpack/source-list-map", 25 | "devDependencies": { 26 | "mocha": "^2.2.1", 27 | "should": "^5.2.0" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 JS Foundation 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. 8 | -------------------------------------------------------------------------------- /lib/MappingsContext.js: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Tobias Koppers @sokra 4 | */ 5 | "use strict"; 6 | 7 | class MappingsContext { 8 | constructor() { 9 | this.sourcesIndices = new Map(); 10 | this.sourcesContent = new Map(); 11 | this.hasSourceContent = false; 12 | this.currentOriginalLine = 1; 13 | this.currentSource = 0; 14 | this.unfinishedGeneratedLine = false; 15 | } 16 | 17 | ensureSource(source, originalSource) { 18 | let idx = this.sourcesIndices.get(source); 19 | if(typeof idx === "number") { 20 | return idx; 21 | } 22 | idx = this.sourcesIndices.size; 23 | this.sourcesIndices.set(source, idx); 24 | this.sourcesContent.set(source, originalSource) 25 | if(typeof originalSource === "string") 26 | this.hasSourceContent = true; 27 | return idx; 28 | } 29 | 30 | getArrays() { 31 | const sources = []; 32 | const sourcesContent = []; 33 | 34 | for(const pair of this.sourcesContent) { 35 | sources.push(pair[0]); 36 | sourcesContent.push(pair[1]); 37 | } 38 | 39 | return { 40 | sources, 41 | sourcesContent 42 | }; 43 | } 44 | } 45 | module.exports = MappingsContext; 46 | -------------------------------------------------------------------------------- /test/MappingGeneration.js: -------------------------------------------------------------------------------- 1 | var should = require("should"); 2 | var SourceListMap = require("../").SourceListMap; 3 | var SingleLineNode = require("../lib/SingleLineNode"); 4 | var SourceNode = require("../lib/SourceNode"); 5 | 6 | describe("MappingGeneration", function() { 7 | it("should generate mappings", function() { 8 | var map = new SourceListMap(); 9 | map.add("Gen\nCode "); 10 | map.add("Source\nCode\n", "file.txt", "Source\nCode\n"); 11 | map.add("Gen "); 12 | map.add("Code "); 13 | map.add("Source\nCode", "file.txt", "Source\nCode\n"); 14 | var result = map.toStringWithSourceMap({ file: "test.txt" }); 15 | result.source.should.be.eql("Gen\nCode Source\nCode\nGen Code Source\nCode"); 16 | result.map.sourcesContent[0].should.be.eql("Source\nCode\n"); 17 | result.map.mappings.should.be.eql(";A,KAAA;AACA;A,SADA;AACA"); 18 | }) 19 | it("should generate the same mappings for SingleLine and normal node", function() { 20 | var map1 = new SourceListMap(); 21 | var map2 = new SourceListMap(); 22 | map1.add(new SingleLineNode("abc", "abc", "source", 10)); 23 | map2.add(new SourceNode("abc", "abc", "source", 10)); 24 | [map1, map2].forEach(map => { 25 | map.add("\n\n"); 26 | map.add("Source Code\n", "file.txt", "Source\nCode\n"); 27 | }) 28 | var result1 = map1.toStringWithSourceMap({ file: "test.txt" }); 29 | var result2 = map2.toStringWithSourceMap({ file: "test.txt" }); 30 | result2.should.be.eql(result1); 31 | }) 32 | }); 33 | -------------------------------------------------------------------------------- /lib/CodeNode.js: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Tobias Koppers @sokra 4 | */ 5 | "use strict"; 6 | 7 | const getNumberOfLines = require("./helpers").getNumberOfLines; 8 | const getUnfinishedLine = require("./helpers").getUnfinishedLine; 9 | 10 | class CodeNode { 11 | constructor(generatedCode) { 12 | this.generatedCode = generatedCode; 13 | } 14 | 15 | clone() { 16 | return new CodeNode(this.generatedCode); 17 | } 18 | 19 | getGeneratedCode() { 20 | return this.generatedCode; 21 | } 22 | 23 | getMappings(mappingsContext) { 24 | const lines = getNumberOfLines(this.generatedCode); 25 | const mapping = Array(lines+1).join(";"); 26 | if(lines > 0) { 27 | mappingsContext.unfinishedGeneratedLine = getUnfinishedLine(this.generatedCode); 28 | if(mappingsContext.unfinishedGeneratedLine > 0) { 29 | return mapping + "A"; 30 | } else { 31 | return mapping; 32 | } 33 | } else { 34 | const prevUnfinished = mappingsContext.unfinishedGeneratedLine; 35 | mappingsContext.unfinishedGeneratedLine += getUnfinishedLine(this.generatedCode); 36 | if(prevUnfinished === 0 && mappingsContext.unfinishedGeneratedLine > 0) { 37 | return "A"; 38 | } else { 39 | return ""; 40 | } 41 | } 42 | } 43 | 44 | addGeneratedCode(generatedCode) { 45 | this.generatedCode += generatedCode; 46 | } 47 | 48 | mapGeneratedCode(fn) { 49 | const generatedCode = fn(this.generatedCode); 50 | return new CodeNode(generatedCode); 51 | } 52 | 53 | getNormalizedNodes() { 54 | return [this]; 55 | } 56 | 57 | merge(otherNode) { 58 | if(otherNode instanceof CodeNode) { 59 | this.generatedCode += otherNode.generatedCode; 60 | return this; 61 | } 62 | return false; 63 | } 64 | } 65 | 66 | module.exports = CodeNode; 67 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/babel2.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "babel2.generated.js", 4 | "sources": [ 5 | "webpack:///webpack/bootstrap b1bcc793378011ad1abd", 6 | "webpack:///./packages/react-scripts/template/src/index.js" 7 | ], 8 | "sourcesContent": [ 9 | " \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap b1bcc793378011ad1abd\n **/", 10 | "class Test {\n foo() {\n console.log('bar')\n throw new Error('bar')\n }\n}\n\n\n\n/** WEBPACK FOOTER **\n ** ./packages/react-scripts/template/src/index.js\n **/" 11 | ], 12 | "mappings": ";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;ACtCA;;;;;;;AACA;AACA;AACA;AACA;;;;;;;;;" 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/babel2.input.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///webpack/bootstrap b1bcc793378011ad1abd","webpack:///./packages/react-scripts/template/src/index.js"],"names":["Test","console","log","Error"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;KCtCMA,I;;;;;;;2BACE;AACJC,eAAQC,GAAR,CAAY,KAAZ;AACA,aAAM,IAAIC,KAAJ,CAAU,KAAV,CAAN;AACD","file":"babel2.generated.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap b1bcc793378011ad1abd\n **/","class Test {\n foo() {\n console.log('bar')\n throw new Error('bar')\n }\n}\n\n\n\n/** WEBPACK FOOTER **\n ** ./packages/react-scripts/template/src/index.js\n **/"],"sourceRoot":""} 2 | -------------------------------------------------------------------------------- /test/fromStringWithSourceMapTest.js: -------------------------------------------------------------------------------- 1 | var should = require("should"); 2 | var fs = require("fs"); 3 | var path = require("path"); 4 | var SourceListMap = require("../").SourceListMap; 5 | var fromStringWithSourceMap = require("../").fromStringWithSourceMap; 6 | 7 | describe("fromStringWithSourceMap", function() { 8 | fs.readdirSync(path.resolve(__dirname, "fixtures/from-to-tests")).filter(function(name) { 9 | return /\.input\.map$/.test(name); 10 | }).forEach(function(name) { 11 | it("should parse and generate " + name, function() { 12 | var MAP = JSON.parse(fs.readFileSync(path.resolve(__dirname, "fixtures/from-to-tests/" + name), "utf-8")); 13 | var GENERATED_CODE = fs.readFileSync(path.resolve(__dirname, "fixtures/from-to-tests/" + MAP.file), "utf-8"); 14 | var EXPECTED_MAP = JSON.parse(fs.readFileSync(path.resolve(__dirname, "fixtures/from-to-tests/" + 15 | name.replace(/\.input\.map$/, ".expected.map")), "utf-8")); 16 | var slm = fromStringWithSourceMap(GENERATED_CODE, MAP); 17 | var result = slm.toStringWithSourceMap({ 18 | file: MAP.file 19 | }); 20 | if(result.map.mappings !== EXPECTED_MAP.mappings) { 21 | fs.writeFileSync(path.resolve(__dirname, "fixtures/from-to-tests/" + 22 | name.replace(/\.input\.map$/, ".output.map")), JSON.stringify(result.map, null, 2), "utf-8"); 23 | } 24 | JSON.parse(JSON.stringify(result.map)).should.be.eql(EXPECTED_MAP); 25 | if(result.source !== GENERATED_CODE) { 26 | fs.writeFileSync(path.resolve(__dirname, "fixtures/from-to-tests/" + 27 | path.basename(MAP.file, path.extname(MAP.file)) + ".output" + path.extname(MAP.file)), result.source, "utf-8"); 28 | } 29 | result.source.should.be.eql(GENERATED_CODE); 30 | 31 | slm = fromStringWithSourceMap(GENERATED_CODE, EXPECTED_MAP); 32 | result = slm.toStringWithSourceMap({ 33 | file: MAP.file 34 | }); 35 | result.source.should.be.eql(GENERATED_CODE); 36 | JSON.parse(JSON.stringify(result.map)).should.be.eql(EXPECTED_MAP); 37 | }); 38 | 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /test/mapGeneratedCode.js: -------------------------------------------------------------------------------- 1 | var should = require("should"); 2 | var SourceListMap = require("../").SourceListMap; 3 | 4 | describe("mapGeneratedCode", function() { 5 | it("should map generated code correctly", function() { 6 | var map = new SourceListMap(); 7 | var source = [ 8 | "Normal Line 1", 9 | "Normal Line 2", 10 | "$", 11 | "Normal Line 3", 12 | "Line A;Line B;Line C", 13 | "Line A;Line B;Line C", 14 | "No\\", 15 | "New\\", 16 | "Line 1", 17 | "No\\", 18 | "$", 19 | "New\\", 20 | "$", 21 | "$", 22 | "Line 2", 23 | "End Line" 24 | ].join("\n"); 25 | map.add(source + "\n", "file.txt", source + "\n"); 26 | map.add(source + "\n", "file.txt", source + "\n"); 27 | map.add(source + "\n"); 28 | map.add(source, "file.txt", source); 29 | function mappingFunction(line) { 30 | return line.replace(/;/g, "\n").replace(/\\\n/g, " ").replace(/\$\n/g, ""); 31 | } 32 | var newMap = map.mapGeneratedCode(mappingFunction); 33 | var result = newMap.toStringWithSourceMap({ file: "test.txt" }); 34 | var expectedPart = [ 35 | "AACA", 36 | "AAEA", 37 | "AACA", 38 | "AAAA", 39 | "AAAA", 40 | "AACA", 41 | "AAAA", 42 | "AAAA", 43 | "AACA,GACA,IACA", 44 | "AACA,GAEA,IAGA", 45 | "AACA" 46 | ].join(";"); 47 | result.map.mappings.should.be.eql([ 48 | "AAAA", 49 | expectedPart, 50 | "AAfA", 51 | expectedPart, 52 | ";;;;;;;;;;;", 53 | "AAfA", 54 | expectedPart 55 | ].join(";")); 56 | result.source.should.be.eql( 57 | mappingFunction([source, source, source, source].join("\n")) 58 | ); 59 | }); 60 | 61 | it("should map code with many lines in time", function() { 62 | var bigString = Array(100000).join("MyLine\n"); 63 | var source = bigString + "MyLine\n" + bigString; 64 | var map = new SourceListMap(); 65 | map.add(source, "file.txt", source); 66 | var newMap = map.mapGeneratedCode(function(line) { 67 | return line; 68 | }); 69 | var result = newMap.toStringWithSourceMap({ file: "test.txt" }); 70 | result.source.should.be.eql(source); 71 | result.map.sourcesContent[0].should.be.eql(source); 72 | }) 73 | }); 74 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/babel-source.js: -------------------------------------------------------------------------------- 1 | // Expression bodies 2 | var odds = evens.map(v => v + 1); 3 | var nums = evens.map((v, i) => v + i); 4 | 5 | // Statement bodies 6 | nums.forEach(v => { 7 | if (v % 5 === 0) 8 | fives.push(v); 9 | }); 10 | 11 | // Lexical this 12 | var bob = { 13 | _name: "Bob", 14 | _friends: [], 15 | printFriends() { 16 | this._friends.forEach(f => 17 | console.log(this._name + " knows " + f)); 18 | } 19 | } 20 | 21 | class SkinnedMesh extends THREE.Mesh { 22 | constructor(geometry, materials) { 23 | super(geometry, materials); 24 | 25 | this.idMatrix = SkinnedMesh.defaultMatrix(); 26 | this.bones = []; 27 | this.boneMatrices = []; 28 | //... 29 | } 30 | update(camera) { 31 | //... 32 | super.update(); 33 | } 34 | static defaultMatrix() { 35 | return new THREE.Matrix4(); 36 | } 37 | } 38 | 39 | var obj = { 40 | // __proto__ 41 | __proto__: theProtoObj, 42 | // Shorthand for ‘handler: handler’ 43 | handler, 44 | // Methods 45 | toString() { 46 | // Super calls 47 | return "d " + super.toString(); 48 | }, 49 | // Computed (dynamic) property names 50 | [ "prop_" + (() => 42)() ]: 42 51 | }; 52 | 53 | // Basic literal string creation 54 | `In JavaScript "\n" is a line-feed.` 55 | 56 | // Multiline strings 57 | `In JavaScript this is 58 | not legal.` 59 | 60 | // Interpolate variable bindings 61 | var name = "Bob", time = "today"; 62 | `Hello ${name}, how are you ${time}?` 63 | 64 | // Construct an HTTP request prefix is used to interpret the replacements and construction 65 | GET`http://foo.org/bar?a=${a}&b=${b} 66 | Content-Type: application/json 67 | X-Credentials: ${credentials} 68 | { "foo": ${foo}, 69 | "bar": ${bar}}`(myOnReadyStateChangeHandler); 70 | 71 | // list matching 72 | var [a, , b] = [1,2,3]; 73 | 74 | // object matching 75 | var { op: a, lhs: { op: b }, rhs: c } 76 | = getASTNode() 77 | 78 | // object matching shorthand 79 | // binds `op`, `lhs` and `rhs` in scope 80 | var {op, lhs, rhs} = getASTNode() 81 | 82 | // Can be used in parameter position 83 | function g({name: x}) { 84 | console.log(x); 85 | } 86 | g({name: 5}) 87 | 88 | // Fail-soft destructuring 89 | var [a] = []; 90 | a === undefined; 91 | 92 | // Fail-soft destructuring with defaults 93 | var [a = 1] = []; 94 | a === 1; 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # source-list-map 2 | 3 | ## API 4 | 5 | ### Example 6 | 7 | ``` js 8 | var SourceListMap = require("source-list-map").SourceListMap; 9 | 10 | // Create a new map 11 | var map = new SourceListMap(); 12 | 13 | // Add generated code that is map line to line to some soure 14 | map.add("Generated\ncode1\n", "source-code.js", "Orginal\nsource"); 15 | 16 | // Add generated code that isn't mapped 17 | map.add("Generated\ncode2\n"); 18 | 19 | // Get SourceMap and generated source 20 | map.toStringWithSourceMap({ file: "generated-code.js" }); 21 | // { 22 | // source: 'Generated\ncode1\nGenerated\ncode2\n', 23 | // map: { 24 | // version: 3, 25 | // file: 'generated-code.js', 26 | // sources: [ 'source-code.js' ], 27 | // sourcesContent: [ 'Orginal\nsource' ], 28 | // mappings: 'AAAA;AACA;;;' 29 | // } 30 | // } 31 | 32 | // Convert existing SourceMap into SourceListMap 33 | // (Only the first mapping per line is preserved) 34 | var fromStringWithSourceMap = require("source-list-map").fromStringWithSourceMap; 35 | var map = fromStringWithSourceMap("Generated\ncode", { version: 3, ... }); 36 | 37 | ``` 38 | 39 | ### `new SourceListMap()` 40 | 41 | ### `SourceListMap.prototype.add` 42 | 43 | ``` js 44 | SourceListMap.prototype.add(generatedCode: string) 45 | SourceListMap.prototype.add(generatedCode: string, source: string, originalSource: string) 46 | SourceListMap.prototype.add(sourceListMap: SourceListMap) 47 | ``` 48 | 49 | Append some stuff. 50 | 51 | ### `SourceListMap.prototype.prepend` 52 | 53 | ``` js 54 | SourceListMap.prototype.prepend(generatedCode: string) 55 | SourceListMap.prototype.prepend(generatedCode: string, source: string, originalSource: string) 56 | SourceListMap.prototype.prepend(sourceListMap: SourceListMap) 57 | ``` 58 | 59 | Prepend some stuff. 60 | 61 | ### `SourceListMap.prototype.toString()` 62 | 63 | Get generated code. 64 | 65 | ### `SourceListMap.prototype.toStringWithSourceMap` 66 | 67 | ``` js 68 | SourceListMap.prototype.toStringWithSourceMap(options: object) 69 | ``` 70 | 71 | Get generated code and SourceMap. `options` can contains `file` property which defines the `file` property of the SourceMap. 72 | 73 | ### `SourceListMap.prototype.mapGeneratedCode` 74 | 75 | ``` js 76 | SourceListMap.prototype.mapGeneratedCode(fn: function) : SourceListMap 77 | ``` 78 | 79 | Applies `fn` to each generated code block (per line). The returned value is set as new generated code. Returns a new SourceListMap. 80 | 81 | Removing and adding lines is supported. The SourceMap complexity will increase when doing this. 82 | 83 | ## Test 84 | 85 | [![Build Status](https://travis-ci.org/webpack/source-list-map.svg)](https://travis-ci.org/webpack/source-list-map) 86 | 87 | ## License 88 | 89 | Copyright (c) 2017 JS Foundation 90 | 91 | MIT (http://www.opensource.org/licenses/mit-license.php) -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/babel.expected.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "babel.generated.js", 4 | "sources": [ 5 | "babel-source.js" 6 | ], 7 | "sourcesContent": [ 8 | "// Expression bodies\r\nvar odds = evens.map(v => v + 1);\r\nvar nums = evens.map((v, i) => v + i);\r\n\r\n// Statement bodies\r\nnums.forEach(v => {\r\n if (v % 5 === 0)\r\n fives.push(v);\r\n});\r\n\r\n// Lexical this\r\nvar bob = {\r\n _name: \"Bob\",\r\n _friends: [],\r\n printFriends() {\r\n this._friends.forEach(f =>\r\n console.log(this._name + \" knows \" + f));\r\n }\r\n}\r\n\r\nclass SkinnedMesh extends THREE.Mesh {\r\n constructor(geometry, materials) {\r\n super(geometry, materials);\r\n\r\n this.idMatrix = SkinnedMesh.defaultMatrix();\r\n this.bones = [];\r\n this.boneMatrices = [];\r\n //...\r\n }\r\n update(camera) {\r\n //...\r\n super.update();\r\n }\r\n static defaultMatrix() {\r\n return new THREE.Matrix4();\r\n }\r\n}\r\n\r\nvar obj = {\r\n // __proto__\r\n __proto__: theProtoObj,\r\n // Shorthand for ‘handler: handler’\r\n handler,\r\n // Methods\r\n toString() {\r\n // Super calls\r\n return \"d \" + super.toString();\r\n },\r\n // Computed (dynamic) property names\r\n [ \"prop_\" + (() => 42)() ]: 42\r\n};\r\n\r\n// Basic literal string creation\r\n`In JavaScript \"\\n\" is a line-feed.`\r\n\r\n// Multiline strings\r\n`In JavaScript this is\r\n not legal.`\r\n\r\n// Interpolate variable bindings\r\nvar name = \"Bob\", time = \"today\";\r\n`Hello ${name}, how are you ${time}?`\r\n\r\n// Construct an HTTP request prefix is used to interpret the replacements and construction\r\nGET`http://foo.org/bar?a=${a}&b=${b}\r\n Content-Type: application/json\r\n X-Credentials: ${credentials}\r\n { \"foo\": ${foo},\r\n \"bar\": ${bar}}`(myOnReadyStateChangeHandler);\r\n\r\n// list matching\r\nvar [a, , b] = [1,2,3];\r\n\r\n// object matching\r\nvar { op: a, lhs: { op: b }, rhs: c }\r\n = getASTNode()\r\n\r\n// object matching shorthand\r\n// binds `op`, `lhs` and `rhs` in scope\r\nvar {op, lhs, rhs} = getASTNode()\r\n\r\n// Can be used in parameter position\r\nfunction g({name: x}) {\r\n console.log(x);\r\n}\r\ng({name: 5})\r\n\r\n// Fail-soft destructuring\r\nvar [a] = [];\r\na === undefined;\r\n\r\n// Fail-soft destructuring with defaults\r\nvar [a = 1] = [];\r\na === 1;\r\n" 9 | ], 10 | "mappings": ";;;;;;;;;;;;;;;;;AACA;AAAA;AAAA;AACA;AAAA;AAAA;AACA;;AAEA;AACA;AAEA;AACA;;AAEA;AACA;AACA;AACA;;;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AACA;AADA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AATA;AACA;AADA;;AASA;;AAEA;AACA;;;AACA;AACA;AACA;;;AAfA;AAAA;AACA;AAiBA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AAEA;AAAA;AACA;;AAGA;AACA;;AAMA;AAAA;AACA;AACA;;AAEA;AACA;;AAMA;AAAA;AAAA;AACA;;;AAGA;AACA;AAFA;AAAA;AAAA;AACA;;;;AAIA;AACA;AADA;AAAA;AAAA;AACA;;AAEA;AAAA;AACA;AAAA;AACA;AACA;AACA;;AAEA;AAAA;AACA;AAAA;AACA;;AAEA;;AAAA;AACA;AAAA;AACA;;;;;A" 11 | } 12 | -------------------------------------------------------------------------------- /lib/SingleLineNode.js: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Tobias Koppers @sokra 4 | */ 5 | "use strict"; 6 | 7 | const base64VLQ = require("./base64-vlq"); 8 | const getNumberOfLines = require("./helpers").getNumberOfLines; 9 | const getUnfinishedLine = require("./helpers").getUnfinishedLine; 10 | 11 | const LINE_MAPPING = ";AAAA"; 12 | 13 | class SingleLineNode { 14 | 15 | constructor(generatedCode, source, originalSource, line) { 16 | this.generatedCode = generatedCode; 17 | this.originalSource = originalSource; 18 | this.source = source; 19 | this.line = line || 1; 20 | this._numberOfLines = getNumberOfLines(this.generatedCode); 21 | this._endsWithNewLine = generatedCode[generatedCode.length - 1] === "\n"; 22 | } 23 | 24 | clone() { 25 | return new SingleLineNode(this.generatedCode, this.source, this.originalSource, this.line); 26 | } 27 | 28 | getGeneratedCode() { 29 | return this.generatedCode; 30 | } 31 | 32 | getMappings(mappingsContext) { 33 | if(!this.generatedCode) 34 | return ""; 35 | const lines = this._numberOfLines; 36 | const sourceIdx = mappingsContext.ensureSource(this.source, this.originalSource); 37 | let mappings = "A"; // generated column 0 38 | if(mappingsContext.unfinishedGeneratedLine) 39 | mappings = "," + base64VLQ.encode(mappingsContext.unfinishedGeneratedLine); 40 | mappings += base64VLQ.encode(sourceIdx - mappingsContext.currentSource); // source index 41 | mappings += base64VLQ.encode(this.line - mappingsContext.currentOriginalLine); // original line index 42 | mappings += "A"; // original column 0 43 | mappingsContext.currentSource = sourceIdx; 44 | mappingsContext.currentOriginalLine = this.line; 45 | const unfinishedGeneratedLine = mappingsContext.unfinishedGeneratedLine = getUnfinishedLine(this.generatedCode) 46 | mappings += Array(lines).join(LINE_MAPPING); 47 | if(unfinishedGeneratedLine === 0) { 48 | mappings += ";"; 49 | } else { 50 | if(lines !== 0) 51 | mappings += LINE_MAPPING; 52 | } 53 | return mappings; 54 | } 55 | 56 | getNormalizedNodes() { 57 | return [this]; 58 | } 59 | 60 | mapGeneratedCode(fn) { 61 | const generatedCode = fn(this.generatedCode); 62 | return new SingleLineNode(generatedCode, this.source, this.originalSource, this.line); 63 | } 64 | 65 | merge(otherNode) { 66 | if(otherNode instanceof SingleLineNode) { 67 | return this.mergeSingleLineNode(otherNode); 68 | } 69 | return false; 70 | } 71 | 72 | mergeSingleLineNode(otherNode) { 73 | if(this.source === otherNode.source && 74 | this.originalSource === otherNode.originalSource) { 75 | if(this.line === otherNode.line) { 76 | this.generatedCode += otherNode.generatedCode; 77 | this._numberOfLines += otherNode._numberOfLines; 78 | this._endsWithNewLine = otherNode._endsWithNewLine; 79 | return this; 80 | } else if(this.line + 1 === otherNode.line && 81 | this._endsWithNewLine && 82 | this._numberOfLines === 1 && 83 | otherNode._numberOfLines <= 1) { 84 | return new SourceNode(this.generatedCode + otherNode.generatedCode, this.source, this.originalSource, this.line); 85 | } 86 | } 87 | return false; 88 | } 89 | } 90 | 91 | module.exports = SingleLineNode; 92 | 93 | const SourceNode = require("./SourceNode"); // circular dependency 94 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/babel2.generated.js: -------------------------------------------------------------------------------- 1 | /******/ (function(modules) { // webpackBootstrap 2 | /******/ // The module cache 3 | /******/ var installedModules = {}; 4 | /******/ 5 | /******/ // The require function 6 | /******/ function __webpack_require__(moduleId) { 7 | /******/ 8 | /******/ // Check if module is in cache 9 | /******/ if(installedModules[moduleId]) 10 | /******/ return installedModules[moduleId].exports; 11 | /******/ 12 | /******/ // Create a new module (and put it into the cache) 13 | /******/ var module = installedModules[moduleId] = { 14 | /******/ exports: {}, 15 | /******/ id: moduleId, 16 | /******/ loaded: false 17 | /******/ }; 18 | /******/ 19 | /******/ // Execute the module function 20 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 21 | /******/ 22 | /******/ // Flag the module as loaded 23 | /******/ module.loaded = true; 24 | /******/ 25 | /******/ // Return the exports of the module 26 | /******/ return module.exports; 27 | /******/ } 28 | /******/ 29 | /******/ 30 | /******/ // expose the modules object (__webpack_modules__) 31 | /******/ __webpack_require__.m = modules; 32 | /******/ 33 | /******/ // expose the module cache 34 | /******/ __webpack_require__.c = installedModules; 35 | /******/ 36 | /******/ // __webpack_public_path__ 37 | /******/ __webpack_require__.p = "/"; 38 | /******/ 39 | /******/ // Load entry module and return exports 40 | /******/ return __webpack_require__(0); 41 | /******/ }) 42 | /************************************************************************/ 43 | /******/ ([ 44 | /* 0 */ 45 | /*!******************!*\ 46 | !*** multi main ***! 47 | \******************/ 48 | /***/ function(module, exports, __webpack_require__) { 49 | 50 | module.exports = __webpack_require__(/*! /Users/joe/Documents/Development/create-react-app/packages/react-scripts/template/src/index.js */1); 51 | 52 | 53 | /***/ }, 54 | /* 1 */ 55 | /*!******************************************************!*\ 56 | !*** ./packages/react-scripts/template/src/index.js ***! 57 | \******************************************************/ 58 | /***/ function(module, exports) { 59 | 60 | 'use strict'; 61 | 62 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 63 | 64 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 65 | 66 | var Test = function () { 67 | function Test() { 68 | _classCallCheck(this, Test); 69 | } 70 | 71 | _createClass(Test, [{ 72 | key: 'foo', 73 | value: function foo() { 74 | console.log('bar'); 75 | throw new Error('bar'); 76 | } 77 | }]); 78 | 79 | return Test; 80 | }(); 81 | 82 | /***/ } 83 | /******/ ]); 84 | //# sourceMappingURL=bundle.js.map 85 | -------------------------------------------------------------------------------- /lib/fromStringWithSourceMap.js: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Tobias Koppers @sokra 4 | */ 5 | "use strict"; 6 | 7 | const base64VLQ = require("./base64-vlq"); 8 | const SourceNode = require("./SourceNode"); 9 | const CodeNode = require("./CodeNode"); 10 | const SourceListMap = require("./SourceListMap"); 11 | 12 | module.exports = function fromStringWithSourceMap(code, map) { 13 | const sources = map.sources; 14 | const sourcesContent = map.sourcesContent; 15 | const mappings = map.mappings.split(";"); 16 | const lines = code.split("\n"); 17 | const nodes = []; 18 | let currentNode = null; 19 | let currentLine = 1; 20 | let currentSourceIdx = 0; 21 | let currentSourceNodeLine; 22 | function addCode(generatedCode) { 23 | if(currentNode && currentNode instanceof CodeNode) { 24 | currentNode.addGeneratedCode(generatedCode); 25 | } else if(currentNode && currentNode instanceof SourceNode && !generatedCode.trim()) { 26 | currentNode.addGeneratedCode(generatedCode); 27 | currentSourceNodeLine++; 28 | } else { 29 | currentNode = new CodeNode(generatedCode); 30 | nodes.push(currentNode); 31 | } 32 | } 33 | function addSource(generatedCode, source, originalSource, linePosition) { 34 | if(currentNode && currentNode instanceof SourceNode && 35 | currentNode.source === source && 36 | currentSourceNodeLine === linePosition 37 | ) { 38 | currentNode.addGeneratedCode(generatedCode); 39 | currentSourceNodeLine++; 40 | } else { 41 | currentNode = new SourceNode(generatedCode, source, originalSource, linePosition); 42 | currentSourceNodeLine = linePosition + 1; 43 | nodes.push(currentNode); 44 | } 45 | } 46 | mappings.forEach(function(mapping, idx) { 47 | let line = lines[idx]; 48 | if(typeof line === 'undefined') return; 49 | if(idx !== lines.length - 1) line += "\n"; 50 | if(!mapping) 51 | return addCode(line); 52 | mapping = { value: 0, rest: mapping }; 53 | let lineAdded = false; 54 | while(mapping.rest) 55 | lineAdded = processMapping(mapping, line, lineAdded) || lineAdded; 56 | if(!lineAdded) 57 | addCode(line); 58 | }); 59 | if(mappings.length < lines.length) { 60 | let idx = mappings.length; 61 | while(!lines[idx].trim() && idx < lines.length-1) { 62 | addCode(lines[idx] + "\n"); 63 | idx++; 64 | } 65 | addCode(lines.slice(idx).join("\n")); 66 | } 67 | return new SourceListMap(nodes); 68 | function processMapping(mapping, line, ignore) { 69 | if(mapping.rest && mapping.rest[0] !== ",") { 70 | base64VLQ.decode(mapping.rest, mapping); 71 | } 72 | if(!mapping.rest) 73 | return false; 74 | if(mapping.rest[0] === ",") { 75 | mapping.rest = mapping.rest.substr(1); 76 | return false; 77 | } 78 | 79 | base64VLQ.decode(mapping.rest, mapping); 80 | const sourceIdx = mapping.value + currentSourceIdx; 81 | currentSourceIdx = sourceIdx; 82 | 83 | let linePosition; 84 | if(mapping.rest && mapping.rest[0] !== ",") { 85 | base64VLQ.decode(mapping.rest, mapping); 86 | linePosition = mapping.value + currentLine; 87 | currentLine = linePosition; 88 | } else { 89 | linePosition = currentLine; 90 | } 91 | 92 | if(mapping.rest) { 93 | const next = mapping.rest.indexOf(","); 94 | mapping.rest = next === -1 ? "" : mapping.rest.substr(next); 95 | } 96 | 97 | if(!ignore) { 98 | addSource(line, sources ? sources[sourceIdx] : null, sourcesContent ? sourcesContent[sourceIdx] : null, linePosition) 99 | return true; 100 | } 101 | } 102 | }; 103 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/babel.input.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["babel-source.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,UAAA,CAAC;SAAI,CAAC,GAAG,CAAC;CAAA,CAAC,CAAC;AACjC,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,UAAC,CAAC,EAAE,CAAC;SAAK,CAAC,GAAG,CAAC;CAAA,CAAC,CAAC;;;AAGtC,IAAI,CAAC,OAAO,CAAC,UAAA,CAAC,EAAI;AAChB,MAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EACb,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB,CAAC,CAAC;;;AAGH,IAAI,GAAG,GAAG;AACR,OAAK,EAAE,KAAK;AACZ,UAAQ,EAAE,EAAE;AACZ,cAAY,EAAA,wBAAG;;;AACb,QAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAA,CAAC;aACrB,OAAO,CAAC,GAAG,CAAC,OAAK,KAAK,GAAG,SAAS,GAAG,CAAC,CAAC;KAAA,CAAC,CAAC;GAC5C;CACF,CAAA;;IAEK,WAAW;AACJ,WADP,WAAW,CACH,QAAQ,EAAE,SAAS,EAAE;0BAD7B,WAAW;;AAEb,+BAFE,WAAW,6CAEP,QAAQ,EAAE,SAAS,EAAE;;AAE3B,QAAI,CAAC,QAAQ,GAAG,WAAW,CAAC,aAAa,EAAE,CAAC;AAC5C,QAAI,CAAC,KAAK,GAAG,EAAE,CAAC;AAChB,QAAI,CAAC,YAAY,GAAG,EAAE,CAAC;;GAExB;;YARG,WAAW;;eAAX,WAAW;;WAST,gBAAC,MAAM,EAAE;;AAEb,iCAXE,WAAW,wCAWE;KAChB;;;WACmB,yBAAG;AACrB,aAAO,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;KAC5B;;;SAfG,WAAW;GAAS,KAAK,CAAC,IAAI;;AAkBpC,IAAI,GAAG;;AAEH,aAAW,WAAW;;AAEtB,WAAA,OAAO;;AAEP,YAAQ,oBAAG;;AAEV,WAAO,IAAI,iEAAmB,CAAC;GAC/B,IAEC,OAAO,GAAG,CAAC;SAAM,EAAE;EAAA,EAAG,EAAI,EAAE,CACjC,CAAC;;;AAGF,iJAIY;;;AAGZ,IAAI,IAAI,GAAG,KAAK;IAAE,IAAI,GAAG,OAAO,CAAC;AACjC,WAAS,IAAI,sBAAiB,IAAI,OAAG;;;AAGrC,GAAG,+TAAwB,CAAC,EAAM,CAAC,EAEd,WAAW,EACjB,GAAG,EACH,GAAG,EAAI,2BAA2B,CAAC,CAAC;;;WAGpC,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC;IAAjB,CAAC;IAAI,CAAC;;;;kBAIF,UAAU,EAAE;;IADX,CAAC,eAAL,EAAE;IAAgB,CAAC,eAAZ,GAAG,CAAI,EAAE;IAAY,CAAC,eAAN,GAAG;;;;;mBAKX,UAAU,EAAE;;IAA5B,EAAE,gBAAF,EAAE;IAAE,GAAG,gBAAH,GAAG;IAAE,GAAG,gBAAH,GAAG;;;AAGjB,SAAS,CAAC,QAAY;MAAJ,CAAC,SAAP,IAAI;;AACd,SAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChB;AACD,CAAC,CAAC,EAAC,IAAI,EAAE,CAAC,EAAC,CAAC,CAAA;;;YAGF,EAAE;IAAP,CAAC;;AACN,CAAC,KAAK,SAAS,CAAC;;;YAGF,EAAE;;IAAX,CAAC,2BAAG,CAAC;;AACV,CAAC,KAAK,CAAC,CAAC","file":"babel.generated.js","sourcesContent":["// Expression bodies\r\nvar odds = evens.map(v => v + 1);\r\nvar nums = evens.map((v, i) => v + i);\r\n\r\n// Statement bodies\r\nnums.forEach(v => {\r\n if (v % 5 === 0)\r\n fives.push(v);\r\n});\r\n\r\n// Lexical this\r\nvar bob = {\r\n _name: \"Bob\",\r\n _friends: [],\r\n printFriends() {\r\n this._friends.forEach(f =>\r\n console.log(this._name + \" knows \" + f));\r\n }\r\n}\r\n\r\nclass SkinnedMesh extends THREE.Mesh {\r\n constructor(geometry, materials) {\r\n super(geometry, materials);\r\n\r\n this.idMatrix = SkinnedMesh.defaultMatrix();\r\n this.bones = [];\r\n this.boneMatrices = [];\r\n //...\r\n }\r\n update(camera) {\r\n //...\r\n super.update();\r\n }\r\n static defaultMatrix() {\r\n return new THREE.Matrix4();\r\n }\r\n}\r\n\r\nvar obj = {\r\n // __proto__\r\n __proto__: theProtoObj,\r\n // Shorthand for ‘handler: handler’\r\n handler,\r\n // Methods\r\n toString() {\r\n // Super calls\r\n return \"d \" + super.toString();\r\n },\r\n // Computed (dynamic) property names\r\n [ \"prop_\" + (() => 42)() ]: 42\r\n};\r\n\r\n// Basic literal string creation\r\n`In JavaScript \"\\n\" is a line-feed.`\r\n\r\n// Multiline strings\r\n`In JavaScript this is\r\n not legal.`\r\n\r\n// Interpolate variable bindings\r\nvar name = \"Bob\", time = \"today\";\r\n`Hello ${name}, how are you ${time}?`\r\n\r\n// Construct an HTTP request prefix is used to interpret the replacements and construction\r\nGET`http://foo.org/bar?a=${a}&b=${b}\r\n Content-Type: application/json\r\n X-Credentials: ${credentials}\r\n { \"foo\": ${foo},\r\n \"bar\": ${bar}}`(myOnReadyStateChangeHandler);\r\n\r\n// list matching\r\nvar [a, , b] = [1,2,3];\r\n\r\n// object matching\r\nvar { op: a, lhs: { op: b }, rhs: c }\r\n = getASTNode()\r\n\r\n// object matching shorthand\r\n// binds `op`, `lhs` and `rhs` in scope\r\nvar {op, lhs, rhs} = getASTNode()\r\n\r\n// Can be used in parameter position\r\nfunction g({name: x}) {\r\n console.log(x);\r\n}\r\ng({name: 5})\r\n\r\n// Fail-soft destructuring\r\nvar [a] = [];\r\na === undefined;\r\n\r\n// Fail-soft destructuring with defaults\r\nvar [a = 1] = [];\r\na === 1;\r\n"]} -------------------------------------------------------------------------------- /lib/SourceListMap.js: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Tobias Koppers @sokra 4 | */ 5 | "use strict"; 6 | 7 | const CodeNode = require("./CodeNode"); 8 | const SourceNode = require("./SourceNode"); 9 | const MappingsContext = require("./MappingsContext"); 10 | const getNumberOfLines = require("./helpers").getNumberOfLines; 11 | 12 | class SourceListMap { 13 | 14 | constructor(generatedCode, source, originalSource) { 15 | if(Array.isArray(generatedCode)) { 16 | this.children = generatedCode; 17 | } else { 18 | this.children = []; 19 | if(generatedCode || source) 20 | this.add(generatedCode, source, originalSource); 21 | } 22 | } 23 | 24 | add(generatedCode, source, originalSource) { 25 | if(typeof generatedCode === "string") { 26 | if(source) { 27 | this.children.push(new SourceNode(generatedCode, source, originalSource)); 28 | } else if(this.children.length > 0 && this.children[this.children.length - 1] instanceof CodeNode) { 29 | this.children[this.children.length - 1].addGeneratedCode(generatedCode); 30 | } else { 31 | this.children.push(new CodeNode(generatedCode)); 32 | } 33 | } else if(generatedCode.getMappings && generatedCode.getGeneratedCode) { 34 | this.children.push(generatedCode); 35 | } else if(generatedCode.children) { 36 | generatedCode.children.forEach(function(sln) { 37 | this.children.push(sln); 38 | }, this); 39 | } else { 40 | throw new Error("Invalid arguments to SourceListMap.protfotype.add: Expected string, Node or SourceListMap"); 41 | } 42 | }; 43 | 44 | preprend(generatedCode, source, originalSource) { 45 | if(typeof generatedCode === "string") { 46 | if(source) { 47 | this.children.unshift(new SourceNode(generatedCode, source, originalSource)); 48 | } else if(this.children.length > 0 && this.children[this.children.length - 1].preprendGeneratedCode) { 49 | this.children[this.children.length - 1].preprendGeneratedCode(generatedCode); 50 | } else { 51 | this.children.unshift(new CodeNode(generatedCode)); 52 | } 53 | } else if(generatedCode.getMappings && generatedCode.getGeneratedCode) { 54 | this.children.unshift(generatedCode); 55 | } else if(generatedCode.children) { 56 | generatedCode.children.slice().reverse().forEach(function(sln) { 57 | this.children.unshift(sln); 58 | }, this); 59 | } else { 60 | throw new Error("Invalid arguments to SourceListMap.protfotype.prerend: Expected string, Node or SourceListMap"); 61 | } 62 | }; 63 | 64 | mapGeneratedCode(fn) { 65 | const normalizedNodes = []; 66 | this.children.forEach(function(sln) { 67 | sln.getNormalizedNodes().forEach(function(newNode) { 68 | normalizedNodes.push(newNode); 69 | }); 70 | }); 71 | const optimizedNodes = []; 72 | normalizedNodes.forEach(function(sln) { 73 | sln = sln.mapGeneratedCode(fn); 74 | if(optimizedNodes.length === 0) { 75 | optimizedNodes.push(sln); 76 | } else { 77 | const last = optimizedNodes[optimizedNodes.length - 1]; 78 | const mergedNode = last.merge(sln); 79 | if(mergedNode) { 80 | optimizedNodes[optimizedNodes.length - 1] = mergedNode; 81 | } else { 82 | optimizedNodes.push(sln); 83 | } 84 | } 85 | }); 86 | return new SourceListMap(optimizedNodes); 87 | }; 88 | 89 | toString() { 90 | return this.children.map(function(sln) { 91 | return sln.getGeneratedCode(); 92 | }).join(""); 93 | }; 94 | 95 | toStringWithSourceMap(options) { 96 | const mappingsContext = new MappingsContext(); 97 | const source = this.children.map(function(sln) { 98 | return sln.getGeneratedCode(); 99 | }).join(""); 100 | const mappings = this.children.map(function(sln) { 101 | return sln.getMappings(mappingsContext); 102 | }).join(""); 103 | const arrays = mappingsContext.getArrays(); 104 | return { 105 | source, 106 | map: { 107 | version: 3, 108 | file: options && options.file, 109 | sources: arrays.sources, 110 | sourcesContent: mappingsContext.hasSourceContent ? arrays.sourcesContent : undefined, 111 | mappings: mappings 112 | } 113 | }; 114 | } 115 | } 116 | 117 | module.exports = SourceListMap; 118 | -------------------------------------------------------------------------------- /lib/SourceNode.js: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Tobias Koppers @sokra 4 | */ 5 | "use strict"; 6 | 7 | const base64VLQ = require("./base64-vlq"); 8 | const getNumberOfLines = require("./helpers").getNumberOfLines; 9 | const getUnfinishedLine = require("./helpers").getUnfinishedLine; 10 | 11 | const LINE_MAPPING = ";AACA"; 12 | 13 | class SourceNode { 14 | 15 | constructor(generatedCode, source, originalSource, startingLine) { 16 | this.generatedCode = generatedCode; 17 | this.originalSource = originalSource; 18 | this.source = source; 19 | this.startingLine = startingLine || 1; 20 | this._numberOfLines = getNumberOfLines(this.generatedCode); 21 | this._endsWithNewLine = generatedCode[generatedCode.length - 1] === "\n"; 22 | } 23 | 24 | clone() { 25 | return new SourceNode(this.generatedCode, this.source, this.originalSource, this.startingLine); 26 | } 27 | 28 | getGeneratedCode() { 29 | return this.generatedCode; 30 | } 31 | 32 | addGeneratedCode(code) { 33 | this.generatedCode += code; 34 | this._numberOfLines += getNumberOfLines(code); 35 | this._endsWithNewLine = code[code.length - 1] === "\n"; 36 | } 37 | 38 | getMappings(mappingsContext) { 39 | if(!this.generatedCode) 40 | return ""; 41 | const lines = this._numberOfLines; 42 | const sourceIdx = mappingsContext.ensureSource(this.source, this.originalSource); 43 | let mappings = "A"; // generated column 0 44 | if(mappingsContext.unfinishedGeneratedLine) 45 | mappings = "," + base64VLQ.encode(mappingsContext.unfinishedGeneratedLine); 46 | mappings += base64VLQ.encode(sourceIdx - mappingsContext.currentSource); // source index 47 | mappings += base64VLQ.encode(this.startingLine - mappingsContext.currentOriginalLine); // original line index 48 | mappings += "A"; // original column 0 49 | mappingsContext.currentSource = sourceIdx; 50 | mappingsContext.currentOriginalLine = this.startingLine + lines - 1; 51 | const unfinishedGeneratedLine = mappingsContext.unfinishedGeneratedLine = getUnfinishedLine(this.generatedCode) 52 | mappings += Array(lines).join(LINE_MAPPING); 53 | if(unfinishedGeneratedLine === 0) { 54 | mappings += ";"; 55 | } else { 56 | if(lines !== 0) { 57 | mappings += LINE_MAPPING; 58 | } 59 | mappingsContext.currentOriginalLine++; 60 | } 61 | return mappings; 62 | } 63 | 64 | mapGeneratedCode(fn) { 65 | throw new Error("Cannot map generated code on a SourceMap. Normalize to SingleLineNode first."); 66 | } 67 | 68 | getNormalizedNodes() { 69 | var results = []; 70 | var currentLine = this.startingLine; 71 | var generatedCode = this.generatedCode; 72 | var index = 0; 73 | var indexEnd = generatedCode.length; 74 | while(index < indexEnd) { 75 | // get one generated line 76 | var nextLine = generatedCode.indexOf("\n", index) + 1; 77 | if(nextLine === 0) nextLine = indexEnd; 78 | var lineGenerated = generatedCode.substr(index, nextLine - index); 79 | 80 | results.push(new SingleLineNode(lineGenerated, this.source, this.originalSource, currentLine)); 81 | 82 | // move cursors 83 | index = nextLine; 84 | currentLine++; 85 | } 86 | return results; 87 | } 88 | 89 | merge(otherNode) { 90 | if(otherNode instanceof SourceNode) { 91 | return this.mergeSourceNode(otherNode); 92 | } else if(otherNode instanceof SingleLineNode) { 93 | return this.mergeSingleLineNode(otherNode); 94 | } 95 | return false; 96 | } 97 | 98 | mergeSourceNode(otherNode) { 99 | if(this.source === otherNode.source && 100 | this._endsWithNewLine && 101 | this.startingLine + this._numberOfLines === otherNode.startingLine) { 102 | this.generatedCode += otherNode.generatedCode; 103 | this._numberOfLines += otherNode._numberOfLines; 104 | this._endsWithNewLine = otherNode._endsWithNewLine; 105 | return this; 106 | } 107 | return false; 108 | } 109 | 110 | mergeSingleLineNode(otherNode) { 111 | if(this.source === otherNode.source && 112 | this._endsWithNewLine && 113 | this.startingLine + this._numberOfLines === otherNode.line && 114 | otherNode._numberOfLines <= 1) { 115 | this.addSingleLineNode(otherNode); 116 | return this; 117 | } 118 | return false; 119 | } 120 | 121 | addSingleLineNode(otherNode) { 122 | this.generatedCode += otherNode.generatedCode; 123 | this._numberOfLines += otherNode._numberOfLines 124 | this._endsWithNewLine = otherNode._endsWithNewLine; 125 | } 126 | } 127 | 128 | module.exports = SourceNode; 129 | const SingleLineNode = require("./SingleLineNode"); // circular dependency 130 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | commander@0.6.1: 6 | version "0.6.1" 7 | resolved "https://registry.yarnpkg.com/commander/-/commander-0.6.1.tgz#fa68a14f6a945d54dbbe50d8cdb3320e9e3b1a06" 8 | 9 | commander@2.3.0: 10 | version "2.3.0" 11 | resolved "https://registry.yarnpkg.com/commander/-/commander-2.3.0.tgz#fd430e889832ec353b9acd1de217c11cb3eef873" 12 | 13 | debug@2.2.0: 14 | version "2.2.0" 15 | resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da" 16 | dependencies: 17 | ms "0.7.1" 18 | 19 | diff@1.4.0: 20 | version "1.4.0" 21 | resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf" 22 | 23 | escape-string-regexp@1.0.2: 24 | version "1.0.2" 25 | resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz#4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1" 26 | 27 | glob@3.2.11: 28 | version "3.2.11" 29 | resolved "https://registry.yarnpkg.com/glob/-/glob-3.2.11.tgz#4a973f635b9190f715d10987d5c00fd2815ebe3d" 30 | dependencies: 31 | inherits "2" 32 | minimatch "0.3" 33 | 34 | growl@1.9.2: 35 | version "1.9.2" 36 | resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f" 37 | 38 | inherits@2: 39 | version "2.0.3" 40 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" 41 | 42 | jade@0.26.3: 43 | version "0.26.3" 44 | resolved "https://registry.yarnpkg.com/jade/-/jade-0.26.3.tgz#8f10d7977d8d79f2f6ff862a81b0513ccb25686c" 45 | dependencies: 46 | commander "0.6.1" 47 | mkdirp "0.3.0" 48 | 49 | lru-cache@2: 50 | version "2.7.3" 51 | resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952" 52 | 53 | minimatch@0.3: 54 | version "0.3.0" 55 | resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.3.0.tgz#275d8edaac4f1bb3326472089e7949c8394699dd" 56 | dependencies: 57 | lru-cache "2" 58 | sigmund "~1.0.0" 59 | 60 | minimist@0.0.8: 61 | version "0.0.8" 62 | resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" 63 | 64 | mkdirp@0.3.0: 65 | version "0.3.0" 66 | resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.3.0.tgz#1bbf5ab1ba827af23575143490426455f481fe1e" 67 | 68 | mkdirp@0.5.1: 69 | version "0.5.1" 70 | resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" 71 | dependencies: 72 | minimist "0.0.8" 73 | 74 | mocha@^2.2.1: 75 | version "2.5.3" 76 | resolved "https://registry.yarnpkg.com/mocha/-/mocha-2.5.3.tgz#161be5bdeb496771eb9b35745050b622b5aefc58" 77 | dependencies: 78 | commander "2.3.0" 79 | debug "2.2.0" 80 | diff "1.4.0" 81 | escape-string-regexp "1.0.2" 82 | glob "3.2.11" 83 | growl "1.9.2" 84 | jade "0.26.3" 85 | mkdirp "0.5.1" 86 | supports-color "1.2.0" 87 | to-iso-string "0.0.2" 88 | 89 | ms@0.7.1: 90 | version "0.7.1" 91 | resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098" 92 | 93 | should-equal@0.3.1: 94 | version "0.3.1" 95 | resolved "https://registry.yarnpkg.com/should-equal/-/should-equal-0.3.1.tgz#bd8ea97a6748e39fad476a3be6fd72ebc2e72bf0" 96 | dependencies: 97 | should-type "0.0.4" 98 | 99 | should-format@0.0.7: 100 | version "0.0.7" 101 | resolved "https://registry.yarnpkg.com/should-format/-/should-format-0.0.7.tgz#1e2ef86bd91da9c2e0412335b56ababd9a2fde12" 102 | dependencies: 103 | should-type "0.0.4" 104 | 105 | should-type@0.0.4: 106 | version "0.0.4" 107 | resolved "https://registry.yarnpkg.com/should-type/-/should-type-0.0.4.tgz#0132a05417a6126866426acf116f1ed5623a5cd0" 108 | 109 | should@^5.2.0: 110 | version "5.2.0" 111 | resolved "https://registry.yarnpkg.com/should/-/should-5.2.0.tgz#9a4519b447b8b5eedce9eed96af3420d451a540b" 112 | dependencies: 113 | should-equal "0.3.1" 114 | should-format "0.0.7" 115 | should-type "0.0.4" 116 | 117 | sigmund@~1.0.0: 118 | version "1.0.1" 119 | resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" 120 | 121 | supports-color@1.2.0: 122 | version "1.2.0" 123 | resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-1.2.0.tgz#ff1ed1e61169d06b3cf2d588e188b18d8847e17e" 124 | 125 | to-iso-string@0.0.2: 126 | version "0.0.2" 127 | resolved "https://registry.yarnpkg.com/to-iso-string/-/to-iso-string-0.0.2.tgz#4dc19e664dfccbe25bd8db508b00c6da158255d1" 128 | -------------------------------------------------------------------------------- /test/fixtures/from-to-tests/babel.generated.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _obj; 4 | 5 | var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: key == null || typeof Symbol == "undefined" || key.constructor !== Symbol, configurable: true, writable: true }); }; 6 | 7 | var _taggedTemplateLiteral = function (strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }; 8 | 9 | var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; 10 | 11 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); 12 | 13 | var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; 14 | 15 | var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; 16 | 17 | // Expression bodies 18 | var odds = evens.map(function (v) { 19 | return v + 1; 20 | }); 21 | var nums = evens.map(function (v, i) { 22 | return v + i; 23 | }); 24 | 25 | // Statement bodies 26 | nums.forEach(function (v) { 27 | if (v % 5 === 0) fives.push(v); 28 | }); 29 | 30 | // Lexical this 31 | var bob = { 32 | _name: "Bob", 33 | _friends: [], 34 | printFriends: function printFriends() { 35 | var _this4 = this; 36 | 37 | this._friends.forEach(function (f) { 38 | return console.log(_this4._name + " knows " + f); 39 | }); 40 | } 41 | }; 42 | 43 | var SkinnedMesh = (function (_THREE$Mesh) { 44 | function SkinnedMesh(geometry, materials) { 45 | _classCallCheck(this, SkinnedMesh); 46 | 47 | _get(Object.getPrototypeOf(SkinnedMesh.prototype), "constructor", this).call(this, geometry, materials); 48 | 49 | this.idMatrix = SkinnedMesh.defaultMatrix(); 50 | this.bones = []; 51 | this.boneMatrices = []; 52 | //... 53 | } 54 | 55 | _inherits(SkinnedMesh, _THREE$Mesh); 56 | 57 | _createClass(SkinnedMesh, [{ 58 | key: "update", 59 | value: function update(camera) { 60 | //... 61 | _get(Object.getPrototypeOf(SkinnedMesh.prototype), "update", this).call(this); 62 | } 63 | }], [{ 64 | key: "defaultMatrix", 65 | value: function defaultMatrix() { 66 | return new THREE.Matrix4(); 67 | } 68 | }]); 69 | 70 | return SkinnedMesh; 71 | })(THREE.Mesh); 72 | 73 | var obj = _obj = _defineProperty({ 74 | // __proto__ 75 | __proto__: theProtoObj, 76 | // Shorthand for ‘handler: handler’ 77 | handler: handler, 78 | // Methods 79 | toString: function toString() { 80 | // Super calls 81 | return "d " + _get(Object.getPrototypeOf(_obj), "toString", this).call(this); 82 | } }, "prop_" + (function () { 83 | return 42; 84 | })(), 42); 85 | 86 | // Basic literal string creation 87 | "In JavaScript \"\n\" is a line-feed."(_taggedTemplateLiteral(["In JavaScript this is\n not legal."], ["In JavaScript this is\r\n not legal."])); 88 | 89 | // Interpolate variable bindings 90 | var name = "Bob", 91 | time = "today"; 92 | "Hello " + name + ", how are you " + time + "?"; 93 | 94 | // Construct an HTTP request prefix is used to interpret the replacements and construction 95 | GET(_taggedTemplateLiteral(["http://foo.org/bar?a=", "&b=", "\n Content-Type: application/json\n X-Credentials: ", "\n { \"foo\": ", ",\n \"bar\": ", "}"], ["http://foo.org/bar?a=", "&b=", "\r\n Content-Type: application/json\r\n X-Credentials: ", "\r\n { \"foo\": ", ",\r\n \"bar\": ", "}"]), a, b, credentials, foo, bar)(myOnReadyStateChangeHandler); 96 | 97 | // list matching 98 | var _ref = [1, 2, 3]; 99 | var a = _ref[0]; 100 | var b = _ref[2]; 101 | 102 | // object matching 103 | 104 | var _getASTNode = getASTNode(); 105 | 106 | var a = _getASTNode.op; 107 | var b = _getASTNode.lhs.op; 108 | var c = _getASTNode.rhs; 109 | 110 | // object matching shorthand 111 | // binds `op`, `lhs` and `rhs` in scope 112 | 113 | var _getASTNode2 = getASTNode(); 114 | 115 | var op = _getASTNode2.op; 116 | var lhs = _getASTNode2.lhs; 117 | var rhs = _getASTNode2.rhs; 118 | 119 | // Can be used in parameter position 120 | function g(_ref2) { 121 | var x = _ref2.name; 122 | 123 | console.log(x); 124 | } 125 | g({ name: 5 }); 126 | 127 | // Fail-soft destructuring 128 | var _ref3 = []; 129 | var a = _ref3[0]; 130 | 131 | a === undefined; 132 | 133 | // Fail-soft destructuring with defaults 134 | var _ref4 = []; 135 | var _ref4$0 = _ref4[0]; 136 | var a = _ref4$0 === undefined ? 1 : _ref4$0; 137 | 138 | a === 1; 139 | 140 | // Computed (dynamic) property names 141 | 142 | // Multiline strings 143 | 144 | //# sourceMappingURL=babel.generated.js.map -------------------------------------------------------------------------------- /lib/base64-vlq.js: -------------------------------------------------------------------------------- 1 | /* -*- Mode: js; js-indent-level: 2; -*- */ 2 | /* 3 | * Copyright 2011 Mozilla Foundation and contributors 4 | * Licensed under the New BSD license. See LICENSE or: 5 | * http://opensource.org/licenses/BSD-3-Clause 6 | * 7 | * Based on the Base 64 VLQ implementation in Closure Compiler: 8 | * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java 9 | * 10 | * Copyright 2011 The Closure Compiler Authors. All rights reserved. 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are 13 | * met: 14 | * 15 | * * Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * * Redistributions in binary form must reproduce the above 18 | * copyright notice, this list of conditions and the following 19 | * disclaimer in the documentation and/or other materials provided 20 | * with the distribution. 21 | * * Neither the name of Google Inc. nor the names of its 22 | * contributors may be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | /*eslint no-bitwise:0,quotes:0,global-strict:0*/ 39 | 40 | var charToIntMap = {}; 41 | var intToCharMap = {}; 42 | 43 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' 44 | .split('') 45 | .forEach(function (ch, index) { 46 | charToIntMap[ch] = index; 47 | intToCharMap[index] = ch; 48 | }); 49 | 50 | var base64 = {}; 51 | /** 52 | * Encode an integer in the range of 0 to 63 to a single base 64 digit. 53 | */ 54 | base64.encode = function base64_encode(aNumber) { 55 | if (aNumber in intToCharMap) { 56 | return intToCharMap[aNumber]; 57 | } 58 | throw new TypeError("Must be between 0 and 63: " + aNumber); 59 | }; 60 | 61 | /** 62 | * Decode a single base 64 digit to an integer. 63 | */ 64 | base64.decode = function base64_decode(aChar) { 65 | if (aChar in charToIntMap) { 66 | return charToIntMap[aChar]; 67 | } 68 | throw new TypeError("Not a valid base 64 digit: " + aChar); 69 | }; 70 | 71 | 72 | 73 | // A single base 64 digit can contain 6 bits of data. For the base 64 variable 74 | // length quantities we use in the source map spec, the first bit is the sign, 75 | // the next four bits are the actual value, and the 6th bit is the 76 | // continuation bit. The continuation bit tells us whether there are more 77 | // digits in this value following this digit. 78 | // 79 | // Continuation 80 | // | Sign 81 | // | | 82 | // V V 83 | // 101011 84 | 85 | var VLQ_BASE_SHIFT = 5; 86 | 87 | // binary: 100000 88 | var VLQ_BASE = 1 << VLQ_BASE_SHIFT; 89 | 90 | // binary: 011111 91 | var VLQ_BASE_MASK = VLQ_BASE - 1; 92 | 93 | // binary: 100000 94 | var VLQ_CONTINUATION_BIT = VLQ_BASE; 95 | 96 | /** 97 | * Converts from a two-complement value to a value where the sign bit is 98 | * placed in the least significant bit. For example, as decimals: 99 | * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) 100 | * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) 101 | */ 102 | function toVLQSigned(aValue) { 103 | return aValue < 0 104 | ? ((-aValue) << 1) + 1 105 | : (aValue << 1) + 0; 106 | } 107 | 108 | /** 109 | * Converts to a two-complement value from a value where the sign bit is 110 | * placed in the least significant bit. For example, as decimals: 111 | * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 112 | * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 113 | */ 114 | function fromVLQSigned(aValue) { 115 | var isNegative = (aValue & 1) === 1; 116 | var shifted = aValue >> 1; 117 | return isNegative 118 | ? -shifted 119 | : shifted; 120 | } 121 | 122 | /** 123 | * Returns the base 64 VLQ encoded value. 124 | */ 125 | exports.encode = function base64VLQ_encode(aValue) { 126 | var encoded = ""; 127 | var digit; 128 | 129 | var vlq = toVLQSigned(aValue); 130 | 131 | do { 132 | digit = vlq & VLQ_BASE_MASK; 133 | vlq >>>= VLQ_BASE_SHIFT; 134 | if (vlq > 0) { 135 | // There are still more digits in this value, so we must make sure the 136 | // continuation bit is marked. 137 | digit |= VLQ_CONTINUATION_BIT; 138 | } 139 | encoded += base64.encode(digit); 140 | } while (vlq > 0); 141 | 142 | return encoded; 143 | }; 144 | 145 | /** 146 | * Decodes the next base 64 VLQ value from the given string and returns the 147 | * value and the rest of the string via the out parameter. 148 | */ 149 | exports.decode = function base64VLQ_decode(aStr, aOutParam) { 150 | var i = 0; 151 | var strLen = aStr.length; 152 | var result = 0; 153 | var shift = 0; 154 | var continuation, digit; 155 | 156 | do { 157 | if (i >= strLen) { 158 | throw new Error("Expected more digits in base 64 VLQ value."); 159 | } 160 | digit = base64.decode(aStr.charAt(i++)); 161 | continuation = !!(digit & VLQ_CONTINUATION_BIT); 162 | digit &= VLQ_BASE_MASK; 163 | result = result + (digit << shift); 164 | shift += VLQ_BASE_SHIFT; 165 | } while (continuation); 166 | 167 | aOutParam.value = fromVLQSigned(result); 168 | aOutParam.rest = aStr.slice(i); 169 | }; 170 | --------------------------------------------------------------------------------