Sha256: 36ee7283e1ed17e87af9fd5fc64b5b6d7ab63ecb3a9d48814dbdc23060fd441c

Contents?: true

Size: 1.68 KB

Versions: 106

Compression:

Stored size: 1.68 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = getFunctionName;
var _index = require("../validators/generated/index.js");
function getNameFromLiteralId(id) {
  if ((0, _index.isNullLiteral)(id)) {
    return "null";
  }
  if ((0, _index.isRegExpLiteral)(id)) {
    return `/${id.pattern}/${id.flags}`;
  }
  if ((0, _index.isTemplateLiteral)(id)) {
    return id.quasis.map(quasi => quasi.value.raw).join("");
  }
  if (id.value !== undefined) {
    return String(id.value);
  }
  return null;
}
function getObjectMemberKey(node) {
  if (!node.computed || (0, _index.isLiteral)(node.key)) {
    return node.key;
  }
}
function getFunctionName(node, parent) {
  if ("id" in node && node.id) {
    return {
      name: node.id.name,
      originalNode: node.id
    };
  }
  let prefix = "";
  let id;
  if ((0, _index.isObjectProperty)(parent, {
    value: node
  })) {
    id = getObjectMemberKey(parent);
  } else if ((0, _index.isObjectMethod)(node) || (0, _index.isClassMethod)(node)) {
    id = getObjectMemberKey(node);
    if (node.kind === "get") prefix = "get ";else if (node.kind === "set") prefix = "set ";
  } else if ((0, _index.isVariableDeclarator)(parent, {
    init: node
  })) {
    id = parent.id;
  } else if ((0, _index.isAssignmentExpression)(parent, {
    operator: "=",
    right: node
  })) {
    id = parent.left;
  }
  if (!id) return null;
  const name = (0, _index.isLiteral)(id) ? getNameFromLiteralId(id) : (0, _index.isIdentifier)(id) ? id.name : (0, _index.isPrivateName)(id) ? id.id.name : null;
  if (name == null) return null;
  return {
    name: prefix + name,
    originalNode: id
  };
}

//# sourceMappingURL=getFunctionName.js.map

Version data entries

106 entries across 7 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.48 node_modules/@babel/plugin-transform-object-super/node_modules/@babel/helper-replace-supers/node_modules/@babel/traverse/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.48 node_modules/@babel/plugin-transform-react-jsx/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.48 node_modules/@babel/preset-modules/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.48 node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/helper-builder-binary-assignment-operator-visitor/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/preset-modules/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/plugin-transform-react-jsx/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/plugin-transform-object-super/node_modules/@babel/helper-replace-supers/node_modules/@babel/traverse/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/plugin-transform-object-super/node_modules/@babel/helper-replace-supers/node_modules/@babel/helper-member-expression-to-functions/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/plugin-transform-modules-systemjs/node_modules/@babel/traverse/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/plugin-transform-function-name/node_modules/@babel/traverse/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/plugin-transform-computed-properties/node_modules/@babel/template/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/plugin-transform-classes/node_modules/@babel/traverse/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/plugin-transform-classes/node_modules/@babel/helper-replace-supers/node_modules/@babel/helper-member-expression-to-functions/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/plugin-transform-async-generator-functions/node_modules/@babel/traverse/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly/node_modules/@babel/traverse/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/helper-wrap-function/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.47 node_modules/@babel/helper-remap-async-to-generator/node_modules/@babel/traverse/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.46 node_modules/@babel/helper-wrap-function/node_modules/@babel/types/lib/retrievers/getFunctionName.js
immosquare-cleaner-0.1.46 node_modules/@babel/preset-modules/node_modules/@babel/types/lib/retrievers/getFunctionName.js