Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): [triple-slash-reference] fix crash with external module reference #2788

Merged
merged 3 commits into from Nov 25, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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