@openrewrite/rewrite 8.69.0 → 8.69.1
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.
- package/dist/java/type.d.ts +5 -0
- package/dist/java/type.d.ts.map +1 -1
- package/dist/java/type.js +12 -0
- package/dist/java/type.js.map +1 -1
- package/dist/javascript/assertions.d.ts.map +1 -1
- package/dist/javascript/assertions.js +9 -0
- package/dist/javascript/assertions.js.map +1 -1
- package/dist/javascript/comparator.d.ts.map +1 -1
- package/dist/javascript/comparator.js +5 -9
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/{format.d.ts → format/format.d.ts} +15 -33
- package/dist/javascript/format/format.d.ts.map +1 -0
- package/dist/javascript/{format.js → format/format.js} +56 -313
- package/dist/javascript/format/format.js.map +1 -0
- package/dist/javascript/format/index.d.ts +3 -0
- package/dist/javascript/format/index.d.ts.map +1 -0
- package/dist/javascript/format/index.js +38 -0
- package/dist/javascript/format/index.js.map +1 -0
- package/dist/javascript/format/minimum-viable-spacing-visitor.d.ts +28 -0
- package/dist/javascript/format/minimum-viable-spacing-visitor.d.ts.map +1 -0
- package/dist/javascript/format/minimum-viable-spacing-visitor.js +308 -0
- package/dist/javascript/format/minimum-viable-spacing-visitor.js.map +1 -0
- package/dist/javascript/format/normalize-whitespace-visitor.d.ts +14 -0
- package/dist/javascript/format/normalize-whitespace-visitor.d.ts.map +1 -0
- package/dist/javascript/format/normalize-whitespace-visitor.js +65 -0
- package/dist/javascript/format/normalize-whitespace-visitor.js.map +1 -0
- package/dist/javascript/format/prettier-config-loader.d.ts +92 -0
- package/dist/javascript/format/prettier-config-loader.d.ts.map +1 -0
- package/dist/javascript/format/prettier-config-loader.js +419 -0
- package/dist/javascript/format/prettier-config-loader.js.map +1 -0
- package/dist/javascript/format/prettier-format.d.ts +111 -0
- package/dist/javascript/format/prettier-format.d.ts.map +1 -0
- package/dist/javascript/format/prettier-format.js +496 -0
- package/dist/javascript/format/prettier-format.js.map +1 -0
- package/dist/javascript/{tabs-and-indents-visitor.d.ts → format/tabs-and-indents-visitor.d.ts} +4 -4
- package/dist/javascript/format/tabs-and-indents-visitor.d.ts.map +1 -0
- package/dist/javascript/{tabs-and-indents-visitor.js → format/tabs-and-indents-visitor.js} +7 -7
- package/dist/javascript/format/tabs-and-indents-visitor.js.map +1 -0
- package/dist/javascript/format/whitespace-reconciler.d.ts +106 -0
- package/dist/javascript/format/whitespace-reconciler.d.ts.map +1 -0
- package/dist/javascript/format/whitespace-reconciler.js +291 -0
- package/dist/javascript/format/whitespace-reconciler.js.map +1 -0
- package/dist/javascript/markers.d.ts.map +1 -1
- package/dist/javascript/markers.js +21 -0
- package/dist/javascript/markers.js.map +1 -1
- package/dist/javascript/parser.d.ts +15 -3
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +107 -24
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/recipes/auto-format.d.ts +3 -0
- package/dist/javascript/recipes/auto-format.d.ts.map +1 -1
- package/dist/javascript/recipes/auto-format.js +22 -1
- package/dist/javascript/recipes/auto-format.js.map +1 -1
- package/dist/javascript/style.d.ts +52 -1
- package/dist/javascript/style.d.ts.map +1 -1
- package/dist/javascript/style.js +43 -2
- package/dist/javascript/style.js.map +1 -1
- package/dist/test/rewrite-test.d.ts +3 -4
- package/dist/test/rewrite-test.d.ts.map +1 -1
- package/dist/test/rewrite-test.js +6 -18
- package/dist/test/rewrite-test.js.map +1 -1
- package/dist/version.txt +1 -1
- package/dist/yaml/assertions.d.ts +4 -0
- package/dist/yaml/assertions.d.ts.map +1 -0
- package/dist/yaml/assertions.js +31 -0
- package/dist/yaml/assertions.js.map +1 -0
- package/dist/yaml/index.d.ts +2 -1
- package/dist/yaml/index.d.ts.map +1 -1
- package/dist/yaml/index.js +2 -1
- package/dist/yaml/index.js.map +1 -1
- package/package.json +5 -4
- package/src/java/type.ts +12 -0
- package/src/javascript/assertions.ts +9 -0
- package/src/javascript/comparator.ts +6 -11
- package/src/javascript/{format.ts → format/format.ts} +59 -267
- package/src/javascript/format/index.ts +21 -0
- package/src/javascript/format/minimum-viable-spacing-visitor.ts +256 -0
- package/src/javascript/format/normalize-whitespace-visitor.ts +42 -0
- package/src/javascript/format/prettier-config-loader.ts +422 -0
- package/src/javascript/format/prettier-format.ts +622 -0
- package/src/javascript/{tabs-and-indents-visitor.ts → format/tabs-and-indents-visitor.ts} +8 -8
- package/src/javascript/format/whitespace-reconciler.ts +345 -0
- package/src/javascript/markers.ts +19 -0
- package/src/javascript/parser.ts +107 -20
- package/src/javascript/recipes/auto-format.ts +28 -1
- package/src/javascript/style.ts +41 -2
- package/src/test/rewrite-test.ts +6 -18
- package/src/yaml/assertions.ts +28 -0
- package/src/yaml/index.ts +2 -1
- package/dist/javascript/format.d.ts.map +0 -1
- package/dist/javascript/format.js.map +0 -1
- package/dist/javascript/tabs-and-indents-visitor.d.ts.map +0 -1
- package/dist/javascript/tabs-and-indents-visitor.js.map +0 -1
|
@@ -32,6 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
35
44
|
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
36
45
|
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
37
46
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
@@ -75,34 +84,33 @@ const uuid_1 = require("../uuid");
|
|
|
75
84
|
const parser_utils_1 = require("./parser-utils");
|
|
76
85
|
const type_mapping_1 = require("./type-mapping");
|
|
77
86
|
const immer_1 = require("immer");
|
|
87
|
+
const prettier_config_loader_1 = require("./format/prettier-config-loader");
|
|
78
88
|
var Kind = _1.JS.Kind;
|
|
79
89
|
function getScriptKindFromFileName(fileName) {
|
|
80
|
-
const
|
|
81
|
-
if (
|
|
82
|
-
return typescript_1.default.ScriptKind.TSX;
|
|
83
|
-
if (ext.endsWith('.jsx'))
|
|
84
|
-
return typescript_1.default.ScriptKind.JSX;
|
|
85
|
-
if (ext.endsWith('.ts'))
|
|
86
|
-
return typescript_1.default.ScriptKind.TS;
|
|
87
|
-
if (ext.endsWith('.js'))
|
|
88
|
-
return typescript_1.default.ScriptKind.JS;
|
|
89
|
-
if (ext.endsWith('.mjs'))
|
|
90
|
-
return typescript_1.default.ScriptKind.JS;
|
|
91
|
-
if (ext.endsWith('.cjs'))
|
|
92
|
-
return typescript_1.default.ScriptKind.JS;
|
|
93
|
-
if (ext.endsWith('.mts'))
|
|
90
|
+
const dotIndex = fileName.lastIndexOf('.');
|
|
91
|
+
if (dotIndex === -1)
|
|
94
92
|
return typescript_1.default.ScriptKind.TS;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
const ext = fileName.slice(dotIndex);
|
|
94
|
+
switch (ext) {
|
|
95
|
+
case '.tsx': return typescript_1.default.ScriptKind.TSX;
|
|
96
|
+
case '.jsx': return typescript_1.default.ScriptKind.JSX;
|
|
97
|
+
case '.ts':
|
|
98
|
+
case '.mts':
|
|
99
|
+
case '.cts': return typescript_1.default.ScriptKind.TS;
|
|
100
|
+
case '.js':
|
|
101
|
+
case '.mjs':
|
|
102
|
+
case '.cjs': return typescript_1.default.ScriptKind.JS;
|
|
103
|
+
default: return typescript_1.default.ScriptKind.TS;
|
|
104
|
+
}
|
|
98
105
|
}
|
|
99
106
|
class JavaScriptParser extends parser_1.Parser {
|
|
100
|
-
constructor({ ctx, relativeTo, styles, sourceFileCache } = {}) {
|
|
107
|
+
constructor({ ctx, relativeTo, styles, sourceFileCache, } = {}) {
|
|
101
108
|
super({ ctx, relativeTo });
|
|
102
109
|
this.compilerOptions = {
|
|
103
110
|
target: typescript_1.default.ScriptTarget.Latest,
|
|
104
111
|
module: typescript_1.default.ModuleKind.CommonJS,
|
|
105
112
|
moduleResolution: typescript_1.default.ModuleResolutionKind.Node10,
|
|
113
|
+
noEmit: true,
|
|
106
114
|
allowJs: true,
|
|
107
115
|
checkJs: true,
|
|
108
116
|
esModuleInterop: true,
|
|
@@ -116,6 +124,66 @@ class JavaScriptParser extends parser_1.Parser {
|
|
|
116
124
|
this.styles = styles;
|
|
117
125
|
this.sourceFileCache = sourceFileCache;
|
|
118
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Parses a single source file using only ts.createSourceFile(), bypassing
|
|
129
|
+
* the TypeScript type checker entirely. This is significantly faster than
|
|
130
|
+
* the full parse() method when type information is not needed.
|
|
131
|
+
*
|
|
132
|
+
* Use this method for formatting-only operations where AST structure is
|
|
133
|
+
* needed but type attribution is not required.
|
|
134
|
+
*
|
|
135
|
+
* @param input The parser input containing the source code
|
|
136
|
+
* @returns The parsed SourceFile, or a ParseExceptionResult if parsing failed
|
|
137
|
+
*/
|
|
138
|
+
parseOnly(input) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const filePath = (0, parser_1.parserInputFile)(input);
|
|
141
|
+
const sourcePath = this.relativeTo && !path.isAbsolute(filePath)
|
|
142
|
+
? path.join(this.relativeTo, filePath)
|
|
143
|
+
: filePath;
|
|
144
|
+
const sourceText = (0, parser_1.parserInputRead)(input);
|
|
145
|
+
const scriptKind = getScriptKindFromFileName(sourcePath);
|
|
146
|
+
// Create source file directly without a Program
|
|
147
|
+
const sourceFileOptions = {
|
|
148
|
+
languageVersion: typescript_1.default.ScriptTarget.Latest,
|
|
149
|
+
jsDocParsingMode: typescript_1.default.JSDocParsingMode.ParseNone
|
|
150
|
+
};
|
|
151
|
+
const tsSourceFile = typescript_1.default.createSourceFile(sourcePath, sourceText, sourceFileOptions, true, // setParentNodes
|
|
152
|
+
scriptKind);
|
|
153
|
+
// Check for parse-time syntax errors (accessible via internal parseDiagnostics)
|
|
154
|
+
// TypeScript stores parse errors directly on the source file
|
|
155
|
+
const parseDiagnostics = tsSourceFile.parseDiagnostics;
|
|
156
|
+
if (parseDiagnostics && parseDiagnostics.length > 0) {
|
|
157
|
+
const errors = parseDiagnostics.filter(d => d.category === typescript_1.default.DiagnosticCategory.Error);
|
|
158
|
+
if (errors.length > 0) {
|
|
159
|
+
const errorMessages = errors.map(e => {
|
|
160
|
+
if (e.file && e.start !== undefined) {
|
|
161
|
+
const { line, character } = typescript_1.default.getLineAndCharacterOfPosition(e.file, e.start);
|
|
162
|
+
const message = typescript_1.default.flattenDiagnosticMessageText(e.messageText, "\n");
|
|
163
|
+
return `(${line + 1},${character + 1}): ${message} [${e.code}]`;
|
|
164
|
+
}
|
|
165
|
+
return `${typescript_1.default.flattenDiagnosticMessageText(e.messageText, "\n")} [${e.code}]`;
|
|
166
|
+
}).join('; ');
|
|
167
|
+
return this.error(input, new SyntaxError(`Compiler error(s): ${errorMessages}`));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
// Parse without type mapping (no type checker available)
|
|
172
|
+
const result = new JavaScriptParserVisitor(tsSourceFile, this.relativePath(input), undefined)
|
|
173
|
+
.visit(tsSourceFile);
|
|
174
|
+
if (this.styles) {
|
|
175
|
+
const styles = this.styles;
|
|
176
|
+
return (0, immer_1.produce)(result, draft => {
|
|
177
|
+
draft.markers.markers = draft.markers.markers.concat(styles);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
return this.error(input, error instanceof Error ? error : new Error('Parser threw unknown error: ' + error));
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
119
187
|
// noinspection JSUnusedGlobalSymbols
|
|
120
188
|
reset() {
|
|
121
189
|
this.sourceFileCache && this.sourceFileCache.clear();
|
|
@@ -239,10 +307,15 @@ class JavaScriptParser extends parser_1.Parser {
|
|
|
239
307
|
const program = typescript_1.default.createProgram([...inputFiles.keys()], this.compilerOptions, host, this.oldProgram);
|
|
240
308
|
// Update the oldProgram reference
|
|
241
309
|
this.oldProgram = program;
|
|
242
|
-
|
|
310
|
+
// Detect Prettier config for the project
|
|
311
|
+
const prettierLoader = this.relativeTo ? new prettier_config_loader_1.PrettierConfigLoader(this.relativeTo) : undefined;
|
|
312
|
+
if (prettierLoader) {
|
|
313
|
+
yield __await(prettierLoader.detectPrettier());
|
|
314
|
+
}
|
|
243
315
|
// Create a single JavaScriptTypeMapping instance to be shared across all files in this parse batch.
|
|
244
316
|
// This ensures that TypeScript types with the same type.id map to the same Type instance,
|
|
245
317
|
// preventing duplicate Type.Class, Type.Parameterized, etc. instances.
|
|
318
|
+
const typeChecker = program.getTypeChecker();
|
|
246
319
|
const typeMapping = new type_mapping_1.JavaScriptTypeMapping(typeChecker);
|
|
247
320
|
for (const input of inputFiles.values()) {
|
|
248
321
|
const filePath = (0, parser_1.parserInputFile)(input);
|
|
@@ -262,11 +335,16 @@ class JavaScriptParser extends parser_1.Parser {
|
|
|
262
335
|
continue;
|
|
263
336
|
}
|
|
264
337
|
try {
|
|
338
|
+
// Get Prettier config marker for this file (if Prettier is available)
|
|
339
|
+
const prettierConfigMarker = yield __await((prettierLoader === null || prettierLoader === void 0 ? void 0 : prettierLoader.getConfigMarker(filePath)));
|
|
265
340
|
yield yield __await((0, immer_1.produce)(new JavaScriptParserVisitor(sourceFile, this.relativePath(input), typeMapping)
|
|
266
341
|
.visit(sourceFile), draft => {
|
|
267
342
|
if (this.styles) {
|
|
268
343
|
draft.markers.markers = draft.markers.markers.concat(this.styles);
|
|
269
344
|
}
|
|
345
|
+
if (prettierConfigMarker) {
|
|
346
|
+
draft.markers.markers = draft.markers.markers.concat([prettierConfigMarker]);
|
|
347
|
+
}
|
|
270
348
|
}));
|
|
271
349
|
}
|
|
272
350
|
catch (error) {
|
|
@@ -415,6 +493,7 @@ class JavaScriptParserVisitor {
|
|
|
415
493
|
draft.comments = [];
|
|
416
494
|
});
|
|
417
495
|
}
|
|
496
|
+
const eof = this.prefix(node.endOfFileToken);
|
|
418
497
|
let statements = this.semicolonPaddedStatementList(node.statements);
|
|
419
498
|
// If there's trailing whitespace/comments after the shebang, prepend to first statement's prefix
|
|
420
499
|
if (shebangTrailingSpace && statements.length > 0) {
|
|
@@ -442,7 +521,7 @@ class JavaScriptParserVisitor {
|
|
|
442
521
|
statements: shebangStatement
|
|
443
522
|
? [shebangStatement, ...statements]
|
|
444
523
|
: statements,
|
|
445
|
-
eof
|
|
524
|
+
eof
|
|
446
525
|
};
|
|
447
526
|
}
|
|
448
527
|
semicolonPaddedStatementList(statements) {
|
|
@@ -3869,16 +3948,20 @@ class JavaScriptParserVisitor {
|
|
|
3869
3948
|
return prefixFromNode(node, this.sourceFile);
|
|
3870
3949
|
}
|
|
3871
3950
|
mapType(node) {
|
|
3872
|
-
|
|
3951
|
+
var _a;
|
|
3952
|
+
return (_a = this.typeMapping) === null || _a === void 0 ? void 0 : _a.type(node);
|
|
3873
3953
|
}
|
|
3874
3954
|
mapPrimitiveType(node) {
|
|
3875
|
-
|
|
3955
|
+
var _a, _b;
|
|
3956
|
+
return (_b = (_a = this.typeMapping) === null || _a === void 0 ? void 0 : _a.primitiveType(node)) !== null && _b !== void 0 ? _b : java_1.Type.Primitive.None;
|
|
3876
3957
|
}
|
|
3877
3958
|
mapVariableType(node) {
|
|
3878
|
-
|
|
3959
|
+
var _a;
|
|
3960
|
+
return (_a = this.typeMapping) === null || _a === void 0 ? void 0 : _a.variableType(node);
|
|
3879
3961
|
}
|
|
3880
3962
|
mapMethodType(node) {
|
|
3881
|
-
|
|
3963
|
+
var _a;
|
|
3964
|
+
return (_a = this.typeMapping) === null || _a === void 0 ? void 0 : _a.methodType(node);
|
|
3882
3965
|
}
|
|
3883
3966
|
mapCommaSeparatedList(nodes) {
|
|
3884
3967
|
return this.mapToContainer(nodes, this.trailingComma(nodes));
|