🌐 AI搜索 & 代理 主页
Skip to content
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
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/prefer-optional-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ export default util.createRule({

case AST_NODE_TYPES.Literal:
case AST_NODE_TYPES.TemplateLiteral:
case AST_NODE_TYPES.BinaryExpression:
propertyText = sourceCode.getText(node.property);
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ ruleTester.run('prefer-optional-chain', rule, {
'foo && foo[bar as string] && foo[bar as string].baz;',
'foo && foo[1 + 2] && foo[1 + 2].baz;',
'foo && foo[typeof bar] && foo[typeof bar].baz;',
'!foo[1 + 1] || !foo[1 + 2];',
'!foo[1 + 1] || !foo[1 + 1].foo;',
'!foo || !foo[bar as string] || !foo[bar as string].baz;',
'!foo || !foo[1 + 2] || !foo[1 + 2].baz;',
'!foo || !foo[typeof bar] || !foo[typeof bar].baz;',
Expand Down