123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports._params = _params;
- exports._parameters = _parameters;
- exports._param = _param;
- exports._methodHead = _methodHead;
- exports._predicate = _predicate;
- exports._functionHead = _functionHead;
- exports.FunctionDeclaration = exports.FunctionExpression = FunctionExpression;
- exports.ArrowFunctionExpression = ArrowFunctionExpression;
- function t() {
- var data = _interopRequireWildcard(require("@babel/types"));
- t = function t() {
- return data;
- };
- return data;
- }
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
- function _params(node) {
- this.print(node.typeParameters, node);
- this.token("(");
- this._parameters(node.params, node);
- this.token(")");
- this.print(node.returnType, node);
- }
- function _parameters(parameters, parent) {
- for (var i = 0; i < parameters.length; i++) {
- this._param(parameters[i], parent);
- if (i < parameters.length - 1) {
- this.token(",");
- this.space();
- }
- }
- }
- function _param(parameter, parent) {
- this.printJoin(parameter.decorators, parameter);
- this.print(parameter, parent);
- if (parameter.optional) this.token("?");
- this.print(parameter.typeAnnotation, parameter);
- }
- function _methodHead(node) {
- var kind = node.kind;
- var key = node.key;
- if (kind === "get" || kind === "set") {
- this.word(kind);
- this.space();
- }
- if (node.async) {
- this.word("async");
- this.space();
- }
- if (kind === "method" || kind === "init") {
- if (node.generator) {
- this.token("*");
- }
- }
- if (node.computed) {
- this.token("[");
- this.print(key, node);
- this.token("]");
- } else {
- this.print(key, node);
- }
- if (node.optional) {
- this.token("?");
- }
- this._params(node);
- }
- function _predicate(node) {
- if (node.predicate) {
- if (!node.returnType) {
- this.token(":");
- }
- this.space();
- this.print(node.predicate, node);
- }
- }
- function _functionHead(node) {
- if (node.async) {
- this.word("async");
- this.space();
- }
- this.word("function");
- if (node.generator) this.token("*");
- this.space();
- if (node.id) {
- this.print(node.id, node);
- }
- this._params(node);
- this._predicate(node);
- }
- function FunctionExpression(node) {
- this._functionHead(node);
- this.space();
- this.print(node.body, node);
- }
- function ArrowFunctionExpression(node) {
- if (node.async) {
- this.word("async");
- this.space();
- }
- var firstParam = node.params[0];
- if (node.params.length === 1 && t().isIdentifier(firstParam) && !hasTypes(node, firstParam)) {
- this.print(firstParam, node);
- } else {
- this._params(node);
- }
- this._predicate(node);
- this.space();
- this.token("=>");
- this.space();
- this.print(node.body, node);
- }
- function hasTypes(node, param) {
- return node.typeParameters || node.returnType || param.typeAnnotation || param.optional || param.trailingComments;
- }
|