How to use the ClassMethod function from babel-types

Find comprehensive JavaScript babel-types.ClassMethod code examples handpicked from public code repositorys.

83
84
85
86
87
88
89
90
91
92
		const methodObj = insert[key];

		const newAst = getTemplateAst(methodObj.body, {sourceType: 'script'})
		// console.log(newAst)
		const params = checkParams(methodObj.argv, newAst)
		// const property = Types.ClassMethod('method', Types.identifier(methodObj.name), [], Types.BlockStatement(newAst))
		// 转换出新的body插入就可以了
		path.node.body.push(newAst)
	}
}
fork icon9
star icon11
watch icon0

200
201
202
203
204
205
206
207
208
209
    });
    
    const params = checkParams(argv, newAst);
    
    // 通过Types.ClassMethodAPI,生成方法AST
    const property = Types.ClassMethod('method', Types.identifier(name), params, Types.BlockStatement(newAst));

    // 插入进AST
    path.node.body.push(property);
}
fork icon1
star icon9
watch icon3

+ 11 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 (4076 examples)