diff --git a/Cakefile b/Cakefile
index c6382a33..5e9c6adf 100644
--- a/Cakefile
+++ b/Cakefile
@@ -486,6 +486,9 @@ task 'test:integrations', 'test the module integrated with other libraries and e
webpack = require 'webpack'
webpack {
entry: './'
+ optimization:
+ # Webpack’s minification causes the CoffeeScript module to fail some tests.
+ minimize: off
output:
path: tmpdir
filename: 'coffeescript.js'
diff --git a/docs/v2/annotated-source/repl.html b/docs/v2/annotated-source/repl.html
index cebc74ea..a5af45b6 100644
--- a/docs/v2/annotated-source/repl.html
+++ b/docs/v2/annotated-source/repl.html
@@ -376,7 +376,7 @@ undeclared variable __
.
vm.runInContext js, context, filename
nodeLineListener = rli.listeners('line')[0]
- rli.removeListener 'line', nodeLineListener
- rli.on 'line', (cmd) ->
+ nodeLineListener = repl.listeners('line')[0]
+ repl.removeListener 'line', nodeLineListener
+ repl.on 'line', (cmd) ->
if multiline.enabled
multiline.buffer += "#{cmd}\n"
- rli.setPrompt multiline.prompt
- rli.prompt true
+ repl.setPrompt multiline.prompt
+ repl.prompt true
else
- rli.setPrompt origPrompt
+ repl.setPrompt origPrompt
nodeLineListener cmd
return
@@ -456,8 +456,8 @@ undeclared variable __
.
unless multiline.buffer.match /\n/
multiline.enabled = not multiline.enabled
- rli.setPrompt origPrompt
- rli.prompt true
+ repl.setPrompt origPrompt
+ repl.prompt true
return
@@ -473,7 +473,7 @@ undeclared variable __
.
-
return if rli.line? and not rli.line.match /^\s*$/
+
return if repl.line? and not repl.line.match /^\s*$/
@@ -489,10 +489,10 @@ undeclared variable
__
.
multiline.enabled = not multiline.enabled
- rli.line = ''
- rli.cursor = 0
- rli.output.cursorTo 0
- rli.output.clearLine 1
+ repl.line = multiline.buffer = multiline.buffer.replace /\n/g, '\uFF00'
- rli.emit 'line', multiline.buffer
+ repl.emit 'line', multiline.buffer
multiline.buffer = ''
else
multiline.enabled = not multiline.enabled
- rli.setPrompt multiline.initialPrompt
- rli.prompt true
+ repl.setPrompt multiline.initialPrompt
+ repl.prompt true
return
@@ -580,7 +580,7 @@ undeclared variable repl.rli.history = buffer.toString().split('\n').reverse()
+ repl.history = buffer.toString().split('\n').reverse()
@@ -595,7 +595,7 @@ undeclared variable repl.rli.history.pop() if stat.size > maxSize
+ repl.history.pop() if stat.size > maxSize
@@ -610,13 +610,13 @@ undeclared variable repl.rli.history.shift() if repl.rli.history[0] is ''
- repl.rli.historyIndex = -1
- lastLine = repl.rli.history[0]
+ repl.history.shift() if repl.history[0] is ''
+ repl.historyIndex = -1
+ lastLine = repl.history[0]
fd = fs.openSync filename, 'a'
- repl.rli.addListener 'line', (code) ->
+ repl.addListener 'line', (code) ->
if code and code.length and code isnt '.history' and code isnt '.exit' and lastLine isnt code
@@ -667,7 +667,7 @@ undeclared variable __
.
repl.commands[getCommandId(repl, 'history')] =
help: 'Show command history'
action: ->
- repl.outputStream.write "#{repl.rli.history[..].reverse().join '\n'}\n"
+ repl.outputStream.write "#{repl.history[..].reverse().join '\n'}\n"
repl.displayPrompt()
getCommandId = (repl, commandName) ->
@@ -742,7 +742,7 @@ the REPL, the only applicable option is transpile
.
opts = merge replDefaults, opts
repl = nodeREPL.start opts
runInContext opts.prelude, repl.context, 'prelude' if opts.prelude
- repl.on 'exit', -> repl.outputStream.write '\n' if not repl.rli.closed
+ repl.on 'exit', -> repl.outputStream.write '\n' if not repl.closed
addMultilineHandler repl
addHistory repl, opts.historyFile, opts.historyMaxInputSize if opts.historyFile
diff --git a/lib/coffeescript/coffeescript.js b/lib/coffeescript/coffeescript.js
index 34dec1b1..2df4762b 100644
--- a/lib/coffeescript/coffeescript.js
+++ b/lib/coffeescript/coffeescript.js
@@ -4,7 +4,7 @@
// on Node.js/V8, or to run CoffeeScript directly in the browser. This module
// contains the main entry functions for tokenizing, parsing, and compiling
// source CoffeeScript into JavaScript.
- var FILE_EXTENSIONS, Lexer, SourceMap, base64encode, checkShebangLine, compile, formatSourcePosition, getSourceMap, helpers, lexer, packageJson, parser, sourceMaps, sources, withPrettyErrors,
+ var FILE_EXTENSIONS, Lexer, SourceMap, base64encode, checkShebangLine, compile, formatSourcePosition, getSourceMap, helpers, lexer, packageJson, parser, registerCompiled, sourceMaps, sources, withPrettyErrors,
indexOf = [].indexOf;
({Lexer} = require('./lexer'));
@@ -74,6 +74,24 @@
// Also save source maps if generated, in form of `(source)`: [`(source map)`].
sourceMaps = {};
+ // This is exported to enable an external module to implement caching of
+ // compilation results. When the compiled js source is loaded from cache, the
+ // original coffee code should be added with this method in order to enable the
+ // Error.prepareStackTrace below to correctly adjust the stack trace for the
+ // corresponding file (the source map will be generated on demand).
+ exports.registerCompiled = registerCompiled = function(filename, source, sourcemap) {
+ if (sources[filename] == null) {
+ sources[filename] = [];
+ }
+ sources[filename].push(source);
+ if (sourcemap != null) {
+ if (sourceMaps[filename] == null) {
+ sourceMaps[filename] = [];
+ }
+ return sourceMaps[filename].push(sourcemap);
+ }
+ };
+
// Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.
// If `options.sourceMap` is specified, then `options.filename` must also be
@@ -94,10 +112,6 @@
generateSourceMap = options.sourceMap || options.inlineMap || (options.filename == null);
filename = options.filename || '