@thethracian/oxlint-config 0.2.0 → 0.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 (279) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +125 -19
  3. package/dist/codemod-fix/cli.d.ts +3 -0
  4. package/dist/codemod-fix/cli.d.ts.map +1 -0
  5. package/dist/codemod-fix/cli.js +22 -0
  6. package/dist/codemod-fix/cli.js.map +1 -0
  7. package/dist/codemod-fix/index.d.ts +44 -0
  8. package/dist/codemod-fix/index.d.ts.map +1 -0
  9. package/dist/codemod-fix/index.js +110 -0
  10. package/dist/codemod-fix/index.js.map +1 -0
  11. package/dist/codemods/arrow-body-style.d.ts +7 -0
  12. package/dist/codemods/arrow-body-style.d.ts.map +1 -0
  13. package/dist/codemods/arrow-body-style.js +106 -0
  14. package/dist/codemods/arrow-body-style.js.map +1 -0
  15. package/dist/codemods/comment-format.d.ts +24 -0
  16. package/dist/codemods/comment-format.d.ts.map +1 -0
  17. package/dist/codemods/comment-format.js +100 -0
  18. package/dist/codemods/comment-format.js.map +1 -0
  19. package/dist/codemods/explicit-return-types.d.ts +7 -0
  20. package/dist/codemods/explicit-return-types.d.ts.map +1 -0
  21. package/dist/codemods/explicit-return-types.js +350 -0
  22. package/dist/codemods/explicit-return-types.js.map +1 -0
  23. package/dist/codemods/format-file-header.d.ts +7 -0
  24. package/dist/codemods/format-file-header.d.ts.map +1 -0
  25. package/dist/codemods/format-file-header.js +163 -0
  26. package/dist/codemods/format-file-header.js.map +1 -0
  27. package/dist/codemods/format-jsdoc-comments.d.ts +7 -0
  28. package/dist/codemods/format-jsdoc-comments.d.ts.map +1 -0
  29. package/dist/codemods/format-jsdoc-comments.js +129 -0
  30. package/dist/codemods/format-jsdoc-comments.js.map +1 -0
  31. package/dist/codemods/function-declarations.d.ts +7 -0
  32. package/dist/codemods/function-declarations.d.ts.map +1 -0
  33. package/dist/codemods/function-declarations.js +202 -0
  34. package/dist/codemods/function-declarations.js.map +1 -0
  35. package/dist/codemods/inline-export-lists.d.ts +7 -0
  36. package/dist/codemods/inline-export-lists.d.ts.map +1 -0
  37. package/dist/codemods/inline-export-lists.js +168 -0
  38. package/dist/codemods/inline-export-lists.js.map +1 -0
  39. package/dist/codemods/internal-export-docs.d.ts +7 -0
  40. package/dist/codemods/internal-export-docs.d.ts.map +1 -0
  41. package/dist/codemods/internal-export-docs.js +93 -0
  42. package/dist/codemods/internal-export-docs.js.map +1 -0
  43. package/dist/codemods/no-ternary-branch-initializers.d.ts +14 -0
  44. package/dist/codemods/no-ternary-branch-initializers.d.ts.map +1 -0
  45. package/dist/codemods/no-ternary-branch-initializers.js +240 -0
  46. package/dist/codemods/no-ternary-branch-initializers.js.map +1 -0
  47. package/dist/codemods/no-ternary-variable-initializers.d.ts +14 -0
  48. package/dist/codemods/no-ternary-variable-initializers.d.ts.map +1 -0
  49. package/dist/codemods/no-ternary-variable-initializers.js +235 -0
  50. package/dist/codemods/no-ternary-variable-initializers.js.map +1 -0
  51. package/dist/codemods/no-ternary.d.ts +7 -0
  52. package/dist/codemods/no-ternary.d.ts.map +1 -0
  53. package/dist/codemods/no-ternary.js +215 -0
  54. package/dist/codemods/no-ternary.js.map +1 -0
  55. package/dist/codemods/rename-acronyms.d.ts +8 -0
  56. package/dist/codemods/rename-acronyms.d.ts.map +1 -0
  57. package/dist/codemods/rename-acronyms.js +193 -0
  58. package/dist/codemods/rename-acronyms.js.map +1 -0
  59. package/dist/codemods/run.d.ts +2 -0
  60. package/dist/codemods/run.d.ts.map +1 -0
  61. package/dist/codemods/run.js +14 -0
  62. package/dist/codemods/run.js.map +1 -0
  63. package/dist/codemods/sort-imports.d.ts +7 -0
  64. package/dist/codemods/sort-imports.d.ts.map +1 -0
  65. package/dist/codemods/sort-imports.js +235 -0
  66. package/dist/codemods/sort-imports.js.map +1 -0
  67. package/dist/index.d.ts +30 -96
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +157 -95
  70. package/dist/index.js.map +1 -1
  71. package/dist/rules/acronym-case.d.ts +7 -3
  72. package/dist/rules/acronym-case.d.ts.map +1 -1
  73. package/dist/rules/acronym-case.js +129 -120
  74. package/dist/rules/acronym-case.js.map +1 -1
  75. package/dist/rules/acronyms-1.d.ts +3 -0
  76. package/dist/rules/acronyms-1.d.ts.map +1 -0
  77. package/dist/rules/acronyms-1.js +407 -0
  78. package/dist/rules/acronyms-1.js.map +1 -0
  79. package/dist/rules/acronyms-2.d.ts +3 -0
  80. package/dist/rules/acronyms-2.d.ts.map +1 -0
  81. package/dist/rules/acronyms-2.js +407 -0
  82. package/dist/rules/acronyms-2.js.map +1 -0
  83. package/dist/rules/acronyms-3.d.ts +3 -0
  84. package/dist/rules/acronyms-3.d.ts.map +1 -0
  85. package/dist/rules/acronyms-3.js +407 -0
  86. package/dist/rules/acronyms-3.js.map +1 -0
  87. package/dist/rules/acronyms-4.d.ts +3 -0
  88. package/dist/rules/acronyms-4.d.ts.map +1 -0
  89. package/dist/rules/acronyms-4.js +377 -0
  90. package/dist/rules/acronyms-4.js.map +1 -0
  91. package/dist/rules/acronyms.d.ts +1 -8
  92. package/dist/rules/acronyms.d.ts.map +1 -1
  93. package/dist/rules/acronyms.js +14 -1578
  94. package/dist/rules/acronyms.js.map +1 -1
  95. package/dist/rules/boolean-prefix.d.ts +11 -2
  96. package/dist/rules/boolean-prefix.d.ts.map +1 -1
  97. package/dist/rules/boolean-prefix.js +95 -59
  98. package/dist/rules/boolean-prefix.js.map +1 -1
  99. package/dist/rules/camel-case-identifiers.d.ts +3 -4
  100. package/dist/rules/camel-case-identifiers.d.ts.map +1 -1
  101. package/dist/rules/camel-case-identifiers.js +59 -40
  102. package/dist/rules/camel-case-identifiers.js.map +1 -1
  103. package/dist/rules/char-class.d.ts +26 -13
  104. package/dist/rules/char-class.d.ts.map +1 -1
  105. package/dist/rules/char-class.js +56 -24
  106. package/dist/rules/char-class.js.map +1 -1
  107. package/dist/rules/diagnostic-guidance.d.ts +91 -0
  108. package/dist/rules/diagnostic-guidance.d.ts.map +1 -0
  109. package/dist/rules/diagnostic-guidance.js +243 -0
  110. package/dist/rules/diagnostic-guidance.js.map +1 -0
  111. package/dist/rules/effect-default-ast.d.ts +89 -0
  112. package/dist/rules/effect-default-ast.d.ts.map +1 -0
  113. package/dist/rules/effect-default-ast.js +208 -0
  114. package/dist/rules/effect-default-ast.js.map +1 -0
  115. package/dist/rules/effect-default-compat-rules.d.ts +76 -0
  116. package/dist/rules/effect-default-compat-rules.d.ts.map +1 -0
  117. package/dist/rules/effect-default-compat-rules.js +270 -0
  118. package/dist/rules/effect-default-compat-rules.js.map +1 -0
  119. package/dist/rules/effect-default-env-rules.d.ts +60 -0
  120. package/dist/rules/effect-default-env-rules.d.ts.map +1 -0
  121. package/dist/rules/effect-default-env-rules.js +259 -0
  122. package/dist/rules/effect-default-env-rules.js.map +1 -0
  123. package/dist/rules/effect-default-fiber-helpers.d.ts +13 -0
  124. package/dist/rules/effect-default-fiber-helpers.d.ts.map +1 -0
  125. package/dist/rules/effect-default-fiber-helpers.js +76 -0
  126. package/dist/rules/effect-default-fiber-helpers.js.map +1 -0
  127. package/dist/rules/effect-default-floating-helpers.d.ts +7 -0
  128. package/dist/rules/effect-default-floating-helpers.d.ts.map +1 -0
  129. package/dist/rules/effect-default-floating-helpers.js +113 -0
  130. package/dist/rules/effect-default-floating-helpers.js.map +1 -0
  131. package/dist/rules/effect-default-helpers.d.ts +8 -32
  132. package/dist/rules/effect-default-helpers.d.ts.map +1 -1
  133. package/dist/rules/effect-default-helpers.js +11 -458
  134. package/dist/rules/effect-default-helpers.js.map +1 -1
  135. package/dist/rules/effect-default-resource-helpers.d.ts +18 -4
  136. package/dist/rules/effect-default-resource-helpers.d.ts.map +1 -1
  137. package/dist/rules/effect-default-resource-helpers.js +30 -13
  138. package/dist/rules/effect-default-resource-helpers.js.map +1 -1
  139. package/dist/rules/effect-default-safety-helpers.d.ts +43 -0
  140. package/dist/rules/effect-default-safety-helpers.d.ts.map +1 -0
  141. package/dist/rules/effect-default-safety-helpers.js +126 -0
  142. package/dist/rules/effect-default-safety-helpers.js.map +1 -0
  143. package/dist/rules/effect-default-scan-helpers.d.ts +43 -0
  144. package/dist/rules/effect-default-scan-helpers.d.ts.map +1 -0
  145. package/dist/rules/effect-default-scan-helpers.js +141 -0
  146. package/dist/rules/effect-default-scan-helpers.js.map +1 -0
  147. package/dist/rules/effect-default-schema-helpers.d.ts +37 -0
  148. package/dist/rules/effect-default-schema-helpers.d.ts.map +1 -0
  149. package/dist/rules/effect-default-schema-helpers.js +104 -0
  150. package/dist/rules/effect-default-schema-helpers.js.map +1 -0
  151. package/dist/rules/effect-default-test-helpers.d.ts +18 -4
  152. package/dist/rules/effect-default-test-helpers.d.ts.map +1 -1
  153. package/dist/rules/effect-default-test-helpers.js +41 -20
  154. package/dist/rules/effect-default-test-helpers.js.map +1 -1
  155. package/dist/rules/effect-default-workflow-helpers.d.ts +91 -0
  156. package/dist/rules/effect-default-workflow-helpers.d.ts.map +1 -0
  157. package/dist/rules/effect-default-workflow-helpers.js +247 -0
  158. package/dist/rules/effect-default-workflow-helpers.js.map +1 -0
  159. package/dist/rules/effect-default.d.ts +1 -1
  160. package/dist/rules/effect-default.d.ts.map +1 -1
  161. package/dist/rules/effect-default.js +198 -637
  162. package/dist/rules/effect-default.js.map +1 -1
  163. package/dist/rules/effect-exported-declarations.d.ts +19 -0
  164. package/dist/rules/effect-exported-declarations.d.ts.map +1 -0
  165. package/dist/rules/effect-exported-declarations.js +237 -0
  166. package/dist/rules/effect-exported-declarations.js.map +1 -0
  167. package/dist/rules/effect-path-options.d.ts +49 -11
  168. package/dist/rules/effect-path-options.d.ts.map +1 -1
  169. package/dist/rules/effect-path-options.js +85 -52
  170. package/dist/rules/effect-path-options.js.map +1 -1
  171. package/dist/rules/effect-rule-aliases.d.ts +55 -0
  172. package/dist/rules/effect-rule-aliases.d.ts.map +1 -0
  173. package/dist/rules/effect-rule-aliases.js +278 -0
  174. package/dist/rules/effect-rule-aliases.js.map +1 -0
  175. package/dist/rules/effect-rule-core.d.ts +46 -24
  176. package/dist/rules/effect-rule-core.d.ts.map +1 -1
  177. package/dist/rules/effect-rule-core.js +263 -303
  178. package/dist/rules/effect-rule-core.js.map +1 -1
  179. package/dist/rules/effect-rule-names.d.ts +12 -3
  180. package/dist/rules/effect-rule-names.d.ts.map +1 -1
  181. package/dist/rules/effect-rule-names.js +15 -3
  182. package/dist/rules/effect-rule-names.js.map +1 -1
  183. package/dist/rules/effect-source-comments.d.ts +7 -0
  184. package/dist/rules/effect-source-comments.d.ts.map +1 -0
  185. package/dist/rules/effect-source-comments.js +227 -0
  186. package/dist/rules/effect-source-comments.js.map +1 -0
  187. package/dist/rules/effect-source-helpers.d.ts +4 -9
  188. package/dist/rules/effect-source-helpers.d.ts.map +1 -1
  189. package/dist/rules/effect-source-helpers.js +7 -333
  190. package/dist/rules/effect-source-helpers.js.map +1 -1
  191. package/dist/rules/effect-source-navigation.d.ts +25 -0
  192. package/dist/rules/effect-source-navigation.d.ts.map +1 -0
  193. package/dist/rules/effect-source-navigation.js +244 -0
  194. package/dist/rules/effect-source-navigation.js.map +1 -0
  195. package/dist/rules/effect-source-scan.d.ts +30 -7
  196. package/dist/rules/effect-source-scan.d.ts.map +1 -1
  197. package/dist/rules/effect-source-scan.js +377 -297
  198. package/dist/rules/effect-source-scan.js.map +1 -1
  199. package/dist/rules/effect-strict-ast-specs.d.ts +8 -0
  200. package/dist/rules/effect-strict-ast-specs.d.ts.map +1 -0
  201. package/dist/rules/effect-strict-ast-specs.js +166 -0
  202. package/dist/rules/effect-strict-ast-specs.js.map +1 -0
  203. package/dist/rules/effect-strict-boundary-helpers.d.ts +25 -0
  204. package/dist/rules/effect-strict-boundary-helpers.d.ts.map +1 -0
  205. package/dist/rules/effect-strict-boundary-helpers.js +127 -0
  206. package/dist/rules/effect-strict-boundary-helpers.js.map +1 -0
  207. package/dist/rules/effect-strict-core-specs.d.ts +8 -0
  208. package/dist/rules/effect-strict-core-specs.d.ts.map +1 -0
  209. package/dist/rules/effect-strict-core-specs.js +334 -0
  210. package/dist/rules/effect-strict-core-specs.js.map +1 -0
  211. package/dist/rules/effect-strict-external-helpers.d.ts +25 -0
  212. package/dist/rules/effect-strict-external-helpers.d.ts.map +1 -0
  213. package/dist/rules/effect-strict-external-helpers.js +87 -0
  214. package/dist/rules/effect-strict-external-helpers.js.map +1 -0
  215. package/dist/rules/effect-strict-helpers.d.ts +75 -33
  216. package/dist/rules/effect-strict-helpers.d.ts.map +1 -1
  217. package/dist/rules/effect-strict-helpers.js +124 -246
  218. package/dist/rules/effect-strict-helpers.js.map +1 -1
  219. package/dist/rules/effect-strict-internals.d.ts +198 -0
  220. package/dist/rules/effect-strict-internals.d.ts.map +1 -0
  221. package/dist/rules/effect-strict-internals.js +477 -0
  222. package/dist/rules/effect-strict-internals.js.map +1 -0
  223. package/dist/rules/effect-strict-segment-helpers.d.ts +79 -0
  224. package/dist/rules/effect-strict-segment-helpers.d.ts.map +1 -0
  225. package/dist/rules/effect-strict-segment-helpers.js +308 -0
  226. package/dist/rules/effect-strict-segment-helpers.js.map +1 -0
  227. package/dist/rules/effect-strict.d.ts +1 -1
  228. package/dist/rules/effect-strict.d.ts.map +1 -1
  229. package/dist/rules/effect-strict.js +10 -661
  230. package/dist/rules/effect-strict.js.map +1 -1
  231. package/dist/rules/max-import-depth.d.ts +2 -2
  232. package/dist/rules/max-import-depth.d.ts.map +1 -1
  233. package/dist/rules/max-import-depth.js +52 -17
  234. package/dist/rules/max-import-depth.js.map +1 -1
  235. package/dist/rules/max-line-length.d.ts +9 -2
  236. package/dist/rules/max-line-length.d.ts.map +1 -1
  237. package/dist/rules/max-line-length.js +62 -7
  238. package/dist/rules/max-line-length.js.map +1 -1
  239. package/dist/rules/no-commented-out-code.d.ts +3 -7
  240. package/dist/rules/no-commented-out-code.d.ts.map +1 -1
  241. package/dist/rules/no-commented-out-code.js +157 -102
  242. package/dist/rules/no-commented-out-code.js.map +1 -1
  243. package/dist/rules/pascal-case-types.d.ts +1 -1
  244. package/dist/rules/pascal-case-types.d.ts.map +1 -1
  245. package/dist/rules/pascal-case-types.js +65 -46
  246. package/dist/rules/pascal-case-types.js.map +1 -1
  247. package/dist/rules/plugin-commented-out-code-rule.d.ts +32 -0
  248. package/dist/rules/plugin-commented-out-code-rule.d.ts.map +1 -0
  249. package/dist/rules/plugin-commented-out-code-rule.js +135 -0
  250. package/dist/rules/plugin-commented-out-code-rule.js.map +1 -0
  251. package/dist/rules/plugin.d.ts +3 -121
  252. package/dist/rules/plugin.d.ts.map +1 -1
  253. package/dist/rules/plugin.js +195 -201
  254. package/dist/rules/plugin.js.map +1 -1
  255. package/dist/rules/private-underscore.d.ts +1 -1
  256. package/dist/rules/private-underscore.d.ts.map +1 -1
  257. package/dist/rules/private-underscore.js +11 -4
  258. package/dist/rules/private-underscore.js.map +1 -1
  259. package/dist/rules/require-file-doc.d.ts +5 -6
  260. package/dist/rules/require-file-doc.d.ts.map +1 -1
  261. package/dist/rules/require-file-doc.js +127 -78
  262. package/dist/rules/require-file-doc.js.map +1 -1
  263. package/dist/rules/require-function-doc-ignored-text.d.ts +7 -0
  264. package/dist/rules/require-function-doc-ignored-text.d.ts.map +1 -0
  265. package/dist/rules/require-function-doc-ignored-text.js +67 -0
  266. package/dist/rules/require-function-doc-ignored-text.js.map +1 -0
  267. package/dist/rules/require-function-doc-local-exports.d.ts +7 -0
  268. package/dist/rules/require-function-doc-local-exports.d.ts.map +1 -0
  269. package/dist/rules/require-function-doc-local-exports.js +114 -0
  270. package/dist/rules/require-function-doc-local-exports.js.map +1 -0
  271. package/dist/rules/require-function-doc.d.ts +3 -18
  272. package/dist/rules/require-function-doc.d.ts.map +1 -1
  273. package/dist/rules/require-function-doc.js +404 -218
  274. package/dist/rules/require-function-doc.js.map +1 -1
  275. package/dist/rules/source-cache.d.ts +19 -0
  276. package/dist/rules/source-cache.d.ts.map +1 -0
  277. package/dist/rules/source-cache.js +63 -0
  278. package/dist/rules/source-cache.js.map +1 -0
  279. package/package.json +15 -10
