From e29599bed014a3afa558ae31b6bdbd26d72587fb Mon Sep 17 00:00:00 2001 From: Oleh Dokuka <5380167+OlegDokuka@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:24:38 +0200 Subject: [PATCH] fix indexed access type to return TypeTree (#165) --- openrewrite/src/javascript/parser.ts | 16 +- openrewrite/src/javascript/remote/receiver.ts | 42 ++++- openrewrite/src/javascript/remote/sender.ts | 21 ++- .../src/javascript/tree/support_types.ts | 6 + openrewrite/src/javascript/tree/tree.ts | 174 +++++++++++++++++- openrewrite/src/javascript/visitor.ts | 29 ++- .../test/javascript/e2e/twenty.files.test.ts | 119 ++++++++++++ .../parser/indexedAccessType.test.ts | 66 +++++++ .../javascript/remote/JavaScriptReceiver.java | 42 +++++ .../javascript/remote/JavaScriptSender.java | 21 +++ .../remote/JavaScriptValidator.java | 13 ++ .../javascript/JavaScriptVisitor.java | 31 ++++ .../internal/JavaScriptPrinter.java | 36 ++++ .../org/openrewrite/javascript/tree/JS.java | 165 ++++++++++++++++- .../javascript/tree/JsRightPadded.java | 2 + .../openrewrite/javascript/tree/JsSpace.java | 4 + 16 files changed, 773 insertions(+), 14 deletions(-) create mode 100644 openrewrite/test/javascript/parser/indexedAccessType.test.ts diff --git a/openrewrite/src/javascript/parser.ts b/openrewrite/src/javascript/parser.ts index 03985b06..72113667 100644 --- a/openrewrite/src/javascript/parser.ts +++ b/openrewrite/src/javascript/parser.ts @@ -1420,16 +1420,20 @@ export class JavaScriptParserVisitor { } visitIndexedAccessType(node: ts.IndexedAccessTypeNode) { - return new J.ArrayAccess( + return new JS.IndexedAccessType( randomId(), this.prefix(node), Markers.EMPTY, this.convert(node.objectType), - new J.ArrayDimension( - randomId(), - this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenBracketToken)!), - Markers.EMPTY, - this.rightPadded(this.convert(node.indexType), this.suffix(node.indexType)) + this.rightPadded( + new JS.IndexedAccessType.IndexType( + randomId(), + this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenBracketToken)!), + Markers.EMPTY, + this.rightPadded(this.convert(node.indexType), this.suffix(node.indexType)), + this.mapType(node.indexType) + ), + this.suffix(this.findChildNode(node, ts.SyntaxKind.CloseBracketToken)!) ), this.mapType(node) ); diff --git a/openrewrite/src/javascript/remote/receiver.ts b/openrewrite/src/javascript/remote/receiver.ts index 64135831..05d115e6 100644 --- a/openrewrite/src/javascript/remote/receiver.ts +++ b/openrewrite/src/javascript/remote/receiver.ts @@ -2,7 +2,7 @@ import * as extensions from "./remote_extensions"; import {Checksum, Cursor, FileAttributes, ListUtils, Tree} from '../../core'; import {DetailsReceiver, Receiver, ReceiverContext, ReceiverFactory, ValueType} from '@openrewrite/rewrite-remote'; import {JavaScriptVisitor} from '..'; -import {JS, JsLeftPadded, JsRightPadded, JsContainer, JsSpace, CompilationUnit, Alias, ArrowFunction, Await, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier} from '../tree'; +import {JS, JsLeftPadded, JsRightPadded, JsContainer, JsSpace, CompilationUnit, Alias, ArrowFunction, Await, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier, IndexedAccessType} from '../tree'; import {Expression, J, JContainer, JLeftPadded, JRightPadded, NameTree, Space, Statement, TypeTree, TypedTree} from "../../java"; import * as Java from "../../java/tree"; @@ -572,6 +572,25 @@ class Visitor extends JavaScriptVisitor { return exportSpecifier; } + public visitIndexedAccessType(indexedAccessType: IndexedAccessType, ctx: ReceiverContext): J { + indexedAccessType = indexedAccessType.withId(ctx.receiveValue(indexedAccessType.id, ValueType.UUID)!); + indexedAccessType = indexedAccessType.withPrefix(ctx.receiveNode(indexedAccessType.prefix, receiveSpace)!); + indexedAccessType = indexedAccessType.withMarkers(ctx.receiveNode(indexedAccessType.markers, ctx.receiveMarkers)!); + indexedAccessType = indexedAccessType.withObjectType(ctx.receiveNode(indexedAccessType.objectType, ctx.receiveTree)!); + indexedAccessType = indexedAccessType.padding.withIndexType(ctx.receiveNode(indexedAccessType.padding.indexType, receiveRightPaddedTree)!); + indexedAccessType = indexedAccessType.withType(ctx.receiveValue(indexedAccessType.type, ValueType.Object)); + return indexedAccessType; + } + + public visitIndexedAccessTypeIndexType(indexType: IndexedAccessType.IndexType, ctx: ReceiverContext): J { + indexType = indexType.withId(ctx.receiveValue(indexType.id, ValueType.UUID)!); + indexType = indexType.withPrefix(ctx.receiveNode(indexType.prefix, receiveSpace)!); + indexType = indexType.withMarkers(ctx.receiveNode(indexType.markers, ctx.receiveMarkers)!); + indexType = indexType.padding.withElement(ctx.receiveNode(indexType.padding.element, receiveRightPaddedTree)!); + indexType = indexType.withType(ctx.receiveValue(indexType.type, ValueType.Object)); + return indexType; + } + public visitAnnotatedType(annotatedType: Java.AnnotatedType, ctx: ReceiverContext): J { annotatedType = annotatedType.withId(ctx.receiveValue(annotatedType.id, ValueType.UUID)!); annotatedType = annotatedType.withPrefix(ctx.receiveNode(annotatedType.prefix, receiveSpace)!); @@ -1840,6 +1859,27 @@ class Factory implements ReceiverFactory { ); } + if (type === "org.openrewrite.javascript.tree.JS$IndexedAccessType") { + return new IndexedAccessType( + ctx.receiveValue(null, ValueType.UUID)!, + ctx.receiveNode(null, receiveSpace)!, + ctx.receiveNode(null, ctx.receiveMarkers)!, + ctx.receiveNode(null, ctx.receiveTree)!, + ctx.receiveNode>(null, receiveRightPaddedTree)!, + ctx.receiveValue(null, ValueType.Object) + ); + } + + if (type === "org.openrewrite.javascript.tree.JS$IndexedAccessType$IndexType") { + return new IndexedAccessType.IndexType( + ctx.receiveValue(null, ValueType.UUID)!, + ctx.receiveNode(null, receiveSpace)!, + ctx.receiveNode(null, ctx.receiveMarkers)!, + ctx.receiveNode>(null, receiveRightPaddedTree)!, + ctx.receiveValue(null, ValueType.Object) + ); + } + if (type === "org.openrewrite.java.tree.J$AnnotatedType") { return new Java.AnnotatedType( ctx.receiveValue(null, ValueType.UUID)!, diff --git a/openrewrite/src/javascript/remote/sender.ts b/openrewrite/src/javascript/remote/sender.ts index 7b3df00f..90ae8ee7 100644 --- a/openrewrite/src/javascript/remote/sender.ts +++ b/openrewrite/src/javascript/remote/sender.ts @@ -2,7 +2,7 @@ import * as extensions from "./remote_extensions"; import {Cursor, ListUtils, Tree} from '../../core'; import {Sender, SenderContext, ValueType} from '@openrewrite/rewrite-remote'; import {JavaScriptVisitor} from '..'; -import {JS, JsLeftPadded, JsRightPadded, JsContainer, JsSpace, CompilationUnit, Alias, ArrowFunction, Await, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier} from '../tree'; +import {JS, JsLeftPadded, JsRightPadded, JsContainer, JsSpace, CompilationUnit, Alias, ArrowFunction, Await, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier, IndexedAccessType} from '../tree'; import {Expression, J, JContainer, JLeftPadded, JRightPadded, Space, Statement} from "../../java"; import * as Java from "../../java/tree"; @@ -567,6 +567,25 @@ class Visitor extends JavaScriptVisitor { return exportSpecifier; } + public visitIndexedAccessType(indexedAccessType: IndexedAccessType, ctx: SenderContext): J { + ctx.sendValue(indexedAccessType, v => v.id, ValueType.UUID); + ctx.sendNode(indexedAccessType, v => v.prefix, Visitor.sendSpace); + ctx.sendNode(indexedAccessType, v => v.markers, ctx.sendMarkers); + ctx.sendNode(indexedAccessType, v => v.objectType, ctx.sendTree); + ctx.sendNode(indexedAccessType, v => v.padding.indexType, Visitor.sendRightPadded(ValueType.Tree)); + ctx.sendTypedValue(indexedAccessType, v => v.type, ValueType.Object); + return indexedAccessType; + } + + public visitIndexedAccessTypeIndexType(indexType: IndexedAccessType.IndexType, ctx: SenderContext): J { + ctx.sendValue(indexType, v => v.id, ValueType.UUID); + ctx.sendNode(indexType, v => v.prefix, Visitor.sendSpace); + ctx.sendNode(indexType, v => v.markers, ctx.sendMarkers); + ctx.sendNode(indexType, v => v.padding.element, Visitor.sendRightPadded(ValueType.Tree)); + ctx.sendTypedValue(indexType, v => v.type, ValueType.Object); + return indexType; + } + public visitAnnotatedType(annotatedType: Java.AnnotatedType, ctx: SenderContext): J { ctx.sendValue(annotatedType, v => v.id, ValueType.UUID); ctx.sendNode(annotatedType, v => v.prefix, Visitor.sendSpace); diff --git a/openrewrite/src/javascript/tree/support_types.ts b/openrewrite/src/javascript/tree/support_types.ts index 3ce653bd..72d70db4 100644 --- a/openrewrite/src/javascript/tree/support_types.ts +++ b/openrewrite/src/javascript/tree/support_types.ts @@ -251,6 +251,10 @@ export namespace JsSpace { EXPORT_SPECIFIER_PREFIX, NAMED_EXPORTS_PREFIX, EXPORT_ASSIGNMENT_PREFIX, + INDEXED_ACCESS_TYPE_PREFIX, + INDEXED_ACCESS_TYPE_INDEX_TYPE_PREFIX, + INDEXED_ACCESS_TYPE_INDEX_TYPE_SUFFIX, + INDEXED_ACCESS_TYPE_INDEX_TYPE_ELEMENT_SUFFIX, } } export namespace JsLeftPadded { @@ -311,6 +315,8 @@ export namespace JsRightPadded { TEMPLATE_EXPRESSION_TEMPLATE_SPANS, TAGGED_TEMPLATE_EXPRESSION_TAG, IMPORT_TYPE_HAS_TYPEOF, + INDEXED_ACCESS_TYPE_INDEX_TYPE, + INDEXED_ACCESS_TYPE_INDEX_TYPE_ELEMENT, } } export namespace JsContainer { diff --git a/openrewrite/src/javascript/tree/tree.ts b/openrewrite/src/javascript/tree/tree.ts index d7025a0f..fe89641c 100644 --- a/openrewrite/src/javascript/tree/tree.ts +++ b/openrewrite/src/javascript/tree/tree.ts @@ -2632,7 +2632,7 @@ export class TypeQuery extends JSMixin(Object) implements Expression, TypeTree { } @LstType("org.openrewrite.javascript.tree.JS$TypeOperator") -export class TypeOperator extends JSMixin(Object) implements Expression, TypedTree, NameTree { +export class TypeOperator extends JSMixin(Object) implements Expression, TypeTree { public constructor(id: UUID, prefix: Space, markers: Markers, operator: TypeOperator.Type, expression: JLeftPadded) { super(); this._id = id; @@ -4991,3 +4991,175 @@ export class ExportSpecifier extends JSMixin(Object) implements Expression, Type } } + +@LstType("org.openrewrite.javascript.tree.JS$IndexedAccessType") +export class IndexedAccessType extends JSMixin(Object) implements Expression, TypeTree { + public constructor(id: UUID, prefix: Space, markers: Markers, objectType: TypeTree, indexType: JRightPadded, _type: JavaType | null) { + super(); + this._id = id; + this._prefix = prefix; + this._markers = markers; + this._objectType = objectType; + this._indexType = indexType; + this._type = _type; + } + + private readonly _id: UUID; + + public get id(): UUID { + return this._id; + } + + public withId(id: UUID): IndexedAccessType { + return id === this._id ? this : new IndexedAccessType(id, this._prefix, this._markers, this._objectType, this._indexType, this._type); + } + + private readonly _prefix: Space; + + public get prefix(): Space { + return this._prefix; + } + + public withPrefix(prefix: Space): IndexedAccessType { + return prefix === this._prefix ? this : new IndexedAccessType(this._id, prefix, this._markers, this._objectType, this._indexType, this._type); + } + + private readonly _markers: Markers; + + public get markers(): Markers { + return this._markers; + } + + public withMarkers(markers: Markers): IndexedAccessType { + return markers === this._markers ? this : new IndexedAccessType(this._id, this._prefix, markers, this._objectType, this._indexType, this._type); + } + + private readonly _objectType: TypeTree; + + public get objectType(): TypeTree { + return this._objectType; + } + + public withObjectType(objectType: TypeTree): IndexedAccessType { + return objectType === this._objectType ? this : new IndexedAccessType(this._id, this._prefix, this._markers, objectType, this._indexType, this._type); + } + + private readonly _indexType: JRightPadded; + + public get indexType(): TypeTree { + return this._indexType.element; + } + + public withIndexType(indexType: TypeTree): IndexedAccessType { + return this.padding.withIndexType(this._indexType.withElement(indexType)); + } + + private readonly _type: JavaType | null; + + public get type(): JavaType | null { + return this._type; + } + + public withType(_type: JavaType | null): IndexedAccessType { + return _type === this._type ? this : new IndexedAccessType(this._id, this._prefix, this._markers, this._objectType, this._indexType, _type); + } + + public acceptJavaScript

(v: JavaScriptVisitor

, p: P): J | null { + return v.visitIndexedAccessType(this, p); + } + + get padding() { + const t = this; + return new class { + public get indexType(): JRightPadded { + return t._indexType; + } + public withIndexType(indexType: JRightPadded): IndexedAccessType { + return t._indexType === indexType ? t : new IndexedAccessType(t._id, t._prefix, t._markers, t._objectType, indexType, t._type); + } + } + } + +} + +export namespace IndexedAccessType { + @LstType("org.openrewrite.javascript.tree.JS$IndexedAccessType$IndexType") + export class IndexType extends JSMixin(Object) implements Expression, TypeTree { + public constructor(id: UUID, prefix: Space, markers: Markers, element: JRightPadded, _type: JavaType | null) { + super(); + this._id = id; + this._prefix = prefix; + this._markers = markers; + this._element = element; + this._type = _type; + } + + private readonly _id: UUID; + + public get id(): UUID { + return this._id; + } + + public withId(id: UUID): IndexedAccessType.IndexType { + return id === this._id ? this : new IndexedAccessType.IndexType(id, this._prefix, this._markers, this._element, this._type); + } + + private readonly _prefix: Space; + + public get prefix(): Space { + return this._prefix; + } + + public withPrefix(prefix: Space): IndexedAccessType.IndexType { + return prefix === this._prefix ? this : new IndexedAccessType.IndexType(this._id, prefix, this._markers, this._element, this._type); + } + + private readonly _markers: Markers; + + public get markers(): Markers { + return this._markers; + } + + public withMarkers(markers: Markers): IndexedAccessType.IndexType { + return markers === this._markers ? this : new IndexedAccessType.IndexType(this._id, this._prefix, markers, this._element, this._type); + } + + private readonly _element: JRightPadded; + + public get element(): TypeTree { + return this._element.element; + } + + public withElement(element: TypeTree): IndexedAccessType.IndexType { + return this.padding.withElement(this._element.withElement(element)); + } + + private readonly _type: JavaType | null; + + public get type(): JavaType | null { + return this._type; + } + + public withType(_type: JavaType | null): IndexedAccessType.IndexType { + return _type === this._type ? this : new IndexedAccessType.IndexType(this._id, this._prefix, this._markers, this._element, _type); + } + + public acceptJavaScript

(v: JavaScriptVisitor

, p: P): J | null { + return v.visitIndexedAccessTypeIndexType(this, p); + } + + get padding() { + const t = this; + return new class { + public get element(): JRightPadded { + return t._element; + } + public withElement(element: JRightPadded): IndexedAccessType.IndexType { + return t._element === element ? t : new IndexedAccessType.IndexType(t._id, t._prefix, t._markers, element, t._type); + } + } + } + + } + +} diff --git a/openrewrite/src/javascript/visitor.ts b/openrewrite/src/javascript/visitor.ts index a67beb92..2bacb66f 100644 --- a/openrewrite/src/javascript/visitor.ts +++ b/openrewrite/src/javascript/visitor.ts @@ -1,7 +1,7 @@ import * as extensions from "./extensions"; import {ListUtils, SourceFile, Tree, TreeVisitor} from "../core"; import {JS, isJavaScript, JsLeftPadded, JsRightPadded, JsContainer, JsSpace} from "./tree"; -import {CompilationUnit, Alias, ArrowFunction, Await, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier} from "./tree"; +import {CompilationUnit, Alias, ArrowFunction, Await, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier, IndexedAccessType} from "./tree"; import {Expression, J, JContainer, JLeftPadded, JRightPadded, Space, Statement} from "../java/tree"; import {JavaVisitor} from "../java"; import * as Java from "../java/tree"; @@ -793,6 +793,33 @@ export class JavaScriptVisitor

