js2flowchart
Version:
> Why? While I've been working on [Under-the-hood-ReactJS](https://github.com/Bogdan-Lyashenko/Under-the-hood-ReactJS) I spent enormous amount of time on creating schemes. Each change in code or flowchart affects all entire scheme instantly, forcing you t
49 lines • 1.91 kB
JavaScript
import generate from '@babel/generator';
import { TOKEN_TYPES } from 'shared/constants';
export var importDeclarationConverter = function importDeclarationConverter(_ref) {
var node = _ref.node;
return 'import from' + generate(node.source).code;
};
export var exportNamedDeclarationConverter = function exportNamedDeclarationConverter(_ref2) {
var node = _ref2.node;
return "export".concat(getExportedTokenName(node));
};
export var exportDefaultDeclarationConverter = function exportDefaultDeclarationConverter(_ref3) {
var node = _ref3.node;
return "export default ".concat(getExportedTokenName(node));
};
var getExportedTokenName = function getExportedTokenName(path) {
var declaration = path.declaration,
specifiers = path.specifiers;
if (declaration) {
return ' ' + getExportDeclarations(declaration);
}
if (specifiers) {
return '';
}
return generate(specifiers).code;
};
var getExportDeclarations = function getExportDeclarations(declaration) {
if ([TOKEN_TYPES.FUNCTION_DECLARATION, TOKEN_TYPES.ARROW_FUNCTION_EXPRESSION].indexOf(declaration.type) !== -1) {
return declaration.id ? declaration.id.name : 'function';
}
if (declaration.type === TOKEN_TYPES.VARIABLE_DECLARATION) {
return declaration.declarations[0].id.name;
}
if (declaration.type === TOKEN_TYPES.IDENTIFIER) {
return declaration.name;
}
if (declaration.type === TOKEN_TYPES.ASSIGNMENT_EXPRESSION) {
return declaration.left.name;
}
};
export var classDeclarationConverter = function classDeclarationConverter(_ref4) {
var node = _ref4.node;
return "class ".concat(generate(node.id).code, " ").concat(node.superClass ? " extends ".concat(generate(node.superClass).code) : '');
};
export var objectPatternConverter = function objectPatternConverter() {
return '{...}';
};
export var arrayPatternConverter = function arrayPatternConverter() {
return '[...]';
};