Skip to content

Commit

Permalink
fix(eslint-plugin): [triple-slash-reference] fix crash with external …
Browse files Browse the repository at this point in the history
…module reference (#2788)
  • Loading branch information
ddubrava committed Nov 25, 2020
1 parent c816b84 commit 32b1b68
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/eslint-plugin/src/rules/triple-slash-reference.ts
@@ -1,4 +1,5 @@
import {
AST_NODE_TYPES,
AST_TOKEN_TYPES,
TSESTree,
} from '@typescript-eslint/experimental-utils';
Expand Down Expand Up @@ -81,9 +82,11 @@ export default util.createRule<Options, MessageIds>({
},
TSImportEqualsDeclaration(node): void {
if (programNode) {
const source = (node.moduleReference as TSESTree.TSExternalModuleReference)
.expression as TSESTree.Literal;
hasMatchingReference(source);
const reference = node.moduleReference;

if (reference.type === AST_NODE_TYPES.TSExternalModuleReference) {
hasMatchingReference(reference.expression as TSESTree.Literal);
}
}
},
Program(node): void {
Expand Down
22 changes: 22 additions & 0 deletions packages/eslint-plugin/tests/rules/triple-slash-reference.test.ts
Expand Up @@ -54,6 +54,28 @@ ruleTester.run('triple-slash-reference', rule, {
`,
options: [{ path: 'always', types: 'always', lib: 'always' }],
},
{
code: `
/// <reference path="foo" />
/// <reference types="bar" />
/// <reference lib="baz" />
import foo = foo;
import bar = bar;
import baz = baz;
`,
options: [{ path: 'always', types: 'always', lib: 'always' }],
},
{
code: `
/// <reference path="foo" />
/// <reference types="bar" />
/// <reference lib="baz" />
import foo = foo.foo;
import bar = bar.bar.bar.bar;
import baz = baz.baz;
`,
options: [{ path: 'always', types: 'always', lib: 'always' }],
},
{
code: "import * as foo from 'foo';",
options: [{ path: 'never' }],
Expand Down

0 comments on commit 32b1b68

Please sign in to comment.