How to use the buildMatchMemberExpression function from @babel/types
Find comprehensive JavaScript @babel/types.buildMatchMemberExpression code examples handpicked from public code repositorys.
@babel/types.buildMatchMemberExpression creates a matcher for a member expression AST node.
12 13 14 15 16 17 18 19 20 21 22 23 24 25
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } var isModuleExports = t.buildMatchMemberExpression('module.exports'); function processTaggedTemplateExpression(_ref) { var type = _ref.type, path = _ref.path,
195 196 197 198 199 200 201 202 203 204 205 206
function Func() { return t.genericTypeAnnotation(t.identifier("Function")); } const isArrayFrom = t.buildMatchMemberExpression("Array.from"); const isObjectKeys = t.buildMatchMemberExpression("Object.keys"); const isObjectValues = t.buildMatchMemberExpression("Object.values"); const isObjectEntries = t.buildMatchMemberExpression("Object.entries"); function CallExpression() {
+ 3 other calls in file
How does @babel/types.buildMatchMemberExpression work?
The @babel/types.buildMatchMemberExpression function is used to create an AST (Abstract Syntax Tree) node for matching a member expression against a given pattern. The function takes in two arguments: the first argument is the pattern to match, and the second argument is an options object that can contain properties for specifying the computed and optional flags. The function returns an AST node that can be used in the @babel/traverse library to search for matching member expressions in a given code tree.
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
const t = require("@babel/types"); const expression = t.identifier("foo"); const memberExpression = t.memberExpression( t.identifier("myObject"), expression ); const matcher = t.buildMatchMemberExpression(memberExpression); const matches = matcher("myObject.foo"); console.log(matches); // Output: true
In this example, @babel/types.buildMatchMemberExpression is used to create a matcher function that can be used to check whether a given string matches a specified member expression. The t.buildMatchMemberExpression function takes a member expression as its argument and returns a function that can be used to test whether a given string matches that expression. The matcher function takes a string argument and returns a boolean indicating whether the string matches the specified member expression.
@babel/types.identifier is the most popular function in @babel/types (20936 examples)