Skip to content

Commit

Permalink
fix: fatal error: only variables can be passed by reference, close #31
Browse files Browse the repository at this point in the history
  • Loading branch information
cxtom committed May 5, 2019
1 parent 714c418 commit 0fbb69b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,10 @@ export function emitFile(
// emitModifiers(node, node.modifiers);
// emit(node.dotDotDotToken);

if (node.parent && node.parent.kind === SyntaxKind.FunctionDeclaration) {
if (node.parent && [SyntaxKind.FunctionDeclaration, SyntaxKind.MethodDeclaration].includes(node.parent.kind)) {
const type = typeChecker.getTypeAtLocation(node.name);
if (type && type.flags === ts.TypeFlags.Object) {
const symbol = type.getSymbol();
if (type && type.flags === ts.TypeFlags.Object && symbol && !symbol.members.has('__call' as ts.__String)) {
write('&');
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/features/funcParamRefer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"a" => 1
);
$c = "123";
function aaa(&$m, &$n, $k) {
function aaa(&$m, &$n, $k, $d) {
array_push($m, 4);
$n["b"] = 2;
$k .= "4";
Expand Down
2 changes: 1 addition & 1 deletion test/features/funcParamRefer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let b = {
};
let c = '123';

function aaa(m: number[], n: {[name: string]: number}, k: string) {
function aaa(m: number[], n: {[name: string]: number}, k: string, d?: () => string) {
m.push(4);
n.b = 2;
k += '4';
Expand Down

0 comments on commit 0fbb69b

Please sign in to comment.