UNPKG

6.67 kBMarkdownView Raw
1### esutils [![Build Status](https://secure.travis-ci.org/Constellation/esutils.svg)](http://travis-ci.org/Constellation/esutils)
2esutils ([esutils](http://github.com/Constellation/esutils)) is
3utility box for ECMAScript language tools.
4
5### API
6
7### ast
8
9#### ast.isExpression(node)
10
11Returns 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
16Returns 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
21Returns true if `node` is an IterationStatement as defined in ECMA262 edition
225.1 section [12.6](https://es5.github.io/#x12.6).
23
24#### ast.isSourceElement(node)
25
26Returns true if `node` is a SourceElement as defined in ECMA262 edition 5.1
27section [14](https://es5.github.io/#x14).
28
29#### ast.trailingStatement(node)
30
31Returns `Statement?` if `node` has trailing `Statement`.
32```js
33if (cond)
34 consequent;
35```
36When taking this `IfStatement`, returns `consequent;` statement.
37
38#### ast.isProblematicIfStatement(node)
39
40Returns 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```
54The 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
61Return true if provided code is decimal digit.
62
63#### code.isHexDigit(code)
64
65Return true if provided code is hexadecimal digit.
66
67#### code.isOctalDigit(code)
68
69Return true if provided code is octal digit.
70
71#### code.isWhiteSpace(code)
72
73Return true if provided code is white space. White space characters are formally defined in ECMA262.
74
75#### code.isLineTerminator(code)
76
77Return true if provided code is line terminator. Line terminator characters are formally defined in ECMA262.
78
79#### code.isIdentifierStart(code)
80
81Return true if provided code can be the first character of ECMA262 Identifier. They are formally defined in ECMA262.
82
83#### code.isIdentifierPart(code)
84
85Return 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
91Returns `true` if provided identifier string is a Keyword or Future Reserved Word
92in 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),
94respectively. 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
99Returns `true` if provided identifier string is a Keyword or Future Reserved Word
100in ECMA262 edition 6. They are formally defined in ECMA262 sections
101[11.6.2.1](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-keywords) and
102[11.6.2.2](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-future-reserved-words),
103respectively. 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
108Returns `true` if provided identifier string is a Reserved Word in ECMA262 edition 5.1.
109They are formally defined in ECMA262 section [7.6.1](http://es5.github.io/#x7.6.1).
110If the `strict` flag is truthy, this function additionally checks whether `id`
111is a Reserved Word under strict mode.
112
113#### keyword.isReservedWordES6(id, strict)
114
115Returns `true` if provided identifier string is a Reserved Word in ECMA262 edition 6.
116They are formally defined in ECMA262 section [11.6.2](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-reserved-words).
117If the `strict` flag is truthy, this function additionally checks whether `id`
118is a Reserved Word under strict mode.
119
120#### keyword.isRestrictedWord(id)
121
122Returns `true` if provided identifier string is one of `eval` or `arguments`.
123They are restricted in strict mode code throughout ECMA262 edition 5.1 and
124in ECMA262 edition 6 section [12.1.1](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-identifiers-static-semantics-early-errors).
125
126#### keyword.isIdentifierName(id)
127
128Return true if provided identifier string is an IdentifierName as specified in
129ECMA262 edition 5.1 section [7.6](https://es5.github.io/#x7.6).
130
131#### keyword.isIdentifierES5(id, strict)
132
133Return true if provided identifier string is an Identifier as specified in
134ECMA262 edition 5.1 section [7.6](https://es5.github.io/#x7.6). If the `strict`
135flag is truthy, this function additionally checks whether `id` is an Identifier
136under strict mode.
137
138#### keyword.isIdentifierES6(id, strict)
139
140Return true if provided identifier string is an Identifier as specified in
141ECMA262 edition 6 section [12.1](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-identifiers).
142If the `strict` flag is truthy, this function additionally checks whether `id`
143is an Identifier under strict mode.
144
145### License
146
147Copyright (C) 2013 [Yusuke Suzuki](http://github.com/Constellation)
148 (twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors.
149
150Redistribution and use in source and binary forms, with or without
151modification, are permitted provided that the following conditions are met:
152
153 * Redistributions of source code must retain the above copyright
154 notice, this list of conditions and the following disclaimer.
155
156 * Redistributions in binary form must reproduce the above copyright
157 notice, this list of conditions and the following disclaimer in the
158 documentation and/or other materials provided with the distribution.
159
160THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
161AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
162IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
163ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
164DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
165(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
166LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
167ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
168(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
169THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.