@openrewrite/rewrite 8.96.3 → 8.96.5

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 (142) hide show
  1. package/dist/execution.d.ts +2 -0
  2. package/dist/execution.d.ts.map +1 -1
  3. package/dist/execution.js +4 -0
  4. package/dist/execution.js.map +1 -1
  5. package/dist/heavyweight.d.ts +8 -0
  6. package/dist/heavyweight.d.ts.map +1 -0
  7. package/dist/heavyweight.js +45 -0
  8. package/dist/heavyweight.js.map +1 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +3 -0
  12. package/dist/index.js.map +1 -1
  13. package/dist/java/tree.d.ts +11 -11
  14. package/dist/java/tree.d.ts.map +1 -1
  15. package/dist/java/visitor.d.ts.map +1 -1
  16. package/dist/java/visitor.js +46 -2
  17. package/dist/java/visitor.js.map +1 -1
  18. package/dist/javascript/add-import.d.ts +2 -1
  19. package/dist/javascript/add-import.d.ts.map +1 -1
  20. package/dist/javascript/add-import.js +14 -2
  21. package/dist/javascript/add-import.js.map +1 -1
  22. package/dist/javascript/amd.d.ts.map +1 -1
  23. package/dist/javascript/amd.js +2 -1
  24. package/dist/javascript/amd.js.map +1 -1
  25. package/dist/javascript/cleanup/add-parse-int-radix.js +1 -1
  26. package/dist/javascript/cleanup/add-parse-int-radix.js.map +1 -1
  27. package/dist/javascript/format/format.d.ts +12 -0
  28. package/dist/javascript/format/format.d.ts.map +1 -1
  29. package/dist/javascript/format/format.js +17 -3
  30. package/dist/javascript/format/format.js.map +1 -1
  31. package/dist/javascript/format/tabs-and-indents-visitor.d.ts.map +1 -1
  32. package/dist/javascript/format/tabs-and-indents-visitor.js +4 -0
  33. package/dist/javascript/format/tabs-and-indents-visitor.js.map +1 -1
  34. package/dist/javascript/format/whitespace-reconciler.d.ts.map +1 -1
  35. package/dist/javascript/format/whitespace-reconciler.js +4 -0
  36. package/dist/javascript/format/whitespace-reconciler.js.map +1 -1
  37. package/dist/javascript/node-resolution-result.d.ts.map +1 -1
  38. package/dist/javascript/node-resolution-result.js +2 -0
  39. package/dist/javascript/node-resolution-result.js.map +1 -1
  40. package/dist/javascript/parser-utils.d.ts.map +1 -1
  41. package/dist/javascript/parser-utils.js +16 -5
  42. package/dist/javascript/parser-utils.js.map +1 -1
  43. package/dist/javascript/templating/engine.d.ts.map +1 -1
  44. package/dist/javascript/templating/engine.js +11 -6
  45. package/dist/javascript/templating/engine.js.map +1 -1
  46. package/dist/javascript/templating/pattern.d.ts.map +1 -1
  47. package/dist/javascript/templating/pattern.js +8 -0
  48. package/dist/javascript/templating/pattern.js.map +1 -1
  49. package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -1
  50. package/dist/javascript/templating/placeholder-replacement.js +15 -0
  51. package/dist/javascript/templating/placeholder-replacement.js.map +1 -1
  52. package/dist/javascript/templating/precedence.js +1 -1
  53. package/dist/javascript/templating/precedence.js.map +1 -1
  54. package/dist/javascript/tree.d.ts +12 -12
  55. package/dist/javascript/tree.d.ts.map +1 -1
  56. package/dist/javascript/visitor.d.ts.map +1 -1
  57. package/dist/javascript/visitor.js +96 -0
  58. package/dist/javascript/visitor.js.map +1 -1
  59. package/dist/recipe.d.ts +5 -0
  60. package/dist/recipe.d.ts.map +1 -1
  61. package/dist/recipe.js +5 -0
  62. package/dist/recipe.js.map +1 -1
  63. package/dist/rewrite-javascript-version.txt +1 -1
  64. package/dist/run.d.ts +7 -1
  65. package/dist/run.d.ts.map +1 -1
  66. package/dist/run.js +40 -2
  67. package/dist/run.js.map +1 -1
  68. package/dist/test/accumulator-contents.d.ts +15 -0
  69. package/dist/test/accumulator-contents.d.ts.map +1 -0
  70. package/dist/test/accumulator-contents.js +185 -0
  71. package/dist/test/accumulator-contents.js.map +1 -0
  72. package/dist/test/empty-sources.d.ts +14 -0
  73. package/dist/test/empty-sources.d.ts.map +1 -0
  74. package/dist/test/empty-sources.js +98 -0
  75. package/dist/test/empty-sources.js.map +1 -0
  76. package/dist/test/formatting-scope.d.ts +18 -0
  77. package/dist/test/formatting-scope.d.ts.map +1 -0
  78. package/dist/test/formatting-scope.js +244 -0
  79. package/dist/test/formatting-scope.js.map +1 -0
  80. package/dist/test/probes.d.ts +25 -0
  81. package/dist/test/probes.d.ts.map +1 -0
  82. package/dist/test/probes.js +189 -0
  83. package/dist/test/probes.js.map +1 -0
  84. package/dist/test/rewrite-test.d.ts +27 -0
  85. package/dist/test/rewrite-test.d.ts.map +1 -1
  86. package/dist/test/rewrite-test.js +191 -21
  87. package/dist/test/rewrite-test.js.map +1 -1
  88. package/dist/test/tree-shapes.d.ts +15 -0
  89. package/dist/test/tree-shapes.d.ts.map +1 -0
  90. package/dist/test/tree-shapes.js +288 -0
  91. package/dist/test/tree-shapes.js.map +1 -0
  92. package/dist/test/unparsed-sources.d.ts +17 -0
  93. package/dist/test/unparsed-sources.d.ts.map +1 -0
  94. package/dist/test/unparsed-sources.js +113 -0
  95. package/dist/test/unparsed-sources.js.map +1 -0
  96. package/dist/tree.d.ts.map +1 -1
  97. package/dist/tree.js +2 -0
  98. package/dist/tree.js.map +1 -1
  99. package/dist/visitor.d.ts.map +1 -1
  100. package/dist/visitor.js +2 -0
  101. package/dist/visitor.js.map +1 -1
  102. package/node_modules/picomatch/LICENSE +21 -0
  103. package/node_modules/picomatch/README.md +743 -0
  104. package/node_modules/picomatch/index.js +17 -0
  105. package/node_modules/picomatch/lib/constants.js +184 -0
  106. package/node_modules/picomatch/lib/parse.js +1506 -0
  107. package/node_modules/picomatch/lib/picomatch.js +361 -0
  108. package/node_modules/picomatch/lib/scan.js +403 -0
  109. package/node_modules/picomatch/lib/utils.js +72 -0
  110. package/node_modules/picomatch/package.json +83 -0
  111. package/node_modules/picomatch/posix.js +3 -0
  112. package/package.json +88 -90
  113. package/src/execution.ts +6 -0
  114. package/src/heavyweight.ts +42 -0
  115. package/src/index.ts +1 -0
  116. package/src/java/tree.ts +11 -11
  117. package/src/java/visitor.ts +52 -2
  118. package/src/javascript/add-import.ts +11 -2
  119. package/src/javascript/amd.ts +4 -2
  120. package/src/javascript/cleanup/add-parse-int-radix.ts +2 -2
  121. package/src/javascript/format/format.ts +25 -1
  122. package/src/javascript/format/tabs-and-indents-visitor.ts +4 -0
  123. package/src/javascript/format/whitespace-reconciler.ts +4 -0
  124. package/src/javascript/node-resolution-result.ts +3 -0
  125. package/src/javascript/parser-utils.ts +19 -7
  126. package/src/javascript/templating/engine.ts +11 -6
  127. package/src/javascript/templating/pattern.ts +10 -0
  128. package/src/javascript/templating/placeholder-replacement.ts +16 -0
  129. package/src/javascript/templating/precedence.ts +1 -1
  130. package/src/javascript/tree.ts +12 -12
  131. package/src/javascript/visitor.ts +120 -0
  132. package/src/recipe.ts +5 -0
  133. package/src/run.ts +30 -2
  134. package/src/test/accumulator-contents.ts +194 -0
  135. package/src/test/empty-sources.ts +99 -0
  136. package/src/test/formatting-scope.ts +231 -0
  137. package/src/test/probes.ts +156 -0
  138. package/src/test/rewrite-test.ts +177 -24
  139. package/src/test/tree-shapes.ts +332 -0
  140. package/src/test/unparsed-sources.ts +138 -0
  141. package/src/tree.ts +3 -0
  142. package/src/visitor.ts +3 -0
