1# Copyright 2017 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5# Elementary building blocks: 6 7# Empty 8" " 9 10# Tokens 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# Keywords, contextual keywords, literals, reserved words. 68"__proto__" 69"anonymous" 70"arguments" 71"as" 72"async" 73"await" 74"break" 75"case" 76"catch" 77"class" 78"const" 79"constructor" 80"continue" 81"debugger" 82"default" 83"delete" 84"do" 85"else" 86"enum" 87"eval" 88"export" 89"extends" 90"false" 91"finally" 92"for" 93"from" 94"function" 95"get" 96"if" 97"import" 98"in" 99"instanceof" 100"let" 101"name" 102"new" 103"null" 104"of" 105"prototype" 106"return" 107"sent" 108"set" 109"static" 110"super" 111"switch" 112"target" 113"this" 114"throw" 115"true" 116"try" 117"typeof" 118"undefined" 119"var" 120"void" 121"while" 122"with" 123 124# TODO(marja): Add names of known classes. 125 126# Separators 127"\n" 128"; " 129$0 "\n" 130$0 "; " 131 132$0 "," $1 133"(" $0 ")" 134 135# Identifiers 136"foo" 137"bar" 138"a" 139"b" 140"c" 141 142# Other literals 143"0" 144"0.0" 145 146# TODO(marja): Add strings and numbers! And quotes. 147 148# Other meaningful words from the spec 149"new.target" 150 151# More complicated building blocks 152 153# Block, object, or binding pattern 154"{" $0 "}" 155"{" $0 ": " $1 "}" 156 157# Array or array binding pattern 158"[" $0 "]" 159 160# Rest element or rest parameter 161"..." 162"..." $0 163 164# Variable declarations 165"let" $0 "=" $1 ";" 166"const " $0 "=" $1 ";" 167"var" $0 "=" $1 ";" 168 169# Return statements 170"return" $0 171"return" $0 ";" 172 173# If statements 174"if (" $0 ")" $1 175"if (" $0 ") {" $1 "}" 176"if (" $0 ") {" $1 "} else {" $2 "}" 177"if (" $0 ")" $1 "else" $2 178 179# Iteration statements 180"do" $0 "while (" $1 ");" 181"for (" $0 ")" $1 182"for (" $0 ") {" $1 " }" 183"for (" $0 "in" $1 ")" $2 184"for (" $0 "in" $1 ") {" $2 "}" 185"for (" $0 "of" $1 ")" $2 186"for (" $0 "of" $1 ") {" $2 "}" 187"for (" $0 ";" $1 ";" $2 ")" $3 188"for (" $0 ";" $1 ";" $2 ") {" $3 "}" 189"for await (" $0 ")" $1 190"for await (" $0 ") {" $1 " }" 191"for await (" $0 "in" $1 ")" $2 192"for await (" $0 "in" $1 ") {" $2 "}" 193"for await (" $0 "of" $1 ")" $2 194"for await (" $0 "of" $1 ") {" $2 "}" 195"for await (" $0 ";" $1 ";" $2 ")" $3 196"for await (" $0 ";" $1 ";" $2 ") {" $3 "}" 197"while (" $0 ")" $1 198"while (" $0 ") {" $1 "}" 199"continue" 200"continue;" 201"continue" $0 202"break" 203"break;" 204"break" $0 205 206# With statements 207"with (" $0 ")" $1 208"with (" $0 ") {" $1 "}" 209 210# Switch statements 211"switch (" $0 ")" $1 212"switch (" $0 ") {" $1 "}" 213"case" $0 ": " $1 214"case" $0 ": {" $1 "}" 215"default :" $0 216 217# Try-catch statements 218"try" $0 "catch (" $1 ")" $2 219"try {" $0 "} catch (" $1 ") {" $2 "}" 220"try" $0 "finally (" $1 ")" $2 221"try {" $0 "} finally (" $1 ") {" $2 "}" 222"try" $0 "catch (" $1 ")" $2 "finally" $3 223"try {" $0 "} catch (" $1 ") {" $2 "} finally {" $3 "}" 224 225# Functions and arrow functions 226"function" $0 "(" $1 ") {" $2 "}" 227"function" "(" $0 ") {" $1 "}" 228$0 "=>" $1 229$0 "=> {" $1 "}" 230"(" $0 ") => {" $1 "}" 231"(" $0 ") =>" $1 232 233# Strict functions and arrow functions 234"function" $0 "(" $1 ") { 'use strict';" $2 "}" 235"function" "(" $0 ") { 'use strict';" $1 "}" 236$0 "=> { 'use strict';" $1 "}" 237"(" $0 ") => { 'use strict'; " $1 "}" 238 239# Methods 240$0 "(" $1 ") {" $1 "}" 241"get" $0 "(" $1 ") {" $1 "}" 242"set" $0 "(" $1 ") {" $1 "}" 243"static" $0 "(" $1 ") {" $1 "}" 244"static get" $0 "(" $1 ") {" $1 "}" 245"static set" $0 "(" $1 ") {" $1 "}" 246 247# Generators 248"*" $0 "(" $1 ") {" $2 "}" 249"function *" $0 "(" $1 ") {" $2 "}" 250"function * (" $1 ") {" $2 "}" 251"yield" $0 252"yield *" $0 253 254# Strict generators 255"function *" $0 "(" $1 ") {'use strict'; " $2 "}" 256"function * (" $1 ") { 'use strict'; " $2 "}" 257 258# Classes 259"class" $0 "{" $1 "}" 260"class" $0 "extends" $1 "{" $2 "}" 261 262# Async functions, async methods, async arrow functions 263"async function" $0 "(" $1 ") {" $2 "}" 264"async function" "(" $0 ") {" $1 "}" 265"async" $0 "(" $1 ") {" $2 "}" 266"async" $0 "=>" $1 267"async" $0 "=> {" $1 "}" 268"async(" $0 ") => {" $1 "}" 269"async(" $0 ") =>" $1 270"await" $0 271 272# Strict async functions. 273"async function" $0 "(" $1 ") { 'use strict'; " $2 "}" 274"async function" "(" $0 ") { 'use strict'; " $1 "}" 275"async" $0 "(" $1 ") { 'use strict'; " $2 "}" 276"async" $0 "=> { 'use strict'; " $1 "}" 277"async(" $0 ") => { 'use strict';" $1 "}" 278 279# Call expressions 280$0 "[" $1 "]" 281$0 "(" $1 ")" 282 283# Template literals 284"`foo`" 285$0 "`foo`" 286# TODO(marja): add more 287 288# Strict directive 289"'use strict';" 290 291# Regexps 292"/foo/" 293# TODO(marja): add more 294 295# Conditional expression 296$0 "?" $1 ":" $2 297$0 "?" $1 ":" $2 ";" 298 299# Assignment expressions 300$0 "=" $1 301$0 "=" $1 ";" 302 303# Import / export (for modules) 304"import" $0 ";" 305"export" $0 ";" 306 307# Misc. 308"eval('');" 309 310