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 6 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.
Jump to
Jump to file
Failed to load files.
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.

18 changes: 9 additions & 9 deletions docs/v2/index.html
Expand Up @@ -5364,27 +5364,27 @@ <h3>Bound generator functions</h3>
<h3>Classes are compiled to ES2015 classes</h3>
<p>ES2015 classes and their methods have some restrictions beyond those on regular functions.</p>
<p>Class constructors can’t be invoked without <code>new</code>:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee">(<span class="keyword">class</span>)()
<blockquote class="uneditable-code-block"><pre><code class="language-coffee">(<span class="class"><span class="keyword">class</span>)()</span>
<span class="comment"># Throws a TypeError at runtime</span>
</code></pre>
</blockquote><p>ES2015 classes don’t allow bound (fat arrow) methods. The CoffeeScript compiler goes through some contortions to preserve support for them, but one thing that can’t be accommodated is calling a bound method before it is bound:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="keyword">class</span> <span class="title class_">Base</span>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="class"><span class="keyword">class</span> <span class="title">Base</span></span>
constructor: <span class="function">-&gt;</span>
@onClick() <span class="comment"># This works</span>
clickHandler = @onClick
clickHandler() <span class="comment"># This throws a runtime error</span>

<span class="keyword">class</span> <span class="title class_">Component</span> <span class="keyword">extends</span> <span class="title class_ inherited__">Base</span>
<span class="class"><span class="keyword">class</span> <span class="title">Component</span> <span class="keyword">extends</span> <span class="title">Base</span></span>
onClick: <span class="function">=&gt;</span>
console.log <span class="string">&#x27;Clicked!&#x27;</span>, @
</code></pre>
</blockquote><p>Class methods can’t be used with <code>new</code> (uncommon):</p>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="keyword">class</span> <span class="title class_">Namespace</span>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="class"><span class="keyword">class</span> <span class="title">Namespace</span></span>
@Klass = <span class="function">-&gt;</span>
<span class="keyword">new</span> Namespace.Klass <span class="comment"># Throws a TypeError at runtime</span>
</code></pre>
</blockquote><p>Due to the hoisting required to compile to ES2015 classes, dynamic keys in class methods can’t use values from the executable class body unless the methods are assigned in prototype style.</p>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="keyword">class</span> <span class="title class_">A</span>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="class"><span class="keyword">class</span> <span class="title">A</span></span>
name = <span class="string">&#x27;method&#x27;</span>
<span class="string">&quot;<span class="subst">#{name}</span>&quot;</span>: <span class="function">-&gt;</span> <span class="comment"># This method will be named &#x27;undefined&#x27;</span>
@::[name] = <span class="function">-&gt;</span> <span class="comment"># This will work; assigns to `A.prototype.method`</span>
Expand All @@ -5394,11 +5394,11 @@ <h3>Classes are compiled to ES2015 classes</h3>
<section id="breaking-changes-super-this">
<h3><code>super</code> and <code>this</code></h3>
<p>In the constructor of a derived class (a class that <code>extends</code> another class), <code>this</code> cannot be used before calling <code>super</code>:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="keyword">class</span> <span class="title class_">B</span> <span class="keyword">extends</span> <span class="title class_ inherited__">A</span>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="class"><span class="keyword">class</span> <span class="title">B</span> <span class="keyword">extends</span> <span class="title">A</span></span>
constructor: <span class="function">-&gt;</span> this <span class="comment"># Throws a compiler error</span>
</code></pre>
</blockquote><p>This also means you cannot pass a reference to <code>this</code> as an argument to <code>super</code> in the constructor of a derived class:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="keyword">class</span> <span class="title class_">B</span> <span class="keyword">extends</span> <span class="title class_ inherited__">A</span>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="class"><span class="keyword">class</span> <span class="title">B</span> <span class="keyword">extends</span> <span class="title">A</span></span>
constructor: <span class="function"><span class="params">(@arg)</span> -&gt;</span>
super @arg <span class="comment"># Throws a compiler error</span>
</code></pre>
Expand Down Expand Up @@ -5447,7 +5447,7 @@ <h3><code>super</code> and <code>this</code></h3>
<section id="breaking-changes-super-extends">
<h3><code>super</code> and <code>extends</code></h3>
<p>Due to a syntax clash with <code>super</code> with accessors, “bare” <code>super</code> (the keyword <code>super</code> without parentheses) no longer compiles to a super call forwarding all arguments.</p>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="keyword">class</span> <span class="title class_">B</span> <span class="keyword">extends</span> <span class="title class_ inherited__">A</span>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="class"><span class="keyword">class</span> <span class="title">B</span> <span class="keyword">extends</span> <span class="title">A</span></span>
foo: <span class="function">-&gt;</span> super
<span class="comment"># Throws a compiler error</span>
</code></pre>
Expand Down Expand Up @@ -5704,7 +5704,7 @@ <h3>Argument parsing and shebang (<code>#!</code>) lines</h3>
console.log x
</code></pre>
</blockquote><p>If this were saved as <code>executable.coffee</code>, it could be made executable and run:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-bash">▶ <span class="built_in">chmod</span> +x ./executable.coffee
<blockquote class="uneditable-code-block"><pre><code class="language-bash">▶ chmod +x ./executable.coffee
▶ ./executable.coffee
4
</code></pre>
Expand Down
53 changes: 53 additions & 0 deletions docs/v2/test.html
Expand Up @@ -32712,6 +32712,7 @@ <h2>Another heading</h2>
<script type="text/x-coffeescript" class="test" id="sourcemap">
return if global.testingBrowser

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

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

# Source maps aren't accurate on Node v12 ??
if process.version.split(".")[0] != "v12"
test "native source maps", ->
new Promise (resolve, reject) ->
proc = spawn "node", [
"--enable-source-maps"
"-r", "./register.js"
"-r", "./test/integration/error.coffee"
]

# proc.stdout.setEncoding('utf8')
# proc.stdout.on 'data', (s) -> console.log(s)
err = ""
proc.stderr.setEncoding('utf8')
proc.stderr.on 'data', (s) -> err += s
proc.on 'exit', (status) ->
try
equal status, 1

[_, line] = err.match /error\.coffee:(\d+)/
equal line, 3 # Mapped source line
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", [
"-r", "./test/integration/prepare_stack_trace.js",
"-r", "./register.js",
"-r", "./test/integration/error.coffee",
]

# proc.stdout.setEncoding('utf8')
# proc.stdout.on 'data', (s) -> console.log(s)
err = ""
proc.stderr.setEncoding('utf8')
proc.stderr.on 'data', (s) -> err += s
proc.on 'exit', (status) ->
try
equal status, 1

match = err.match /error\.coffee:(\d+)/
if match
[_, line] = match
equal line, 4 # Unmapped source line
resolve()
else
reject new Error err
catch e
reject(e)

</script>
<script type="text/x-coffeescript" class="test" id="strict">
# Strict Early Errors
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.