How to use the classMethod function from @babel/types

Find comprehensive JavaScript @babel/types.classMethod code examples handpicked from public code repositorys.

62
63
64
65
66
67
68
69
70
71

    if (name === 'componentDidCatch') {
        params = [t.identifier('error'), t.identifier('info')];
    }
    path.traverse(nestedMethodsVisitor, { blocks, state });
    return t.classMethod('method', t.identifier(name), params, t.blockStatement(blocks));
}

function replaceThisExpression (path, key, state) {
    if (state.data[key] || state.props[key]) {
fork icon65
star icon1
watch icon1

119
120
121
122
123
124
125
126
127
128
        blocks = blocks.concat(v['_statements']);
    });
}
blocks = blocks.concat(t.returnStatement(argument))

const render = t.classMethod(
    'method',
    t.identifier('render'),
    [],
    t.blockStatement(blocks)
fork icon1
star icon2
watch icon1

+ 3 other calls in file

144
145
146
147
148
149
150
151
152
153
  param => param.name !== "self"
);
const methodBlock = child.body;
methodBlock.body = methodBlock.body.map(this.mapThis);
const methodBody = methodBlock;
return t.classMethod(
  isConstructor ? "constructor" : "method",
  t.identifier(methodId),
  methodParams,
  methodBody
fork icon0
star icon1
watch icon0

85
86
87
88
89
90
91
92
93
94
  json.prefixedArgs = prefixedArgs;
}

const body = isOverloading ? createOverloadedMethodBody(classJson, json) : createMethodBody(classJson, json);

const m = t.classMethod('method', t.identifier(methodNameToSnakeCase(json.name)), args, body, false, true);

if (json.comment) {
  t.addComment(m, 'leading', json.comment);
}
fork icon0
star icon0
watch icon0

+ 11 other calls in file

278
279
280
281
282
283
284
285
286

var constructorNode;

if (path.has('superClass')) {
  var args = t.identifier('args');
  constructorNode = t.classMethod('constructor', t.identifier('constructor'), [t.restElement(args)], t.blockStatement([t.expressionStatement(t.callExpression(t.super(), [t.spreadElement(args)]))]));
} else {
  constructorNode = t.classMethod('constructor', t.identifier('constructor'), [], t.blockStatement([]));
}
fork icon0
star icon0
watch icon0

+ 3 other calls in file

176
177
178
179
180
181
182
183
184
185
        path.node.body = t.blockStatement([getRepositoriesBody])
        step++;
}
if (path.node.key.name === 'toggleVisibility') {
        if (path.toString().includes('this.visibleRepositories')) {
                const sortRepositories = t.classMethod('method', t.identifier('sortRepositories'), [t.identifier('visibleRepositories')], t.blockStatement(sortRepositoriesBody))
                path.insertAfter(sortRepositories);
                step++;
        }
}
fork icon0
star icon0
watch icon2

+ 19 other calls in file

Other functions in @babel/types

Sorted by popularity

function icon

@babel/types.identifier is the most popular function in @babel/types (20936 examples)