Skip to content

Commit 61d408f

Browse files
2.5.0 (#5284)
* 2.5.0 changelog * Update dependencies * Colors are expected to be globals by the new AST test helpers * Disable testing of deepStrictIncludeExpectedProperties in browsers for now * Update output of compiler only * Update browser compiler output * Update docs output * Document ast option * Update output * Fix and reenable deepStrict test for browser test suite * Update output
1 parent ba41b44 commit 61d408f

37 files changed

+30446
-12277
lines changed

docs/v2/annotated-source/coffeescript.html

Lines changed: 85 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,41 @@ <h1>coffeescript.coffee</h1>
397397
options.bare = <span class="hljs-literal">yes</span>
398398
<span class="hljs-keyword">break</span>
399399

400-
fragments = parser.parse(tokens).compileToFragments options
400+
nodes = parser.parse tokens</pre></div></div>
401+
402+
</li>
403+
404+
405+
<li id="section-16">
406+
<div class="annotation">
407+
408+
<div class="pilwrap ">
409+
<a class="pilcrow" href="#section-16">&#182;</a>
410+
</div>
411+
<p>If all that was requested was a POJO representation of the nodes, e.g.
412+
the abstract syntax tree (AST), we can stop now and just return that
413+
(after fixing the location data for the root/<code>File</code>»<code>Program</code> node,
414+
which might’ve gotten misaligned from the original source due to the
415+
<code>clean</code> function in the lexer).</p>
416+
417+
</div>
418+
419+
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> options.ast
420+
nodes.allCommentTokens = helpers.extractAllCommentTokens tokens
421+
sourceCodeNumberOfLines = (code.match(<span class="hljs-regexp">/\r?\n/g</span>) <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>).length + <span class="hljs-number">1</span>
422+
sourceCodeLastLine = <span class="hljs-regexp">/.*$/</span>.exec(code)[<span class="hljs-number">0</span>] <span class="hljs-comment"># `.*` matches all but line break characters.</span>
423+
ast = nodes.ast options
424+
range = [<span class="hljs-number">0</span>, code.length]
425+
ast.start = ast.program.start = range[<span class="hljs-number">0</span>]
426+
ast.end = ast.program.end = range[<span class="hljs-number">1</span>]
427+
ast.range = ast.program.range = range
428+
ast.loc.start = ast.program.loc.start = {line: <span class="hljs-number">1</span>, column: <span class="hljs-number">0</span>}
429+
ast.loc.end.line = ast.program.loc.end.line = sourceCodeNumberOfLines
430+
ast.loc.end.column = ast.program.loc.end.column = sourceCodeLastLine.length
431+
ast.tokens = tokens
432+
<span class="hljs-keyword">return</span> ast
433+
434+
fragments = nodes.compileToFragments options
401435

402436
currentLine = <span class="hljs-number">0</span>
403437
currentLine += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> options.header
@@ -409,11 +443,11 @@ <h1>coffeescript.coffee</h1>
409443
</li>
410444

411445

412-
<li id="section-16">
446+
<li id="section-17">
413447
<div class="annotation">
414448

415449
<div class="pilwrap ">
416-
<a class="pilcrow" href="#section-16">&#182;</a>
450+
<a class="pilcrow" href="#section-17">&#182;</a>
417451
</div>
418452
<p>Update the sourcemap with data from each fragment.</p>
419453

@@ -424,11 +458,11 @@ <h1>coffeescript.coffee</h1>
424458
</li>
425459

426460

427-
<li id="section-17">
461+
<li id="section-18">
428462
<div class="annotation">
429463

430464
<div class="pilwrap ">
431-
<a class="pilcrow" href="#section-17">&#182;</a>
465+
<a class="pilcrow" href="#section-18">&#182;</a>
432466
</div>
433467
<p>Do not include empty, whitespace, or semicolon-only fragments.</p>
434468

@@ -449,11 +483,11 @@ <h1>coffeescript.coffee</h1>
449483
</li>
450484

451485

452-
<li id="section-18">
486+
<li id="section-19">
453487
<div class="annotation">
454488

455489
<div class="pilwrap ">
456-
<a class="pilcrow" href="#section-18">&#182;</a>
490+
<a class="pilcrow" href="#section-19">&#182;</a>
457491
</div>
458492
<p>Copy the code from each fragment into the final JavaScript.</p>
459493

@@ -474,11 +508,11 @@ <h1>coffeescript.coffee</h1>
474508
</li>
475509

476510

477-
<li id="section-19">
511+
<li id="section-20">
478512
<div class="annotation">
479513

480514
<div class="pilwrap ">
481-
<a class="pilcrow" href="#section-19">&#182;</a>
515+
<a class="pilcrow" href="#section-20">&#182;</a>
482516
</div>
483517
<p>This only happens if run via the Node API and <code>transpile</code> is set to
484518
something other than an object.</p>
@@ -490,11 +524,11 @@ <h1>coffeescript.coffee</h1>
490524
</li>
491525

492526

493-
<li id="section-20">
527+
<li id="section-21">
494528
<div class="annotation">
495529

496530
<div class="pilwrap ">
497-
<a class="pilcrow" href="#section-20">&#182;</a>
531+
<a class="pilcrow" href="#section-21">&#182;</a>
498532
</div>
499533
<p>Get the reference to Babel that we have been passed if this compiler
500534
is run via the CLI or Node API.</p>
@@ -509,11 +543,11 @@ <h1>coffeescript.coffee</h1>
509543
</li>
510544

511545

512-
<li id="section-21">
546+
<li id="section-22">
513547
<div class="annotation">
514548

515549
<div class="pilwrap ">
516-
<a class="pilcrow" href="#section-21">&#182;</a>
550+
<a class="pilcrow" href="#section-22">&#182;</a>
517551
</div>
518552
<p>See <a href="https://github.com/babel/babel/issues/827#issuecomment-77573107">https://github.com/babel/babel/issues/827#issuecomment-77573107</a>:
519553
Babel can take a v3 source map object as input in <code>inputSourceMap</code>
@@ -548,11 +582,11 @@ <h1>coffeescript.coffee</h1>
548582
</li>
549583

550584

551-
<li id="section-22">
585+
<li id="section-23">
552586
<div class="annotation">
553587

554588
<div class="pilwrap ">
555-
<a class="pilcrow" href="#section-22">&#182;</a>
589+
<a class="pilcrow" href="#section-23">&#182;</a>
556590
</div>
557591
<p>Tokenize a string of CoffeeScript code, and return the array of tokens.</p>
558592

@@ -564,11 +598,11 @@ <h1>coffeescript.coffee</h1>
564598
</li>
565599

566600

567-
<li id="section-23">
601+
<li id="section-24">
568602
<div class="annotation">
569603

570604
<div class="pilwrap ">
571-
<a class="pilcrow" href="#section-23">&#182;</a>
605+
<a class="pilcrow" href="#section-24">&#182;</a>
572606
</div>
573607
<p>Parse a string of CoffeeScript code or an array of lexed tokens, and
574608
return the AST. You can then compile it by calling <code>.compile()</code> on the root,
@@ -577,19 +611,17 @@ <h1>coffeescript.coffee</h1>
577611
</div>
578612

579613
<div class="content"><div class='highlight'><pre>exports.nodes = withPrettyErrors (source, options) -&gt;
580-
<span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> source <span class="hljs-keyword">is</span> <span class="hljs-string">'string'</span>
581-
parser.parse lexer.tokenize source, options
582-
<span class="hljs-keyword">else</span>
583-
parser.parse source</pre></div></div>
614+
source = lexer.tokenize source, options <span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> source <span class="hljs-keyword">is</span> <span class="hljs-string">'string'</span>
615+
parser.parse source</pre></div></div>
584616

585617
</li>
586618

587619

588-
<li id="section-24">
620+
<li id="section-25">
589621
<div class="annotation">
590622

591623
<div class="pilwrap ">
592-
<a class="pilcrow" href="#section-24">&#182;</a>
624+
<a class="pilcrow" href="#section-25">&#182;</a>
593625
</div>
594626
<p>This file used to export these methods; leave stubs that throw warnings
595627
instead. These methods have been moved into <code>index.coffee</code> to provide
@@ -605,11 +637,11 @@ <h1>coffeescript.coffee</h1>
605637
</li>
606638

607639

608-
<li id="section-25">
640+
<li id="section-26">
609641
<div class="annotation">
610642

611643
<div class="pilwrap ">
612-
<a class="pilcrow" href="#section-25">&#182;</a>
644+
<a class="pilcrow" href="#section-26">&#182;</a>
613645
</div>
614646
<p>Instantiate a Lexer for our use here.</p>
615647

@@ -620,11 +652,11 @@ <h1>coffeescript.coffee</h1>
620652
</li>
621653

622654

623-
<li id="section-26">
655+
<li id="section-27">
624656
<div class="annotation">
625657

626658
<div class="pilwrap ">
627-
<a class="pilcrow" href="#section-26">&#182;</a>
659+
<a class="pilcrow" href="#section-27">&#182;</a>
628660
</div>
629661
<p>The real Lexer produces a generic stream of tokens. This object provides a
630662
thin wrapper around it, compatible with the Jison API. We can then pass it
@@ -633,6 +665,10 @@ <h1>coffeescript.coffee</h1>
633665
</div>
634666

635667
<div class="content"><div class='highlight'><pre>parser.lexer =
668+
yylloc:
669+
range: []
670+
options:
671+
ranges: <span class="hljs-literal">yes</span>
636672
lex: <span class="hljs-function">-&gt;</span>
637673
token = parser.tokens[@pos++]
638674
<span class="hljs-keyword">if</span> token
@@ -650,11 +686,11 @@ <h1>coffeescript.coffee</h1>
650686
</li>
651687

652688

653-
<li id="section-27">
689+
<li id="section-28">
654690
<div class="annotation">
655691

656692
<div class="pilwrap ">
657-
<a class="pilcrow" href="#section-27">&#182;</a>
693+
<a class="pilcrow" href="#section-28">&#182;</a>
658694
</div>
659695
<p>Make all the AST nodes visible to the parser.</p>
660696

@@ -665,11 +701,11 @@ <h1>coffeescript.coffee</h1>
665701
</li>
666702

667703

668-
<li id="section-28">
704+
<li id="section-29">
669705
<div class="annotation">
670706

671707
<div class="pilwrap ">
672-
<a class="pilcrow" href="#section-28">&#182;</a>
708+
<a class="pilcrow" href="#section-29">&#182;</a>
673709
</div>
674710
<p>Override Jison’s default error handling function.</p>
675711

@@ -680,11 +716,11 @@ <h1>coffeescript.coffee</h1>
680716
</li>
681717

682718

683-
<li id="section-29">
719+
<li id="section-30">
684720
<div class="annotation">
685721

686722
<div class="pilwrap ">
687-
<a class="pilcrow" href="#section-29">&#182;</a>
723+
<a class="pilcrow" href="#section-30">&#182;</a>
688724
</div>
689725
<p>Disregard Jison’s message, it contains redundant line number information.
690726
Disregard the token, we take its value directly from the lexer in case
@@ -708,11 +744,11 @@ <h1>coffeescript.coffee</h1>
708744
</li>
709745

710746

711-
<li id="section-30">
747+
<li id="section-31">
712748
<div class="annotation">
713749

714750
<div class="pilwrap ">
715-
<a class="pilcrow" href="#section-30">&#182;</a>
751+
<a class="pilcrow" href="#section-31">&#182;</a>
716752
</div>
717753
<p>The second argument has a <code>loc</code> property, which should have the location
718754
data for this token. Unfortunately, Jison seems to send an outdated <code>loc</code>
@@ -726,11 +762,11 @@ <h1>coffeescript.coffee</h1>
726762
</li>
727763

728764

729-
<li id="section-31">
765+
<li id="section-32">
730766
<div class="annotation">
731767

732768
<div class="pilwrap ">
733-
<a class="pilcrow" href="#section-31">&#182;</a>
769+
<a class="pilcrow" href="#section-32">&#182;</a>
734770
</div>
735771
<p>Based on <a href="http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js">http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js</a>
736772
Modified to handle sourceMap</p>
@@ -758,11 +794,11 @@ <h1>coffeescript.coffee</h1>
758794
</li>
759795

760796

761-
<li id="section-32">
797+
<li id="section-33">
762798
<div class="annotation">
763799

764800
<div class="pilwrap ">
765-
<a class="pilcrow" href="#section-32">&#182;</a>
801+
<a class="pilcrow" href="#section-33">&#182;</a>
766802
</div>
767803
<p>Check for a sourceMap position</p>
768804

@@ -805,11 +841,11 @@ <h1>coffeescript.coffee</h1>
805841
</li>
806842

807843

808-
<li id="section-33">
844+
<li id="section-34">
809845
<div class="annotation">
810846

811847
<div class="pilwrap ">
812-
<a class="pilcrow" href="#section-33">&#182;</a>
848+
<a class="pilcrow" href="#section-34">&#182;</a>
813849
</div>
814850
<p>Skip files that we didn’t compile, like Node system files that appear in
815851
the stack trace, as they never have source maps.</p>
@@ -824,11 +860,11 @@ <h1>coffeescript.coffee</h1>
824860
</li>
825861

826862

827-
<li id="section-34">
863+
<li id="section-35">
828864
<div class="annotation">
829865

830866
<div class="pilwrap ">
831-
<a class="pilcrow" href="#section-34">&#182;</a>
867+
<a class="pilcrow" href="#section-35">&#182;</a>
832868
</div>
833869
<p>CoffeeScript compiled in a browser or via <code>CoffeeScript.compile</code> or <code>.run</code>
834870
may get compiled with <code>options.filename</code> that’s missing, which becomes
@@ -843,11 +879,11 @@ <h1>coffeescript.coffee</h1>
843879
</li>
844880

845881

846-
<li id="section-35">
882+
<li id="section-36">
847883
<div class="annotation">
848884

849885
<div class="pilwrap ">
850-
<a class="pilcrow" href="#section-35">&#182;</a>
886+
<a class="pilcrow" href="#section-36">&#182;</a>
851887
</div>
852888
<p>Work backwards from the most recent anonymous source maps, until we find
853889
one that works. This isn’t foolproof; there is a chance that multiple
@@ -864,11 +900,11 @@ <h1>coffeescript.coffee</h1>
864900
</li>
865901

866902

867-
<li id="section-36">
903+
<li id="section-37">
868904
<div class="annotation">
869905

870906
<div class="pilwrap ">
871-
<a class="pilcrow" href="#section-36">&#182;</a>
907+
<a class="pilcrow" href="#section-37">&#182;</a>
872908
</div>
873909
<p>If all else fails, recompile this source to get a source map. We need the
874910
previous section (for <code>&lt;anonymous&gt;</code>) despite this option, because after it
@@ -891,11 +927,11 @@ <h1>coffeescript.coffee</h1>
891927
</li>
892928

893929

894-
<li id="section-37">
930+
<li id="section-38">
895931
<div class="annotation">
896932

897933
<div class="pilwrap ">
898-
<a class="pilcrow" href="#section-37">&#182;</a>
934+
<a class="pilcrow" href="#section-38">&#182;</a>
899935
</div>
900936
<p>Based on <a href="http://goo.gl/ZTx1p">michaelficarra/CoffeeScriptRedux</a>
901937
NodeJS / V8 have no support for transforming positions in stack traces using

0 commit comments

Comments
 (0)