UNPKG

eslint-plugin-export-scope

Version:

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

60 lines 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isArrayLiteralExpression = exports.isVariableDeclaration = exports.isExportAssignment = exports.getParentCompletions = exports.getNewCompletions = exports.entry = void 0; const path_1 = require("path"); const typescript_1 = require("typescript"); const entry = (name, kind) => ({ name, kind, kindModifiers: "", sortText: "10", }); exports.entry = entry; const getNewCompletions = () => ({ isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: [], }); exports.getNewCompletions = getNewCompletions; const getParentCompletions = (rootDir, importDir) => { const completions = (0, exports.getNewCompletions)(); let currentDir = importDir; while (currentDir !== rootDir) { completions.entries.push((0, exports.entry)((0, path_1.relative)(rootDir, currentDir), typescript_1.ScriptElementKind.string)); currentDir = (0, path_1.dirname)(currentDir); } const levelsUp = Math.min(3, completions.entries.length); completions.entries.push((0, exports.entry)(".", typescript_1.ScriptElementKind.string)); completions.entries.push((0, exports.entry)("*", typescript_1.ScriptElementKind.string)); for (let i = 1; i <= levelsUp; i++) { completions.entries.push((0, exports.entry)(Array(i).fill("..").join("/"), typescript_1.ScriptElementKind.string)); } return completions; }; exports.getParentCompletions = getParentCompletions; /** * 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; //# sourceMappingURL=tsUtils.js.map