Skip to content

Commit

Permalink
Move a try/catch from compile to loadFile
Browse files Browse the repository at this point in the history
This try/catch should only be necessary for dynamically loaded files. Also added a lengthier explanation of why this try/catch is needed.
  • Loading branch information
epidemian committed Jun 9, 2013
1 parent 8e90aae commit 3c880bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
30 changes: 15 additions & 15 deletions lib/coffee-script/coffee-script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions src/coffee-script.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ exports.compile = compile = (code, options = {}) ->
if options.sourceMap
map = new SourceMap

try
fragments = parser.parse(lexer.tokenize code, options).compileToFragments options
catch err
# Add source file information to error so it can be pretty-printed later.
err.filename = options.filename
err.code = code
throw err
fragments = parser.parse(lexer.tokenize code, options).compileToFragments options

currentLine = 0
currentLine += 1 if options.header
Expand Down Expand Up @@ -152,7 +146,15 @@ exports.eval = (code, options = {}) ->
loadFile = (module, filename) ->
raw = fs.readFileSync filename, 'utf8'
stripped = if raw.charCodeAt(0) is 0xFEFF then raw.substring 1 else raw
answer = compile(stripped, {filename, sourceMap: true, literate: helpers.isLiterate filename})
try
answer = compile(stripped, {filename, sourceMap: true, literate: helpers.isLiterate filename})
catch err
# As the filename and code of a dynamically loaded file will be different
# from the original file compiled with CoffeeScript.run, add that
# information to error so it can be pretty-printed later.
err.filename = filename
err.code = stripped
throw err
sourceMaps[filename] = answer.sourceMap
module._compile answer.js, filename

Expand Down

0 comments on commit 3c880bf

Please sign in to comment.