@alexlit/lint-kit 117.2.0 → 117.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/package.json +2 -2
  2. package/packages/config-commitlint/package.json +2 -2
  3. package/packages/config-eslint/index.js +7 -374
  4. package/packages/config-eslint/legacy.js +3 -0
  5. package/packages/config-eslint/node_modules/@eslint/eslintrc/LICENSE +19 -0
  6. package/packages/config-eslint/node_modules/@eslint/eslintrc/README.md +126 -0
  7. package/packages/config-eslint/node_modules/@eslint/eslintrc/conf/config-schema.js +79 -0
  8. package/packages/config-eslint/node_modules/@eslint/eslintrc/conf/environments.js +215 -0
  9. package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +1143 -0
  10. package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +1 -0
  11. package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +4371 -0
  12. package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +1 -0
  13. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js +532 -0
  14. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/config-array.js +510 -0
  15. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/config-dependency.js +124 -0
  16. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/extracted-config.js +145 -0
  17. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/ignore-pattern.js +238 -0
  18. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/index.js +19 -0
  19. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/override-tester.js +225 -0
  20. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array-factory.js +1155 -0
  21. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/flat-compat.js +318 -0
  22. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/index-universal.js +29 -0
  23. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/index.js +58 -0
  24. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/ajv.js +191 -0
  25. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/config-ops.js +135 -0
  26. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/config-validator.js +370 -0
  27. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/deprecation-warnings.js +63 -0
  28. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/naming.js +96 -0
  29. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js +42 -0
  30. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/types.js +149 -0
  31. package/packages/config-eslint/node_modules/@eslint/eslintrc/package.json +82 -0
  32. package/packages/config-eslint/node_modules/@eslint/eslintrc/universal.js +9 -0
  33. package/packages/config-eslint/node_modules/ajv/.tonic_example.js +20 -0
  34. package/packages/config-eslint/node_modules/ajv/LICENSE +22 -0
  35. package/packages/config-eslint/node_modules/ajv/README.md +1497 -0
  36. package/packages/config-eslint/node_modules/ajv/dist/ajv.bundle.js +7189 -0
  37. package/packages/config-eslint/node_modules/ajv/dist/ajv.min.js +3 -0
  38. package/packages/config-eslint/node_modules/ajv/dist/ajv.min.js.map +1 -0
  39. package/packages/config-eslint/node_modules/ajv/lib/ajv.d.ts +397 -0
  40. package/packages/config-eslint/node_modules/ajv/lib/ajv.js +506 -0
  41. package/packages/config-eslint/node_modules/ajv/lib/cache.js +26 -0
  42. package/packages/config-eslint/node_modules/ajv/lib/compile/async.js +90 -0
  43. package/packages/config-eslint/node_modules/ajv/lib/compile/equal.js +5 -0
  44. package/packages/config-eslint/node_modules/ajv/lib/compile/error_classes.js +34 -0
  45. package/packages/config-eslint/node_modules/ajv/lib/compile/formats.js +142 -0
  46. package/packages/config-eslint/node_modules/ajv/lib/compile/index.js +387 -0
  47. package/packages/config-eslint/node_modules/ajv/lib/compile/resolve.js +270 -0
  48. package/packages/config-eslint/node_modules/ajv/lib/compile/rules.js +66 -0
  49. package/packages/config-eslint/node_modules/ajv/lib/compile/schema_obj.js +9 -0
  50. package/packages/config-eslint/node_modules/ajv/lib/compile/ucs2length.js +20 -0
  51. package/packages/config-eslint/node_modules/ajv/lib/compile/util.js +239 -0
  52. package/packages/config-eslint/node_modules/ajv/lib/data.js +49 -0
  53. package/packages/config-eslint/node_modules/ajv/lib/definition_schema.js +37 -0
  54. package/packages/config-eslint/node_modules/ajv/lib/dot/_limit.jst +113 -0
  55. package/packages/config-eslint/node_modules/ajv/lib/dot/_limitItems.jst +12 -0
  56. package/packages/config-eslint/node_modules/ajv/lib/dot/_limitLength.jst +12 -0
  57. package/packages/config-eslint/node_modules/ajv/lib/dot/_limitProperties.jst +12 -0
  58. package/packages/config-eslint/node_modules/ajv/lib/dot/allOf.jst +32 -0
  59. package/packages/config-eslint/node_modules/ajv/lib/dot/anyOf.jst +46 -0
  60. package/packages/config-eslint/node_modules/ajv/lib/dot/coerce.def +51 -0
  61. package/packages/config-eslint/node_modules/ajv/lib/dot/comment.jst +9 -0
  62. package/packages/config-eslint/node_modules/ajv/lib/dot/const.jst +11 -0
  63. package/packages/config-eslint/node_modules/ajv/lib/dot/contains.jst +55 -0
  64. package/packages/config-eslint/node_modules/ajv/lib/dot/custom.jst +191 -0
  65. package/packages/config-eslint/node_modules/ajv/lib/dot/defaults.def +47 -0
  66. package/packages/config-eslint/node_modules/ajv/lib/dot/definitions.def +203 -0
  67. package/packages/config-eslint/node_modules/ajv/lib/dot/dependencies.jst +79 -0
  68. package/packages/config-eslint/node_modules/ajv/lib/dot/enum.jst +30 -0
  69. package/packages/config-eslint/node_modules/ajv/lib/dot/errors.def +194 -0
  70. package/packages/config-eslint/node_modules/ajv/lib/dot/format.jst +106 -0
  71. package/packages/config-eslint/node_modules/ajv/lib/dot/if.jst +73 -0
  72. package/packages/config-eslint/node_modules/ajv/lib/dot/items.jst +98 -0
  73. package/packages/config-eslint/node_modules/ajv/lib/dot/missing.def +39 -0
  74. package/packages/config-eslint/node_modules/ajv/lib/dot/multipleOf.jst +22 -0
  75. package/packages/config-eslint/node_modules/ajv/lib/dot/not.jst +43 -0
  76. package/packages/config-eslint/node_modules/ajv/lib/dot/oneOf.jst +54 -0
  77. package/packages/config-eslint/node_modules/ajv/lib/dot/pattern.jst +14 -0
  78. package/packages/config-eslint/node_modules/ajv/lib/dot/properties.jst +245 -0
  79. package/packages/config-eslint/node_modules/ajv/lib/dot/propertyNames.jst +52 -0
  80. package/packages/config-eslint/node_modules/ajv/lib/dot/ref.jst +85 -0
  81. package/packages/config-eslint/node_modules/ajv/lib/dot/required.jst +108 -0
  82. package/packages/config-eslint/node_modules/ajv/lib/dot/uniqueItems.jst +62 -0
  83. package/packages/config-eslint/node_modules/ajv/lib/dot/validate.jst +276 -0
  84. package/packages/config-eslint/node_modules/ajv/lib/dotjs/README.md +3 -0
  85. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limit.js +163 -0
  86. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitItems.js +80 -0
  87. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitLength.js +85 -0
  88. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitProperties.js +80 -0
  89. package/packages/config-eslint/node_modules/ajv/lib/dotjs/allOf.js +42 -0
  90. package/packages/config-eslint/node_modules/ajv/lib/dotjs/anyOf.js +73 -0
  91. package/packages/config-eslint/node_modules/ajv/lib/dotjs/comment.js +14 -0
  92. package/packages/config-eslint/node_modules/ajv/lib/dotjs/const.js +56 -0
  93. package/packages/config-eslint/node_modules/ajv/lib/dotjs/contains.js +81 -0
  94. package/packages/config-eslint/node_modules/ajv/lib/dotjs/custom.js +228 -0
  95. package/packages/config-eslint/node_modules/ajv/lib/dotjs/dependencies.js +168 -0
  96. package/packages/config-eslint/node_modules/ajv/lib/dotjs/enum.js +66 -0
  97. package/packages/config-eslint/node_modules/ajv/lib/dotjs/format.js +150 -0
  98. package/packages/config-eslint/node_modules/ajv/lib/dotjs/if.js +103 -0
  99. package/packages/config-eslint/node_modules/ajv/lib/dotjs/index.js +33 -0
  100. package/packages/config-eslint/node_modules/ajv/lib/dotjs/items.js +140 -0
  101. package/packages/config-eslint/node_modules/ajv/lib/dotjs/multipleOf.js +80 -0
  102. package/packages/config-eslint/node_modules/ajv/lib/dotjs/not.js +84 -0
  103. package/packages/config-eslint/node_modules/ajv/lib/dotjs/oneOf.js +73 -0
  104. package/packages/config-eslint/node_modules/ajv/lib/dotjs/pattern.js +75 -0
  105. package/packages/config-eslint/node_modules/ajv/lib/dotjs/properties.js +335 -0
  106. package/packages/config-eslint/node_modules/ajv/lib/dotjs/propertyNames.js +81 -0
  107. package/packages/config-eslint/node_modules/ajv/lib/dotjs/ref.js +124 -0
  108. package/packages/config-eslint/node_modules/ajv/lib/dotjs/required.js +270 -0
  109. package/packages/config-eslint/node_modules/ajv/lib/dotjs/uniqueItems.js +86 -0
  110. package/packages/config-eslint/node_modules/ajv/lib/dotjs/validate.js +482 -0
  111. package/packages/config-eslint/node_modules/ajv/lib/keyword.js +146 -0
  112. package/packages/config-eslint/node_modules/ajv/lib/refs/data.json +17 -0
  113. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-04.json +149 -0
  114. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-06.json +154 -0
  115. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-07.json +168 -0
  116. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-secure.json +94 -0
  117. package/packages/config-eslint/node_modules/ajv/package.json +106 -0
  118. package/packages/config-eslint/node_modules/ajv/scripts/.eslintrc.yml +3 -0
  119. package/packages/config-eslint/node_modules/ajv/scripts/bundle.js +61 -0
  120. package/packages/config-eslint/node_modules/ajv/scripts/compile-dots.js +73 -0
  121. package/packages/config-eslint/node_modules/ajv/scripts/info +10 -0
  122. package/packages/config-eslint/node_modules/ajv/scripts/prepare-tests +12 -0
  123. package/packages/config-eslint/node_modules/ajv/scripts/publish-built-version +32 -0
  124. package/packages/config-eslint/node_modules/ajv/scripts/travis-gh-pages +23 -0
  125. package/packages/config-eslint/node_modules/eslint-visitor-keys/LICENSE +201 -0
  126. package/packages/config-eslint/node_modules/eslint-visitor-keys/README.md +105 -0
  127. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.cjs +384 -0
  128. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.d.cts +27 -0
  129. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/index.d.ts +16 -0
  130. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/visitor-keys.d.ts +12 -0
  131. package/packages/config-eslint/node_modules/eslint-visitor-keys/lib/index.js +65 -0
  132. package/packages/config-eslint/node_modules/eslint-visitor-keys/lib/visitor-keys.js +315 -0
  133. package/packages/config-eslint/node_modules/eslint-visitor-keys/package.json +74 -0
  134. package/packages/config-eslint/node_modules/espree/LICENSE +25 -0
  135. package/packages/config-eslint/node_modules/espree/README.md +244 -0
  136. package/packages/config-eslint/node_modules/espree/dist/espree.cjs +883 -0
  137. package/packages/config-eslint/node_modules/espree/espree.js +177 -0
  138. package/packages/config-eslint/node_modules/espree/lib/espree.js +349 -0
  139. package/packages/config-eslint/node_modules/espree/lib/features.js +27 -0
  140. package/packages/config-eslint/node_modules/espree/lib/options.js +123 -0
  141. package/packages/config-eslint/node_modules/espree/lib/token-translator.js +263 -0
  142. package/packages/config-eslint/node_modules/espree/lib/version.js +3 -0
  143. package/packages/config-eslint/node_modules/espree/package.json +86 -0
  144. package/packages/config-eslint/node_modules/globals/globals.json +1998 -0
  145. package/packages/config-eslint/node_modules/globals/index.d.ts +2077 -0
  146. package/packages/config-eslint/node_modules/globals/index.js +2 -0
  147. package/packages/config-eslint/node_modules/globals/license +9 -0
  148. package/packages/config-eslint/node_modules/globals/package.json +58 -0
  149. package/packages/config-eslint/node_modules/globals/readme.md +44 -0
  150. package/packages/config-eslint/node_modules/json-schema-traverse/.eslintrc.yml +27 -0
  151. package/packages/config-eslint/node_modules/json-schema-traverse/.travis.yml +8 -0
  152. package/packages/config-eslint/node_modules/json-schema-traverse/LICENSE +21 -0
  153. package/packages/config-eslint/node_modules/json-schema-traverse/README.md +83 -0
  154. package/packages/config-eslint/node_modules/json-schema-traverse/index.js +89 -0
  155. package/packages/config-eslint/node_modules/json-schema-traverse/package.json +43 -0
  156. package/packages/config-eslint/node_modules/json-schema-traverse/spec/.eslintrc.yml +6 -0
  157. package/packages/config-eslint/node_modules/json-schema-traverse/spec/fixtures/schema.js +125 -0
  158. package/packages/config-eslint/node_modules/json-schema-traverse/spec/index.spec.js +171 -0
  159. package/packages/config-eslint/package.json +7 -5
  160. package/packages/config-eslint/plugins/no-await-in-promise.js +2 -2
  161. package/packages/config-eslint/utils/create-config.js +377 -0
  162. package/packages/config-hooks/package.json +1 -1
  163. package/packages/config-htmllint/package.json +1 -1
  164. package/packages/config-markdownlint/package.json +2 -2
  165. package/packages/config-npmlint/package.json +1 -1
  166. package/packages/config-prettier/package.json +2 -2
  167. package/packages/config-stylelint/package.json +2 -2
  168. package/scripts/lint.eslint.sh +1 -1
  169. package/.eslintrc.cjs +0 -16
