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

Don’t patch Error.prepareStackTrace if --enable-source-maps is used. #5403

Merged
merged 38 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4d9b901
Fixes #5382
STRd6 Apr 1, 2022
0fb2951
build:browser
STRd6 Apr 1, 2022
bebcec0
Merge remote-tracking branch 'origin/main' into 5382
STRd6 Apr 3, 2022
9354f97
Basic tests and inline source maps when native source maps are enabled
STRd6 Apr 3, 2022
c942bd0
Added exemption for node v12, native source maps don't seem to be acc…
STRd6 Apr 3, 2022
264b009
Added guard for in browser
STRd6 Apr 3, 2022
9f65df3
Use --require rather than -r
STRd6 Apr 4, 2022
05a9502
PR Feedback
STRd6 Apr 4, 2022
6c1312b
Experimental big refactoring of source mappings
STRd6 Apr 4, 2022
3cbbf48
Better tracking anonymous files
STRd6 Apr 4, 2022
b71bad6
Comment cleanup
STRd6 Apr 4, 2022
dad126e
Restored NODE_OPTIONS environment variable check
STRd6 Apr 4, 2022
44234dd
Added test for NODE_OPTIONS
STRd6 Apr 4, 2022
946a82f
Node v12 ... my old nemesis
STRd6 Apr 4, 2022
fae524b
Simplified
STRd6 Apr 5, 2022
f971278
Added default options object
STRd6 Apr 5, 2022
46a3962
Ensuring relative path for `sourceRoot` ends with separator
STRd6 Apr 5, 2022
30489cf
Added test for source mapped stack traces when executing bin/coffee
STRd6 Apr 5, 2022
0410b11
Using static class methods for SourceMap cache
STRd6 Apr 5, 2022
af44a0b
Extend browser test timeout from 30 => 60 seconds
STRd6 Apr 5, 2022
f341739
More reliable stream capturing in tests
STRd6 Apr 5, 2022
b46da93
Report errors when running browser tests
STRd6 Apr 5, 2022
608f0d6
Merge branch 'main' into 5382
STRd6 Apr 5, 2022
40529cd
Removed test pattern grepping
STRd6 Apr 5, 2022
a29f6bf
Merge branch 'main' into 5382
STRd6 Apr 5, 2022
942ce2c
Object.create null instead of empty object for the map cache
STRd6 Apr 6, 2022
1049cc6
Single quote string style
STRd6 Apr 10, 2022
4015fc5
Fixed stack trace in browser docs
STRd6 Apr 11, 2022
8590d28
Removed new stacktrace.coffee file
STRd6 Apr 11, 2022
e6ab9f6
Don't display inline maps on doc examples
STRd6 Apr 11, 2022
58afee8
attachStackTrace -> patchStackTrace
STRd6 Apr 17, 2022
8e2f090
Apply suggestions from code review
STRd6 Apr 17, 2022
2467d7d
Coding style cleanup
STRd6 Apr 17, 2022
219f76a
Updated comment on registerCompiled export
STRd6 Apr 17, 2022
267d91c
doc:test
STRd6 Apr 17, 2022
d24c75b
Fixed test guard conditional
STRd6 Apr 17, 2022
0d64fcc
Slightly more robust version checking
STRd6 Apr 17, 2022
c56d9a2
Comment about spawn vs fork
STRd6 Apr 18, 2022
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
2 changes: 1 addition & 1 deletion docs/v2/browser-compiler-legacy/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/v2/browser-compiler-modern/coffeescript.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/v2/index.html

Large diffs are not rendered by default.

117 changes: 117 additions & 0 deletions docs/v2/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -32712,6 +32712,7 @@ <h2>Another heading</h2>
<script type="text/x-coffeescript" class="test" id="sourcemap">
return if global.testingBrowser

{spawn, fork} = require('child_process')
SourceMap = require '../src/sourcemap'

