use AST selector to simplify things

This commit is contained in:
Johannes Rieken
2019-12-30 14:57:04 +01:00
parent 4db80066b4
commit 53d1dffaff
2 changed files with 11 additions and 25 deletions
+5 -13
View File
@@ -4,7 +4,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
function createImportRuleListener(validateImport) {
function _checkImport(node) {
if (node && node.type === 'Literal' && typeof node.value === 'string') {
@@ -16,20 +15,13 @@ function createImportRuleListener(validateImport) {
ImportDeclaration: (node) => {
_checkImport(node.source);
},
// import('module').then(...)
CallExpression: (node) => {
var _a;
const { callee, arguments: args } = node;
if (callee.type === 'Import' && args.length > 0 && ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.type) === 'Literal') {
_checkImport(args[0]);
}
// import('module').then(...) OR await import('module')
['CallExpression[callee.type="Import"][arguments.length=1] > Literal']: (node) => {
_checkImport(node);
},
// import foo = ...
[experimental_utils_1.AST_NODE_TYPES.TSImportEqualsDeclaration]: (node) => {
const { moduleReference } = node;
if (moduleReference.type === experimental_utils_1.AST_NODE_TYPES.TSExternalModuleReference) {
_checkImport(moduleReference.expression);
}
['TSImportEqualsDeclaration > TSExternalModuleReference > Literal']: (node) => {
_checkImport(node);
},
// export ?? from 'module'
ExportAllDeclaration: (node) => {