Skip to content

Commit

Permalink
fix: #32
Browse files Browse the repository at this point in the history
  • Loading branch information
meixg committed Apr 29, 2019
1 parent c2bda3d commit fd998c7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1770,19 +1770,27 @@ export function emitFile(
const nodeStart = node.getStart();
const nodeEnd = node.getEnd();

let names = {};
identifiers.forEach(item => {
if (
item.getParent().getKind() === ts.SyntaxKind.PropertyAccessExpression
&& (item.getParent().compilerNode as ts.PropertyAccessExpression).name === item.compilerNode
) {
return;
}

const symbolOfIdentifier = item.getSymbol().compilerSymbol;
const nodeSymbol = item.getSymbol();
if (!nodeSymbol) {
return;
}
const symbolOfIdentifier = nodeSymbol.compilerSymbol;
const d = symbolOfIdentifier.getDeclarations();
const inherite = d.find(item => item.getStart() < nodeStart || item.getEnd() > nodeEnd);
if (inherite) {
inheritedVariables.push(item);
const text = item.getText();
if (!names[text]) {
names[text] = 1;
inheritedVariables.push(item);
}
}
});

Expand Down
3 changes: 2 additions & 1 deletion test/features/inheritedVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
return "123" . $b;
},
"b" => function () use(&$b) {
return "123" . $b;
$a = $b;
return "123" . $b . $a;
}
);
6 changes: 5 additions & 1 deletion test/features/inheritedVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ let obj = {
return '123' + b;
},
b() {
return '123' + b;
/**
* @ssr
*/
const a = b;
return '123' + b + a;
}
}

0 comments on commit fd998c7

Please sign in to comment.