@@ -0,0 +1,177 @@
1
+ /* eslint-disable jsdoc/no-multi-asterisks -- needed to preserve original formatting of licences */
2
+
3
+ /**
4
+ * @fileoverview Main Espree file that converts Acorn into Esprima output.
5
+ *
6
+ * This file contains code from the following MIT-licensed projects:
7
+ * 1. Acorn
8
+ * 2. Babylon
9
+ * 3. Babel-ESLint
10
+ *
11
+ * This file also contains code from Esprima, which is BSD licensed.
12
+ *
13
+ * Acorn is Copyright 2012-2015 Acorn Contributors (https://github.com/marijnh/acorn/blob/master/AUTHORS)
14
+ * Babylon is Copyright 2014-2015 various contributors (https://github.com/babel/babel/blob/master/packages/babylon/AUTHORS)
15
+ * Babel-ESLint is Copyright 2014-2015 Sebastian McKenzie <sebmck@gmail.com>
16
+ *
17
+ * Redistribution and use in source and binary forms, with or without
18
+ * modification, are permitted provided that the following conditions are met:
19
+ *
20
+ * * Redistributions of source code must retain the above copyright
21
+ * notice, this list of conditions and the following disclaimer.
22
+ * * Redistributions in binary form must reproduce the above copyright
23
+ * notice, this list of conditions and the following disclaimer in the
24
+ * documentation and/or other materials provided with the distribution.
25
+ *
26
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
+ * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
30
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+ *
37
+ * Esprima is Copyright (c) jQuery Foundation, Inc. and Contributors, All Rights Reserved.
38
+ *
39
+ * Redistribution and use in source and binary forms, with or without
40
+ * modification, are permitted provided that the following conditions are met:
41
+ *
42
+ * * Redistributions of source code must retain the above copyright
43
+ * notice, this list of conditions and the following disclaimer.
44
+ * * Redistributions in binary form must reproduce the above copyright
45
+ * notice, this list of conditions and the following disclaimer in the
46
+ * documentation and/or other materials provided with the distribution.
47
+ *
48
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51
+ * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
52
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
53
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
57
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58
+ */
59
+
60
+ /* eslint-enable jsdoc/no-multi-asterisks -- needed to preserve original formatting of licences */
61
+
62
+ import * as acorn from "acorn";
63
+ import jsx from "acorn-jsx";
64
+ import espree from "./lib/espree.js";
65
+ import espreeVersion from "./lib/version.js";
66
+ import * as visitorKeys from "eslint-visitor-keys";
67
+ import { getLatestEcmaVersion, getSupportedEcmaVersions } from "./lib/options.js";
68
+
69
+
70
+ // To initialize lazily.
71
+ const parsers = {
72
+ _regular: null,
73
+ _jsx: null,
74
+
75
+ get regular() {
76
+ if (this._regular === null) {
77
+ this._regular = acorn.Parser.extend(espree());
78
+ }
79
+ return this._regular;
80
+ },
81
+
82
+ get jsx() {
83
+ if (this._jsx === null) {
84
+ this._jsx = acorn.Parser.extend(jsx(), espree());
85
+ }
86
+ return this._jsx;
87
+ },
88
+
89
+ get(options) {
90
+ const useJsx = Boolean(
91
+ options &&
92
+ options.ecmaFeatures &&
93
+ options.ecmaFeatures.jsx
94
+ );
95
+
96
+ return useJsx ? this.jsx : this.regular;
97
+ }
98
+ };
99
+
100
+ //------------------------------------------------------------------------------
101
+ // Tokenizer
102
+ //------------------------------------------------------------------------------
103
+
104
+ /**
105
+ * Tokenizes the given code.
106
+ * @param {string} code The code to tokenize.
107
+ * @param {Object} options Options defining how to tokenize.
108
+ * @returns {Token[]} An array of tokens.
109
+ * @throws {SyntaxError} If the input code is invalid.
110
+ * @private
111
+ */
112
+ export function tokenize(code, options) {
113
+ const Parser = parsers.get(options);
114
+
115
+ // Ensure to collect tokens.
116
+ if (!options || options.tokens !== true) {
117
+ options = Object.assign({}, options, { tokens: true }); // eslint-disable-line no-param-reassign -- stylistic choice
118
+ }
119
+
120
+ return new Parser(options, code).tokenize();
121
+ }
122
+
123
+ //------------------------------------------------------------------------------
124
+ // Parser
125
+ //------------------------------------------------------------------------------
126
+
127
+ /**
128
+ * Parses the given code.
129
+ * @param {string} code The code to tokenize.
130
+ * @param {Object} options Options defining how to tokenize.
131
+ * @returns {ASTNode} The "Program" AST node.
132
+ * @throws {SyntaxError} If the input code is invalid.
133
+ */
134
+ export function parse(code, options) {
135
+ const Parser = parsers.get(options);
136
+
137
+ return new Parser(options, code).parse();
138
+ }
139
+
140
+ //------------------------------------------------------------------------------
141
+ // Public
142
+ //------------------------------------------------------------------------------
143
+
144
+ export const version = espreeVersion;
145
+ export const name = "espree";
146
+
147
+ /* istanbul ignore next */
148
+ export const VisitorKeys = (function() {
149
+ return visitorKeys.KEYS;
150
+ }());
151
+
152
+ // Derive node types from VisitorKeys
153
+ /* istanbul ignore next */
154
+ export const Syntax = (function() {
155
+ let key,
156
+ types = {};
157
+
158
+ if (typeof Object.create === "function") {
159
+ types = Object.create(null);
160
+ }
161
+
162
+ for (key in VisitorKeys) {
163
+ if (Object.hasOwnProperty.call(VisitorKeys, key)) {
164
+ types[key] = key;
165
+ }
166
+ }
167
+
168
+ if (typeof Object.freeze === "function") {
169
+ Object.freeze(types);
170
+ }
171
+
172
+ return types;
173
+ }());
174
+
175
+ export const latestEcmaVersion = getLatestEcmaVersion();
176
+
177
+ export const supportedEcmaVersions = getSupportedEcmaVersions();
@@ -0,0 +1,349 @@
1
+ /* eslint no-param-reassign: 0 -- stylistic choice */
2
+
3
+ import TokenTranslator from "./token-translator.js";
4
+ import { normalizeOptions } from "./options.js";
5
+
6
+
7
+ const STATE = Symbol("espree's internal state");
8
+ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
9
+
10
+
11
+ /**
12
+ * Converts an Acorn comment to a Esprima comment.
13
+ * @param {boolean} block True if it's a block comment, false if not.
14
+ * @param {string} text The text of the comment.
15
+ * @param {int} start The index at which the comment starts.
16
+ * @param {int} end The index at which the comment ends.
17
+ * @param {Location} startLoc The location at which the comment starts.
18
+ * @param {Location} endLoc The location at which the comment ends.
19
+ * @param {string} code The source code being parsed.
20
+ * @returns {Object} The comment object.
21
+ * @private
22
+ */
23
+ function convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc, code) {
24
+ let type;
25
+
26
+ if (block) {
27
+ type = "Block";
28
+ } else if (code.slice(start, start + 2) === "#!") {
29
+ type = "Hashbang";
30
+ } else {
31
+ type = "Line";
32
+ }
33
+
34
+ const comment = {
35
+ type,
36
+ value: text
37
+ };
38
+
39
+ if (typeof start === "number") {
40
+ comment.start = start;
41
+ comment.end = end;
42
+ comment.range = [start, end];
43
+ }
44
+
45
+ if (typeof startLoc === "object") {
46
+ comment.loc = {
47
+ start: startLoc,
48
+ end: endLoc
49
+ };
50
+ }
51
+
52
+ return comment;
53
+ }
54
+
55
+ export default () => Parser => {
56
+ const tokTypes = Object.assign({}, Parser.acorn.tokTypes);
57
+
58
+ if (Parser.acornJsx) {
59
+ Object.assign(tokTypes, Parser.acornJsx.tokTypes);
60
+ }
61
+
62
+ return class Espree extends Parser {
63
+ constructor(opts, code) {
64
+ if (typeof opts !== "object" || opts === null) {
65
+ opts = {};
66
+ }
67
+ if (typeof code !== "string" && !(code instanceof String)) {
68
+ code = String(code);
69
+ }
70
+
71
+ // save original source type in case of commonjs
72
+ const originalSourceType = opts.sourceType;
73
+ const options = normalizeOptions(opts);
74
+ const ecmaFeatures = options.ecmaFeatures || {};
75
+ const tokenTranslator =
76
+ options.tokens === true
77
+ ? new TokenTranslator(tokTypes, code)
78
+ : null;
79
+
80
+ /*
81
+ * Data that is unique to Espree and is not represented internally
82
+ * in Acorn.
83
+ *
84
+ * For ES2023 hashbangs, Espree will call `onComment()` during the
85
+ * constructor, so we must define state before having access to
86
+ * `this`.
87
+ */
88
+ const state = {
89
+ originalSourceType: originalSourceType || options.sourceType,
90
+ tokens: tokenTranslator ? [] : null,
91
+ comments: options.comment === true ? [] : null,
92
+ impliedStrict: ecmaFeatures.impliedStrict === true && options.ecmaVersion >= 5,
93
+ ecmaVersion: options.ecmaVersion,
94
+ jsxAttrValueToken: false,
95
+ lastToken: null,
96
+ templateElements: []
97
+ };
98
+
99
+ // Initialize acorn parser.
100
+ super({
101
+
102
+ // do not use spread, because we don't want to pass any unknown options to acorn
103
+ ecmaVersion: options.ecmaVersion,
104
+ sourceType: options.sourceType,
105
+ ranges: options.ranges,
106
+ locations: options.locations,
107
+ allowReserved: options.allowReserved,
108
+
109
+ // Truthy value is true for backward compatibility.
110
+ allowReturnOutsideFunction: options.allowReturnOutsideFunction,
111
+
112
+ // Collect tokens
113
+ onToken(token) {
114
+ if (tokenTranslator) {
115
+
116
+ // Use `tokens`, `ecmaVersion`, and `jsxAttrValueToken` in the state.
117
+ tokenTranslator.onToken(token, state);
118
+ }
119
+ if (token.type !== tokTypes.eof) {
120
+ state.lastToken = token;
121
+ }
122
+ },
123
+
124
+ // Collect comments
125
+ onComment(block, text, start, end, startLoc, endLoc) {
126
+ if (state.comments) {
127
+ const comment = convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc, code);
128
+
129
+ state.comments.push(comment);
130
+ }
131
+ }
132
+ }, code);
133
+
134
+ /*
135
+ * We put all of this data into a symbol property as a way to avoid
136
+ * potential naming conflicts with future versions of Acorn.
137
+ */
138
+ this[STATE] = state;
139
+ }
140
+
141
+ tokenize() {
142
+ do {
143
+ this.next();
144
+ } while (this.type !== tokTypes.eof);
145
+
146
+ // Consume the final eof token
147
+ this.next();
148
+
149
+ const extra = this[STATE];
150
+ const tokens = extra.tokens;
151
+
152
+ if (extra.comments) {
153
+ tokens.comments = extra.comments;
154
+ }
155
+
156
+ return tokens;
157
+ }
158
+
159
+ finishNode(...args) {
160
+ const result = super.finishNode(...args);
161
+
162
+ return this[ESPRIMA_FINISH_NODE](result);
163
+ }
164
+
165
+ finishNodeAt(...args) {
166
+ const result = super.finishNodeAt(...args);
167
+
168
+ return this[ESPRIMA_FINISH_NODE](result);
169
+ }
170
+
171
+ parse() {
172
+ const extra = this[STATE];
173
+ const program = super.parse();
174
+
175
+ program.sourceType = extra.originalSourceType;
176
+
177
+ if (extra.comments) {
178
+ program.comments = extra.comments;
179
+ }
180
+ if (extra.tokens) {
181
+ program.tokens = extra.tokens;
182
+ }
183
+
184
+ /*
185
+ * Adjust opening and closing position of program to match Esprima.
186
+ * Acorn always starts programs at range 0 whereas Esprima starts at the
187
+ * first AST node's start (the only real difference is when there's leading
188
+ * whitespace or leading comments). Acorn also counts trailing whitespace
189
+ * as part of the program whereas Esprima only counts up to the last token.
190
+ */
191
+ if (program.body.length) {
192
+ const [firstNode] = program.body;
193
+
194
+ if (program.range) {
195
+ program.range[0] = firstNode.range[0];
196
+ }
197
+ if (program.loc) {
198
+ program.loc.start = firstNode.loc.start;
199
+ }
200
+ program.start = firstNode.start;
201
+ }
202
+ if (extra.lastToken) {
203
+ if (program.range) {
204
+ program.range[1] = extra.lastToken.range[1];
205
+ }
206
+ if (program.loc) {
207
+ program.loc.end = extra.lastToken.loc.end;
208
+ }
209
+ program.end = extra.lastToken.end;
210
+ }
211
+
212
+
213
+ /*
214
+ * https://github.com/eslint/espree/issues/349
215
+ * Ensure that template elements have correct range information.
216
+ * This is one location where Acorn produces a different value
217
+ * for its start and end properties vs. the values present in the
218
+ * range property. In order to avoid confusion, we set the start
219
+ * and end properties to the values that are present in range.
220
+ * This is done here, instead of in finishNode(), because Acorn
221
+ * uses the values of start and end internally while parsing, making
222
+ * it dangerous to change those values while parsing is ongoing.
223
+ * By waiting until the end of parsing, we can safely change these
224
+ * values without affect any other part of the process.
225
+ */
226
+ this[STATE].templateElements.forEach(templateElement => {
227
+ const startOffset = -1;
228
+ const endOffset = templateElement.tail ? 1 : 2;
229
+
230
+ templateElement.start += startOffset;
231
+ templateElement.end += endOffset;
232
+
233
+ if (templateElement.range) {
234
+ templateElement.range[0] += startOffset;
235
+ templateElement.range[1] += endOffset;
236
+ }
237
+
238
+ if (templateElement.loc) {
239
+ templateElement.loc.start.column += startOffset;
240
+ templateElement.loc.end.column += endOffset;
241
+ }
242
+ });
243
+
244
+ return program;
245
+ }
246
+
247
+ parseTopLevel(node) {
248
+ if (this[STATE].impliedStrict) {
249
+ this.strict = true;
250
+ }
251
+ return super.parseTopLevel(node);
252
+ }
253
+
254
+ /**
255
+ * Overwrites the default raise method to throw Esprima-style errors.
256
+ * @param {int} pos The position of the error.
257
+ * @param {string} message The error message.
258
+ * @throws {SyntaxError} A syntax error.
259
+ * @returns {void}
260
+ */
261
+ raise(pos, message) {
262
+ const loc = Parser.acorn.getLineInfo(this.input, pos);
263
+ const err = new SyntaxError(message);
264
+
265
+ err.index = pos;
266
+ err.lineNumber = loc.line;
267
+ err.column = loc.column + 1; // acorn uses 0-based columns
268
+ throw err;
269
+ }
270
+
271
+ /**
272
+ * Overwrites the default raise method to throw Esprima-style errors.
273
+ * @param {int} pos The position of the error.
274
+ * @param {string} message The error message.
275
+ * @throws {SyntaxError} A syntax error.
276
+ * @returns {void}
277
+ */
278
+ raiseRecoverable(pos, message) {
279
+ this.raise(pos, message);
280
+ }
281
+
282
+ /**
283
+ * Overwrites the default unexpected method to throw Esprima-style errors.
284
+ * @param {int} pos The position of the error.
285
+ * @throws {SyntaxError} A syntax error.
286
+ * @returns {void}
287
+ */
288
+ unexpected(pos) {
289
+ let message = "Unexpected token";
290
+
291
+ if (pos !== null && pos !== void 0) {
292
+ this.pos = pos;
293
+
294
+ if (this.options.locations) {
295
+ while (this.pos < this.lineStart) {
296
+ this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;
297
+ --this.curLine;
298
+ }
299
+ }
300
+
301
+ this.nextToken();
302
+ }
303
+
304
+ if (this.end > this.start) {
305
+ message += ` ${this.input.slice(this.start, this.end)}`;
306
+ }
307
+
308
+ this.raise(this.start, message);
309
+ }
310
+
311
+ /*
312
+ * Esprima-FB represents JSX strings as tokens called "JSXText", but Acorn-JSX
313
+ * uses regular tt.string without any distinction between this and regular JS
314
+ * strings. As such, we intercept an attempt to read a JSX string and set a flag
315
+ * on extra so that when tokens are converted, the next token will be switched
316
+ * to JSXText via onToken.
317
+ */
318
+ jsx_readString(quote) { // eslint-disable-line camelcase -- required by API
319
+ const result = super.jsx_readString(quote);
320
+
321
+ if (this.type === tokTypes.string) {
322
+ this[STATE].jsxAttrValueToken = true;
323
+ }
324
+ return result;
325
+ }
326
+
327
+ /**
328
+ * Performs last-minute Esprima-specific compatibility checks and fixes.
329
+ * @param {ASTNode} result The node to check.
330
+ * @returns {ASTNode} The finished node.
331
+ */
332
+ [ESPRIMA_FINISH_NODE](result) {
333
+
334
+ // Acorn doesn't count the opening and closing backticks as part of templates
335
+ // so we have to adjust ranges/locations appropriately.
336
+ if (result.type === "TemplateElement") {
337
+
338
+ // save template element references to fix start/end later
339
+ this[STATE].templateElements.push(result);
340
+ }
341
+
342
+ if (result.type.includes("Function") && !result.generator) {
343
+ result.generator = false;
344
+ }
345
+
346
+ return result;
347
+ }
348
+ };
349
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @fileoverview The list of feature flags supported by the parser and their default
3
+ * settings.
4
+ * @author Nicholas C. Zakas
5
+ */
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ // None!
12
+
13
+ //------------------------------------------------------------------------------
14
+ // Public
15
+ //------------------------------------------------------------------------------
16
+
17
+ export default {
18
+
19
+ // React JSX parsing
20
+ jsx: false,
21
+
22
+ // allow return statement in global scope
23
+ globalReturn: false,
24
+
25
+ // allow implied strict mode
26
+ impliedStrict: false
27
+ };
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @fileoverview A collection of methods for processing Espree's options.
3
+ * @author Kai Cataldo
4
+ */
5
+
6
+ //------------------------------------------------------------------------------
7
+ // Helpers
8
+ //------------------------------------------------------------------------------
9
+
10
+ const SUPPORTED_VERSIONS = [
11
+ 3,
12
+ 5,
13
+ 6, // 2015
14
+ 7, // 2016
15
+ 8, // 2017
16
+ 9, // 2018
17
+ 10, // 2019
18
+ 11, // 2020
19
+ 12, // 2021
20
+ 13, // 2022
21
+ 14, // 2023
22
+ 15 // 2024
23
+ ];
24
+
25
+ /**
26
+ * Get the latest ECMAScript version supported by Espree.
27
+ * @returns {number} The latest ECMAScript version.
28
+ */
29
+ export function getLatestEcmaVersion() {
30
+ return SUPPORTED_VERSIONS[SUPPORTED_VERSIONS.length - 1];
31
+ }
32
+
33
+ /**
34
+ * Get the list of ECMAScript versions supported by Espree.
35
+ * @returns {number[]} An array containing the supported ECMAScript versions.
36
+ */
37
+ export function getSupportedEcmaVersions() {
38
+ return [...SUPPORTED_VERSIONS];
39
+ }
40
+
41
+ /**
42
+ * Normalize ECMAScript version from the initial config
43
+ * @param {(number|"latest")} ecmaVersion ECMAScript version from the initial config
44
+ * @throws {Error} throws an error if the ecmaVersion is invalid.
45
+ * @returns {number} normalized ECMAScript version
46
+ */
47
+ function normalizeEcmaVersion(ecmaVersion = 5) {
48
+
49
+ let version = ecmaVersion === "latest" ? getLatestEcmaVersion() : ecmaVersion;
50
+
51
+ if (typeof version !== "number") {
52
+ throw new Error(`ecmaVersion must be a number or "latest". Received value of type ${typeof ecmaVersion} instead.`);
53
+ }
54
+
55
+ // Calculate ECMAScript edition number from official year version starting with
56
+ // ES2015, which corresponds with ES6 (or a difference of 2009).
57
+ if (version >= 2015) {
58
+ version -= 2009;
59
+ }
60
+
61
+ if (!SUPPORTED_VERSIONS.includes(version)) {
62
+ throw new Error("Invalid ecmaVersion.");
63
+ }
64
+
65
+ return version;
66
+ }
67
+
68
+ /**
69
+ * Normalize sourceType from the initial config
70
+ * @param {string} sourceType to normalize
71
+ * @throws {Error} throw an error if sourceType is invalid
72
+ * @returns {string} normalized sourceType
73
+ */
74
+ function normalizeSourceType(sourceType = "script") {
75
+ if (sourceType === "script" || sourceType === "module") {
76
+ return sourceType;
77
+ }
78
+
79
+ if (sourceType === "commonjs") {
80
+ return "script";
81
+ }
82
+
83
+ throw new Error("Invalid sourceType.");
84
+ }
85
+
86
+ /**
87
+ * Normalize parserOptions
88
+ * @param {Object} options the parser options to normalize
89
+ * @throws {Error} throw an error if found invalid option.
90
+ * @returns {Object} normalized options
91
+ */
92
+ export function normalizeOptions(options) {
93
+ const ecmaVersion = normalizeEcmaVersion(options.ecmaVersion);
94
+ const sourceType = normalizeSourceType(options.sourceType);
95
+ const ranges = options.range === true;
96
+ const locations = options.loc === true;
97
+
98
+ if (ecmaVersion !== 3 && options.allowReserved) {
99
+
100
+ // a value of `false` is intentionally allowed here, so a shared config can overwrite it when needed
101
+ throw new Error("`allowReserved` is only supported when ecmaVersion is 3");
102
+ }
103
+ if (typeof options.allowReserved !== "undefined" && typeof options.allowReserved !== "boolean") {
104
+ throw new Error("`allowReserved`, when present, must be `true` or `false`");
105
+ }
106
+ const allowReserved = ecmaVersion === 3 ? (options.allowReserved || "never") : false;
107
+ const ecmaFeatures = options.ecmaFeatures || {};
108
+ const allowReturnOutsideFunction = options.sourceType === "commonjs" ||
109
+ Boolean(ecmaFeatures.globalReturn);
110
+
111
+ if (sourceType === "module" && ecmaVersion < 6) {
112
+ throw new Error("sourceType 'module' is not supported when ecmaVersion < 2015. Consider adding `{ ecmaVersion: 2015 }` to the parser options.");
113
+ }
114
+
115
+ return Object.assign({}, options, {
116
+ ecmaVersion,
117
+ sourceType,
118
+ ranges,
119
+ locations,
120
+ allowReserved,
121
+ allowReturnOutsideFunction
122
+ });
123
+ }