You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
6.7 KiB

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