From 72e04502579880c9266ac50e6a470a2183f45d65 Mon Sep 17 00:00:00 2001 From: Andrii Rodionov Date: Tue, 4 Feb 2025 13:05:27 +0100 Subject: [PATCH] Refactored JS.FunctionType to eliminate an arrow Space --- openrewrite/src/javascript/parser.ts | 6 +-- openrewrite/src/javascript/remote/receiver.ts | 6 +-- openrewrite/src/javascript/remote/sender.ts | 3 +- .../src/javascript/tree/support_types.ts | 1 + openrewrite/src/javascript/tree/tree.ts | 41 ++++++++----------- openrewrite/src/javascript/visitor.ts | 3 +- .../test/javascript/parser/function.test.ts | 2 +- .../parser/variableDeclarations.test.ts | 12 ++++++ .../javascript/remote/JavaScriptReceiver.java | 6 +-- .../javascript/remote/JavaScriptSender.java | 3 +- .../javascript/JavaScriptVisitor.java | 5 +-- .../internal/JavaScriptPrinter.java | 9 ++-- .../org/openrewrite/javascript/tree/JS.java | 26 ++++++++---- .../javascript/tree/JsContainer.java | 2 +- .../javascript/tree/JsLeftPadded.java | 1 + .../javascript/tree/JsRightPadded.java | 2 +- .../openrewrite/javascript/tree/JsSpace.java | 4 +- 17 files changed, 70 insertions(+), 62 deletions(-) diff --git a/openrewrite/src/javascript/parser.ts b/openrewrite/src/javascript/parser.ts index 4f7e30cd..43ba7f31 100644 --- a/openrewrite/src/javascript/parser.ts +++ b/openrewrite/src/javascript/parser.ts @@ -1408,8 +1408,7 @@ export class JavaScriptParserVisitor { : node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p))) .concat(node.parameters.hasTrailingComma ? this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken)!)) : []), Markers.EMPTY), - this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)!), - this.convert(node.type), + this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)!), this.convert(node.type)), null); } @@ -1428,8 +1427,7 @@ export class JavaScriptParserVisitor { : node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p))) .concat(node.parameters.hasTrailingComma ? this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken)!)) : []), Markers.EMPTY), - this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)!), - this.convert(node.type), + this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)!), this.convert(node.type)), null); } diff --git a/openrewrite/src/javascript/remote/receiver.ts b/openrewrite/src/javascript/remote/receiver.ts index 45f9dc17..30e3cf36 100644 --- a/openrewrite/src/javascript/remote/receiver.ts +++ b/openrewrite/src/javascript/remote/receiver.ts @@ -148,8 +148,7 @@ class Visitor extends JavaScriptVisitor { functionType = functionType.padding.withConstructorType(ctx.receiveNode(functionType.padding.constructorType, leftPaddedValueReceiver(ValueType.Primitive))!); functionType = functionType.withTypeParameters(ctx.receiveNode(functionType.typeParameters, ctx.receiveTree)); functionType = functionType.padding.withParameters(ctx.receiveNode(functionType.padding.parameters, receiveContainer)!); - functionType = functionType.withArrow(ctx.receiveNode(functionType.arrow, receiveSpace)!); - functionType = functionType.withReturnType(ctx.receiveNode(functionType.returnType, ctx.receiveTree)!); + functionType = functionType.padding.withReturnType(ctx.receiveNode(functionType.padding.returnType, receiveLeftPaddedTree)!); functionType = functionType.withType(ctx.receiveValue(functionType.type, ValueType.Object)); return functionType; } @@ -1551,8 +1550,7 @@ class Factory implements ReceiverFactory { ctx.receiveNode>(null, leftPaddedValueReceiver(ValueType.Primitive))!, ctx.receiveNode(null, ctx.receiveTree), ctx.receiveNode>(null, receiveContainer)!, - ctx.receiveNode(null, receiveSpace)!, - ctx.receiveNode(null, ctx.receiveTree)!, + ctx.receiveNode>(null, receiveLeftPaddedTree)!, ctx.receiveValue(null, ValueType.Object) ); } diff --git a/openrewrite/src/javascript/remote/sender.ts b/openrewrite/src/javascript/remote/sender.ts index 8fe3ead1..8d2ac8df 100644 --- a/openrewrite/src/javascript/remote/sender.ts +++ b/openrewrite/src/javascript/remote/sender.ts @@ -143,8 +143,7 @@ class Visitor extends JavaScriptVisitor { ctx.sendNode(functionType, v => v.padding.constructorType, Visitor.sendLeftPadded(ValueType.Primitive)); ctx.sendNode(functionType, v => v.typeParameters, ctx.sendTree); ctx.sendNode(functionType, v => v.padding.parameters, Visitor.sendContainer(ValueType.Tree)); - ctx.sendNode(functionType, v => v.arrow, Visitor.sendSpace); - ctx.sendNode(functionType, v => v.returnType, ctx.sendTree); + ctx.sendNode(functionType, v => v.padding.returnType, Visitor.sendLeftPadded(ValueType.Tree)); ctx.sendTypedValue(functionType, v => v.type, ValueType.Object); return functionType; } diff --git a/openrewrite/src/javascript/tree/support_types.ts b/openrewrite/src/javascript/tree/support_types.ts index e1c570f6..812c0d1e 100644 --- a/openrewrite/src/javascript/tree/support_types.ts +++ b/openrewrite/src/javascript/tree/support_types.ts @@ -315,6 +315,7 @@ export namespace JsLeftPadded { ARROW_FUNCTION_BODY, YIELD_DELEGATED, FUNCTION_TYPE_CONSTRUCTOR_TYPE, + FUNCTION_TYPE_RETURN_TYPE, JSTRY_FINALLIE, IMPORT_ATTRIBUTE_VALUE, JS_IMPORT_MODULE_SPECIFIER, diff --git a/openrewrite/src/javascript/tree/tree.ts b/openrewrite/src/javascript/tree/tree.ts index e27ef4c7..244250bd 100644 --- a/openrewrite/src/javascript/tree/tree.ts +++ b/openrewrite/src/javascript/tree/tree.ts @@ -974,7 +974,7 @@ export class ExpressionWithTypeArguments extends JSMixin(Object) implements Type @LstType("org.openrewrite.javascript.tree.JS$FunctionType") export class FunctionType extends JSMixin(Object) implements Expression, TypeTree { - public constructor(id: UUID, prefix: Space, markers: Markers, modifiers: Java.Modifier[], constructorType: JLeftPadded, typeParameters: Java.TypeParameters | null, parameters: JContainer, arrow: Space, returnType: Expression, _type: JavaType | null) { + public constructor(id: UUID, prefix: Space, markers: Markers, modifiers: Java.Modifier[], constructorType: JLeftPadded, typeParameters: Java.TypeParameters | null, parameters: JContainer, returnType: JLeftPadded, _type: JavaType | null) { super(); this._id = id; this._prefix = prefix; @@ -983,7 +983,6 @@ export class FunctionType extends JSMixin(Object) implements Expression, TypeTre this._constructorType = constructorType; this._typeParameters = typeParameters; this._parameters = parameters; - this._arrow = arrow; this._returnType = returnType; this._type = _type; } @@ -995,7 +994,7 @@ export class FunctionType extends JSMixin(Object) implements Expression, TypeTre } public withId(id: UUID): FunctionType { - return id === this._id ? this : new FunctionType(id, this._prefix, this._markers, this._modifiers, this._constructorType, this._typeParameters, this._parameters, this._arrow, this._returnType, this._type); + return id === this._id ? this : new FunctionType(id, this._prefix, this._markers, this._modifiers, this._constructorType, this._typeParameters, this._parameters, this._returnType, this._type); } private readonly _prefix: Space; @@ -1005,7 +1004,7 @@ export class FunctionType extends JSMixin(Object) implements Expression, TypeTre } public withPrefix(prefix: Space): FunctionType { - return prefix === this._prefix ? this : new FunctionType(this._id, prefix, this._markers, this._modifiers, this._constructorType, this._typeParameters, this._parameters, this._arrow, this._returnType, this._type); + return prefix === this._prefix ? this : new FunctionType(this._id, prefix, this._markers, this._modifiers, this._constructorType, this._typeParameters, this._parameters, this._returnType, this._type); } private readonly _markers: Markers; @@ -1015,7 +1014,7 @@ export class FunctionType extends JSMixin(Object) implements Expression, TypeTre } public withMarkers(markers: Markers): FunctionType { - return markers === this._markers ? this : new FunctionType(this._id, this._prefix, markers, this._modifiers, this._constructorType, this._typeParameters, this._parameters, this._arrow, this._returnType, this._type); + return markers === this._markers ? this : new FunctionType(this._id, this._prefix, markers, this._modifiers, this._constructorType, this._typeParameters, this._parameters, this._returnType, this._type); } private readonly _modifiers: Java.Modifier[]; @@ -1025,7 +1024,7 @@ export class FunctionType extends JSMixin(Object) implements Expression, TypeTre } public withModifiers(modifiers: Java.Modifier[]): FunctionType { - return modifiers === this._modifiers ? this : new FunctionType(this._id, this._prefix, this._markers, modifiers, this._constructorType, this._typeParameters, this._parameters, this._arrow, this._returnType, this._type); + return modifiers === this._modifiers ? this : new FunctionType(this._id, this._prefix, this._markers, modifiers, this._constructorType, this._typeParameters, this._parameters, this._returnType, this._type); } private readonly _constructorType: JLeftPadded; @@ -1045,7 +1044,7 @@ export class FunctionType extends JSMixin(Object) implements Expression, TypeTre } public withTypeParameters(typeParameters: Java.TypeParameters | null): FunctionType { - return typeParameters === this._typeParameters ? this : new FunctionType(this._id, this._prefix, this._markers, this._modifiers, this._constructorType, typeParameters, this._parameters, this._arrow, this._returnType, this._type); + return typeParameters === this._typeParameters ? this : new FunctionType(this._id, this._prefix, this._markers, this._modifiers, this._constructorType, typeParameters, this._parameters, this._returnType, this._type); } private readonly _parameters: JContainer; @@ -1058,24 +1057,14 @@ export class FunctionType extends JSMixin(Object) implements Expression, TypeTre return this.padding.withParameters(JContainer.withElements(this._parameters, parameters)); } - private readonly _arrow: Space; - - public get arrow(): Space { - return this._arrow; - } - - public withArrow(arrow: Space): FunctionType { - return arrow === this._arrow ? this : new FunctionType(this._id, this._prefix, this._markers, this._modifiers, this._constructorType, this._typeParameters, this._parameters, arrow, this._returnType, this._type); - } - - private readonly _returnType: Expression; + private readonly _returnType: JLeftPadded; public get returnType(): Expression { - return this._returnType; + return this._returnType.element; } public withReturnType(returnType: Expression): FunctionType { - return returnType === this._returnType ? this : new FunctionType(this._id, this._prefix, this._markers, this._modifiers, this._constructorType, this._typeParameters, this._parameters, this._arrow, returnType, this._type); + return this.padding.withReturnType(this._returnType.withElement(returnType)); } private readonly _type: JavaType | null; @@ -1085,7 +1074,7 @@ export class FunctionType extends JSMixin(Object) implements Expression, TypeTre } public withType(_type: JavaType | null): FunctionType { - return _type === this._type ? this : new FunctionType(this._id, this._prefix, this._markers, this._modifiers, this._constructorType, this._typeParameters, this._parameters, this._arrow, this._returnType, _type); + return _type === this._type ? this : new FunctionType(this._id, this._prefix, this._markers, this._modifiers, this._constructorType, this._typeParameters, this._parameters, this._returnType, _type); } public acceptJavaScript

