UNPKG

monk-import-export

Version:

Simple import & export sorting ESLint plugin

29 lines (28 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sortSpecifierItems = void 0; const compare_1 = require("./compare"); const getImportExportKind_1 = require("./getImportExportKind"); function sortSpecifierItems(items) { return items.slice().sort((itemA, itemB) => // Put type imports/exports before regular ones. (0, compare_1.compare)((0, getImportExportKind_1.getImportExportKind)(itemA.node), (0, getImportExportKind_1.getImportExportKind)(itemB.node)) || // Then compare by imported or exported name (external interface name). // import { a as b } from "a" // ^ // export { b as a } // ^ (0, compare_1.compare)((itemA.node.imported || itemA.node.exported).name, (itemB.node.imported || itemB.node.exported).name) || // Then compare by the file-local name. // import { a as b } from "a" // ^ // export { b as a } // ^ (0, compare_1.compare)(itemA.node.local.name, itemB.node.local.name) || // Keep the original order if the names are the same. It’s not worth // trying to compare anything else, `import {a, a} from "mod"` is a syntax // error anyway (but @babel/eslint-parser kind of supports it). // istanbul ignore next itemA.index - itemB.index); } exports.sortSpecifierItems = sortSpecifierItems;