Skip to content

Commit cf00746

Browse files
Fixed invalid code for binding expressions.
1 parent 5e84ed3 commit cf00746

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

scripts/tslint/preferConstRule.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,23 @@ class PreferConstWalker extends Lint.RuleWalker {
106106
if (node.kind === ts.SyntaxKind.ObjectLiteralExpression) {
107107
const pattern = node as ts.ObjectLiteralExpression;
108108
for (const element of pattern.properties) {
109-
if (element.name.kind === ts.SyntaxKind.Identifier) {
110-
this.markAssignment(element.name as ts.Identifier);
109+
const kind = element.kind;
110+
111+
if (kind === ts.SyntaxKind.ShorthandPropertyAssignment) {
112+
this.markAssignment((element as ts.ShorthandPropertyAssignment).name);
111113
}
112-
else if (isBindingPattern(element.name)) {
113-
this.visitBindingPatternIdentifiers(element.name as ts.BindingPattern);
114+
else if (kind === ts.SyntaxKind.PropertyAssignment) {
115+
const rhs = (element as ts.PropertyAssignment).initializer;
116+
117+
if (rhs.kind === ts.SyntaxKind.Identifier) {
118+
this.markAssignment(rhs as ts.Identifier);
119+
}
120+
else if (rhs.kind === ts.SyntaxKind.ObjectLiteralExpression || rhs.kind === ts.SyntaxKind.ArrayLiteralExpression) {
121+
this.visitBindingLiteralExpression(rhs as ts.ObjectLiteralExpression | ts.ArrayLiteralExpression);
122+
}
123+
else {
124+
// Should be an error, but do nothing for now.
125+
}
114126
}
115127
}
116128
}

0 commit comments

Comments
 (0)