@openrewrite/rewrite 8.91.1 → 8.91.3
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/execution.d.ts +8 -0
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +31 -0
- package/dist/execution.js.map +1 -1
- package/dist/javascript/add-import.d.ts +127 -38
- package/dist/javascript/add-import.d.ts.map +1 -1
- package/dist/javascript/add-import.js +684 -195
- package/dist/javascript/add-import.js.map +1 -1
- package/dist/javascript/amd.d.ts +148 -0
- package/dist/javascript/amd.d.ts.map +1 -0
- package/dist/javascript/amd.js +802 -0
- package/dist/javascript/amd.js.map +1 -0
- package/dist/javascript/binding.d.ts +102 -0
- package/dist/javascript/binding.d.ts.map +1 -0
- package/dist/javascript/binding.js +308 -0
- package/dist/javascript/binding.js.map +1 -0
- package/dist/javascript/comparator.d.ts +2 -0
- package/dist/javascript/comparator.d.ts.map +1 -1
- package/dist/javascript/comparator.js +5 -1
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/format/format.d.ts +5 -2
- package/dist/javascript/format/format.d.ts.map +1 -1
- package/dist/javascript/format/format.js +51 -11
- package/dist/javascript/format/format.js.map +1 -1
- package/dist/javascript/format/minimum-viable-spacing-visitor.d.ts +19 -0
- package/dist/javascript/format/minimum-viable-spacing-visitor.d.ts.map +1 -1
- package/dist/javascript/format/minimum-viable-spacing-visitor.js +180 -7
- package/dist/javascript/format/minimum-viable-spacing-visitor.js.map +1 -1
- package/dist/javascript/format/prettier-format.d.ts +2 -1
- package/dist/javascript/format/prettier-format.d.ts.map +1 -1
- package/dist/javascript/format/prettier-format.js +33 -23
- package/dist/javascript/format/prettier-format.js.map +1 -1
- package/dist/javascript/index.d.ts +8 -1
- package/dist/javascript/index.d.ts.map +1 -1
- package/dist/javascript/index.js +46 -1
- package/dist/javascript/index.js.map +1 -1
- package/dist/javascript/parser-utils.d.ts.map +1 -1
- package/dist/javascript/parser-utils.js +7 -9
- package/dist/javascript/parser-utils.js.map +1 -1
- package/dist/javascript/parser.d.ts +7 -1
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +55 -4
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/print.d.ts +1 -0
- package/dist/javascript/print.d.ts.map +1 -1
- package/dist/javascript/print.js +9 -0
- package/dist/javascript/print.js.map +1 -1
- package/dist/javascript/recipes/change-import.d.ts +4 -3
- package/dist/javascript/recipes/change-import.d.ts.map +1 -1
- package/dist/javascript/recipes/change-import.js +12 -504
- package/dist/javascript/recipes/change-import.js.map +1 -1
- package/dist/javascript/remove-import.d.ts +2 -28
- package/dist/javascript/remove-import.d.ts.map +1 -1
- package/dist/javascript/remove-import.js +19 -57
- package/dist/javascript/remove-import.js.map +1 -1
- package/dist/javascript/rpc.js +2 -0
- package/dist/javascript/rpc.js.map +1 -1
- package/dist/javascript/scope.d.ts +82 -0
- package/dist/javascript/scope.d.ts.map +1 -0
- package/dist/javascript/scope.js +476 -0
- package/dist/javascript/scope.js.map +1 -0
- package/dist/javascript/templating/bindings.d.ts +0 -11
- package/dist/javascript/templating/bindings.d.ts.map +1 -1
- package/dist/javascript/templating/bindings.js +2 -49
- package/dist/javascript/templating/bindings.js.map +1 -1
- package/dist/javascript/templating/comparator.d.ts +12 -0
- package/dist/javascript/templating/comparator.d.ts.map +1 -1
- package/dist/javascript/templating/comparator.js +68 -14
- package/dist/javascript/templating/comparator.js.map +1 -1
- package/dist/javascript/templating/engine.d.ts +22 -4
- package/dist/javascript/templating/engine.d.ts.map +1 -1
- package/dist/javascript/templating/engine.js +68 -24
- package/dist/javascript/templating/engine.js.map +1 -1
- package/dist/javascript/templating/index.d.ts +1 -1
- package/dist/javascript/templating/index.d.ts.map +1 -1
- package/dist/javascript/templating/index.js.map +1 -1
- package/dist/javascript/templating/pattern.d.ts.map +1 -1
- package/dist/javascript/templating/pattern.js +2 -2
- package/dist/javascript/templating/pattern.js.map +1 -1
- package/dist/javascript/templating/placeholder-replacement.d.ts +2 -0
- package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -1
- package/dist/javascript/templating/placeholder-replacement.js +10 -5
- package/dist/javascript/templating/placeholder-replacement.js.map +1 -1
- package/dist/javascript/templating/precedence.d.ts +12 -4
- package/dist/javascript/templating/precedence.d.ts.map +1 -1
- package/dist/javascript/templating/precedence.js +18 -11
- package/dist/javascript/templating/precedence.js.map +1 -1
- package/dist/javascript/templating/rewrite.d.ts.map +1 -1
- package/dist/javascript/templating/rewrite.js +7 -1
- package/dist/javascript/templating/rewrite.js.map +1 -1
- package/dist/javascript/templating/template.d.ts +7 -1
- package/dist/javascript/templating/template.d.ts.map +1 -1
- package/dist/javascript/templating/template.js +54 -28
- package/dist/javascript/templating/template.js.map +1 -1
- package/dist/javascript/templating/types.d.ts +15 -18
- package/dist/javascript/templating/types.d.ts.map +1 -1
- package/dist/javascript/templating/utils.d.ts +1 -1
- package/dist/javascript/templating/utils.d.ts.map +1 -1
- package/dist/javascript/templating/utils.js +3 -2
- package/dist/javascript/templating/utils.js.map +1 -1
- package/dist/javascript/tree.d.ts +1 -0
- package/dist/javascript/tree.d.ts.map +1 -1
- package/dist/javascript/tree.js.map +1 -1
- package/dist/javascript/type-mapping.d.ts.map +1 -1
- package/dist/javascript/type-mapping.js +14 -0
- package/dist/javascript/type-mapping.js.map +1 -1
- package/dist/javascript/visitor.d.ts.map +1 -1
- package/dist/javascript/visitor.js +1 -0
- package/dist/javascript/visitor.js.map +1 -1
- package/dist/parser.d.ts +6 -0
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +23 -1
- package/dist/parser.js.map +1 -1
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +5 -2
- package/dist/print.js.map +1 -1
- package/dist/rewrite-javascript-version.txt +1 -1
- package/dist/rpc/request/parse-project.d.ts +11 -1
- package/dist/rpc/request/parse-project.d.ts.map +1 -1
- package/dist/rpc/request/parse-project.js +7 -2
- package/dist/rpc/request/parse-project.js.map +1 -1
- package/dist/rpc/request/parse.d.ts +13 -1
- package/dist/rpc/request/parse.d.ts.map +1 -1
- package/dist/rpc/request/parse.js +8 -2
- package/dist/rpc/request/parse.js.map +1 -1
- package/package.json +2 -2
- package/src/execution.ts +23 -0
- package/src/javascript/add-import.ts +753 -238
- package/src/javascript/amd.ts +954 -0
- package/src/javascript/binding.ts +435 -0
- package/src/javascript/comparator.ts +6 -1
- package/src/javascript/format/format.ts +56 -12
- package/src/javascript/format/minimum-viable-spacing-visitor.ts +196 -7
- package/src/javascript/format/prettier-format.ts +35 -25
- package/src/javascript/index.ts +19 -1
- package/src/javascript/parser-utils.ts +7 -11
- package/src/javascript/parser.ts +78 -6
- package/src/javascript/print.ts +10 -0
- package/src/javascript/recipes/change-import.ts +13 -593
- package/src/javascript/remove-import.ts +20 -56
- package/src/javascript/rpc.ts +2 -0
- package/src/javascript/scope.ts +517 -0
- package/src/javascript/templating/bindings.ts +2 -55
- package/src/javascript/templating/comparator.ts +81 -16
- package/src/javascript/templating/engine.ts +107 -38
- package/src/javascript/templating/index.ts +0 -1
- package/src/javascript/templating/pattern.ts +4 -2
- package/src/javascript/templating/placeholder-replacement.ts +16 -6
- package/src/javascript/templating/precedence.ts +21 -13
- package/src/javascript/templating/rewrite.ts +9 -1
- package/src/javascript/templating/template.ts +68 -29
- package/src/javascript/templating/types.ts +17 -18
- package/src/javascript/templating/utils.ts +4 -2
- package/src/javascript/tree.ts +1 -0
- package/src/javascript/type-mapping.ts +15 -0
- package/src/javascript/visitor.ts +1 -0
- package/src/parser.ts +24 -1
- package/src/print.ts +5 -2
- package/src/rpc/request/parse-project.ts +6 -2
- package/src/rpc/request/parse.ts +7 -2
|
@@ -93,7 +93,7 @@ function getScriptKindFromFileName(fileName) {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
class JavaScriptParser extends parser_1.Parser {
|
|
96
|
-
constructor({ ctx, relativeTo, styles, sourceFileCache, } = {}) {
|
|
96
|
+
constructor({ ctx, relativeTo, styles, sourceFileCache, types, } = {}) {
|
|
97
97
|
super({ ctx, relativeTo });
|
|
98
98
|
this.compilerOptions = {
|
|
99
99
|
target: typescript_1.default.ScriptTarget.Latest,
|
|
@@ -114,6 +114,12 @@ class JavaScriptParser extends parser_1.Parser {
|
|
|
114
114
|
emitDecoratorMetadata: true,
|
|
115
115
|
forceConsistentCasingInFileNames: false,
|
|
116
116
|
jsx: typescript_1.default.JsxEmit.Preserve,
|
|
117
|
+
// Strictness is a property of the parsed project rather than of the compiler we pin: under
|
|
118
|
+
// `strictNullChecks` every nullable type carries an extra `null` union constituent.
|
|
119
|
+
strict: false,
|
|
120
|
+
// `types` defaults to `[]`, which attributes ambient `@types/*` packages only when named;
|
|
121
|
+
// `*` enumerates everything under `node_modules/@types`.
|
|
122
|
+
types: types !== null && types !== void 0 ? types : ["*"],
|
|
117
123
|
baseUrl: relativeTo || process.cwd()
|
|
118
124
|
};
|
|
119
125
|
this.styles = styles;
|
|
@@ -329,12 +335,12 @@ class JavaScriptParser extends parser_1.Parser {
|
|
|
329
335
|
continue;
|
|
330
336
|
}
|
|
331
337
|
try {
|
|
332
|
-
yield yield __await((0, mutative_1.create)(new JavaScriptParserVisitor(sourceFile, this.relativePath(input), typeMapping)
|
|
338
|
+
yield yield __await(yield __await(this.requirePrintEqualsInput((0, mutative_1.create)(new JavaScriptParserVisitor(sourceFile, this.relativePath(input), typeMapping)
|
|
333
339
|
.visit(sourceFile), draft => {
|
|
334
340
|
if (this.styles) {
|
|
335
341
|
draft.markers = this.styles.reduce((m, s) => (0, markers_1.replaceMarkerByKind)(m, s), draft.markers);
|
|
336
342
|
}
|
|
337
|
-
}));
|
|
343
|
+
}), input, escapeLoneSurrogates(sourceFile.getFullText()))));
|
|
338
344
|
}
|
|
339
345
|
catch (error) {
|
|
340
346
|
yield yield __await(this.error(input, error instanceof Error ? error : new Error('Parser threw unknown error: ' + error)));
|
|
@@ -557,6 +563,10 @@ class JavaScriptParserVisitor {
|
|
|
557
563
|
}
|
|
558
564
|
mapModifiers(node) {
|
|
559
565
|
var _a, _b, _c, _d;
|
|
566
|
+
if (typescript_1.default.isPropertyAssignment(node) || typescript_1.default.isShorthandPropertyAssignment(node)) {
|
|
567
|
+
const modifiers = node.modifiers;
|
|
568
|
+
return modifiers ? modifiers.filter(typescript_1.default.isModifier).map(this.mapModifier) : [];
|
|
569
|
+
}
|
|
560
570
|
if (typescript_1.default.isVariableStatement(node) || typescript_1.default.isModuleDeclaration(node) || typescript_1.default.isClassDeclaration(node) || typescript_1.default.isEnumDeclaration(node)
|
|
561
571
|
|| typescript_1.default.isInterfaceDeclaration(node) || typescript_1.default.isPropertyDeclaration(node) || typescript_1.default.isPropertySignature(node) || typescript_1.default.isParameter(node)
|
|
562
572
|
|| typescript_1.default.isMethodDeclaration(node) || typescript_1.default.isConstructorDeclaration(node) || typescript_1.default.isArrowFunction(node)
|
|
@@ -1056,6 +1066,7 @@ class JavaScriptParserVisitor {
|
|
|
1056
1066
|
visitPropertySignature(node) {
|
|
1057
1067
|
// FIXME We are mapping the literals in things like type ascii = { " ": 32; "!": 33; } to
|
|
1058
1068
|
// named variables, which is not a good use of this construct.
|
|
1069
|
+
const initializer = node.initializer;
|
|
1059
1070
|
return {
|
|
1060
1071
|
kind: java_1.J.Kind.VariableDeclarations,
|
|
1061
1072
|
id: (0, uuid_1.randomId)(),
|
|
@@ -1073,6 +1084,7 @@ class JavaScriptParserVisitor {
|
|
|
1073
1084
|
draft.markers = this.maybeAddOptionalMarker(draft, node);
|
|
1074
1085
|
}),
|
|
1075
1086
|
dimensionsAfterName: [],
|
|
1087
|
+
initializer: initializer && this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(initializer) - 1)), this.visit(initializer)),
|
|
1076
1088
|
variableType: this.mapVariableType(node)
|
|
1077
1089
|
}, java_1.emptySpace)]
|
|
1078
1090
|
};
|
|
@@ -1259,6 +1271,7 @@ class JavaScriptParserVisitor {
|
|
|
1259
1271
|
leadingAnnotations: this.mapDecorators(node),
|
|
1260
1272
|
modifiers: this.mapModifiers(node),
|
|
1261
1273
|
nameAnnotations: [],
|
|
1274
|
+
returnTypeExpression: this.mapTypeInfo(node),
|
|
1262
1275
|
name: Object.assign(Object.assign({}, this.mapIdentifier(constructorKeyword, constructorKeyword.getText(), false)), { type: methodType }),
|
|
1263
1276
|
parameters: this.mapCommaSeparatedList(this.getParameterListNodes(node)),
|
|
1264
1277
|
dimensionsAfterName: [],
|
|
@@ -1277,6 +1290,7 @@ class JavaScriptParserVisitor {
|
|
|
1277
1290
|
markers: markers_1.emptyMarkers,
|
|
1278
1291
|
leadingAnnotations: this.mapDecorators(node),
|
|
1279
1292
|
modifiers: this.mapModifiers(node),
|
|
1293
|
+
typeParameters: node.typeParameters && this.mapTypeParametersAsObject(node),
|
|
1280
1294
|
returnTypeExpression: this.mapTypeInfo(node),
|
|
1281
1295
|
name: name,
|
|
1282
1296
|
parameters: this.mapCommaSeparatedList(this.getParameterListNodes(node)),
|
|
@@ -1291,6 +1305,7 @@ class JavaScriptParserVisitor {
|
|
|
1291
1305
|
markers: markers_1.emptyMarkers,
|
|
1292
1306
|
leadingAnnotations: this.mapDecorators(node),
|
|
1293
1307
|
modifiers: this.mapModifiers(node),
|
|
1308
|
+
typeParameters: node.typeParameters && this.mapTypeParametersAsObject(node),
|
|
1294
1309
|
returnTypeExpression: this.mapTypeInfo(node),
|
|
1295
1310
|
nameAnnotations: [],
|
|
1296
1311
|
name: name,
|
|
@@ -1311,6 +1326,8 @@ class JavaScriptParserVisitor {
|
|
|
1311
1326
|
markers: markers_1.emptyMarkers,
|
|
1312
1327
|
leadingAnnotations: this.mapDecorators(node),
|
|
1313
1328
|
modifiers: this.mapModifiers(node),
|
|
1329
|
+
typeParameters: node.typeParameters && this.mapTypeParametersAsObject(node),
|
|
1330
|
+
returnTypeExpression: this.mapTypeInfo(node),
|
|
1314
1331
|
name: name,
|
|
1315
1332
|
parameters: this.mapCommaSeparatedList(this.getParameterListNodes(node)),
|
|
1316
1333
|
body: node.body && this.convert(node.body),
|
|
@@ -1324,6 +1341,8 @@ class JavaScriptParserVisitor {
|
|
|
1324
1341
|
markers: markers_1.emptyMarkers,
|
|
1325
1342
|
leadingAnnotations: this.mapDecorators(node),
|
|
1326
1343
|
modifiers: this.mapModifiers(node),
|
|
1344
|
+
typeParameters: node.typeParameters && this.mapTypeParametersAsObject(node),
|
|
1345
|
+
returnTypeExpression: this.mapTypeInfo(node),
|
|
1327
1346
|
nameAnnotations: [],
|
|
1328
1347
|
name: name,
|
|
1329
1348
|
parameters: this.mapCommaSeparatedList(this.getParameterListNodes(node)),
|
|
@@ -3842,6 +3861,7 @@ class JavaScriptParserVisitor {
|
|
|
3842
3861
|
id: (0, uuid_1.randomId)(),
|
|
3843
3862
|
prefix: this.prefix(node),
|
|
3844
3863
|
markers: markers_1.emptyMarkers,
|
|
3864
|
+
modifiers: this.mapModifiers(node),
|
|
3845
3865
|
name: this.rightPadded(this.visit(node.name), this.suffix(node.name)),
|
|
3846
3866
|
assigmentToken: _1.JS.PropertyAssignment.Token.Colon,
|
|
3847
3867
|
initializer: this.visit(node.initializer)
|
|
@@ -3853,6 +3873,7 @@ class JavaScriptParserVisitor {
|
|
|
3853
3873
|
id: (0, uuid_1.randomId)(),
|
|
3854
3874
|
prefix: this.prefix(node),
|
|
3855
3875
|
markers: markers_1.emptyMarkers,
|
|
3876
|
+
modifiers: this.mapModifiers(node),
|
|
3856
3877
|
name: this.rightPadded(this.visit(node.name), this.suffix(node.name)),
|
|
3857
3878
|
assigmentToken: _1.JS.PropertyAssignment.Token.Equals,
|
|
3858
3879
|
initializer: node.objectAssignmentInitializer && this.visit(node.objectAssignmentInitializer)
|
|
@@ -4311,6 +4332,8 @@ class FlowSyntaxNotSupportedError extends SyntaxError {
|
|
|
4311
4332
|
}
|
|
4312
4333
|
const SURR_FIRST = 0xD800;
|
|
4313
4334
|
const SURR_LAST = 0xDFFF;
|
|
4335
|
+
const HIGH_SURR_LAST = 0xDBFF;
|
|
4336
|
+
const LOW_SURR_FIRST = 0xDC00;
|
|
4314
4337
|
/**
|
|
4315
4338
|
* Extracts invalid UTF-16 surrogate pairs from a string literal's value source.
|
|
4316
4339
|
* Unmatched UTF-16 surrogate pairs (composed of two escape and code point pairs) are unserializable
|
|
@@ -4323,6 +4346,25 @@ const SURR_LAST = 0xDFFF;
|
|
|
4323
4346
|
* 1. Unicode escape sequences (\uXXXX) where XXXX is in the surrogate range
|
|
4324
4347
|
* 2. Raw surrogate characters in the source (character codes 0xD800-0xDFFF)
|
|
4325
4348
|
*/
|
|
4349
|
+
/** The form {@link extractSurrogateEscapes} can hold, against which print idempotence is measured. */
|
|
4350
|
+
function escapeLoneSurrogates(source) {
|
|
4351
|
+
let escaped = '';
|
|
4352
|
+
for (let j = 0; j < source.length; j++) {
|
|
4353
|
+
const charCode = source.charCodeAt(j);
|
|
4354
|
+
if (charCode >= SURR_FIRST && charCode <= SURR_LAST) {
|
|
4355
|
+
const next = source.charCodeAt(j + 1);
|
|
4356
|
+
if (charCode <= HIGH_SURR_LAST && next >= LOW_SURR_FIRST && next <= SURR_LAST) {
|
|
4357
|
+
escaped += source.charAt(j) + source.charAt(j + 1);
|
|
4358
|
+
j++;
|
|
4359
|
+
continue;
|
|
4360
|
+
}
|
|
4361
|
+
escaped += "\\u" + charCode.toString(16).toUpperCase().padStart(4, '0');
|
|
4362
|
+
continue;
|
|
4363
|
+
}
|
|
4364
|
+
escaped += source.charAt(j);
|
|
4365
|
+
}
|
|
4366
|
+
return escaped;
|
|
4367
|
+
}
|
|
4326
4368
|
function extractSurrogateEscapes(valueSource) {
|
|
4327
4369
|
const unicodeEscapes = [];
|
|
4328
4370
|
let cleanedSource = '';
|
|
@@ -4343,8 +4385,17 @@ function extractSurrogateEscapes(valueSource) {
|
|
|
4343
4385
|
}
|
|
4344
4386
|
}
|
|
4345
4387
|
}
|
|
4346
|
-
//
|
|
4388
|
+
// A raw surrogate pair spells one code point — an emoji, say — and is carried as itself. A lone
|
|
4389
|
+
// surrogate is not text on its own and does not survive serialization (#6599), so it is held as a
|
|
4390
|
+
// `\uXXXX` escape and prints back as one.
|
|
4347
4391
|
if (charCode >= SURR_FIRST && charCode <= SURR_LAST) {
|
|
4392
|
+
const next = valueSource.charCodeAt(j + 1);
|
|
4393
|
+
if (charCode <= HIGH_SURR_LAST && next >= LOW_SURR_FIRST && next <= SURR_LAST) {
|
|
4394
|
+
cleanedSource += c + valueSource.charAt(j + 1);
|
|
4395
|
+
cleanedIndex += 2;
|
|
4396
|
+
j++;
|
|
4397
|
+
continue;
|
|
4398
|
+
}
|
|
4348
4399
|
const codePoint = charCode.toString(16).toUpperCase().padStart(4, '0');
|
|
4349
4400
|
unicodeEscapes.push({ valueSourceIndex: cleanedIndex, codePoint });
|
|
4350
4401
|
continue;
|