Skip to content

Commit 72f55bd

Browse files
authored
Merge pull request #3 from Timer/master
Fix babel source map parsing
2 parents c8824e4 + 855b4f6 commit 72f55bd

File tree

5 files changed

+107
-2
lines changed

5 files changed

+107
-2
lines changed

lib/fromStringWithSourceMap.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ module.exports = function fromStringWithSourceMap(code, map) {
6262
var linePosition = currentLine;
6363
}
6464

65-
if(mapping.rest && mapping.rest[0] === ",") {
66-
mapping.rest = mapping.rest.substr(1);
65+
if(mapping.rest) {
66+
var next = mapping.rest.indexOf(",");
67+
mapping.rest = next === -1 ? "" : mapping.rest.substr(next);
6768
}
6869

6970
if(!ignore) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Test {
2+
foo() {
3+
console.log('bar')
4+
throw new Error('bar')
5+
}
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

test/fixtures/from-to-tests/babel2.generated.js

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/from-to-tests/babel2.input.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)