@@ -0,0 +1,361 @@
1
+ 'use strict';
2
+
3
+ const scan = require('./scan');
4
+ const parse = require('./parse');
5
+ const utils = require('./utils');
6
+ const constants = require('./constants');
7
+ const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
8
+
9
+ /**
10
+ * Creates a matcher function from one or more glob patterns. The
11
+ * returned function takes a string to match as its first argument,
12
+ * and returns true if the string is a match. The returned matcher
13
+ * function also takes a boolean as the second argument that, when true,
14
+ * returns an object with additional information.
15
+ *
16
+ * ```js
17
+ * const picomatch = require('picomatch');
18
+ * // picomatch(glob[, options]);
19
+ *
20
+ * const isMatch = picomatch('*.!(*a)');
21
+ * console.log(isMatch('a.a')); //=> false
22
+ * console.log(isMatch('a.b')); //=> true
23
+ *
24
+ * // For environments without `node.js`, `picomatch/posix` provides you a dependency-free matcher, without automatic OS detection.
25
+ * const picomatch = require('picomatch/posix');
26
+ * // the same API, defaulting to posix paths
27
+ * const isMatch = picomatch('a/*');
28
+ * console.log(isMatch('a\\b')); //=> false
29
+ * console.log(isMatch('a/b')); //=> true
30
+ *
31
+ * // you can still configure the matcher function to accept windows paths
32
+ * const isMatch = picomatch('a/*', { options: windows });
33
+ * console.log(isMatch('a\\b')); //=> true
34
+ * console.log(isMatch('a/b')); //=> true
35
+ * ```
36
+ * @name picomatch
37
+ * @param {String|Array} `globs` One or more glob patterns.
38
+ * @param {Object=} `options`
39
+ * @return {Function=} Returns a matcher function.
40
+ * @api public
41
+ */
42
+
43
+ const picomatch = (glob, options, returnState = false) => {
44
+ if (Array.isArray(glob)) {
45
+ const fns = glob.map(input => picomatch(input, options, returnState));
46
+ const arrayMatcher = str => {
47
+ for (const isMatch of fns) {
48
+ const state = isMatch(str);
49
+ if (state) return state;
50
+ }
51
+ return false;
52
+ };
53
+ return arrayMatcher;
54
+ }
55
+
56
+ const isState = isObject(glob) && glob.tokens && glob.input;
57
+
58
+ if (glob === '' || (typeof glob !== 'string' && !isState)) {
59
+ throw new TypeError('Expected pattern to be a non-empty string');
60
+ }
61
+
62
+ const opts = options || {};
63
+ const posix = opts.windows;
64
+ const regex = isState
65
+ ? picomatch.compileRe(glob, options)
66
+ : picomatch.makeRe(glob, options, false, true);
67
+
68
+ const state = regex.state;
69
+ delete regex.state;
70
+
71
+ let isIgnored = () => false;
72
+ if (opts.ignore) {
73
+ const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
74
+ isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
75
+ }
76
+
77
+ const matcher = (input, returnObject = false) => {
78
+ const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
79
+ const result = { glob, state, regex, posix, input, output, match, isMatch };
80
+
81
+ if (typeof opts.onResult === 'function') {
82
+ opts.onResult(result);
83
+ }
84
+
85
+ if (isMatch === false) {
86
+ result.isMatch = false;
87
+ return returnObject ? result : false;
88
+ }
89
+
90
+ if (isIgnored(input)) {
91
+ if (typeof opts.onIgnore === 'function') {
92
+ opts.onIgnore(result);
93
+ }
94
+ result.isMatch = false;
95
+ return returnObject ? result : false;
96
+ }
97
+
98
+ if (typeof opts.onMatch === 'function') {
99
+ opts.onMatch(result);
100
+ }
101
+ return returnObject ? result : true;
102
+ };
103
+
104
+ if (returnState) {
105
+ matcher.state = state;
106
+ }
107
+
108
+ return matcher;
109
+ };
110
+
111
+ /**
112
+ * Test `input` with the given `regex`. This is used by the main
113
+ * `picomatch()` function to test the input string.
114
+ *
115
+ * ```js
116
+ * const picomatch = require('picomatch');
117
+ * // picomatch.test(input, regex[, options]);
118
+ *
119
+ * console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
120
+ * // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
121
+ * ```
122
+ * @param {String} `input` String to test.
123
+ * @param {RegExp} `regex`
124
+ * @return {Object} Returns an object with matching info.
125
+ * @api public
126
+ */
127
+
128
+ picomatch.test = (input, regex, options, { glob, posix } = {}) => {
129
+ if (typeof input !== 'string') {
130
+ throw new TypeError('Expected input to be a string');
131
+ }
132
+
133
+ if (input === '') {
134
+ return { isMatch: false, output: '' };
135
+ }
136
+
137
+ const opts = options || {};
138
+ const format = opts.format || (posix ? utils.toPosixSlashes : null);
139
+ let match = input === glob;
140
+ let output = (match && format) ? format(input) : input;
141
+
142
+ if (match === false) {
143
+ output = format ? format(input) : input;
144
+ match = output === glob;
145
+ }
146
+
147
+ if (match === false || opts.capture === true) {
148
+ if (opts.matchBase === true || opts.basename === true) {
149
+ match = picomatch.matchBase(input, regex, options, posix);
150
+ } else {
151
+ match = regex.exec(output);
152
+ }
153
+ }
154
+
155
+ return { isMatch: Boolean(match), match, output };
156
+ };
157
+
158
+ /**
159
+ * Match the basename of a filepath.
160
+ *
161
+ * ```js
162
+ * const picomatch = require('picomatch');
163
+ * // picomatch.matchBase(input, glob[, options]);
164
+ * console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
165
+ * ```
166
+ * @param {String} `input` String to test.
167
+ * @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
168
+ * @return {Boolean}
169
+ * @api public
170
+ */
171
+
172
+ picomatch.matchBase = (input, glob, options, posix = options && options.windows) => {
173
+ const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
174
+ return regex.test(utils.basename(input, { windows: posix }));
175
+ };
176
+
177
+ /**
178
+ * Returns true if **any** of the given glob `patterns` match the specified `string`.
179
+ *
180
+ * ```js
181
+ * const picomatch = require('picomatch');
182
+ * // picomatch.isMatch(string, patterns[, options]);
183
+ *
184
+ * console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
185
+ * console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
186
+ * ```
187
+ * @param {String|Array} str The string to test.
188
+ * @param {String|Array} patterns One or more glob patterns to use for matching.
189
+ * @param {Object} [options] See available [options](#options).
190
+ * @return {Boolean} Returns true if any patterns match `str`
191
+ * @api public
192
+ */
193
+
194
+ picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
195
+
196
+ /**
197
+ * Parse a glob pattern to create the source string for a regular
198
+ * expression.
199
+ *
200
+ * ```js
201
+ * const picomatch = require('picomatch');
202
+ * const result = picomatch.parse(pattern[, options]);
203
+ * ```
204
+ * @param {String} `pattern`
205
+ * @param {Object} `options`
206
+ * @return {Object} Returns an object with useful properties and output to be used as a regex source string.
207
+ * @api public
208
+ */
209
+
210
+ picomatch.parse = (pattern, options) => {
211
+ if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
212
+ return parse(pattern, { ...options, fastpaths: false });
213
+ };
214
+
215
+ /**
216
+ * Scan a glob pattern to separate the pattern into segments.
217
+ *
218
+ * ```js
219
+ * const picomatch = require('picomatch');
220
+ * // picomatch.scan(input[, options]);
221
+ *
222
+ * const result = picomatch.scan('!./foo/*.js');
223
+ * console.log(result);
224
+ * { prefix: '!./',
225
+ * input: '!./foo/*.js',
226
+ * start: 3,
227
+ * base: 'foo',
228
+ * glob: '*.js',
229
+ * isBrace: false,
230
+ * isBracket: false,
231
+ * isGlob: true,
232
+ * isExtglob: false,
233
+ * isGlobstar: false,
234
+ * negated: true }
235
+ * ```
236
+ * @param {String} `input` Glob pattern to scan.
237
+ * @param {Object} `options`
238
+ * @return {Object} Returns an object with
239
+ * @api public
240
+ */
241
+
242
+ picomatch.scan = (input, options) => scan(input, options);
243
+
244
+ /**
245
+ * Compile a regular expression from the `state` object returned by the
246
+ * [parse()](#parse) method.
247
+ *
248
+ * ```js
249
+ * const picomatch = require('picomatch');
250
+ * const state = picomatch.parse('*.js');
251
+ * // picomatch.compileRe(state[, options]);
252
+ *
253
+ * console.log(picomatch.compileRe(state));
254
+ * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
255
+ * ```
256
+ * @param {Object} `state`
257
+ * @param {Object} `options`
258
+ * @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
259
+ * @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
260
+ * @return {RegExp}
261
+ * @api public
262
+ */
263
+
264
+ picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
265
+ if (returnOutput === true) {
266
+ return state.output;
267
+ }
268
+
269
+ const opts = options || {};
270
+ const prepend = opts.contains ? '' : '^';
271
+ const append = opts.contains ? '' : '$';
272
+
273
+ let source = `${prepend}(?:${state.output})${append}`;
274
+ if (state && state.negated === true) {
275
+ source = `^(?!${source}).*$`;
276
+ }
277
+
278
+ const regex = picomatch.toRegex(source, options);
279
+ if (returnState === true) {
280
+ regex.state = state;
281
+ }
282
+
283
+ return regex;
284
+ };
285
+
286
+ /**
287
+ * Create a regular expression from a parsed glob pattern.
288
+ *
289
+ * ```js
290
+ * const picomatch = require('picomatch');
291
+ * // picomatch.makeRe(state[, options]);
292
+ *
293
+ * const result = picomatch.makeRe('*.js');
294
+ * console.log(result);
295
+ * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
296
+ * ```
297
+ * @param {String} `state` The object returned from the `.parse` method.
298
+ * @param {Object} `options`
299
+ * @param {Boolean} `returnOutput` Implementors may use this argument to return the compiled output, instead of a regular expression. This is not exposed on the options to prevent end-users from mutating the result.
300
+ * @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
301
+ * @return {RegExp} Returns a regex created from the given pattern.
302
+ * @api public
303
+ */
304
+
305
+ picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
306
+ if (!input || typeof input !== 'string') {
307
+ throw new TypeError('Expected a non-empty string');
308
+ }
309
+
310
+ let parsed = { negated: false, fastpaths: true };
311
+
312
+ if (options.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
313
+ parsed.output = parse.fastpaths(input, options);
314
+ }
315
+
316
+ if (!parsed.output) {
317
+ parsed = parse(input, options);
318
+ }
319
+
320
+ return picomatch.compileRe(parsed, options, returnOutput, returnState);
321
+ };
322
+
323
+ /**
324
+ * Create a regular expression from the given regex source string.
325
+ *
326
+ * ```js
327
+ * const picomatch = require('picomatch');
328
+ * // picomatch.toRegex(source[, options]);
329
+ *
330
+ * const { output } = picomatch.parse('*.js');
331
+ * console.log(picomatch.toRegex(output));
332
+ * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
333
+ * ```
334
+ * @param {String} `source` Regular expression source string.
335
+ * @param {Object} `options`
336
+ * @return {RegExp}
337
+ * @api public
338
+ */
339
+
340
+ picomatch.toRegex = (source, options) => {
341
+ try {
342
+ const opts = options || {};
343
+ return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
344
+ } catch (err) {
345
+ if (options && options.debug === true) throw err;
346
+ return /$^/;
347
+ }
348
+ };
349
+
350
+ /**
351
+ * Picomatch constants.
352
+ * @return {Object}
353
+ */
354
+
355
+ picomatch.constants = constants;
356
+
357
+ /**
358
+ * Expose "picomatch"
359
+ */
360
+
361
+ module.exports = picomatch;