Warning, /frameworks/syntax-highlighting/autotests/input/test.coffee is written in an unsupported language. File is not indexed.
0001 # CoffeeScript test
0002 # Source: https://coffeescript.org
0003
0004 ### Multiline
0005 comment ###
0006 import 'local-file.coffee'
0007
0008 # Assignment:
0009 number = 42
0010 opposite = true
0011
0012 # Conditions:
0013 number = -42 if opposite
0014
0015 # Functions:
0016 square = (x) -> x * x
0017
0018 # Arrays:
0019 list = [1, 2, 3, 4, 5]
0020
0021 # Objects:
0022 math =
0023 root: Math.sqrt
0024 square: square
0025 cube: (x) -> x * square x
0026
0027 # Splats:
0028 race = (winner, runners...) ->
0029 print winner, runners
0030
0031 # Existence:
0032 alert "I knew it!" if elvis?
0033
0034 # Array comprehensions:
0035 cubes = (math.cube num for num in list)
0036
0037 # Classes:
0038 class Animal
0039 constructor: (@name) ->
0040
0041 move: (meters) ->
0042 alert @name + " moved #{meters}m."
0043
0044 # Switch/When/Else:
0045 switch day
0046 when "Mon" then go work
0047 when "Tue" then go relax
0048 when "Thu" then go iceFishing
0049 when "Fri", "Sat"
0050 if day is bingoDay
0051 go bingo
0052 go dancing
0053 when "Sun" then go church
0054 else go work
0055
0056 # Member objects:
0057 Object.prop. Object .Object Object
0058 timelineEvent.class
0059
0060 # Embedded JavaScript Code
0061 markdown = `function () {
0062 return \`In Markdown, write code like \\\`this\\\`\`;
0063 }`
0064
0065 ```
0066 // Comment
0067 var array = new Array(500);
0068 var name = "Willy";
0069 alert(`Hello ${name}!`);
0070 ```
0071 ` String.raw\`String ${x} \` `
0072
0073 ` // Regular Expression after template
0074 const a = \`6\` / 2; /*comment*/
0075 \`template\` /regex/ `
0076
0077 ` // Tagged template literals
0078 tagFunc\`Setting ${setting} is ${value}!\` `