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

fix(php) - remove $ from constants #15

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions src/phpTranspiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ export class PhpTranspiler extends BaseTranspiler {
}
}

// below is commented, due to : https://github.com/ccxt/ast-transpiler/pull/15
//
// If the identifier is a function parameter (callback), it should remain a variable with `$` prefix
if (node.parent && ts.isParameter(node.parent) || (node.parent && ts.isCallExpression(node.parent) && ts.isIdentifier(node))) {
return "$" + identifier;
}
// if (node.parent && (ts.isParameter(node.parent) || (ts.isCallExpression(node.parent) && ts.isIdentifier(node)))) {
// return "$" + identifier;
// }

// Default case: prepend $ for variables (non-functions), unless it's a class or constant
if (!this.startsWithUpperCase(identifier)) {
Expand Down
9 changes: 9 additions & 0 deletions tests/phpTranspiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,15 @@ describe('php transpiling tests', () => {
const output = transpiler.transpilePhp(ts).content;
expect(output).toBe(php);
});
test.only('transpile constants & imports', () => {
const ts = "import { decimalToPrecision, ROUND, TRUNCATE, DECIMAL_PLACES, } from '../../somewhere.js';\n" +
"const exc = new xyz ();\n" +
"assert (exc.decimalToPrecision ('12.3456000', TRUNCATE, 100, DECIMAL_PLACES) === '12.3456');";
const php = "$exc = new xyz();\n" +
"assert($exc->decimalToPrecision('12.3456000', TRUNCATE, 100, DECIMAL_PLACES) === '12.3456');";
const output = transpiler.transpilePhp(ts).content;
expect(output).toBe(php);
});
test('should transpile Number.isInteger', () => {
const ts = "Number.isInteger(1)";
const php = "is_int(1);";
Expand Down
Loading