eslint-plugin-export-scope
Version:
Don't leak LOCAL utils, states, components into the global scope
26 lines • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCodeFixesAtPosition = void 0;
const checkIsImportable_1 = require("../checkIsImportable");
const getCodeFixesAtPosition = (ts, info) => (importPath, ...args) => {
const ls = info.languageService;
const fixes = ls.getCodeFixesAtPosition(importPath, ...args);
const tsProgram = ls.getProgram();
if (!tsProgram)
return fixes;
return fixes.filter((fix) => {
if (fix.fixName !== "import")
return true;
const exportPathRegex = /["]([^"]+?)["]$/;
// TODO: find a more reliable source of this data
const [, relativeExportPath] = fix.description.match(exportPathRegex) ?? [];
const exportName = fix.changes?.[0]?.textChanges?.[0]?.newText.replace(/[{} ]/g, "");
if (!relativeExportPath)
return true;
const { resolvedModule } = ts.resolveModuleName(relativeExportPath, importPath, info.project.getCompilerOptions(), ts.sys);
const exportPath = resolvedModule?.resolvedFileName;
return (0, checkIsImportable_1.checkIsImportable)({ tsProgram, importPath, exportPath, exportName });
});
};
exports.getCodeFixesAtPosition = getCodeFixesAtPosition;
//# sourceMappingURL=getCodeFixesAtPosition.js.map