Skip to content

Commit 32b1b68

Browse files
authored
fix(eslint-plugin): [triple-slash-reference] fix crash with external module reference (typescript-eslint#2788)
1 parent c816b84 commit 32b1b68

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/eslint-plugin/src/rules/triple-slash-reference.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
AST_NODE_TYPES,
23
AST_TOKEN_TYPES,
34
TSESTree,
45
} from '@typescript-eslint/experimental-utils';
@@ -81,9 +82,11 @@ export default util.createRule<Options, MessageIds>({
8182
},
8283
TSImportEqualsDeclaration(node): void {
8384
if (programNode) {
84-
const source = (node.moduleReference as TSESTree.TSExternalModuleReference)
85-
.expression as TSESTree.Literal;
86-
hasMatchingReference(source);
85+
const reference = node.moduleReference;
86+
87+
if (reference.type === AST_NODE_TYPES.TSExternalModuleReference) {
88+
hasMatchingReference(reference.expression as TSESTree.Literal);
89+
}
8790
}
8891
},
8992
Program(node): void {

packages/eslint-plugin/tests/rules/triple-slash-reference.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,28 @@ ruleTester.run('triple-slash-reference', rule, {
5454
`,
5555
options: [{ path: 'always', types: 'always', lib: 'always' }],
5656
},
57+
{
58+
code: `
59+
/// <reference path="foo" />
60+
/// <reference types="bar" />
61+
/// <reference lib="baz" />
62+
import foo = foo;
63+
import bar = bar;
64+
import baz = baz;
65+
`,
66+
options: [{ path: 'always', types: 'always', lib: 'always' }],
67+
},
68+
{
69+
code: `
70+
/// <reference path="foo" />
71+
/// <reference types="bar" />
72+
/// <reference lib="baz" />
73+
import foo = foo.foo;
74+
import bar = bar.bar.bar.bar;
75+
import baz = baz.baz;
76+
`,
77+
options: [{ path: 'always', types: 'always', lib: 'always' }],
78+
},
5779
{
5880
code: "import * as foo from 'foo';",
5981
options: [{ path: 'never' }],

0 commit comments

Comments
 (0)