Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 177 lines (138 sloc) 1.851 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
#! line comment

  #!comment
func = ->
#!comment
  false
  false #!comment
  false

#!comment
  true

switch 'string'
#!comment
case false then something()
#!comment
case null
  somethingElse()

->
  code()
  #!comment

ok func()

func
func
#!Line3

obj = {
#!comment
  #!comment
    #!comment
  one: 1
#!comment
  two: 2
    #!comment
}

result = if true # comment
  false

ok not result

result = if false
  false
else # comment
  45

eq result, 45


test =
  'test ' +
  'test ' + # comment
  'test'

eq test, 'test test test'

/*
  This is a block comment.
  Just like JS.
*/

func = ->
  /*
  Another block comment.
  */
  code
  /*
  debug code commented
  */


func = ->
  one = ->
    two = ->
      three = ->
  /*
  block.
  */
  four = ->

fn1 = ->
  oneLevel = null
/* This is fine. */

ok ok


# Spaced comments in if / elses.
result = if false
  1

#!comment
else if false
  2

#!comment
else
  3

eq result, 3


result = switch 'z'
case 'z' then 7
#!comment
eq result, 7


# Trailing-line comment before an outdent.
func = ->
  if true
    true # comment
  7

eq func(), 7


eq '''
/* leading block comments */
/* are placed before declarations */
var obj;
obj = {
  /*
   * v
   */
  key: val
  /*
   * ^
   */
};
if (1) {
  /* no semicolon at end -> */
  2;
}
/* trailing top level comment */
''', Coco.compile '''
/* leading block comments */
/* are placed before declarations */
obj = {
   /*
    * v
    */
   key : val
   /*
    * ^
    */
}
if 1
  /* no semicolon at end -> */
  2
  /* trailing comments in a block */
  /* are removed */
/* trailing top level comment */
''', {+bare}


# Block comments within non-statement `if`s.
eq void, if true then /* 1 */
eq true, do
  if true
    /* 2 */
    true
eq true, do
  if true
    true
    /* 3 */


eq 0, [0]/* inline block comment */[0]


/*
Trailing block comment works.
Something went wrong with that request. Please try again.