jashkenas/coffee-script — pull request #2856 by epidemian (2013-03-19 07:45:25+00:00)
Title: Fixes #2849: use correct filename and code in require()d sources

This PR should fix #2849.

As CS source files can be `require()`d on the fly when using the `coffee` command, the `file` and `input` arguments that are [passed to `compileScript`](https://github.com/jashkenas/coffee-script/blob/f217a10721ca4461f68fcce5990ff0bb92395ac4/src/command.coffee#L115) may not match with the actual file being compiled and run (which could potentially throw compilation errors).

This patch modifies the `CoffeeScript.compile` function (which is in turn used by `compileScript` and the Node.js `require.extensions` mechanism used to `require()` CS files) so in case a compiler error is raised there, the filename and source information will be attached to it and then used to correctly report errors.

This means that if one runs `coffee a.coffee` and that file, in turn, does `require './b'` and the `b.coffee` file has syntax errors, the error messages will now correctly point to `b.coffee`.