vlqEncodedValues = [
Expand Down Expand Up @@ -32776,6 +32777,122 @@ <h2>Another heading</h2>
arrayEq v3SourceMap.sources, ['tempus_fugit.coffee']
eq v3SourceMap.sourceRoot, './www_root/coffee/'

test "node --enable-source-map built in stack trace mapping", ->
new Promise (resolve, reject) ->
proc = fork "./test/importing/error.coffee", [
"--enable-source-maps"
], stdio: "pipe"

err = ""
proc.stderr.setEncoding('utf8')
proc.stderr.on 'data', (s) -> err += s
proc.stderr.on 'finish', ->
try
match = err.match /error\.coffee:(\d+):(\d+)/
throw new Error err unless match

[_, line, column] = match
equal line, 3 # Mapped source line
equal column, 9 # Mapped source column

resolve()
catch e
reject(e)

unless process.version.slice(1, 3) is "12"
test "NODE_OPTIONS=--enable-source-maps environment variable stack trace mapping", ->
new Promise (resolve, reject) ->
proc = fork "./test/importing/error.coffee", [],
env:
NODE_OPTIONS: "--enable-source-maps"
stdio: "pipe"

err = ""
proc.stderr.setEncoding('utf8')
proc.stderr.on 'data', (s) -> err += s
proc.stderr.on 'finish', ->
try
match = err.match /error\.coffee:(\d+):(\d+)/
throw new Error err unless match

[_, line, column] = match
equal line, 3 # Mapped source line
equal column, 9 # Mapped source column

resolve()
catch e
reject(e)

test "generate correct stack traces with --enable-source-maps from bin/coffee", ->
new Promise (resolve, reject) ->
proc = spawn "node", [
"./bin/coffee"
"--nodejs"
"--enable-source-maps"
"test/importing/error.coffee"
]

err = ""
proc.stderr.setEncoding('utf8')
proc.stderr.on 'data', (s) -> err += s
proc.stderr.on 'finish', ->
try
match = err.match /error\.coffee:(\d+):(\d+)/
throw new Error err unless match

[_, line, column] = match
equal line, 3 # Mapped source line
equal column, 9 # Mapped source column

resolve()
catch e
reject e

test "don't change stack traces if another library has patched `Error.prepareStackTrace`", ->
new Promise (resolve, reject) ->
proc = spawn "node", [
"--eval", """
const patchedPrepareStackTrace = Error.prepareStackTrace = function() {};
require('./register.js');
console.log(Error.prepareStackTrace === patchedPrepareStackTrace);
"""
]

out = ""
proc.stdout.setEncoding('utf8')
proc.stdout.on 'data', (s) -> out += s

proc.on 'exit', (status) ->
try
equal status, 0
equal out, "true\n"

resolve()
catch e
reject e

test "requiring 'CoffeeScript' doesn't change `Error.prepareStackTrace`", ->
new Promise (resolve, reject) ->
proc = spawn "node", [
"--eval", """
require('./lib/coffeescript/coffeescript.js');
console.log(Error.prepareStackTrace);
"""
]

out = ""
proc.stdout.setEncoding('utf8')
proc.stdout.on 'data', (s) -> out += s

proc.on 'exit', (status) ->
try
equal status, 0
equal out, "undefined\n"

resolve()
catch e
reject e

</script>
<script type="text/x-coffeescript" class="test" id="strict">
# Strict Early Errors
Expand Down
12 changes: 10 additions & 2 deletions documentation/site/docs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ window.gtag 'config', window.GA_TRACKING_ID

# Initialize the CoffeeScript docs interactions
$(document).ready ->
CoffeeScript.attachStackTrace()

# Format dates for the user’s locale, e.g. 'December 24, 2009' or '24 décembre 2009'
$('time').each (index, el) ->
date = el.dateTime or $(el).text()
Expand Down Expand Up @@ -105,11 +107,17 @@ $(document).ready ->
if window.localStorage?
window.localStorage.setItem 'tryCoffeeScriptCode', coffee
catch exception
output = CoffeeScript.compile coffee, bare: yes

js = CoffeeScript.compile coffee, bare: yes, inlineMap: true
# Inline map is added to adjust stack trace line numbers but we strip it from the displayed JS for visual clarity.
output = js.replace /(\n\/\/# [^\n]*){2}$/, ""
lastCompilationElapsedTime = Math.max(200, Date.now() - lastCompilationStartTime)
catch exception
output = "#{exception}"

editors[index + 1].js = js
editors[index + 1].setValue output

gtag 'event', 'edit_code',
event_category: 'engagement'
event_label: $textarea.closest('[data-example]').data('example')
Expand Down Expand Up @@ -149,7 +157,7 @@ $(document).ready ->
run = $(@).data 'run'
index = $("##{$(@).data('example')}-js").data 'index'
js = if editors[index]?
editors[index].getValue()
editors[index].js
else
$(textareas[index]).val()
js = "#{js}\nalert(#{unescape run});" unless run is yes
Expand Down
2 changes: 1 addition & 1 deletion lib/coffeescript-browser-compiler-legacy/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/coffeescript-browser-compiler-modern/coffeescript.js

Large diffs are not rendered by default.

Loading