(v: JavaScriptVisitor

, p: P): J | null { @@ -1099,13 +1088,19 @@ export class FunctionType extends JSMixin(Object) implements Expression, TypeTre return t._constructorType; } public withConstructorType(constructorType: JLeftPadded): FunctionType { - return t._constructorType === constructorType ? t : new FunctionType(t._id, t._prefix, t._markers, t._modifiers, constructorType, t._typeParameters, t._parameters, t._arrow, t._returnType, t._type); + return t._constructorType === constructorType ? t : new FunctionType(t._id, t._prefix, t._markers, t._modifiers, constructorType, t._typeParameters, t._parameters, t._returnType, t._type); } public get parameters(): JContainer { return t._parameters; } public withParameters(parameters: JContainer): FunctionType { - return t._parameters === parameters ? t : new FunctionType(t._id, t._prefix, t._markers, t._modifiers, t._constructorType, t._typeParameters, parameters, t._arrow, t._returnType, t._type); + return t._parameters === parameters ? t : new FunctionType(t._id, t._prefix, t._markers, t._modifiers, t._constructorType, t._typeParameters, parameters, t._returnType, t._type); + } + public get returnType(): JLeftPadded { + return t._returnType; + } + public withReturnType(returnType: JLeftPadded): FunctionType { + return t._returnType === returnType ? t : new FunctionType(t._id, t._prefix, t._markers, t._modifiers, t._constructorType, t._typeParameters, t._parameters, returnType, t._type); } } } diff --git a/openrewrite/src/javascript/visitor.ts b/openrewrite/src/javascript/visitor.ts index 1582fb0e..8d4c5a03 100644 --- a/openrewrite/src/javascript/visitor.ts +++ b/openrewrite/src/javascript/visitor.ts @@ -186,8 +186,7 @@ export class JavaScriptVisitor

