Last active
June 24, 2016 05:09
-
-
Save gotwarlost/d56d60f2847edc17d5e5dfe22ee04779 to your computer and use it in GitHub Desktop.
Issues with babel source map generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -33,6 +33,7 @@ var SourceMap = function () { | |
this.position = position; | |
this.opts = opts; | |
this.last = { generated: {}, original: {} }; | |
+ this.seen = {}; | |
if (opts.sourceMaps) { | |
this.map = new _sourceMap2.default.SourceMapGenerator({ | |
@@ -89,6 +90,12 @@ var SourceMap = function () { | |
this._lastSourceLine = sourcePos.line; | |
this._lastSourceColumn = sourcePos.column; | |
+ var key = sourcePos.line + ':' + sourcePos.column; | |
+ if (this.seen[key]) { | |
+ return; | |
+ } | |
+ this.seen[key] = true; | |
+ console.error('[', sourcePos.line, ',', sourcePos.column, '] => [', this.position.line, ',', this.position.column, ']'); | |
map.addMapping({ | |
generated: { | |
line: position.line, | |
@@ -106,4 +113,4 @@ var SourceMap = function () { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = false || true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = (false, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var i = 0; | |
var a = (++i, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var i = 0, j = 0; | |
var a = (++i, true) || (++j, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm install babel-cli | |
babel-cli@6.10.1 node_modules/babel-cli | |
├── slash@1.0.0 | |
├── log-symbols@1.0.2 | |
├── path-exists@1.0.0 | |
├── path-is-absolute@1.0.0 | |
├── fs-readdir-recursive@0.1.2 | |
├── convert-source-map@1.2.0 | |
├── source-map@0.5.6 | |
├── v8flags@2.0.11 (user-home@1.1.1) | |
├── commander@2.9.0 (graceful-readlink@1.0.1) | |
├── glob@5.0.15 (inherits@2.0.1, once@1.3.3, inflight@1.0.5, minimatch@3.0.2) | |
├── lodash@4.13.1 | |
├── babel-register@6.9.0 (mkdirp@0.5.1, home-or-tmp@1.0.0, source-map-support@0.2.10, core-js@2.4.0) | |
├── babel-runtime@6.9.2 (regenerator-runtime@0.9.5, core-js@2.4.0) | |
├── babel-polyfill@6.9.1 (regenerator-runtime@0.9.5, core-js@2.4.0) | |
├── chalk@1.1.1 (escape-string-regexp@1.0.5, supports-color@2.0.0, ansi-styles@2.2.1, has-ansi@2.0.0, strip-ansi@3.0.1) | |
├── request@2.72.0 (is-typedarray@1.0.0, oauth-sign@0.8.2, aws-sign2@0.6.0, forever-agent@0.6.1, caseless@0.11.0, tunnel-agent@0.4.3, stringstream@0.0.5, isstream@0.1.2, json-stringify-safe@5.0.1, extend@3.0.0, aws4@1.4.1, node-uuid@1.4.7, qs@6.1.0, tough-cookie@2.2.2, mime-types@2.1.11, form-data@1.0.0-rc4, hawk@3.1.3, combined-stream@1.0.5, bl@1.1.2, http-signature@1.1.1, har-validator@2.0.6) | |
├── output-file-sync@1.1.2 (object-assign@4.1.0, graceful-fs@4.1.4, mkdirp@0.5.1) | |
├── chokidar@1.6.0 (inherits@2.0.1, glob-parent@2.0.0, async-each@1.0.0, is-binary-path@1.0.1, is-glob@2.0.1, fsevents@1.0.12, anymatch@1.3.0, readdirp@2.0.1) | |
├── babel-core@6.10.4 (shebang-regex@1.0.0, babel-messages@6.8.0, babel-template@6.9.0, babel-helpers@6.8.0, private@0.1.6, babylon@6.8.1, json5@0.4.0, babel-code-frame@6.8.0, debug@2.2.0, babel-types@6.10.2, minimatch@3.0.2, babel-traverse@6.10.4, babel-generator@6.10.2) | |
└── bin-version-check@2.1.0 (minimist@1.2.0, semver-truncate@1.1.0, semver@4.3.6, bin-version@1.0.4) | |
$ vi node_modules/babel-cli/node_modules/babel-core/node_modules/babel-generator/lib/source-map.js | |
#### ADDED THE FOLLOWING LINE BEFORE the map.addMapping line | |
console.error('[', sourcePos.line, ',', sourcePos.column, '] => [', this.position.line, ',', this.position.column, ']'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### I have manually marked the bad lines as #BAD #### | |
f1.js | |
--- | |
#12345678901234567890123456789012345678901234567890123456789 | |
var a = true; | |
--- | |
var a = true; | |
--- | |
[ 1 , 0 ] => [ 1 , 0 ] | |
[ 1 , 4 ] => [ 1 , 4 ] | |
[ 1 , 8 ] => [ 1 , 8 ] | |
[ 1 , 0 ] => [ 1 , 12 ] #BAD | |
--- | |
f2.js | |
--- | |
#12345678901234567890123456789012345678901234567890123456789 | |
var a = false || true; | |
--- | |
var a = false || true; | |
--- | |
[ 1 , 0 ] => [ 1 , 0 ] | |
[ 1 , 4 ] => [ 1 , 4 ] | |
[ 1 , 8 ] => [ 1 , 8 ] | |
[ 1 , 17 ] => [ 1 , 17 ] | |
[ 1 , 0 ] => [ 1 , 21 ] #BAD | |
--- | |
f3.js | |
--- | |
#12345678901234567890123456789012345678901234567890123456789 | |
var a = (false, true); | |
--- | |
var a = (false, true); | |
--- | |
[ 1 , 0 ] => [ 1 , 0 ] | |
[ 1 , 4 ] => [ 1 , 4 ] | |
[ 1 , 9 ] => [ 1 , 9 ] | |
[ 1 , 16 ] => [ 1 , 16 ] | |
[ 1 , 4 ] => [ 1 , 20 ] #BAD | |
[ 1 , 0 ] => [ 1 , 21 ] #BAD | |
--- | |
f4.js | |
--- | |
#12345678901234567890123456789012345678901234567890123456789 | |
var i = 0; | |
var a = (++i, true); | |
--- | |
var i = 0; | |
var a = (++i, true); | |
--- | |
[ 1 , 0 ] => [ 1 , 0 ] | |
[ 1 , 4 ] => [ 1 , 4 ] | |
[ 1 , 8 ] => [ 1 , 8 ] | |
[ 1 , 0 ] => [ 1 , 9 ] #BAD | |
[ 2 , 0 ] => [ 2 , 0 ] | |
[ 2 , 4 ] => [ 2 , 4 ] | |
[ 2 , 9 ] => [ 2 , 9 ] | |
[ 2 , 11 ] => [ 2 , 11 ] | |
[ 2 , 9 ] => [ 2 , 12 ] #BAD | |
[ 2 , 14 ] => [ 2 , 14 ] | |
[ 2 , 4 ] => [ 2 , 18 ] #BAD | |
[ 2 , 0 ] => [ 2 , 19 ] #BAD | |
--- | |
f5.js | |
--- | |
#12345678901234567890123456789012345678901234567890123456789 | |
var i = 0, j = 0; | |
var a = (++i, true) || (++j, false); | |
--- | |
var i = 0, | |
j = 0; | |
var a = (++i, true) || (++j, false); | |
--- | |
[ 1 , 0 ] => [ 1 , 0 ] | |
[ 1 , 4 ] => [ 1 , 4 ] | |
[ 1 , 8 ] => [ 1 , 8 ] | |
[ 1 , 0 ] => [ 1 , 9 ] #BAD | |
[ 1 , 0 ] => [ 2 , 0 ] #BAD | |
[ 1 , 11 ] => [ 2 , 4 ] | |
[ 1 , 15 ] => [ 2 , 8 ] | |
[ 1 , 0 ] => [ 2 , 9 ] #BAD | |
[ 2 , 0 ] => [ 3 , 0 ] | |
[ 2 , 4 ] => [ 3 , 4 ] | |
[ 2 , 8 ] => [ 3 , 8 ] | |
[ 2 , 9 ] => [ 3 , 9 ] | |
[ 2 , 11 ] => [ 3 , 11 ] | |
[ 2 , 9 ] => [ 3 , 12 ] #BAD | |
[ 2 , 14 ] => [ 3 , 14 ] | |
[ 2 , 8 ] => [ 3 , 18 ] #BAD | |
[ 2 , 24 ] => [ 3 , 24 ] | |
[ 2 , 26 ] => [ 3 , 26 ] | |
[ 2 , 24 ] => [ 3 , 27 ] #BAD | |
[ 2 , 29 ] => [ 3 , 29 ] | |
[ 2 , 8 ] => [ 3 , 34 ] #BAD | |
[ 2 , 0 ] => [ 3 , 35 ] #BAD | |
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
$ for i in *js; do ./test.sh $i; done>run.log | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo $1 | |
echo --- | |
echo '#12345678901234567890123456789012345678901234567890123456789' | |
cat $1 | |
echo --- | |
./node_modules/.bin/babel -s inline $1 2>map.txt | grep -v '^//' | |
echo --- | |
cat map.txt && rm map.txt | |
echo --- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment