Skip to content

Commit

Permalink
remove separate Space field in favor of JLeftPadded
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegDokuka committed Nov 13, 2024
1 parent ac916bb commit 92d8196
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 111 deletions.
50 changes: 31 additions & 19 deletions openrewrite/src/javascript/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1841,21 +1841,29 @@ export class JavaScriptParserVisitor {
Space.EMPTY,
Markers.EMPTY,
[],
this.prefix(node),
kind?.kind === ts.SyntaxKind.LetKeyword ? JS.ScopedVariableDeclarations.Scope.Let :
kind?.kind === ts.SyntaxKind.ConstKeyword ? JS.ScopedVariableDeclarations.Scope.Const : JS.ScopedVariableDeclarations.Scope.Var,
node.declarations.map(declaration => {
return this.rightPadded(new J.VariableDeclarations(
randomId(),
this.prefix(declaration),
Markers.EMPTY,
[], // FIXME decorators?
[], // FIXME modifiers?
this.mapTypeInfo(declaration),
null, // FIXME varargs
[],
[this.rightPadded(this.visit(declaration), Space.EMPTY)]
), this.suffix(declaration));
this.leftPadded(
this.prefix(node),
kind?.kind === ts.SyntaxKind.LetKeyword
? JS.ScopedVariableDeclarations.Scope.Let
: kind?.kind === ts.SyntaxKind.ConstKeyword
? JS.ScopedVariableDeclarations.Scope.Const
: JS.ScopedVariableDeclarations.Scope.Var
),
node.declarations.map((declaration) => {
return this.rightPadded(
new J.VariableDeclarations(
randomId(),
this.prefix(declaration),
Markers.EMPTY,
[], // FIXME decorators?
[], // FIXME modifiers?
this.mapTypeInfo(declaration),
null, // FIXME varargs
[],
[this.rightPadded(this.visit(declaration), Space.EMPTY)]
),
this.suffix(declaration)
);
})
);
}
Expand Down Expand Up @@ -2010,8 +2018,10 @@ export class JavaScriptParserVisitor {
Space.EMPTY,
Markers.EMPTY,
this.mapModifiers(node),
namespaceKeyword ? this.prefix(namespaceKeyword) : Space.EMPTY,
keywordType,
this.leftPadded(
namespaceKeyword ? this.prefix(namespaceKeyword) : Space.EMPTY,
keywordType
),
this.rightPadded(
new J.FieldAccess(
randomId(),
Expand All @@ -2035,8 +2045,10 @@ export class JavaScriptParserVisitor {
node.parent.kind === ts.SyntaxKind.ModuleBlock ? this.prefix(node) : Space.EMPTY,
Markers.EMPTY,
this.mapModifiers(node),
namespaceKeyword ? this.prefix(namespaceKeyword) : Space.EMPTY,
keywordType,
this.leftPadded(
namespaceKeyword ? this.prefix(namespaceKeyword) : Space.EMPTY,
keywordType
),
this.rightPadded(this.convert(node.name), this.prefix(node)), // J.FieldAccess
body // J.Block
);
Expand Down
12 changes: 4 additions & 8 deletions openrewrite/src/javascript/remote/receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ class Visitor extends JavaScriptVisitor<ReceiverContext> {
scopedVariableDeclarations = scopedVariableDeclarations.withPrefix(ctx.receiveNode(scopedVariableDeclarations.prefix, receiveSpace)!);
scopedVariableDeclarations = scopedVariableDeclarations.withMarkers(ctx.receiveNode(scopedVariableDeclarations.markers, ctx.receiveMarkers)!);
scopedVariableDeclarations = scopedVariableDeclarations.withModifiers(ctx.receiveNodes(scopedVariableDeclarations.modifiers, ctx.receiveTree)!);
scopedVariableDeclarations = scopedVariableDeclarations.withScopePrefix(ctx.receiveNode(scopedVariableDeclarations.scopePrefix, receiveSpace)!);
scopedVariableDeclarations = scopedVariableDeclarations.withScope(ctx.receiveValue(scopedVariableDeclarations.scope, ValueType.Enum));
scopedVariableDeclarations = scopedVariableDeclarations.padding.withScope(ctx.receiveNode(scopedVariableDeclarations.padding.scope, leftPaddedValueReceiver(ValueType.Enum)));
scopedVariableDeclarations = scopedVariableDeclarations.padding.withVariables(ctx.receiveNodes(scopedVariableDeclarations.padding.variables, receiveRightPaddedTree)!);
return scopedVariableDeclarations;
}
Expand Down Expand Up @@ -347,8 +346,7 @@ class Visitor extends JavaScriptVisitor<ReceiverContext> {
namespaceDeclaration = namespaceDeclaration.withPrefix(ctx.receiveNode(namespaceDeclaration.prefix, receiveSpace)!);
namespaceDeclaration = namespaceDeclaration.withMarkers(ctx.receiveNode(namespaceDeclaration.markers, ctx.receiveMarkers)!);
namespaceDeclaration = namespaceDeclaration.withModifiers(ctx.receiveNodes(namespaceDeclaration.modifiers, ctx.receiveTree)!);
namespaceDeclaration = namespaceDeclaration.withKeywordPrefix(ctx.receiveNode(namespaceDeclaration.keywordPrefix, receiveSpace)!);
namespaceDeclaration = namespaceDeclaration.withKeywordType(ctx.receiveValue(namespaceDeclaration.keywordType, ValueType.Enum)!);
namespaceDeclaration = namespaceDeclaration.padding.withKeywordType(ctx.receiveNode(namespaceDeclaration.padding.keywordType, leftPaddedValueReceiver(ValueType.Enum))!);
namespaceDeclaration = namespaceDeclaration.padding.withName(ctx.receiveNode(namespaceDeclaration.padding.name, receiveRightPaddedTree)!);
namespaceDeclaration = namespaceDeclaration.withBody(ctx.receiveNode(namespaceDeclaration.body, ctx.receiveTree)!);
return namespaceDeclaration;
Expand Down Expand Up @@ -1196,8 +1194,7 @@ class Factory implements ReceiverFactory {
ctx.receiveNode(null, receiveSpace)!,
ctx.receiveNode(null, ctx.receiveMarkers)!,
ctx.receiveNodes<Java.Modifier>(null, ctx.receiveTree)!,
ctx.receiveNode(null, receiveSpace)!,
ctx.receiveValue(null, ValueType.Enum),
ctx.receiveNode<JLeftPadded<ScopedVariableDeclarations.Scope>>(null, leftPaddedValueReceiver(ValueType.Enum)),
ctx.receiveNodes(null, receiveRightPaddedTree)!
);
}
Expand Down Expand Up @@ -1375,8 +1372,7 @@ class Factory implements ReceiverFactory {
ctx.receiveNode(null, receiveSpace)!,
ctx.receiveNode(null, ctx.receiveMarkers)!,
ctx.receiveNodes<Java.Modifier>(null, ctx.receiveTree)!,
ctx.receiveNode(null, receiveSpace)!,
ctx.receiveValue(null, ValueType.Enum)!,
ctx.receiveNode<JLeftPadded<NamespaceDeclaration.KeywordType>>(null, leftPaddedValueReceiver(ValueType.Enum))!,
ctx.receiveNode<JRightPadded<Expression>>(null, receiveRightPaddedTree)!,
ctx.receiveNode<Java.Block>(null, ctx.receiveTree)!
);
Expand Down
6 changes: 2 additions & 4 deletions openrewrite/src/javascript/remote/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ class Visitor extends JavaScriptVisitor<SenderContext> {
ctx.sendNode(scopedVariableDeclarations, v => v.prefix, Visitor.sendSpace);
ctx.sendNode(scopedVariableDeclarations, v => v.markers, ctx.sendMarkers);
ctx.sendNodes(scopedVariableDeclarations, v => v.modifiers, ctx.sendTree, t => t.id);
ctx.sendNode(scopedVariableDeclarations, v => v.scopePrefix, Visitor.sendSpace);
ctx.sendValue(scopedVariableDeclarations, v => v.scope, ValueType.Enum);
ctx.sendNode(scopedVariableDeclarations, v => v.padding.scope, Visitor.sendLeftPadded(ValueType.Enum));
ctx.sendNodes(scopedVariableDeclarations, v => v.padding.variables, Visitor.sendRightPadded(ValueType.Tree), t => t.element.id);
return scopedVariableDeclarations;
}
Expand Down Expand Up @@ -342,8 +341,7 @@ class Visitor extends JavaScriptVisitor<SenderContext> {
ctx.sendNode(namespaceDeclaration, v => v.prefix, Visitor.sendSpace);
ctx.sendNode(namespaceDeclaration, v => v.markers, ctx.sendMarkers);
ctx.sendNodes(namespaceDeclaration, v => v.modifiers, ctx.sendTree, t => t.id);
ctx.sendNode(namespaceDeclaration, v => v.keywordPrefix, Visitor.sendSpace);
ctx.sendValue(namespaceDeclaration, v => v.keywordType, ValueType.Enum);
ctx.sendNode(namespaceDeclaration, v => v.padding.keywordType, Visitor.sendLeftPadded(ValueType.Enum));
ctx.sendNode(namespaceDeclaration, v => v.padding.name, Visitor.sendRightPadded(ValueType.Tree));
ctx.sendNode(namespaceDeclaration, v => v.body, ctx.sendTree);
return namespaceDeclaration;
Expand Down
4 changes: 3 additions & 1 deletion openrewrite/src/javascript/tree/support_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ export namespace JsLeftPadded {
UNARY_OPERATOR,
JSVARIABLE_DECLARATIONS_JSNAMED_VARIABLE_INITIALIZER,
JSVARIABLE_DECLARATIONS_JSNAMED_VARIABLE_DIMENSIONS_AFTER_NAME,
JSMETHOD_DECLARATION_DEFAULT_VALUE
JSMETHOD_DECLARATION_DEFAULT_VALUE,
NAMESPACE_DECLARATION_KEYWORD_TYPE,
SCOPED_VARIABLE_DECLARATIONS_SCOPE
}
}
export namespace JsRightPadded {
Expand Down
Loading

0 comments on commit 92d8196

Please sign in to comment.