extends JavaVisitor

{ functionType = functionType.padding.withConstructorType(this.visitJsLeftPadded(functionType.padding.constructorType, JsLeftPadded.Location.FUNCTION_TYPE_CONSTRUCTOR_TYPE, p)!); functionType = functionType.withTypeParameters(this.visitAndCast(functionType.typeParameters, p)); functionType = functionType.padding.withParameters(this.visitJsContainer(functionType.padding.parameters, JsContainer.Location.FUNCTION_TYPE_PARAMETERS, p)!); - functionType = functionType.withArrow(this.visitJsSpace(functionType.arrow, JsSpace.Location.FUNCTION_TYPE_ARROW, p)!); - functionType = functionType.withReturnType(this.visitAndCast(functionType.returnType, p)!); + functionType = functionType.padding.withReturnType(this.visitJsLeftPadded(functionType.padding.returnType, JsLeftPadded.Location.FUNCTION_TYPE_RETURN_TYPE, p)!); return functionType; } diff --git a/openrewrite/test/javascript/parser/function.test.ts b/openrewrite/test/javascript/parser/function.test.ts index f198d8dc..c7c29032 100644 --- a/openrewrite/test/javascript/parser/function.test.ts +++ b/openrewrite/test/javascript/parser/function.test.ts @@ -48,7 +48,7 @@ describe('function mapping', () => { ); }); - test('parameter with trailing comma', () => { + test('function with type params', () => { rewriteRun( //language=typescript typeScript(` diff --git a/openrewrite/test/javascript/parser/variableDeclarations.test.ts b/openrewrite/test/javascript/parser/variableDeclarations.test.ts index ebe2aa04..f6d28861 100644 --- a/openrewrite/test/javascript/parser/variableDeclarations.test.ts +++ b/openrewrite/test/javascript/parser/variableDeclarations.test.ts @@ -204,4 +204,16 @@ describe('variable declaration mapping', () => { `) ); }); + + test.skip('variable declaration with decorator', () => { + rewriteRun( + //language=typescript + typeScript(` + export namespace process { + // @ts-ignore: decorator + @lazy export const platform = "wasm"; + } + `) + ); + }); }); diff --git a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptReceiver.java b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptReceiver.java index 2db8e1eb..83df3ef1 100644 --- a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptReceiver.java +++ b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptReceiver.java @@ -207,8 +207,7 @@ public JS.FunctionType visitFunctionType(JS.FunctionType functionType, ReceiverC functionType = functionType.getPadding().withConstructorType(ctx.receiveNonNullNode(functionType.getPadding().getConstructorType(), leftPaddedValueReceiver(java.lang.Boolean.class))); functionType = functionType.withTypeParameters(ctx.receiveNode(functionType.getTypeParameters(), ctx::receiveTree)); functionType = functionType.getPadding().withParameters(ctx.receiveNonNullNode(functionType.getPadding().getParameters(), JavaScriptReceiver::receiveContainer)); - functionType = functionType.withArrow(ctx.receiveNonNullNode(functionType.getArrow(), JavaScriptReceiver::receiveSpace)); - functionType = functionType.withReturnType(ctx.receiveNonNullNode(functionType.getReturnType(), ctx::receiveTree)); + functionType = functionType.getPadding().withReturnType(ctx.receiveNonNullNode(functionType.getPadding().getReturnType(), JavaScriptReceiver::receiveLeftPaddedTree)); functionType = functionType.withType(ctx.receiveValue(functionType.getType(), JavaType.class)); return functionType; } @@ -1859,8 +1858,7 @@ private static JS.FunctionType createJSFunctionType(ReceiverContext ctx) { ctx.receiveNonNullNode(null, leftPaddedValueReceiver(java.lang.Boolean.class)), ctx.receiveNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), - ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), - ctx.receiveNonNullNode(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.class) ); } diff --git a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSender.java b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSender.java index 92c5e922..42169389 100644 --- a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSender.java +++ b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSender.java @@ -189,8 +189,7 @@ public JS.FunctionType visitFunctionType(JS.FunctionType functionType, SenderCon ctx.sendNode(functionType, e -> e.getPadding().getConstructorType(), JavaScriptSender::sendLeftPadded); ctx.sendNode(functionType, JS.FunctionType::getTypeParameters, ctx::sendTree); ctx.sendNode(functionType, e -> e.getPadding().getParameters(), JavaScriptSender::sendContainer); - ctx.sendNode(functionType, JS.FunctionType::getArrow, JavaScriptSender::sendSpace); - ctx.sendNode(functionType, JS.FunctionType::getReturnType, ctx::sendTree); + ctx.sendNode(functionType, e -> e.getPadding().getReturnType(), JavaScriptSender::sendLeftPadded); ctx.sendTypedValue(functionType, JS.FunctionType::getType); return functionType; } diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java index b87a512f..d442b673 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java @@ -267,10 +267,9 @@ public J visitFunctionType(JS.FunctionType functionType, P p) { f = f.withModifiers(Objects.requireNonNull(ListUtils.map(f.getModifiers(), e -> visitAndCast(e, p)))); f = f.getPadding().withConstructorType(Objects.requireNonNull(visitLeftPadded(f.getPadding().getConstructorType(), JsLeftPadded.Location.FUNCTION_TYPE_CONSTRUCTOR, p))); f = f.withTypeParameters(visitAndCast(f.getTypeParameters(), p)); - f = f.getPadding().withParameters(Objects.requireNonNull(visitContainer(f.getPadding().getParameters(), JContainer.Location.LANGUAGE_EXTENSION, p))); + f = f.getPadding().withParameters(Objects.requireNonNull(visitContainer(f.getPadding().getParameters(), JsContainer.Location.FUNCTION_TYPE_PARAMETERS, p))); f = f.withParameters(Objects.requireNonNull(ListUtils.map(f.getParameters(), e -> visitAndCast(e, p)))); - f = f.withArrow(visitSpace(f.getArrow(), JsSpace.Location.FUNCTION_TYPE_ARROW_PREFIX, p)); - f = f.withReturnType(Objects.requireNonNull(visitAndCast(f.getReturnType(), p))); + f = f.getPadding().withReturnType((Objects.requireNonNull(visitLeftPadded(f.getPadding().getReturnType(), JsLeftPadded.Location.FUNCTION_TYPE_RETURN_TYPE, p)))); f = f.withType(visitType(f.getType(), p)); return f; } diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java index caa63fa4..4a49dce3 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java @@ -190,7 +190,7 @@ public J visitExport(JS.Export export, PrintOutputCapture

p) { p.append("export"); boolean printBrackets = export.getPadding().getExports() != null && export.getPadding().getExports().getMarkers().findFirst(Braces.class).isPresent(); - visitContainer(printBrackets ? "{" : "", export.getPadding().getExports(), JsContainer.Location.FUNCTION_TYPE_PARAMETER, ",", printBrackets ? "}" : "", p); + visitContainer(printBrackets ? "{" : "", export.getPadding().getExports(), JsContainer.Location.FUNCTION_TYPE_PARAMETERS, ",", printBrackets ? "}" : "", p); if (export.getFrom() != null) { visitSpace(export.getFrom(), Space.Location.LANGUAGE_EXTENSION, p); @@ -220,10 +220,9 @@ public J visitFunctionType(JS.FunctionType functionType, PrintOutputCapture

p visitRightPadded(typeParameters.getPadding().getTypeParameters(), JRightPadded.Location.TYPE_PARAMETER, ",", p); p.append(">"); } - visitContainer("(", functionType.getPadding().getParameters(), JsContainer.Location.FUNCTION_TYPE_PARAMETER, ",", ")", p); - visitSpace(functionType.getArrow(), JsSpace.Location.FUNCTION_TYPE_ARROW_PREFIX, p); - p.append("=>"); - visit(functionType.getReturnType(), p); + visitContainer("(", functionType.getPadding().getParameters(), JsContainer.Location.FUNCTION_TYPE_PARAMETERS, ",", ")", p); + visitLeftPadded("=>", functionType.getPadding().getReturnType(), JsLeftPadded.Location.FUNCTION_TYPE_RETURN_TYPE, p); + afterSyntax(functionType, p); return functionType; } diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JS.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JS.java index 2ea5b147..5f0a4ccd 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JS.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JS.java @@ -1024,13 +1024,15 @@ public FunctionType withParameters(List parameters) { return getPadding().withParameters(JContainer.withElements(this.parameters, parameters)); } - @Getter - @With - Space arrow; + JLeftPadded returnType; - @Getter - @With - Expression returnType; + public Expression getReturnType() { + return returnType.getElement(); + } + + public FunctionType withReturnType(Expression returnType) { + return getPadding().withReturnType(JLeftPadded.withElement(this.returnType, returnType)); + } @Getter @With @@ -1072,7 +1074,7 @@ public JLeftPadded getConstructorType() { public FunctionType withConstructorType(JLeftPadded constructor) { return t.constructorType == constructor ? t : - new FunctionType(t.id, t.prefix, t.markers, t.modifiers, constructor, t.typeParameters, t.parameters, t.arrow, t.returnType, t.type); + new FunctionType(t.id, t.prefix, t.markers, t.modifiers, constructor, t.typeParameters, t.parameters, t.returnType, t.type); } public JContainer getParameters() { @@ -1080,7 +1082,15 @@ public JContainer getParameters() { } public FunctionType withParameters(JContainer parameters) { - return t.parameters == parameters ? t : new FunctionType(t.id, t.prefix, t.markers, t.modifiers, t.constructorType, t.typeParameters, parameters, t.arrow, t.returnType, t.type); + return t.parameters == parameters ? t : new FunctionType(t.id, t.prefix, t.markers, t.modifiers, t.constructorType, t.typeParameters, parameters, t.returnType, t.type); + } + + public JLeftPadded getReturnType() { + return t.returnType; + } + + public FunctionType withReturnType(JLeftPadded returnType) { + return t.returnType == returnType ? t : new FunctionType(t.id, t.prefix, t.markers, t.modifiers, t.constructorType, t.typeParameters, t.parameters, returnType, t.type); } } } diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsContainer.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsContainer.java index 304815d3..9ec658fe 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsContainer.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsContainer.java @@ -23,7 +23,7 @@ public enum Location { ARRAY_LITERAL_EXPRESSION(JsSpace.Location.ARRAY_LITERAL_ELEMENTS, JsRightPadded.Location.ARRAY_LITERAL_ELEMENT_SUFFIX), BINDING_ELEMENT(JsSpace.Location.BINDING_ELEMENTS, JsRightPadded.Location.BINDING_ELEMENT), EXPORT_ELEMENT(JsSpace.Location.EXPORT_ELEMENTS, JsRightPadded.Location.EXPORT_ELEMENT_SUFFIX), - FUNCTION_TYPE_PARAMETER(JsSpace.Location.FUNCTION_TYPE_PARAMETERS, JsRightPadded.Location.FUNCTION_TYPE_PARAMETER_SUFFIX), + FUNCTION_TYPE_PARAMETERS(JsSpace.Location.FUNCTION_TYPE_PARAMETERS, JsRightPadded.Location.FUNCTION_TYPE_PARAMETERS_SUFFIX), IMPORT_ELEMENT(JsSpace.Location.IMPORT_ELEMENTS, JsRightPadded.Location.IMPORT_ELEMENT_SUFFIX), TUPLE_ELEMENT(JsSpace.Location.TUPLE_ELEMENT, JsRightPadded.Location.TUPLE_ELEMENT_SUFFIX), JSMETHOD_DECLARATION_PARAMETERS(JsSpace.Location.JSMETHOD_DECLARATION_PARAMETERS, JsRightPadded.Location.JSMETHOD_DECLARATION_PARAMETER), diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsLeftPadded.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsLeftPadded.java index 8efbfa9f..3746cc8f 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsLeftPadded.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsLeftPadded.java @@ -54,6 +54,7 @@ public enum Location { LAMBDA_ARROW(JsSpace.Location.LAMBDA_ARROW_PREFIX), JS_YIELD_DELEGATED(JsSpace.Location.JS_YIELD_DELEGATED_PREFIX), FUNCTION_TYPE_CONSTRUCTOR(JsSpace.Location.FUNCTION_TYPE_CONSTRUCTOR_PREFIX), + FUNCTION_TYPE_RETURN_TYPE(JsSpace.Location.FUNCTION_TYPE_RETURN_TYPE_PREFIX), JSTRY_FINALLY(JsSpace.Location.JSTRY_FINALLY_PREFIX), JS_IMPORT_MODULE_SPECIFIER(JsSpace.Location.JS_IMPORT_MODULE_SPECIFIER_PREFIX), JS_IMPORT_ATTRIBUTE_VALUE(JsSpace.Location.JS_IMPORT_ATTRIBUTE_VALUE_PREFIX), diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsRightPadded.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsRightPadded.java index 338d6623..d0f3073f 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsRightPadded.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsRightPadded.java @@ -25,7 +25,7 @@ public enum Location { BINDING_ELEMENT(JsSpace.Location.BINDING_ELEMENT_SUFFIX), BINDING_ELEMENT_PROPERTY_NAME(JsSpace.Location.BINDING_ELEMENT_PROPERTY_NAME_SUFFIX), EXPORT_ELEMENT_SUFFIX(JsSpace.Location.EXPORT_ELEMENT_SUFFIX), - FUNCTION_TYPE_PARAMETER_SUFFIX(JsSpace.Location.FUNCTION_TYPE_SUFFIX), + FUNCTION_TYPE_PARAMETERS_SUFFIX(JsSpace.Location.FUNCTION_TYPE_PARAMETERS_SUFFIX), IMPORT_ELEMENT_SUFFIX(JsSpace.Location.IMPORT_ELEMENT_SUFFIX), IMPORT_NAME_SUFFIX(JsSpace.Location.IMPORT_NAME_SUFFIX), PROPERTY_ASSIGNMENT_NAME(JsSpace.Location.PROPERTY_ASSIGNMENT_NAME_SUFFIX), diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsSpace.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsSpace.java index 93f3e418..ace1661f 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsSpace.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsSpace.java @@ -37,10 +37,10 @@ public enum Location { EXPORT_FROM_PREFIX, EXPORT_INITIALIZER_PREFIX, EXPORT_PREFIX, - FUNCTION_TYPE_ARROW_PREFIX, + FUNCTION_TYPE_RETURN_TYPE_PREFIX, FUNCTION_TYPE_PARAMETERS, FUNCTION_TYPE_PREFIX, - FUNCTION_TYPE_SUFFIX, + FUNCTION_TYPE_PARAMETERS_SUFFIX, IMPORT_ELEMENTS, IMPORT_ELEMENT_SUFFIX, IMPORT_FROM_PREFIX,