Skip to content

Commit

Permalink
Implemented qualifiedName visitor
Browse files Browse the repository at this point in the history
Most of the tests are skipped because enum, class, namespace constructions not supported yet.

Also modified testHarness runner to be able to join to remotely running rewrite-remote test engine
  • Loading branch information
arodionov committed Oct 18, 2024
1 parent ab4c47a commit 3ab6fe1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
9 changes: 8 additions & 1 deletion openrewrite/src/javascript/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,14 @@ export class JavaScriptParserVisitor {
}

visitQualifiedName(node: ts.QualifiedName) {
return this.visitUnknown(node);
return new J.FieldAccess(
randomId(),
this.prefix(node),
Markers.EMPTY,
this.visit(node.left),
new JLeftPadded<J.Identifier>(this.suffix(node.left), this.convert<J.Identifier>(node.right), Markers.EMPTY),
this.mapType(node)
);
}

visitComputedPropertyName(node: ts.ComputedPropertyName) {
Expand Down
50 changes: 50 additions & 0 deletions openrewrite/test/javascript/parser/qualifiedName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {connect, disconnect, rewriteRun, typeScript} from '../testHarness';

describe('empty mapping', () => {
beforeAll(() => connect());
afterAll(() => disconnect());

test('globalThis qualified name', () => {
rewriteRun(
//language=typescript
typeScript('const value: globalThis.Number = 1')
);
});

test.skip('nested class qualified name', () => {
rewriteRun(
//language=typescript
typeScript(`
class OuterClass {
public static InnerClass = class extends Number { };
}
const a: typeof OuterClass.InnerClass.prototype = 1;
`)
);
});

test.skip('namespace qualified name', () => {
rewriteRun(
//language=typescript
typeScript(`
namespace TestNamespace {
export class Test {}
};
const value: TestNamespace.Test = null;
`)
);
});

test.skip('enum qualified name', () => {
rewriteRun(
//language=typescript
typeScript(`
enum Test {
A
};
const val: Test.A = Test.A;
`)
);
});
});
25 changes: 19 additions & 6 deletions openrewrite/test/javascript/testHarness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ export async function connect(): Promise<RemotingContext> {
return new Promise((resolve, reject) => {
const pathToJar = path.resolve(__dirname, '../../../rewrite-test-engine-remote/build/libs/rewrite-test-engine-remote-fat-jar.jar');
console.log(pathToJar);
const randomPort = getRandomInt(50000, 60000);
client = new net.Socket();
client.connect(65432, 'localhost');

getNextPort(randomPort).then(port => {
client.once('error', (err) => {
const randomPort = getRandomInt(50000, 60000);
getNextPort(randomPort).then(port => {
javaTestEngine = spawn('java', ['-jar', pathToJar, port.toString()]);
const errorfn = (data: string) => {
console.error(`stderr: ${data}`);
Expand All @@ -110,7 +113,15 @@ export async function connect(): Promise<RemotingContext> {

javaTestEngine.stdout.once('data', startfn);
javaTestEngine.stderr.on('data', errorfn);
});
});
client.once('connect', () => {
remoting = new RemotingContext();
remoting.connect(client);
PrinterFactory.current = new RemotePrinterFactory(remoting.client!);
resolve(remoting);
});

});
}

Expand All @@ -123,10 +134,12 @@ export async function disconnect(): Promise<void> {
remoting.close();
}

javaTestEngine.once('close', (code: string) => {
resolve()
});
javaTestEngine.kill("SIGKILL");
if (javaTestEngine) {
javaTestEngine.once('close', (code: string) => {
resolve()
});
javaTestEngine.kill("SIGKILL");
}
} else {
resolve();
}
Expand Down

0 comments on commit 3ab6fe1

Please sign in to comment.