Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stack trace #4428

Merged
merged 14 commits into from
Jan 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
raw
presentation
test.coffee
test*.coffee
test.litcoffee
parser.output
test*.litcoffee
test/*.js
parser.output
/node_modules
npm-debug.log
npm-debug.log*
11 changes: 9 additions & 2 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,15 @@ task 'build:full', 'rebuild the source twice, and run the tests', ->
task 'build:parser', 'rebuild the Jison parser (run build first)', ->
helpers.extend global, require 'util'
require 'jison'
parser = require('./lib/coffee-script/grammar').parser
fs.writeFileSync 'lib/coffee-script/parser.js', parser.generate()
parser = require('./lib/coffee-script/grammar').parser.generate()
# Patch Jison’s output, until https://github.com/zaach/jison/pull/339 is accepted,
# to ensure that require('fs') is only called where it exists.
parser = parser.replace "var source = require('fs')", """
var source = '';
var fs = require('fs');
if (typeof fs !== 'undefined' && fs !== null)
source = fs"""
fs.writeFileSync 'lib/coffee-script/parser.js', parser


task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
Expand Down
690 changes: 346 additions & 344 deletions docs/v1/browser-compiler/coffee-script.js

Large diffs are not rendered by default.

88 changes: 85 additions & 3 deletions docs/v1/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2882,6 +2882,16 @@ <h1>CoffeeScript Test Suite</h1>
obj.method()
eq obj.item, 3

test "#4411: Allow @values as loop indices", ->
obj =
index: null
get: -> @index
method: ->
@get() for _, @index in [1, 2, 3]
eq obj.index, null
arrayEq obj.method(), [0, 1, 2]
eq obj.index, 3

test "#2525, #1187, #1208, #1758, looping over an array forwards", ->
list = [0, 1, 2, 3, 4]

Expand Down Expand Up @@ -3470,9 +3480,21 @@ <h1>CoffeeScript Test Suite</h1>


if require?
os = require 'os'
fs = require 'fs'
path = require 'path'

test "patchStackTrace line patching", ->
err = new Error 'error'
ok err.stack.match /test[\/\\]error_messages\.coffee:\d+:\d+\b/

test "patchStackTrace stack prelude consistent with V8", ->
err = new Error
ok err.stack.match /^Error\n/ # Notice no colon when no message.

err = new Error 'error'
ok err.stack.match /^Error: error\n/

test "#2849: compilation error in a require()d file", ->
# Create a temporary file to require().
ok not fs.existsSync 'test/syntax-error.coffee'
Expand All @@ -3490,6 +3512,57 @@ <h1>CoffeeScript Test Suite</h1>
finally
fs.unlinkSync 'test/syntax-error.coffee'

test "#3890 Error.prepareStackTrace doesn't throw an error if a compiled file is deleted", ->
# Adapted from https://github.com/atom/coffee-cash/blob/master/spec/coffee-cash-spec.coffee
filePath = path.join os.tmpdir(), 'PrepareStackTraceTestFile.coffee'
fs.writeFileSync filePath, "module.exports = -> throw new Error('hello world')"
throwsAnError = require filePath
fs.unlinkSync filePath

try
throwsAnError()
catch error

eq error.message, 'hello world'
doesNotThrow(-> error.stack)
notEqual error.stack.toString().indexOf(filePath), -1

test "#4418 stack traces for compiled files reference the correct line number", ->
filePath = path.join os.tmpdir(), 'StackTraceLineNumberTestFile.coffee'
fileContents = """
testCompiledFileStackTraceLineNumber = ->
# `a` on the next line is undefined and should throw a ReferenceError
console.log a if true

do testCompiledFileStackTraceLineNumber
"""
fs.writeFileSync filePath, fileContents

try
require filePath
catch error
fs.unlinkSync filePath

# Make sure the line number reported is line 3 (the original Coffee source)
# and not line 6 (the generated JavaScript).
eq /StackTraceLineNumberTestFile.coffee:(\d)/.exec(error.stack.toString())[1], '3'


test "#4418 stack traces for compiled strings reference the correct line number", ->
try
CoffeeScript.run """
testCompiledStringStackTraceLineNumber = ->
# `a` on the next line is undefined and should throw a ReferenceError
console.log a if true

do testCompiledStringStackTraceLineNumber
"""
catch error

# Make sure the line number reported is line 3 (the original Coffee source)
# and not line 6 (the generated JavaScript).
eq /at testCompiledStringStackTraceLineNumber.*:(\d):/.exec(error.stack.toString())[1], '3'


test "#1096: unexpected generated tokens", ->
# Implicit ends
Expand Down Expand Up @@ -3844,7 +3917,7 @@ <h1>CoffeeScript Test Suite</h1>
assertErrorFormat '''
///a \\u002 0 space///
''', '''
[stdin]:1:6: error: invalid escape sequence \\u002
[stdin]:1:6: error: invalid escape sequence \\u002 \n\
///a \\u002 0 space///
^\^^^^^
'''
Expand Down Expand Up @@ -4596,6 +4669,13 @@ <h1>CoffeeScript Test Suite</h1>
^
'''

test "can't use pattern matches for loop indices", ->
assertErrorFormat 'a for b, {c} in d', '''
[stdin]:1:10: error: index cannot be a pattern matching expression
a for b, {c} in d
^^^
'''

</script>
<script type="text/x-coffeescript" class="test" id="eval">
if vm = require? 'vm'
Expand Down Expand Up @@ -9227,7 +9307,7 @@ <h1>CoffeeScript Test Suite</h1>

test "floor division operator compound assignment", ->
a = 7
a //= 2
a //= 1 + 1
eq 3, a

test "modulo operator", ->
Expand Down Expand Up @@ -9823,7 +9903,9 @@ <h1>CoffeeScript Test Suite</h1>
<script type="text/x-coffeescript" class="test" id="repl">
return if global.testingBrowser

os = require 'os'
fs = require 'fs'
path = require 'path'

# REPL
# ----
Expand Down Expand Up @@ -9851,7 +9933,7 @@ <h1>CoffeeScript Test Suite</h1>
@written[@written.length - 1 + fromEnd].replace /\r?\n$/, ''

# Create a dummy history file
historyFile = '.coffee_history_test'
historyFile = path.join os.tmpdir(), '.coffee_history_test'
fs.writeFileSync historyFile, '1 + 2\n'

testRepl = (desc, fn) ->
Expand Down
111 changes: 106 additions & 5 deletions lib/coffee-script/coffee-script.js

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

5 changes: 4 additions & 1 deletion lib/coffee-script/parser.js

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

Loading