UNPKG

eslint-plugin-export-scope

Version:

Don't leak LOCAL utils, states, components into the global scope

72 lines 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAutocompletionFileTree = exports.isArrayLiteralExpression = exports.isVariableDeclaration = exports.isExportAssignment = exports.getNewCompletions = exports.entry = void 0; const fs_1 = require("fs"); const path_1 = require("path"); const constants_1 = require("../constants"); const entry = (name, kind) => ({ name, kind, kindModifiers: "", sortText: "10", }); exports.entry = entry; const getNewCompletions = () => ({ isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: [], }); exports.getNewCompletions = getNewCompletions; /** * This function should us isExportAssignment from 'typescript', * but it relies on SyntaxKind which differs based on the urser's ts version */ const isExportAssignment = (declaration) => { return !!declaration && "expression" in declaration; }; exports.isExportAssignment = isExportAssignment; /** * This function should us isVariableDeclaration from 'typescript', * but it relies on SyntaxKind which differs based on the urser's ts version */ const isVariableDeclaration = (declaration) => { return !!declaration && "initializer" in declaration; }; exports.isVariableDeclaration = isVariableDeclaration; /** * This function should us isArrayLiteralExpression from 'typescript', * but it relies on SyntaxKind which differs based on the urser's ts version */ const isArrayLiteralExpression = (expression) => { return !!expression && "elements" in expression && Array.isArray(expression.elements); }; exports.isArrayLiteralExpression = isArrayLiteralExpression; const getAutocompletionFileTree = (dir, extensions = [".ts", ".tsx", ".mts", ".js", ".jsx", ".mjs"]) => { const extSet = new Set(extensions); const filePaths = []; const dirPaths = []; const traverse = (dir) => { const entries = (0, fs_1.readdirSync)(dir, { withFileTypes: true }); entries.map((x) => { if (constants_1.SCOPE_FILE_NAMES.includes(x.name)) return; if (x.name === "node_modules" || x.name.startsWith(".")) return; const path = (0, path_1.resolve)(dir, x.name); if (x.isDirectory()) { dirPaths.push(path); return traverse(path); } else { if (extSet.has((0, path_1.extname)(x.name))) { filePaths.push(path); } } }); }; traverse(dir); return { filePaths, dirPaths }; }; exports.getAutocompletionFileTree = getAutocompletionFileTree; //# sourceMappingURL=tsUtils.js.map