extract import path detection into util

This commit is contained in:
Johannes Rieken
2019-12-30 13:01:33 +01:00
parent b05b481265
commit 808865cf57
12 changed files with 273 additions and 327 deletions
+36
View File
@@ -0,0 +1,36 @@
"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
function createImportRuleListener(validateImport) {
function _checkImport(node) {
if (node && node.type === 'Literal' && typeof node.value === 'string') {
validateImport(node, node.value);
}
}
return {
// import ??? from 'module'
ImportDeclaration: (node) => {
_checkImport(node.source);
},
// import('module').then(...)
CallExpression: (node) => {
var _a;
const { callee, arguments: args } = node;
if (callee.type === 'Import' && ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.type) === 'Literal') {
_checkImport(args[0]);
}
},
// export ?? from 'module'
ExportAllDeclaration: (node) => {
_checkImport(node.source);
},
// export {foo} from 'module'
ExportNamedDeclaration: (node) => {
_checkImport(node.source);
}
};
}
exports.createImportRuleListener = createImportRuleListener;