1
|
### esutils [![Build Status](https://secure.travis-ci.org/estools/esutils.svg)](http://travis-ci.org/estools/esutils)
|
2
|
esutils ([esutils](http://github.com/estools/esutils)) is
|
3
|
utility box for ECMAScript language tools.
|
4
|
|
5
|
### API
|
6
|
|
7
|
### ast
|
8
|
|
9
|
#### ast.isExpression(node)
|
10
|
|
11
|
Returns true if `node` is an Expression as defined in ECMA262 edition 5.1 section
|
12
|
[11](https://es5.github.io/#x11).
|
13
|
|
14
|
#### ast.isStatement(node)
|
15
|
|
16
|
Returns true if `node` is a Statement as defined in ECMA262 edition 5.1 section
|
17
|
[12](https://es5.github.io/#x12).
|
18
|
|
19
|
#### ast.isIterationStatement(node)
|
20
|
|
21
|
Returns true if `node` is an IterationStatement as defined in ECMA262 edition
|
22
|
5.1 section [12.6](https://es5.github.io/#x12.6).
|
23
|
|
24
|
#### ast.isSourceElement(node)
|
25
|
|
26
|
Returns true if `node` is a SourceElement as defined in ECMA262 edition 5.1
|
27
|
section [14](https://es5.github.io/#x14).
|
28
|
|
29
|
#### ast.trailingStatement(node)
|
30
|
|
31
|
Returns `Statement?` if `node` has trailing `Statement`.
|
32
|
```js
|
33
|
if (cond)
|
34
|
consequent;
|
35
|
```
|
36
|
When taking this `IfStatement`, returns `consequent;` statement.
|
37
|
|
38
|
#### ast.isProblematicIfStatement(node)
|
39
|
|
40
|
Returns true if `node` is a problematic IfStatement. If `node` is a problematic `IfStatement`, `node` cannot be represented as an one on one JavaScript code.
|
41
|
```js
|
42
|
{
|
43
|
type: 'IfStatement',
|
44
|
consequent: {
|
45
|
type: 'WithStatement',
|
46
|
body: {
|
47
|
type: 'IfStatement',
|
48
|
consequent: {type: 'EmptyStatement'}
|
49
|
}
|
50
|
},
|
51
|
alternate: {type: 'EmptyStatement'}
|
52
|
}
|
53
|
```
|
54
|
The above node cannot be represented as a JavaScript code, since the top level `else` alternate belongs to an inner `IfStatement`.
|
55
|
|
56
|
|
57
|
### code
|
58
|
|
59
|
#### code.isDecimalDigit(code)
|
60
|
|
61
|
Return true if provided code is decimal digit.
|
62
|
|
63
|
#### code.isHexDigit(code)
|
64
|
|
65
|
Return true if provided code is hexadecimal digit.
|
66
|
|
67
|
#### code.isOctalDigit(code)
|
68
|
|
69
|
Return true if provided code is octal digit.
|
70
|
|
71
|
#### code.isWhiteSpace(code)
|
72
|
|
73
|
Return true if provided code is white space. White space characters are formally defined in ECMA262.
|
74
|
|
75
|
#### code.isLineTerminator(code)
|
76
|
|
77
|
Return true if provided code is line terminator. Line terminator characters are formally defined in ECMA262.
|
78
|
|
79
|
#### code.isIdentifierStart(code)
|
80
|
|
81
|
Return true if provided code can be the first character of ECMA262 Identifier. They are formally defined in ECMA262.
|
82
|
|
83
|
#### code.isIdentifierPart(code)
|
84
|
|
85
|
Return true if provided code can be the trailing character of ECMA262 Identifier. They are formally defined in ECMA262.
|
86
|
|
87
|
### keyword
|
88
|
|
89
|
#### keyword.isKeywordES5(id, strict)
|
90
|
|
91
|
Returns `true` if provided identifier string is a Keyword or Future Reserved Word
|
92
|
in ECMA262 edition 5.1. They are formally defined in ECMA262 sections
|
93
|
[7.6.1.1](http://es5.github.io/#x7.6.1.1) and [7.6.1.2](http://es5.github.io/#x7.6.1.2),
|
94
|
respectively. If the `strict` flag is truthy, this function additionally checks whether
|
95
|
`id` is a Keyword or Future Reserved Word under strict mode.
|
96
|
|
97
|
#### keyword.isKeywordES6(id, strict)
|
98
|
|
99
|
Returns `true` if provided identifier string is a Keyword or Future Reserved Word
|
100
|
in ECMA262 edition 6. They are formally defined in ECMA262 sections
|
101
|
[11.6.2.1](http://ecma-international.org/ecma-262/6.0/#sec-keywords) and
|
102
|
[11.6.2.2](http://ecma-international.org/ecma-262/6.0/#sec-future-reserved-words),
|
103
|
respectively. If the `strict` flag is truthy, this function additionally checks whether
|
104
|
`id` is a Keyword or Future Reserved Word under strict mode.
|
105
|
|
106
|
#### keyword.isReservedWordES5(id, strict)
|
107
|
|
108
|
Returns `true` if provided identifier string is a Reserved Word in ECMA262 edition 5.1.
|
109
|
They are formally defined in ECMA262 section [7.6.1](http://es5.github.io/#x7.6.1).
|
110
|
If the `strict` flag is truthy, this function additionally checks whether `id`
|
111
|
is a Reserved Word under strict mode.
|
112
|
|
113
|
#### keyword.isReservedWordES6(id, strict)
|
114
|
|
115
|
Returns `true` if provided identifier string is a Reserved Word in ECMA262 edition 6.
|
116
|
They are formally defined in ECMA262 section [11.6.2](http://ecma-international.org/ecma-262/6.0/#sec-reserved-words).
|
117
|
If the `strict` flag is truthy, this function additionally checks whether `id`
|
118
|
is a Reserved Word under strict mode.
|
119
|
|
120
|
#### keyword.isRestrictedWord(id)
|
121
|
|
122
|
Returns `true` if provided identifier string is one of `eval` or `arguments`.
|
123
|
They are restricted in strict mode code throughout ECMA262 edition 5.1 and
|
124
|
in ECMA262 edition 6 section [12.1.1](http://ecma-international.org/ecma-262/6.0/#sec-identifiers-static-semantics-early-errors).
|
125
|
|
126
|
#### keyword.isIdentifierNameES5(id)
|
127
|
|
128
|
Return true if provided identifier string is an IdentifierName as specified in
|
129
|
ECMA262 edition 5.1 section [7.6](https://es5.github.io/#x7.6).
|
130
|
|
131
|
#### keyword.isIdentifierNameES6(id)
|
132
|
|
133
|
Return true if provided identifier string is an IdentifierName as specified in
|
134
|
ECMA262 edition 6 section [11.6](http://ecma-international.org/ecma-262/6.0/#sec-names-and-keywords).
|
135
|
|
136
|
#### keyword.isIdentifierES5(id, strict)
|
137
|
|
138
|
Return true if provided identifier string is an Identifier as specified in
|
139
|
ECMA262 edition 5.1 section [7.6](https://es5.github.io/#x7.6). If the `strict`
|
140
|
flag is truthy, this function additionally checks whether `id` is an Identifier
|
141
|
under strict mode.
|
142
|
|
143
|
#### keyword.isIdentifierES6(id, strict)
|
144
|
|
145
|
Return true if provided identifier string is an Identifier as specified in
|
146
|
ECMA262 edition 6 section [12.1](http://ecma-international.org/ecma-262/6.0/#sec-identifiers).
|
147
|
If the `strict` flag is truthy, this function additionally checks whether `id`
|
148
|
is an Identifier under strict mode.
|
149
|
|
150
|
### License
|
151
|
|
152
|
Copyright (C) 2013 [Yusuke Suzuki](http://github.com/Constellation)
|
153
|
(twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors.
|
154
|
|
155
|
Redistribution and use in source and binary forms, with or without
|
156
|
modification, are permitted provided that the following conditions are met:
|
157
|
|
158
|
* Redistributions of source code must retain the above copyright
|
159
|
notice, this list of conditions and the following disclaimer.
|
160
|
|
161
|
* Redistributions in binary form must reproduce the above copyright
|
162
|
notice, this list of conditions and the following disclaimer in the
|
163
|
documentation and/or other materials provided with the distribution.
|
164
|
|
165
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
166
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
167
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
168
|
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
169
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
170
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
171
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
172
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
173
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
174
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|