forked from jquery/esprima
/
es6.html
292 lines (263 loc) · 9.47 KB
/
es6.html
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<title>ECMAScript 6 Support in Esprima</title>
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" type="text/css" href="../assets/style.css"/>
<link rel="stylesheet" href="../assets/foundation/foundation.min.css">
<link rel="stylesheet" type="text/css" href="../assets/prettify/prettify.css"/>
<script type="text/javascript" src="../assets/prettify/prettify.js"></script>
<style>
pre.prettyprint {
border: 1px solid #ccc;
background-color: #f8f8f8;
border-radius: 3px;
padding: 6px 10px;
xfont-size: 13px;
xline-height: 19px;
margin-bottom: 14px;
}
</style>
</head>
<body onload="prettyPrint()">
<!-- Navigation bar -->
<div class="row">
<div class="twelve columns">
<nav class="top-bar">
<ul>
<li class="name">
<h1><a href="../index.html">Esprima</a></h1>
</li>
</ul>
<section>
<ul class="right">
<li class="divider show-for-medium-and-up"></li>
<li class="has-dropdown">
<a href="../demo/index.html">Demo</a>
<ul class="dropdown">
<li><label>Static Analysis</label></li>
<li><a href="../demo/parse.html">Online Parsing</a></li>
<li><a href="../demo/validate.html">Syntax Validator</a></li>
<li><a href="../demo/precedence.html">Operator Precedence</a></li>
<li><a href="../demo/collector.html">Regex Collector</a></li>
<li><label>Dynamic Tracing</label></li>
<li><a href="../demo/functiontrace.html">Function Instrumentation</a></li>
<li><label>Code Transformation</label></li>
<li><a href="../demo/rewrite.html">Source Rewrite</a></li>
<li><a href="../demo/minify.html">Minifiy & Obfuscate</a></li>
<li><label>Editing Tools</label></li>
<li><a href="../demo/highlight.html">Identifier Highlight</a></li>
<li><a href="../demo/rename.html">Rename Refactoring</a></li>
<li><a href="../demo/autocomplete.html">Autocomplete</a></li>
</ul>
</li>
<li class="has-dropdown">
<a href="#">Project</a>
<ul class="dropdown">
<li><a href="http://github.com/jquery/esprima">Git Repository</a></li>
<li><a href="https://travis-ci.org/jquery/esprima">Continuous Integration</a></li>
<li><a href="http://groups.google.com/group/esprima">Mailing List</a></li>
<li><a href="https://github.com/jquery/esprima/issues">Issue Tracker</a></li>
<li class="divider"></li>
<li><label>QA</label></li>
<li><a href="../test/index.html">Unit Tests</a></li>
<li><a href="../test/benchmarks.html">Benchmarks Suite</a></li>
<li><a href="../test/compare.html">Speed Comparison</a></li>
<li><a href="../test/module.html">Module Loading</a></li>
<li><a href="https://coveralls.io/r/jquery/esprima">Coverage Analysis</a></li>
</ul>
</li>
<li><a href="../doc/index.html">Documentation</a></li>
</ul>
</section>
</nav>
</div>
</div>
<!-- Title and subtitle -->
<div class="row">
<div class="twelve columns">
<h3 class="subheader"><strong>ECMAScript 6</strong> with Esprima</h3>
</div>
</div>
<!-- Main content -->
<div class="row">
<div class="eight columns">
<p>From version 2.0, Esprima starts to support new features in ECMAScript 6.</p>
<h4 id="arrowfunction">Arrow Function</h4>
<p><em>Since: version 2.0. Specification: <a href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-arrow-function-definitions">section 14.2</a>.</em></p>
<p>Example code snippet:</p>
<pre class="prettyprint lang-js">
array.map(x => x * x)
</pre>
<p>The corresponding syntax tree:</p>
<pre class="prettyprint lang-json">
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "Identifier",
"name": "array"
},
"property": {
"type": "Identifier",
"name": "map"
}
},
"arguments": [
{
"type": "ArrowFunctionExpression",
"id": null,
"params": [
{
"type": "Identifier",
"name": "x"
}
],
"defaults": [],
"body": {
"type": "BinaryExpression",
"operator": "*",
"left": {
"type": "Identifier",
"name": "x"
},
"right": {
"type": "Identifier",
"name": "x"
}
},
"rest": null,
"generator": false,
"expression": true
}
]
}
}
]
}
</pre>
<h4 id="defaultparameter">Default Parameter Value</h4>
<p><em>Since: version 2.0. Specification: <a href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-function-definitions">section 14.1</a>.</em></p>
<p>Example code snippet:</p>
<pre class="prettyprint lang-js">
function answer(x = 42) { say(x); }
</pre>
<p>The corresponding syntax tree:</p>
<pre class="prettyprint lang-json">
{
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "answer"
},
"params": [
{
"type": "Identifier",
"name": "x"
}
],
"defaults": [
{
"type": "Literal",
"value": 42,
"raw": "42"
}
],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "say"
},
"arguments": [
{
"type": "Identifier",
"name": "x"
}
]
}
}
]
},
"rest": null,
"generator": false,
"expression": false
}
]
}
</pre>
<h4 id="codepointescape">Unicode Code Point Escape Sequence</h4>
<p><em>Since: version 2.0. Specification: <a href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-literals-string-literals">section 11.8.4</a>.</em></p>
<p>Example code snippet:</p>
<pre class="prettyprint lang-js">
x = '\u{41}'
</pre>
<p>The corresponding syntax tree:</p>
<pre class="prettyprint lang-js">
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "Identifier",
"name": "x"
},
"right": {
"type": "Literal",
"value": "A",
"raw": "'\\u{41}'"
}
}
}
]
}
</pre>
</div>
<div class="four columns">
<div class="panel">
<p><b>Contents</b></p>
<ol>
<li><a href="#arrowfunction">Arrow Function</a></li>
<li><a href="#defaultparameter">Default Parameter Value</a></li>
<li><a href="#codepointescape">Unicode Code Point Escapee</a></li>
</ol>
</div>
<p><strong>Note</strong>: Partial ES6 support also exists in the experimental <em>harmony</em> branch.
However, this branch has never been officially released and the features are not documented.</p>
</div>
</div>
<!-- Footer -->
<div class="row copyright">
<div class="six columns">
<p>Esprima is created and maintained by <a href="http://ariya.ofilabs.com/about">Ariya Hidayat</a>.</p>
</div>
<div class="six columns">
<ul class="link-list right">
<li><a href="http://twitter.com/esprima">@Esprima</a></li>
<li><a href="https://github.com/jquery/esprima">GitHub</a></li>
</ul>
</div>
</div>
</body>
</html>