UNPKG

eslint-plugin-export-scope

Version:

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

42 lines 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractPathFromImport = exports.getPathLoc = exports.getScopeDeclarations = void 0; const utils_1 = require("@typescript-eslint/utils"); const getScopeDeclarations = (comments) => { return comments.reduce((acc, { type, value, loc }) => { if (type !== utils_1.AST_TOKEN_TYPES.Block) return acc; const [, prefix, scopeType, path] = value.match(/(\s*\*\s*@)(scope|scopeDefault|scopeException)\s+([^\s]+)/) ?? []; if (prefix && scopeType && path) { // loc.start.column = loc.start.column + prefix.length + scopeType.length + 1; acc.push({ type: scopeType, path, loc }); } return acc; }, []); }; exports.getScopeDeclarations = getScopeDeclarations; const getPathLoc = (text, loc) => { const commentLine = text.split("\n")[loc.start.line - 1]; const [, prefix, tag, postfix, path] = commentLine?.match(/^([^]*@)(scope|scopeDefault|scopeException)(\s+)([^\s]+)/) ?? []; if (prefix && tag && postfix && path) { return { start: { line: loc.start.line, column: loc.start.column + prefix.length + tag.length + postfix.length }, end: { line: loc.start.line, column: loc.start.column + prefix.length + tag.length + postfix.length + path.length, }, }; } return loc; }; exports.getPathLoc = getPathLoc; const extractPathFromImport = (node) => { if (node.type === utils_1.AST_NODE_TYPES.ImportDeclaration) return node.source.value; if (node.type === utils_1.AST_NODE_TYPES.ImportExpression && node.source.type === utils_1.AST_NODE_TYPES.Literal && typeof node.source.value === "string") return node.source.value; }; exports.extractPathFromImport = extractPathFromImport; //# sourceMappingURL=esLintUtils.js.map