UNPKG

webpack-react-docgen-typescript

Version:
39 lines (38 loc) 1.38 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const path = __importStar(require("path")); exports.getDefaultExportForFile = (source) => { const name = path.basename(source.fileName, path.extname(source.fileName)); const filename = name === 'index' ? path.basename(path.dirname(source.fileName)) : name; // JS identifiers must starts with a letter, and contain letters and/or numbers // So, you could not take filename as is const identifier = filename .replace(/^[^A-Z]*/gi, '') .replace(/[^A-Z0-9]*/gi, ''); return identifier.length ? identifier : 'DefaultName'; }; const exoticNames = [ 'default', '__function', 'Stateless', 'StyledComponentClass', 'StyledComponent', 'FunctionComponent', 'StatelessComponent', 'ForwardRefExoticComponent', 'RefForwardingComponent' ]; exports.computeComponentName = (exp, source) => { const exportName = exp.getName(); if (exoticNames.indexOf(exportName) >= 0) { return exports.getDefaultExportForFile(source); } return undefined; };