mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
Move a try/catch from compile to loadFile
This try/catch should only be necessary for dynamically loaded files. Also added a lengthier explanation of why this try/catch is needed.
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
exports.helpers = helpers;
|
||||
|
||||
exports.compile = compile = function(code, options) {
|
||||
var answer, currentColumn, currentLine, err, fragment, fragments, header, js, map, merge, newLines, _i, _len;
|
||||
var answer, currentColumn, currentLine, fragment, fragments, header, js, map, merge, newLines, _i, _len;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
@@ -32,14 +32,7 @@
|
||||
if (options.sourceMap) {
|
||||
map = new SourceMap;
|
||||
}
|
||||
try {
|
||||
fragments = parser.parse(lexer.tokenize(code, options)).compileToFragments(options);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
err.filename = options.filename;
|
||||
err.code = code;
|
||||
throw err;
|
||||
}
|
||||
fragments = parser.parse(lexer.tokenize(code, options)).compileToFragments(options);
|
||||
currentLine = 0;
|
||||
if (options.header) {
|
||||
currentLine += 1;
|
||||
@@ -177,14 +170,21 @@
|
||||
};
|
||||
|
||||
loadFile = function(module, filename) {
|
||||
var answer, raw, stripped;
|
||||
var answer, err, raw, stripped;
|
||||
raw = fs.readFileSync(filename, 'utf8');
|
||||
stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw;
|
||||
answer = compile(stripped, {
|
||||
filename: filename,
|
||||
sourceMap: true,
|
||||
literate: helpers.isLiterate(filename)
|
||||
});
|
||||
try {
|
||||
answer = compile(stripped, {
|
||||
filename: filename,
|
||||
sourceMap: true,
|
||||
literate: helpers.isLiterate(filename)
|
||||
});
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
err.filename = filename;
|
||||
err.code = stripped;
|
||||
throw err;
|
||||
}
|
||||
sourceMaps[filename] = answer.sourceMap;
|
||||
return module._compile(answer.js, filename);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user