@openrewrite/rewrite 8.66.0-20251029-104214 → 8.66.0-20251029-133057
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/javascript/format.d.ts.map +1 -1
- package/dist/javascript/format.js +13 -3
- package/dist/javascript/format.js.map +1 -1
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +5 -2
- package/dist/javascript/parser.js.map +1 -1
- package/dist/version.txt +1 -1
- package/package.json +1 -1
- package/src/javascript/format.ts +11 -3
- package/src/javascript/parser.ts +5 -2
package/dist/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
8.66.0-20251029-
|
|
1
|
+
8.66.0-20251029-132557
|
package/package.json
CHANGED
package/src/javascript/format.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import {JS} from "./tree";
|
|
17
17
|
import {JavaScriptVisitor} from "./visitor";
|
|
18
|
-
import {Comment,
|
|
18
|
+
import {Comment, J, Statement} from "../java";
|
|
19
19
|
import {Draft, produce} from "immer";
|
|
20
20
|
import {Cursor, isScope, Tree} from "../tree";
|
|
21
21
|
import {
|
|
@@ -445,6 +445,10 @@ export class SpacesVisitor<P> extends JavaScriptVisitor<P> {
|
|
|
445
445
|
}
|
|
446
446
|
protected async visitVariable(variable: J.VariableDeclarations.NamedVariable, p: P): Promise<J | undefined> {
|
|
447
447
|
const ret = await super.visitVariable(variable, p) as J.VariableDeclarations.NamedVariable;
|
|
448
|
+
if (variable.initializer?.element?.kind == JS.Kind.StatementExpression
|
|
449
|
+
&& (variable.initializer.element as JS.StatementExpression).statement.kind == J.Kind.MethodDeclaration) {
|
|
450
|
+
return ret;
|
|
451
|
+
}
|
|
448
452
|
return produceAsync(ret, async draft => {
|
|
449
453
|
if (draft.initializer) {
|
|
450
454
|
draft.initializer.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
@@ -968,7 +972,11 @@ export class BlankLinesVisitor<P> extends JavaScriptVisitor<P> {
|
|
|
968
972
|
});
|
|
969
973
|
return super.visit(cu, p, cursor);
|
|
970
974
|
}
|
|
971
|
-
if (tree.kind === J.Kind.MethodDeclaration) {
|
|
975
|
+
if (tree.kind === JS.Kind.StatementExpression && (tree as JS.StatementExpression).statement.kind == J.Kind.MethodDeclaration) {
|
|
976
|
+
tree = produce(tree as JS.StatementExpression, draft => {
|
|
977
|
+
this.ensurePrefixHasNewLine(draft);
|
|
978
|
+
});
|
|
979
|
+
} else if (tree.kind === J.Kind.MethodDeclaration && this.cursor.value.kind != JS.Kind.StatementExpression) {
|
|
972
980
|
tree = produce(tree as J.MethodDeclaration, draft => {
|
|
973
981
|
this.ensurePrefixHasNewLine(draft);
|
|
974
982
|
});
|
|
@@ -1149,7 +1157,7 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
|
|
|
1149
1157
|
let indentShouldIncrease =
|
|
1150
1158
|
tree.kind === J.Kind.Block
|
|
1151
1159
|
|| this.cursor.parent?.parent?.parent?.value.kind == J.Kind.Case
|
|
1152
|
-
|| (tree.kind ===
|
|
1160
|
+
|| (tree.kind === JS.Kind.StatementExpression && (tree as JS.StatementExpression).statement.kind == J.Kind.MethodDeclaration);
|
|
1153
1161
|
|
|
1154
1162
|
const previousIndent = this.currentIndent;
|
|
1155
1163
|
|
package/src/javascript/parser.ts
CHANGED
|
@@ -3131,12 +3131,15 @@ export class JavaScriptParserVisitor {
|
|
|
3131
3131
|
}
|
|
3132
3132
|
|
|
3133
3133
|
visitFunctionExpression(node: ts.FunctionExpression): JS.StatementExpression {
|
|
3134
|
+
const delegate = this.mapFunctionDeclaration(node);
|
|
3134
3135
|
return {
|
|
3135
3136
|
kind: JS.Kind.StatementExpression,
|
|
3136
3137
|
id: randomId(),
|
|
3137
|
-
prefix:
|
|
3138
|
+
prefix: delegate.prefix,
|
|
3138
3139
|
markers: emptyMarkers,
|
|
3139
|
-
statement:
|
|
3140
|
+
statement: produce(delegate, draft => {
|
|
3141
|
+
draft.prefix = emptySpace;
|
|
3142
|
+
})
|
|
3140
3143
|
};
|
|
3141
3144
|
}
|
|
3142
3145
|
|