1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Fix source maps for errors thrown from .coffee.md files

Before:

```
$ cat tmp.coffee.md
test

    a
$ ./bin/coffee tmp.coffee.md
ReferenceError: a is not defined
  at Object.<anonymous> (/src/coffee-script/tmp.coffee.md:2:3)
  ...
```

Note how the line and column numbers (2 and 3, respectively) are not
correct.

After:

```
$ ./bin/coffee tmp.coffee.md
ReferenceError: a is not defined
  at Object.<anonymous> (/home/lydell/forks/coffee-script/tmp.coffee.md:3:5)
  ...
```

Line 3, column 5 is the actual position of the `a` in tmp.coffee.md.

Supersedes and fixes #4204.
This commit is contained in:
Simon Lydell 2016-09-14 21:45:06 +02:00
parent 0e0e8f87e1
commit 9ae377b481
2 changed files with 15 additions and 10 deletions

View file

@ -1,8 +1,7 @@
// Generated by CoffeeScript 1.10.0
(function() {
var Lexer, SourceMap, base64encode, compile, ext, fn1, formatSourcePosition, fs, getSourceMap, helpers, i, len, lexer, parser, path, ref, sourceMaps, vm, withPrettyErrors,
hasProp = {}.hasOwnProperty,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
hasProp = {}.hasOwnProperty;
fs = require('fs');
@ -369,15 +368,19 @@
sourceMaps = {};
getSourceMap = function(filename) {
var answer, ref1;
var answer, j, len1, ref1;
if (sourceMaps[filename]) {
return sourceMaps[filename];
}
if (ref1 = path != null ? path.extname(filename) : void 0, indexOf.call(exports.FILE_EXTENSIONS, ref1) < 0) {
return;
ref1 = exports.FILE_EXTENSIONS;
for (j = 0, len1 = ref1.length; j < len1; j++) {
ext = ref1[j];
if (helpers.ends(filename, ext)) {
answer = exports._compileFile(filename, true);
return sourceMaps[filename] = answer.sourceMap;
}
}
answer = exports._compileFile(filename, true);
return sourceMaps[filename] = answer.sourceMap;
return null;
};
Error.prepareStackTrace = function(err, stack) {

View file

@ -334,9 +334,11 @@ sourceMaps = {}
# Generates the source map for a coffee file and stores it in the local cache variable.
getSourceMap = (filename) ->
return sourceMaps[filename] if sourceMaps[filename]
return unless path?.extname(filename) in exports.FILE_EXTENSIONS
answer = exports._compileFile filename, true
sourceMaps[filename] = answer.sourceMap
for ext in exports.FILE_EXTENSIONS
if helpers.ends filename, ext
answer = exports._compileFile filename, true
return sourceMaps[filename] = answer.sourceMap
return null
# Based on [michaelficarra/CoffeeScriptRedux](http://goo.gl/ZTx1p)
# NodeJS / V8 have no support for transforming positions in stack traces using