extends JavaVisitor

{ return exportSpecifier; } + public visitIndexedAccessType(indexedAccessType: IndexedAccessType, p: P): J | null { + indexedAccessType = indexedAccessType.withPrefix(this.visitJsSpace(indexedAccessType.prefix, JsSpace.Location.INDEXED_ACCESS_TYPE_PREFIX, p)!); + let tempExpression = this.visitExpression(indexedAccessType, p) as Expression; + if (!(tempExpression instanceof IndexedAccessType)) + { + return tempExpression; + } + indexedAccessType = tempExpression as IndexedAccessType; + indexedAccessType = indexedAccessType.withMarkers(this.visitMarkers(indexedAccessType.markers, p)); + indexedAccessType = indexedAccessType.withObjectType(this.visitAndCast(indexedAccessType.objectType, p)!); + indexedAccessType = indexedAccessType.padding.withIndexType(this.visitJsRightPadded(indexedAccessType.padding.indexType, JsRightPadded.Location.INDEXED_ACCESS_TYPE_INDEX_TYPE, p)!); + return indexedAccessType; + } + + public visitIndexedAccessTypeIndexType(indexType: IndexedAccessType.IndexType, p: P): J | null { + indexType = indexType.withPrefix(this.visitJsSpace(indexType.prefix, JsSpace.Location.INDEXED_ACCESS_TYPE_INDEX_TYPE_PREFIX, p)!); + let tempExpression = this.visitExpression(indexType, p) as Expression; + if (!(tempExpression instanceof IndexedAccessType.IndexType)) + { + return tempExpression; + } + indexType = tempExpression as IndexedAccessType.IndexType; + indexType = indexType.withMarkers(this.visitMarkers(indexType.markers, p)); + indexType = indexType.padding.withElement(this.visitJsRightPadded(indexType.padding.element, JsRightPadded.Location.INDEXED_ACCESS_TYPE_INDEX_TYPE_ELEMENT, p)!); + return indexType; + } + public visitJsLeftPadded(left: JLeftPadded | null, loc: JsLeftPadded.Location, p: P): JLeftPadded { return extensions.visitJsLeftPadded(this, left, loc, p); } diff --git a/openrewrite/test/javascript/e2e/twenty.files.test.ts b/openrewrite/test/javascript/e2e/twenty.files.test.ts index a9a4fcfd..ed97d990 100644 --- a/openrewrite/test/javascript/e2e/twenty.files.test.ts +++ b/openrewrite/test/javascript/e2e/twenty.files.test.ts @@ -26,4 +26,123 @@ describe('highlight.js files tests', () => { ); }); + test('twenty/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts', () => { + rewriteRun( + //language=typescript + typeScript(` + import { Injectable } from '@nestjs/common'; + + import { + WorkflowRunOutput, + WorkflowRunStatus, + } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity'; + import { WorkflowActionFactory } from 'src/modules/workflow/workflow-executor/factories/workflow-action.factory'; + import { resolveInput } from 'src/modules/workflow/workflow-executor/utils/variable-resolver.util'; + import { WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type'; + + const MAX_RETRIES_ON_FAILURE = 3; + + export type WorkflowExecutorOutput = { + steps: WorkflowRunOutput['steps']; + status: WorkflowRunStatus; + }; + + @Injectable() + export class WorkflowExecutorWorkspaceService { + constructor(private readonly workflowActionFactory: WorkflowActionFactory) {} + + async execute({ + currentStepIndex, + steps, + context, + output, + attemptCount = 1, + }: { + currentStepIndex: number; + steps: WorkflowAction[]; + output: WorkflowExecutorOutput; + context: Record; + attemptCount?: number; + }): Promise { + if (currentStepIndex >= steps.length) { + return { ...output, status: WorkflowRunStatus.COMPLETED }; + } + + const step = steps[currentStepIndex]; + + const workflowAction = this.workflowActionFactory.get(step.type); + + const actionPayload = resolveInput(step.settings.input, context); + + const result = await workflowAction.execute(actionPayload); + + const stepOutput = output.steps[step.id]; + + const error = + result.error?.errorMessage ?? + (result.result ? undefined : 'Execution result error, no data or error'); + + const updatedStepOutput = { + id: step.id, + name: step.name, + type: step.type, + outputs: [ + ...(stepOutput?.outputs ?? []), + { + attemptCount, + result: result.result, + error, + }, + ], + }; + + const updatedOutput = { + ...output, + steps: { + ...output.steps, + [step.id]: updatedStepOutput, + }, + }; + + if (result.result) { + return await this.execute({ + currentStepIndex: currentStepIndex + 1, + steps, + context: { + ...context, + [step.id]: result.result, + }, + output: updatedOutput, + }); + } + + if (step.settings.errorHandlingOptions.continueOnFailure.value) { + return await this.execute({ + currentStepIndex: currentStepIndex + 1, + steps, + context, + output: updatedOutput, + }); + } + + if ( + step.settings.errorHandlingOptions.retryOnFailure.value && + attemptCount < MAX_RETRIES_ON_FAILURE + ) { + return await this.execute({ + currentStepIndex, + steps, + context, + output: updatedOutput, + attemptCount: attemptCount + 1, + }); + } + + return { ...updatedOutput, status: WorkflowRunStatus.FAILED }; + } + } + `) + ); + }); + }); diff --git a/openrewrite/test/javascript/parser/indexedAccessType.test.ts b/openrewrite/test/javascript/parser/indexedAccessType.test.ts new file mode 100644 index 00000000..153c4622 --- /dev/null +++ b/openrewrite/test/javascript/parser/indexedAccessType.test.ts @@ -0,0 +1,66 @@ +import {connect, disconnect, rewriteRun, typeScript} from '../testHarness'; + +describe('indexed access type mapping', () => { + beforeAll(() => connect()); + afterAll(() => disconnect()); + + test('simple type access', () => { + rewriteRun( + //language=typescript + typeScript(` + type Person = { age: number; name: string; alive: boolean }; + type Age = Person["age"]; + `), + //language=typescript + typeScript(` + /*1*/type/*2*/ Person/*3*/ =/*4*/ {/*5*/ age/*6*/: /*7*/number/*8*/; /*9*/name/*10*/:/*11*/ string/*12*/; /*13*/alive/*14*/: /*15*/boolean /*16*/}/*17*/;/*18*/ + /*19*/type/*20*/ Age/*21*/ =/*22*/ Person/*23*/[/*24*/"age"/*25*/]/*26*/;/*27*/ + `), + ); + }); + + test('advanced indexed access type', () => { + rewriteRun( + //language=typescript + typeScript(` + type Person = { age: number; name: string; alive: boolean }; + type I1 = Person["age" | "name"]; + type I2 = Person[keyof Person]; + type AliveOrName = "alive" | "name"; + type I3 = Person[AliveOrName]; + `) + ); + }); + + test('multy-dimension indexed access type', () => { + rewriteRun( + //language=typescript + typeScript(` + const MyArray = [ + { name: "Alice", age: 15 }, + { name: "Bob", age: 23 }, + { name: "Eve", age: 38 }, + ]; + + type Person = typeof MyArray[number]; + type Age = typeof MyArray[number]["age"]; + // Or + type Age2 = Person["age"]; + `), + //language=typescript + typeScript(` + const MyArray = [ + { name: "Alice", age: 15 }, + { name: "Bob", age: 23 }, + { name: "Eve", age: 38 }, + ]; + + /*1*/type/*2*/ Person/*3*/ =/*4*/ typeof/*5*/ MyArray/*6*/[/*7*/number/*8*/]/*9*/;/*10*/ + type Age = typeof MyArray/*11*/[number]/*12*/[/*13*/"age"/*14*/]/*15*/;/*16*/ + // Or + type Age2 = Person["age"]; + `), + ); + }); + +}); 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 ee66876a..1ec43053 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 @@ -671,6 +671,27 @@ public JS.ExportSpecifier visitExportSpecifier(JS.ExportSpecifier exportSpecifie return exportSpecifier; } + @Override + public JS.IndexedAccessType visitIndexedAccessType(JS.IndexedAccessType indexedAccessType, ReceiverContext ctx) { + indexedAccessType = indexedAccessType.withId(ctx.receiveNonNullValue(indexedAccessType.getId(), UUID.class)); + indexedAccessType = indexedAccessType.withPrefix(ctx.receiveNonNullNode(indexedAccessType.getPrefix(), JavaScriptReceiver::receiveSpace)); + indexedAccessType = indexedAccessType.withMarkers(ctx.receiveNonNullNode(indexedAccessType.getMarkers(), ctx::receiveMarkers)); + indexedAccessType = indexedAccessType.withObjectType(ctx.receiveNonNullNode(indexedAccessType.getObjectType(), ctx::receiveTree)); + indexedAccessType = indexedAccessType.getPadding().withIndexType(ctx.receiveNonNullNode(indexedAccessType.getPadding().getIndexType(), JavaScriptReceiver::receiveRightPaddedTree)); + indexedAccessType = indexedAccessType.withType(ctx.receiveValue(indexedAccessType.getType(), JavaType.class)); + return indexedAccessType; + } + + @Override + public JS.IndexedAccessType.IndexType visitIndexedAccessTypeIndexType(JS.IndexedAccessType.IndexType indexType, ReceiverContext ctx) { + indexType = indexType.withId(ctx.receiveNonNullValue(indexType.getId(), UUID.class)); + indexType = indexType.withPrefix(ctx.receiveNonNullNode(indexType.getPrefix(), JavaScriptReceiver::receiveSpace)); + indexType = indexType.withMarkers(ctx.receiveNonNullNode(indexType.getMarkers(), ctx::receiveMarkers)); + indexType = indexType.getPadding().withElement(ctx.receiveNonNullNode(indexType.getPadding().getElement(), JavaScriptReceiver::receiveRightPaddedTree)); + indexType = indexType.withType(ctx.receiveValue(indexType.getType(), JavaType.class)); + return indexType; + } + @Override public J.AnnotatedType visitAnnotatedType(J.AnnotatedType annotatedType, ReceiverContext ctx) { annotatedType = annotatedType.withId(ctx.receiveNonNullValue(annotatedType.getId(), UUID.class)); @@ -1969,6 +1990,27 @@ public T create(Class type, ReceiverContext ctx) { ); } + if (type == JS.IndexedAccessType.class) { + return (T) new JS.IndexedAccessType( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), + ctx.receiveValue(null, JavaType.class) + ); + } + + if (type == JS.IndexedAccessType.IndexType.class) { + return (T) new JS.IndexedAccessType.IndexType( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), + ctx.receiveValue(null, JavaType.class) + ); + } + if (type == J.AnnotatedType.class) { return (T) new J.AnnotatedType( ctx.receiveNonNullValue(null, UUID.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 9fd942e4..1aa8639b 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 @@ -654,6 +654,27 @@ public JS.ExportSpecifier visitExportSpecifier(JS.ExportSpecifier exportSpecifie return exportSpecifier; } + @Override + public JS.IndexedAccessType visitIndexedAccessType(JS.IndexedAccessType indexedAccessType, SenderContext ctx) { + ctx.sendValue(indexedAccessType, JS.IndexedAccessType::getId); + ctx.sendNode(indexedAccessType, JS.IndexedAccessType::getPrefix, JavaScriptSender::sendSpace); + ctx.sendNode(indexedAccessType, JS.IndexedAccessType::getMarkers, ctx::sendMarkers); + ctx.sendNode(indexedAccessType, JS.IndexedAccessType::getObjectType, ctx::sendTree); + ctx.sendNode(indexedAccessType, e -> e.getPadding().getIndexType(), JavaScriptSender::sendRightPadded); + ctx.sendTypedValue(indexedAccessType, JS.IndexedAccessType::getType); + return indexedAccessType; + } + + @Override + public JS.IndexedAccessType.IndexType visitIndexedAccessTypeIndexType(JS.IndexedAccessType.IndexType indexType, SenderContext ctx) { + ctx.sendValue(indexType, JS.IndexedAccessType.IndexType::getId); + ctx.sendNode(indexType, JS.IndexedAccessType.IndexType::getPrefix, JavaScriptSender::sendSpace); + ctx.sendNode(indexType, JS.IndexedAccessType.IndexType::getMarkers, ctx::sendMarkers); + ctx.sendNode(indexType, e -> e.getPadding().getElement(), JavaScriptSender::sendRightPadded); + ctx.sendTypedValue(indexType, JS.IndexedAccessType.IndexType::getType); + return indexType; + } + @Override public J.AnnotatedType visitAnnotatedType(J.AnnotatedType annotatedType, SenderContext ctx) { ctx.sendValue(annotatedType, J.AnnotatedType::getId); diff --git a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptValidator.java b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptValidator.java index c49448dc..9c056783 100644 --- a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptValidator.java +++ b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptValidator.java @@ -429,6 +429,19 @@ public JS.ExportSpecifier visitExportSpecifier(JS.ExportSpecifier exportSpecifie return exportSpecifier; } + @Override + public JS.IndexedAccessType visitIndexedAccessType(JS.IndexedAccessType indexedAccessType, P p) { + visitAndValidate(indexedAccessType.getObjectType(), TypeTree.class, p); + visitAndValidate(indexedAccessType.getIndexType(), TypeTree.class, p); + return indexedAccessType; + } + + @Override + public JS.IndexedAccessType.IndexType visitIndexedAccessTypeIndexType(JS.IndexedAccessType.IndexType indexType, P p) { + visitAndValidate(indexType.getElement(), TypeTree.class, p); + return indexType; + } + @Override public J.AnnotatedType visitAnnotatedType(J.AnnotatedType annotatedType, P p) { ListUtils.map(annotatedType.getAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); 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 037d96fe..78e6cdc3 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java @@ -652,6 +652,37 @@ public J visitExportSpecifier(JS.ExportSpecifier exportSpecifier, P p) { return es; } + public J visitIndexedAccessType(JS.IndexedAccessType indexedAccessType, P p) { + JS.IndexedAccessType iat = indexedAccessType; + iat = iat.withPrefix(visitSpace(iat.getPrefix(), JsSpace.Location.INDEXED_ACCESS_TYPE_PREFIX, p)); + iat = iat.withMarkers(visitMarkers(iat.getMarkers(), p)); + Expression temp = (Expression) visitExpression(iat, p); + if (!(temp instanceof JS.IndexedAccessType)) { + return temp; + } else { + iat = (JS.IndexedAccessType) temp; + } + iat = iat.withObjectType(Objects.requireNonNull(visitAndCast(iat.getObjectType(), p))); + iat = iat.getPadding().withIndexType(Objects.requireNonNull(visitRightPadded(iat.getPadding().getIndexType(), JsRightPadded.Location.INDEXED_ACCESS_TYPE_INDEX_TYPE, p))); + iat = iat.withType(visitType(iat.getType(), p)); + return iat; + } + + public J visitIndexedAccessTypeIndexType(JS.IndexedAccessType.IndexType indexedAccessTypeIndexType, P p) { + JS.IndexedAccessType.IndexType iatit = indexedAccessTypeIndexType; + iatit = iatit.withPrefix(visitSpace(iatit.getPrefix(), JsSpace.Location.INDEXED_ACCESS_TYPE_INDEX_TYPE_PREFIX, p)); + iatit = iatit.withMarkers(visitMarkers(iatit.getMarkers(), p)); + Expression temp = (Expression) visitExpression(iatit, p); + if (!(temp instanceof JS.IndexedAccessType.IndexType)) { + return temp; + } else { + iatit = (JS.IndexedAccessType.IndexType) temp; + } + iatit = iatit.getPadding().withElement(Objects.requireNonNull(visitRightPadded(iatit.getPadding().getElement(), JsRightPadded.Location.INDEXED_ACCESS_TYPE_INDEX_TYPE_ELEMENT, p))); + iatit = iatit.withType(visitType(iatit.getType(), p)); + return iatit; + } + // TODO: remove me. Requires changes from rewrite-java. @Override public J visitAnnotatedType(J.AnnotatedType annotatedType, P p) { 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 6ec9ce1f..1787b74e 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 @@ -823,6 +823,35 @@ public J visitExportSpecifier(JS.ExportSpecifier es, PrintOutputCapture

p) { return es; } + @Override + public J visitIndexedAccessType(JS.IndexedAccessType iat, PrintOutputCapture

p) { + beforeSyntax(iat, JsSpace.Location.INDEXED_ACCESS_TYPE_PREFIX, p); + + visit(iat.getObjectType(), p); + // expect that this element is printed accordingly + // [index] + visitRightPadded(iat.getPadding().getIndexType(), JsRightPadded.Location.INDEXED_ACCESS_TYPE_INDEX_TYPE, "", p); + + afterSyntax(iat, p); + + return iat; + } + + @Override + public J visitIndexedAccessTypeIndexType(JS.IndexedAccessType.IndexType iatit, PrintOutputCapture

p) { + beforeSyntax(iatit, JsSpace.Location.INDEXED_ACCESS_TYPE_INDEX_TYPE_PREFIX, p); + + p.append("["); + + visitRightPadded(iatit.getPadding().getElement(), JsRightPadded.Location.INDEXED_ACCESS_TYPE_INDEX_TYPE_ELEMENT, p); + + p.append("]"); + + afterSyntax(iatit, p); + + return iatit; + } + private class JavaScriptJavaPrinter extends JavaPrinter

{ @Override @@ -1317,6 +1346,13 @@ protected void visitContainer(String before, @Nullable JContainer c p.append(after == null ? "" : after); } + protected void visitRightPadded(JRightPadded node, JsRightPadded.Location location, String suffixBetween, PrintOutputCapture

p) { + visit(node.getElement(), p); + p.append(suffixBetween); + visitSpace(node.getAfter(), location.getAfterLocation(), p); + afterSyntax(node.getMarkers(), p); + } + protected void visitLeftPadded(@Nullable String prefix, @Nullable JLeftPadded leftPadded, JsLeftPadded.Location location, PrintOutputCapture

p) { if (leftPadded != null) { beforeSyntax(leftPadded.getBefore(), leftPadded.getMarkers(), location.getBeforeLocation(), p); 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 164b1c2e..3c156730 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 @@ -36,9 +36,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -2414,7 +2412,7 @@ public CoordinateBuilder.Expression getCoordinates() { @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) @Data - final class TypeOperator implements JS, Expression, TypedTree, NameTree { + final class TypeOperator implements JS, Expression, TypeTree { @Nullable @NonFinal @@ -4548,4 +4546,163 @@ public ExportSpecifier withTypeOnly(JLeftPadded typeOnly) { } } + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class IndexedAccessType implements JS, Expression, TypeTree { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + * (prefix)objectType(rightPaddedSuffix)[(prefix)indexType(suffix)](rightPaddedSuffix) + */ + @With + @Getter + TypeTree objectType; + + JRightPadded indexType; + + public TypeTree getIndexType() { + return indexType.getElement(); + } + + public TypeTree withIndexType(IndexType indexType) { + return getPadding().withIndexType(JRightPadded.withElement(this.indexType, indexType)); + } + + @With + @Nullable + @Getter + JavaType type; + + @Override + public

J acceptJavaScript(JavaScriptVisitor

v, P p) { + return v.visitIndexedAccessType(this, p); + } + + @Override + public CoordinateBuilder.Expression getCoordinates() { + return new CoordinateBuilder.Expression(this); + } + + public IndexedAccessType.Padding getPadding() { + IndexedAccessType.Padding p; + if (this.padding == null) { + p = new IndexedAccessType.Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new IndexedAccessType.Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final IndexedAccessType t; + + public JRightPadded getIndexType() { + return t.indexType; + } + + public IndexedAccessType withIndexType(JRightPadded indexType) { + return t.indexType == indexType ? t : new IndexedAccessType(t.id, t.prefix, t.markers, t.objectType, indexType, t.type); + } + } + + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + public static final class IndexType implements JS, Expression, TypeTree { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + JRightPadded element; + + public TypeTree getElement() { + return element.getElement(); + } + + public IndexType withElement(TypeTree element) { + return getPadding().withElement(JRightPadded.withElement(this.element, element)); + } + + @With + @Getter + @Nullable + JavaType type; + + @Override + public

J acceptJavaScript(JavaScriptVisitor

v, P p) { + return v.visitIndexedAccessTypeIndexType(this, p); + } + + @Override + public CoordinateBuilder.Expression getCoordinates() { + return new CoordinateBuilder.Expression(this); + } + + public IndexType.Padding getPadding() { + IndexType.Padding p; + if (this.padding == null) { + p = new IndexType.Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new IndexType.Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final IndexType t; + + public JRightPadded getElement() { + return t.element; + } + + public IndexType withElement(JRightPadded element) { + return t.element == element ? t : new IndexType(t.id, t.prefix, t.markers, element, t.type); + } + } + } + + } } 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 09fc954b..6d8cde29 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 @@ -52,6 +52,8 @@ public enum Location { IMPORT_TYPE_TYPEOF(JsSpace.Location.IMPORT_TYPE_TYPEOF_SUFFIX), IMPORT_TYPE_TYPE_ARGUMENTS(JsSpace.Location.IMPORT_TYPE_TYPE_ARGUMENTS_SUFFIX), NAMED_EXPORTS_ELEMENTS(JsSpace.Location.NAMED_EXPORTS_ELEMENTS_SUFFIX), + INDEXED_ACCESS_TYPE_INDEX_TYPE(JsSpace.Location.INDEXED_ACCESS_TYPE_INDEX_TYPE_SUFFIX), + INDEXED_ACCESS_TYPE_INDEX_TYPE_ELEMENT(JsSpace.Location.INDEXED_ACCESS_TYPE_INDEX_TYPE_ELEMENT_SUFFIX), ; private final JsSpace.Location afterLocation; 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 6a0b7d8c..8965178c 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 @@ -144,5 +144,9 @@ public enum Location { EXPORT_ASSIGNMENT_EXPORT_EQUALS_PREFIX, FUNCTION_DECLARATION_NAME_PREFIX, FUNCTION_DECLARATION_ASTERISK_TOKEN_PREFIX, + INDEXED_ACCESS_TYPE_PREFIX, + INDEXED_ACCESS_TYPE_INDEX_TYPE_SUFFIX, + INDEXED_ACCESS_TYPE_INDEX_TYPE_PREFIX, + INDEXED_ACCESS_TYPE_INDEX_TYPE_ELEMENT_SUFFIX, } }