Skip to content

Commit f2d6483

Browse files
committed
Added correctly handling exported variables which uses other props in its initializers
Fixes #7
1 parent dc11196 commit f2d6483

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/exports-symbol-tree.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ export class ExportsSymbolTree {
5151
}
5252

5353
private computeTreeForChildren(targetSymbolsSet: Set<ts.Symbol>, node: ts.Node, visitedSymbols: Set<ts.Symbol>): void {
54+
// it's similar to handling ts.Block node - both Block and variable's initializer are part of _implementation_
55+
// and we don't care about that implementation at all - we just only need to worry it's definition
56+
// for functions it is arguments and return type
57+
// for variables - the type of a variable
58+
if (ts.isVariableDeclaration(node)) {
59+
const typeChecker = this.program.getTypeChecker();
60+
const variableType = typeChecker.getTypeAtLocation(node);
61+
const variableTypeSymbol = variableType.getSymbol();
62+
if (variableTypeSymbol !== undefined) {
63+
targetSymbolsSet.add(variableTypeSymbol);
64+
}
65+
66+
return;
67+
}
68+
5469
ts.forEachChild(node, (childNode: ts.Node) => this.computeTreeForNode(targetSymbolsSet, childNode, visitedSymbols));
5570
}
5671

tests/test-cases/class-properties/input.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@ class TestProperties {
88
const test1 = new TestProperties();
99
test1.salad = 0;
1010
test1.dressing = 0;
11-
const totalSalad = test1.salad + 1;
12-
const totalDressing = test1.dressing + 0;
13-
14-
export const temp = 1;
11+
export const totalSalad = test1.salad + 1;
12+
export const totalDressing = test1.dressing + 0;

tests/test-cases/class-properties/output.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ var TestProperties = /** @class */ (function () {
1616
var test1 = new TestProperties();
1717
test1._internal_salad = 0;
1818
test1._internal_dressing = 0;
19-
var totalSalad = test1._internal_salad + 1;
20-
var totalDressing = test1._internal_dressing + 0;
21-
exports.temp = 1;
19+
exports.totalSalad = test1._internal_salad + 1;
20+
exports.totalDressing = test1._internal_dressing + 0;

0 commit comments

Comments
 (0)