UNPKG

babel-plugin-transform-private-underscore

Version:

Babel plugin to make class properties starting with an underscore really private

23 lines (17 loc) 1.01 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.isPrivateAttributeAccess = exports.isPrivateMethodCall = undefined; var _babelTypes = require('babel-types'); var isPrivateProperyAccess = function isPrivateProperyAccess(memberExpressionNode) { return (0, _babelTypes.isThisExpression)(memberExpressionNode.object) && memberExpressionNode.property.name.startsWith('_'); }; var isPrivateMethodCall = function isPrivateMethodCall(callExpressionNode, privateMethodsNames) { return isPrivateProperyAccess(callExpressionNode.callee) && privateMethodsNames.indexOf(callExpressionNode.callee.property.name) !== -1; }; var isPrivateAttributeAccess = function isPrivateAttributeAccess(memberExpressionNode, privateMethodsNames) { return isPrivateProperyAccess(memberExpressionNode) && privateMethodsNames.indexOf(memberExpressionNode.property.name) === -1; }; exports.isPrivateMethodCall = isPrivateMethodCall; exports.isPrivateAttributeAccess = isPrivateAttributeAccess;