@@ -1,17 +1,213 @@
1
+ /* -------------------------------------------------------------------------- */
2
+ /* Source scanning utilities for Effect lint rules. */
3
+ /* -------------------------------------------------------------------------- */
4
+ import { CHAR_CLASS, CLS_DIGIT, CLS_LOWER, CLS_UNDER, CLS_UPPER } from './char-class.js';
1
5
  const regexPrefixChars = new Set(['(', '[', '{', '=', ':', ',', ';', '!', '?', '&', '|']);
2
6
  const regexPrefixWords = new Set(['case', 'delete', 'return', 'throw', 'typeof', 'void', 'yield']);
3
7
  const STRIP_CACHE_MAX = 256;
4
- const commentCache = new Map();
5
8
  const codeOnlyCache = new Map();
6
- function cached(cache, source) {
7
- const value = cache.get(source);
8
- if (value !== undefined) {
9
- cache.delete(source);
10
- cache.set(source, value);
9
+ const IDENTIFIER_MASK = CLS_UPPER | CLS_LOWER | CLS_DIGIT | CLS_UNDER;
10
+ const CHAR_CODE_SPACE = 32;
11
+ const CHAR_CODE_TAB = 9;
12
+ const CHAR_CODE_NEWLINE = 10;
13
+ const CHAR_CODE_CARRIAGE_RETURN = 13;
14
+ const CHAR_CODE_VERTICAL_TAB = 11;
15
+ const CHAR_CODE_FORM_FEED = 12;
16
+ const CHAR_CODE_DOLLAR = 36;
17
+ const isWhitespaceCode = (code) => code === CHAR_CODE_SPACE ||
18
+ code === CHAR_CODE_TAB ||
19
+ code === CHAR_CODE_NEWLINE ||
20
+ code === CHAR_CODE_CARRIAGE_RETURN ||
21
+ code === CHAR_CODE_VERTICAL_TAB ||
22
+ code === CHAR_CODE_FORM_FEED;
23
+ const appendNewlineOrBlank = (output, char) => {
24
+ if (char === '\n') {
25
+ return output + char;
11
26
  }
12
- return value;
13
- }
14
- function cacheResult(cache, source, value) {
27
+ return `${output} `;
28
+ };
29
+ const appendPreservedOrBlank = (output, shouldPreserve, char) => {
30
+ if (shouldPreserve) {
31
+ return output + char;
32
+ }
33
+ return `${output} `;
34
+ };
35
+ const lineCommentStep = (state, char) => {
36
+ if (char === '\n') {
37
+ return {
38
+ ...state,
39
+ isLineComment: false,
40
+ stripped: state.stripped + char,
41
+ };
42
+ }
43
+ return {
44
+ ...state,
45
+ stripped: `${state.stripped} `,
46
+ };
47
+ };
48
+ const blockCommentStep = (state, char, nextChar) => {
49
+ if (char === '*' && nextChar === '/') {
50
+ return {
51
+ ...state,
52
+ index: state.index + 1,
53
+ isBlockComment: false,
54
+ stripped: `${state.stripped} `,
55
+ };
56
+ }
57
+ return {
58
+ ...state,
59
+ stripped: appendNewlineOrBlank(state.stripped, char),
60
+ };
61
+ };
62
+ const templateInterpolationStartStep = (state) => ({
63
+ ...state,
64
+ index: state.index + 1,
65
+ quote: '',
66
+ stripped: `${state.stripped} `,
67
+ templateExpressionDepth: state.templateExpressionDepth + 1,
68
+ });
69
+ const quotedStep = (state, char, nextChar) => {
70
+ const shouldPreserve = char === '\n';
71
+ if (state.quote === '`' && char === '$' && nextChar === '{' && !state.isEscaped) {
72
+ return templateInterpolationStartStep(state);
73
+ }
74
+ if (state.isEscaped) {
75
+ return {
76
+ ...state,
77
+ isEscaped: false,
78
+ stripped: appendNewlineOrBlank(state.stripped, char),
79
+ };
80
+ }
81
+ if (char === '\\') {
82
+ return {
83
+ ...state,
84
+ isEscaped: true,
85
+ stripped: appendNewlineOrBlank(state.stripped, char),
86
+ };
87
+ }
88
+ if (char === state.quote) {
89
+ return {
90
+ ...state,
91
+ quote: '',
92
+ stripped: state.stripped + char,
93
+ };
94
+ }
95
+ return {
96
+ ...state,
97
+ stripped: appendPreservedOrBlank(state.stripped, shouldPreserve || char === state.quote, char),
98
+ };
99
+ };
100
+ const templateBraceStep = (state, char) => {
101
+ if (state.templateExpressionDepth <= 0) {
102
+ return undefined;
103
+ }
104
+ if (char === '{') {
105
+ return {
106
+ ...state,
107
+ stripped: state.stripped + char,
108
+ templateExpressionDepth: state.templateExpressionDepth + 1,
109
+ };
110
+ }
111
+ if (char !== '}') {
112
+ return undefined;
113
+ }
114
+ const templateExpressionDepth = state.templateExpressionDepth - 1;
115
+ if (templateExpressionDepth === 0) {
116
+ return {
117
+ ...state,
118
+ quote: '`',
119
+ stripped: `${state.stripped} `,
120
+ templateExpressionDepth,
121
+ };
122
+ }
123
+ return {
124
+ ...state,
125
+ stripped: state.stripped + char,
126
+ templateExpressionDepth,
127
+ };
128
+ };
129
+ const codeStep = (source, state, char, nextChar) => {
130
+ if (char === '/' && nextChar === '/') {
131
+ return {
132
+ ...state,
133
+ index: state.index + 1,
134
+ isLineComment: true,
135
+ stripped: `${state.stripped} `,
136
+ };
137
+ }
138
+ if (char === '/' && nextChar === '*') {
139
+ return {
140
+ ...state,
141
+ index: state.index + 1,
142
+ isBlockComment: true,
143
+ stripped: `${state.stripped} `,
144
+ };
145
+ }
146
+ if (isREGEXLiteralStart(source, state.index)) {
147
+ const endIndex = findREGEXLiteralEnd(source, state.index);
148
+ return {
149
+ ...state,
150
+ index: endIndex,
151
+ stripped: state.stripped + ' '.repeat(endIndex - state.index + 1),
152
+ };
153
+ }
154
+ if (char === '"' || char === "'" || char === '`') {
155
+ return { ...state, quote: char, stripped: state.stripped + char };
156
+ }
157
+ return { ...state, stripped: state.stripped + char };
158
+ };
159
+ const stripCodeOnlyStep = (source, state) => {
160
+ const char = source[state.index];
161
+ const nextChar = source[state.index + 1];
162
+ if (state.isLineComment) {
163
+ return lineCommentStep(state, char);
164
+ }
165
+ if (state.isBlockComment) {
166
+ return blockCommentStep(state, char, nextChar);
167
+ }
168
+ if (state.quote) {
169
+ return quotedStep(state, char, nextChar);
170
+ }
171
+ return templateBraceStep(state, char) ?? codeStep(source, state, char, nextChar);
172
+ };
173
+ const initialStripState = () => ({
174
+ index: 0,
175
+ isBlockComment: false,
176
+ isEscaped: false,
177
+ isLineComment: false,
178
+ quote: '',
179
+ stripped: '',
180
+ templateExpressionDepth: 0,
181
+ });
182
+ const isASCIIIdentifierChar = (source, index) => {
183
+ const code = source.charCodeAt(index);
184
+ return (code === CHAR_CODE_DOLLAR ||
185
+ (code < CHAR_CLASS.length && (CHAR_CLASS[code] & IDENTIFIER_MASK) !== 0));
186
+ };
187
+ const isASCIILetter = (source, index) => {
188
+ const code = source.charCodeAt(index);
189
+ return code < CHAR_CLASS.length && (CHAR_CLASS[code] & (CLS_UPPER | CLS_LOWER)) !== 0;
190
+ };
191
+ const quoteStart = (char) => {
192
+ if (char === '"' || char === "'" || char === '`') {
193
+ return char;
194
+ }
195
+ return '';
196
+ };
197
+ const nextQuoteState = (state, char) => {
198
+ if (state.isEscaped) {
199
+ return { ...state, isEscaped: false };
200
+ }
201
+ if (char === '\\') {
202
+ return { ...state, isEscaped: true };
203
+ }
204
+ if (char === state.quote) {
205
+ return { isEscaped: false, quote: '' };
206
+ }
207
+ return state;
208
+ };
209
+ const cached = (cache, source) => cache.get(source);
210
+ const cacheResult = (cache, source, value) => {
15
211
  if (cache.size >= STRIP_CACHE_MAX) {
16
212
  const firstKey = cache.keys().next().value;
17
213
  if (firstKey !== undefined) {
@@ -20,27 +216,32 @@ function cacheResult(cache, source, value) {
20
216
  }
21
217
  cache.set(source, value);
22
218
  return value;
23
- }
24
- function previousSignificantIndex(source, index) {
219
+ };
220
+ const previousSignificantIndex = (source, index) => {
25
221
  for (let cursor = index - 1; cursor >= 0; cursor--) {
26
- if (!/\s/.test(source[cursor])) {
222
+ if (!isWhitespaceCode(source.charCodeAt(cursor))) {
27
223
  return cursor;
28
224
  }
29
225
  }
30
226
  return -1;
31
- }
32
- function wordBefore(source, index) {
227
+ };
228
+ const wordBefore = (source, index) => {
33
229
  const endIndex = previousSignificantIndex(source, index);
34
- if (endIndex === -1 || !/[\w$]/.test(source[endIndex])) {
230
+ if (endIndex === -1 || !isASCIIIdentifierChar(source, endIndex)) {
35
231
  return '';
36
232
  }
37
233
  let startIndex = endIndex;
38
- while (startIndex > 0 && /[\w$]/.test(source[startIndex - 1])) {
234
+ while (startIndex > 0 && isASCIIIdentifierChar(source, startIndex - 1)) {
39
235
  startIndex--;
40
236
  }
41
237
  return source.slice(startIndex, endIndex + 1);
42
- }
43
- function isRegexLiteralStart(source, index) {
238
+ };
239
+ /**
240
+ * Internal helper exported for package-local composition.
241
+ *
242
+ * @internal
243
+ */
244
+ export const isREGEXLiteralStart = (source, index) => {
44
245
  if (source[index] !== '/' || source[index + 1] === '/' || source[index + 1] === '*') {
45
246
  return false;
46
247
  }
@@ -49,308 +250,187 @@ function isRegexLiteralStart(source, index) {
49
250
  return true;
50
251
  }
51
252
  return (regexPrefixChars.has(source[previousIndex]) || regexPrefixWords.has(wordBefore(source, index)));
52
- }
53
- function findRegexLiteralEnd(source, startIndex) {
253
+ };
254
+ const regexFlagsEndIndex = (source, index) => {
255
+ let flagsEndIndex = index;
256
+ while (isASCIILetter(source, flagsEndIndex + 1)) {
257
+ flagsEndIndex++;
258
+ }
259
+ return flagsEndIndex;
260
+ };
261
+ const scanREGEXDelimiter = (source, index, isCharacterClass) => {
262
+ const char = source[index];
263
+ if (char === '\n') {
264
+ return { endIndex: -1, isCharacterClass, isEscaped: false };
265
+ }
266
+ if (char === '/' && !isCharacterClass) {
267
+ return { endIndex: regexFlagsEndIndex(source, index), isCharacterClass, isEscaped: false };
268
+ }
269
+ return undefined;
270
+ };
271
+ const scanREGEXCharacterClass = (char, isCharacterClass) => {
272
+ if (char === '[') {
273
+ return { isCharacterClass: true, isEscaped: false };
274
+ }
275
+ if (char === ']') {
276
+ return { isCharacterClass: false, isEscaped: false };
277
+ }
278
+ return { isCharacterClass, isEscaped: false };
279
+ };
280
+ const scanREGEXLiteralChar = (source, index, isEscaped, isCharacterClass) => {
281
+ const char = source[index];
282
+ if (isEscaped) {
283
+ return { isCharacterClass, isEscaped: false };
284
+ }
285
+ if (char === '\\') {
286
+ return { isCharacterClass, isEscaped: true };
287
+ }
288
+ const delimiter = scanREGEXDelimiter(source, index, isCharacterClass);
289
+ if (delimiter) {
290
+ return delimiter;
291
+ }
292
+ return scanREGEXCharacterClass(char, isCharacterClass);
293
+ };
294
+ /**
295
+ * Internal helper exported for package-local composition.
296
+ *
297
+ * @internal
298
+ */
299
+ export const findREGEXLiteralEnd = (source, startIndex) => {
54
300
  let isEscaped = false;
55
301
  let isCharacterClass = false;
56
302
  for (let index = startIndex + 1; index < source.length; index++) {
57
- const char = source[index];
58
- if (isEscaped) {
59
- isEscaped = false;
60
- continue;
61
- }
62
- if (char === '\\') {
63
- isEscaped = true;
64
- continue;
65
- }
66
- if (char === '[') {
67
- isCharacterClass = true;
68
- continue;
69
- }
70
- if (char === ']') {
71
- isCharacterClass = false;
72
- continue;
73
- }
74
- if (char === '\n') {
303
+ const result = scanREGEXLiteralChar(source, index, isEscaped, isCharacterClass);
304
+ if (result.endIndex === -1) {
75
305
  return startIndex;
76
306
  }
77
- if (char === '/' && !isCharacterClass) {
78
- let flagsEndIndex = index;
79
- while (/[a-z]/i.test(source[flagsEndIndex + 1] ?? '')) {
80
- flagsEndIndex++;
81
- }
82
- return flagsEndIndex;
307
+ if (result.endIndex !== undefined) {
308
+ return result.endIndex;
83
309
  }
310
+ ({ isCharacterClass, isEscaped } = result);
84
311
  }
85
312
  return startIndex;
86
- }
87
- function findBalancedCallEnd(source, openParenIndex) {
313
+ };
314
+ const skipLineCommentIndex = (source, index) => {
315
+ const newlineIndex = source.indexOf('\n', index + 2);
316
+ if (newlineIndex === -1) {
317
+ return source.length;
318
+ }
319
+ return newlineIndex;
320
+ };
321
+ const skipBlockCommentIndex = (source, index) => {
322
+ const commentEnd = source.indexOf('*/', index + 2);
323
+ if (commentEnd === -1) {
324
+ return source.length;
325
+ }
326
+ return commentEnd + 1;
327
+ };
328
+ const skipNonCodeIndex = (source, index) => {
329
+ const char = source[index];
330
+ const nextChar = source[index + 1];
331
+ if (char === '/' && nextChar === '/') {
332
+ return skipLineCommentIndex(source, index);
333
+ }
334
+ if (char === '/' && nextChar === '*') {
335
+ return skipBlockCommentIndex(source, index);
336
+ }
337
+ if (isREGEXLiteralStart(source, index)) {
338
+ return findREGEXLiteralEnd(source, index);
339
+ }
340
+ return undefined;
341
+ };
342
+ const quoteOrNonCodeScan = (source, index, quoteState) => {
343
+ const char = source[index];
344
+ if (quoteState.quote) {
345
+ return { index, quoteState: nextQuoteState(quoteState, char) };
346
+ }
347
+ const quote = quoteStart(char);
348
+ if (quote) {
349
+ return { index, quoteState: { isEscaped: false, quote } };
350
+ }
351
+ const nonCodeIndex = skipNonCodeIndex(source, index);
352
+ if (nonCodeIndex !== undefined) {
353
+ return { index: nonCodeIndex, quoteState };
354
+ }
355
+ return undefined;
356
+ };
357
+ const nextBalancedCallScan = (source, index, depth, quoteState) => {
358
+ const quoteOrNonCode = quoteOrNonCodeScan(source, index, quoteState);
359
+ if (quoteOrNonCode) {
360
+ return { ...quoteOrNonCode, depth, isEnd: false };
361
+ }
362
+ const char = source[index];
363
+ if (char === '(') {
364
+ return { depth: depth + 1, index, isEnd: false, quoteState };
365
+ }
366
+ if (char !== ')') {
367
+ return { depth, index, isEnd: false, quoteState };
368
+ }
369
+ return { depth: depth - 1, index, isEnd: depth - 1 === 0, quoteState };
370
+ };
371
+ /**
372
+ * Internal helper exported for package-local composition.
373
+ *
374
+ * @internal
375
+ */
376
+ export const findBalancedCallEnd = (source, openParenIndex) => {
88
377
  let depth = 0;
89
- let quote = '';
90
- let isEscaped = false;
378
+ let quoteState = { isEscaped: false, quote: '' };
91
379
  for (let index = openParenIndex; index < source.length; index++) {
92
- const char = source[index];
93
- const nextChar = source[index + 1];
94
- if (quote) {
95
- if (isEscaped) {
96
- isEscaped = false;
97
- }
98
- else if (char === '\\') {
99
- isEscaped = true;
100
- }
101
- else if (char === quote) {
102
- quote = '';
103
- }
104
- continue;
105
- }
106
- if (char === '/' && nextChar === '/') {
107
- const newlineIndex = source.indexOf('\n', index + 2);
108
- index = newlineIndex === -1 ? source.length : newlineIndex;
109
- continue;
110
- }
111
- if (char === '/' && nextChar === '*') {
112
- const commentEnd = source.indexOf('*/', index + 2);
113
- index = commentEnd === -1 ? source.length : commentEnd + 1;
114
- continue;
115
- }
116
- if (isRegexLiteralStart(source, index)) {
117
- index = findRegexLiteralEnd(source, index);
118
- continue;
119
- }
120
- if (char === '"' || char === "'" || char === '`') {
121
- quote = char;
122
- continue;
123
- }
124
- if (char === '(') {
125
- depth++;
126
- }
127
- else if (char === ')') {
128
- depth--;
129
- if (depth === 0) {
130
- return index;
131
- }
380
+ const next = nextBalancedCallScan(source, index, depth, quoteState);
381
+ if (next.isEnd) {
382
+ return index;
132
383
  }
384
+ ({ depth, index, quoteState } = next);
133
385
  }
134
386
  return source.length - 1;
135
- }
136
- function stripComments(source) {
137
- const cachedValue = cached(commentCache, source);
138
- if (cachedValue !== undefined) {
139
- return cachedValue;
387
+ };
388
+ const nextBraceScan = (source, index, depth, quoteState) => {
389
+ const quoteOrNonCode = quoteOrNonCodeScan(source, index, quoteState);
390
+ if (quoteOrNonCode) {
391
+ return { ...quoteOrNonCode, depth, isEnd: false };
140
392
  }
141
- let stripped = '';
142
- let quote = '';
143
- let isEscaped = false;
144
- let isLineComment = false;
145
- let isBlockComment = false;
146
- for (let index = 0; index < source.length; index++) {
147
- const char = source[index];
148
- const nextChar = source[index + 1];
149
- if (isLineComment) {
150
- if (char === '\n') {
151
- isLineComment = false;
152
- stripped += char;
153
- }
154
- else {
155
- stripped += ' ';
156
- }
157
- continue;
158
- }
159
- if (isBlockComment) {
160
- if (char === '*' && nextChar === '/') {
161
- isBlockComment = false;
162
- stripped += ' ';
163
- index++;
164
- }
165
- else {
166
- stripped += char === '\n' ? char : ' ';
167
- }
168
- continue;
169
- }
170
- if (quote) {
171
- if (isEscaped) {
172
- isEscaped = false;
173
- }
174
- else if (char === '\\') {
175
- isEscaped = true;
176
- }
177
- else if (char === quote) {
178
- quote = '';
179
- }
180
- stripped += char;
181
- continue;
182
- }
183
- if (char === '/' && nextChar === '/') {
184
- isLineComment = true;
185
- stripped += ' ';
186
- index++;
187
- continue;
188
- }
189
- if (char === '/' && nextChar === '*') {
190
- isBlockComment = true;
191
- stripped += ' ';
192
- index++;
193
- continue;
194
- }
195
- if (isRegexLiteralStart(source, index)) {
196
- const endIndex = findRegexLiteralEnd(source, index);
197
- stripped += source.slice(index, endIndex + 1);
198
- index = endIndex;
199
- continue;
200
- }
201
- if (char === '"' || char === "'" || char === '`') {
202
- quote = char;
203
- }
204
- stripped += char;
393
+ const char = source[index];
394
+ if (char === '{') {
395
+ return { depth: depth + 1, index, isEnd: false, quoteState };
205
396
  }
206
- return cacheResult(commentCache, source, stripped);
207
- }
208
- function stripCommentsAndStrings(source) {
397
+ if (char !== '}') {
398
+ return { depth, index, isEnd: false, quoteState };
399
+ }
400
+ return { depth: depth - 1, index, isEnd: depth - 1 === 0, quoteState };
401
+ };
402
+ /**
403
+ * Internal helper exported for package-local composition.
404
+ *
405
+ * @internal
406
+ */
407
+ export const stripCommentsAndStrings = (source) => {
209
408
  const cachedValue = cached(codeOnlyCache, source);
210
409
  if (cachedValue !== undefined) {
211
410
  return cachedValue;
212
411
  }
213
- let stripped = '';
214
- let quote = '';
215
- let isEscaped = false;
216
- let isLineComment = false;
217
- let isBlockComment = false;
218
- let templateExpressionDepth = 0;
219
- for (let index = 0; index < source.length; index++) {
220
- const char = source[index];
221
- const nextChar = source[index + 1];
222
- if (isLineComment) {
223
- if (char === '\n') {
224
- isLineComment = false;
225
- stripped += char;
226
- }
227
- else {
228
- stripped += ' ';
229
- }
230
- continue;
231
- }
232
- if (isBlockComment) {
233
- if (char === '*' && nextChar === '/') {
234
- isBlockComment = false;
235
- stripped += ' ';
236
- index++;
237
- }
238
- else {
239
- stripped += char === '\n' ? char : ' ';
240
- }
241
- continue;
242
- }
243
- if (quote) {
244
- const currentQuote = quote;
245
- let shouldPreserve = char === '\n';
246
- if (quote === '`' && char === '$' && nextChar === '{' && !isEscaped) {
247
- templateExpressionDepth++;
248
- quote = '';
249
- stripped += ' ';
250
- index++;
251
- continue;
252
- }
253
- if (isEscaped) {
254
- isEscaped = false;
255
- }
256
- else if (char === '\\') {
257
- isEscaped = true;
258
- }
259
- else if (char === quote) {
260
- shouldPreserve = true;
261
- quote = '';
262
- }
263
- stripped += shouldPreserve || char === currentQuote ? char : ' ';
264
- continue;
265
- }
266
- if (templateExpressionDepth > 0) {
267
- if (char === '{') {
268
- templateExpressionDepth++;
269
- }
270
- else if (char === '}') {
271
- templateExpressionDepth--;
272
- if (templateExpressionDepth === 0) {
273
- stripped += ' ';
274
- quote = '`';
275
- continue;
276
- }
277
- }
278
- }
279
- if (char === '/' && nextChar === '/') {
280
- isLineComment = true;
281
- stripped += ' ';
282
- index++;
283
- continue;
284
- }
285
- if (char === '/' && nextChar === '*') {
286
- isBlockComment = true;
287
- stripped += ' ';
288
- index++;
289
- continue;
290
- }
291
- if (isRegexLiteralStart(source, index)) {
292
- const endIndex = findRegexLiteralEnd(source, index);
293
- stripped += ' '.repeat(endIndex - index + 1);
294
- index = endIndex;
295
- continue;
296
- }
297
- if (char === '"' || char === "'" || char === '`') {
298
- quote = char;
299
- stripped += char;
300
- continue;
301
- }
302
- stripped += char;
412
+ let state = initialStripState();
413
+ while (state.index < source.length) {
414
+ const stepped = stripCodeOnlyStep(source, state);
415
+ state = { ...stepped, index: stepped.index + 1 };
303
416
  }
304
- return cacheResult(codeOnlyCache, source, stripped);
305
- }
306
- function findMatchingBrace(source, openIndex) {
417
+ return cacheResult(codeOnlyCache, source, state.stripped);
418
+ };
419
+ /**
420
+ * Internal helper exported for package-local composition.
421
+ *
422
+ * @internal
423
+ */
424
+ export const findMatchingBrace = (source, openIndex) => {
307
425
  let depth = 0;
308
- let quote = '';
309
- let isEscaped = false;
426
+ let quoteState = { isEscaped: false, quote: '' };
310
427
  for (let index = openIndex; index < source.length; index++) {
311
- const char = source[index];
312
- const nextChar = source[index + 1];
313
- if (quote) {
314
- if (isEscaped) {
315
- isEscaped = false;
316
- }
317
- else if (char === '\\') {
318
- isEscaped = true;
319
- }
320
- else if (char === quote) {
321
- quote = '';
322
- }
323
- continue;
324
- }
325
- if (char === '/' && nextChar === '/') {
326
- const newlineIndex = source.indexOf('\n', index + 2);
327
- index = newlineIndex === -1 ? source.length : newlineIndex;
328
- continue;
329
- }
330
- if (char === '/' && nextChar === '*') {
331
- const commentEnd = source.indexOf('*/', index + 2);
332
- index = commentEnd === -1 ? source.length : commentEnd + 1;
333
- continue;
334
- }
335
- if (isRegexLiteralStart(source, index)) {
336
- index = findRegexLiteralEnd(source, index);
337
- continue;
338
- }
339
- if (char === '"' || char === "'" || char === '`') {
340
- quote = char;
341
- continue;
342
- }
343
- if (char === '{') {
344
- depth++;
345
- }
346
- else if (char === '}') {
347
- depth--;
348
- if (depth === 0) {
349
- return index;
350
- }
428
+ const next = nextBraceScan(source, index, depth, quoteState);
429
+ if (next.isEnd) {
430
+ return index;
351
431
  }
432
+ ({ depth, index, quoteState } = next);
352
433
  }
353
434
  return -1;
354
- }
355
- export { findBalancedCallEnd, findMatchingBrace, findRegexLiteralEnd, isRegexLiteralStart, stripComments, stripCommentsAndStrings, };
435
+ };
356
436
  //# sourceMappingURL=effect-source-scan.js.map