Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concat: cs & php &py #4

Merged
merged 20 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/baseTranspiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@

let method = undefined;

let parentClass = (ts as any).getAllSuperTypeNodes(node.parent)[0];

Check warning on line 336 in src/baseTranspiler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

while (parentClass !== undefined) {
const parentClassType = global.checker.getTypeAtLocation(parentClass);
Expand All @@ -350,13 +350,13 @@
if (ts.isMethodDeclaration(elem)) {

const name = elem.name.getText().trim();
if ((node as any).name.escapedText === name) {

Check warning on line 353 in src/baseTranspiler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type
method = elem;
}
}
});

parentClass = (ts as any).getAllSuperTypeNodes(parentClassDecl)[0] ?? undefined;

Check warning on line 359 in src/baseTranspiler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type
}


Expand All @@ -369,7 +369,7 @@
return this.DEFAULT_IDENTATION.repeat(num);
}

getBlockOpen(identation){

Check warning on line 372 in src/baseTranspiler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'identation' is defined but never used
return this.SPACE_BEFORE_BLOCK_OPENING + this.BLOCK_OPENING_TOKEN + "\n";
}

Expand Down Expand Up @@ -426,11 +426,11 @@
return this.getIden(identation) + `${left} instanceof ${right}`;
}

getCustomOperatorIfAny(left, right, operator) {

Check warning on line 429 in src/baseTranspiler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'left' is defined but never used

Check warning on line 429 in src/baseTranspiler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'right' is defined but never used

Check warning on line 429 in src/baseTranspiler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'operator' is defined but never used
return undefined;
}

printCustomBinaryExpressionIfAny(node, identation) {

Check warning on line 433 in src/baseTranspiler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'node' is defined but never used

Check warning on line 433 in src/baseTranspiler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'identation' is defined but never used
return undefined; // stub to override
}

Expand Down Expand Up @@ -478,7 +478,7 @@
return leftVar +" "+ operator + " " + rightVar.trim();
}

transformPropertyAcessExpressionIfNeeded (node) {

Check warning on line 481 in src/baseTranspiler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'node' is defined but never used
return undefined;
}

Expand Down Expand Up @@ -1079,6 +1079,10 @@
return undefined; // stub
}

printConcatCall(node, identation, name = undefined, parsedArg = undefined) {
return undefined; // stub
}

printToFixedCall(node, identation, name = undefined, parsedArg = undefined) {
return undefined; // stub
}
Expand Down Expand Up @@ -1220,6 +1224,8 @@
return this.printSplitCall(node, identation, name, parsedArg);
case 'toFixed':
return this.printToFixedCall(node, identation, name, parsedArg);
case 'concat':
return this.printConcatCall(node, identation, name, parsedArg);
case 'search':
return this.printSearchCall(node, identation, name, parsedArg);
case 'endsWith':
Expand Down
4 changes: 4 additions & 0 deletions src/csharpTranspiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,10 @@ export class CSharpTranspiler extends BaseTranspiler {
return `((string)${name}).Split(new [] {((string)${parsedArg})}, StringSplitOptions.None).ToList<object>()`;
}

printConcatCall(node, identation, name = undefined, parsedArg = undefined) {
return `${name}.Concat(${parsedArg}).ToList()`;
carlosmiei marked this conversation as resolved.
Show resolved Hide resolved
}

printToFixedCall(node, identation, name = undefined, parsedArg = undefined) {
return `toFixed(${name}, ${parsedArg})`;
}
Expand Down
4 changes: 4 additions & 0 deletions src/phpTranspiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ export class PhpTranspiler extends BaseTranspiler {
return `explode(${parsedArg}, ${name})`;
}

printConcatCall(node: any, identation: any, name?: any, parsedArg?: any) {
return `array_merge(${name}, ${parsedArg})`;
}

printPadEndCall(node, identation, name, parsedArg, parsedArg2) {
return `str_pad(${name}, ${parsedArg}, ${parsedArg2}, STR_PAD_RIGHT)`;
}
Expand Down
4 changes: 4 additions & 0 deletions src/pythonTranspiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export class PythonTranspiler extends BaseTranspiler {
return `${name}.split(${parsedArg})`;
}

printConcatCall(node: any, identation: any, name?: any, parsedArg?: any) {
return `${name} + ${parsedArg}`;
}

printPopCall(node: any, identation: any, name?: any) {
return `${name}.pop()`;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/csharpTranspiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ describe('csharp transpiling tests', () => {
const output = transpiler.transpileCSharp(ts).content;
expect(output).toBe(csharp);
});
test('should convert concat', () => {
const ts = "y.concat(z)";
const result = "y.Concat(z).ToList();";
const output = transpiler.transpileCSharp(ts).content;
expect(output).toBe(result);
});
test('string literal', () => {
const ts = "const x = \"foo, 'single', \\\"double\\\" \\t \\n \\r \\b \\f \";";
const csharp = "object x = \"foo, 'single', \\\"double\\\" \\t \\n \\r \\b \\f \";";
Expand Down
6 changes: 6 additions & 0 deletions tests/phpTranspiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,12 @@ describe('php transpiling tests', () => {
const output = transpiler.transpilePhp(ts).content;
expect(output).toBe(php);
});
test('should convert concat', () => {
const ts = "y.concat(z)";
const result = "array_merge($x, $y);";
const output = transpiler.transpilePhp(ts).content;
expect(output).toBe(result);
});
test('string literal', () => {
const ts = "const x = \"foo, 'single', \\\"double\\\" \\t \\n \\r \\b \\f \";";
const php = "$x = 'foo, \\\'single\\\', \"double\" \\t \\n \\r \\b \\f ';";
Expand Down
6 changes: 6 additions & 0 deletions tests/pythonTranspiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,12 @@ describe('python tests', () => {
const output = transpiler.transpilePython(ts).content;
expect(output).toBe(python);
});
test('should convert concat', () => {
const ts = "y.concat(z)";
const result = "y + z";
const output = transpiler.transpilePython(ts).content;
expect(output).toBe(result);
});
test('should convert search', () => {
const ts = '"abcdxtzyw".search("xt");';
const python = "'abcdxtzyw'.find('xt')";
Expand Down
Loading