本文整理汇总了TypeScript中babel-types.isExpressionStatement函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isExpressionStatement函数的具体用法?TypeScript isExpressionStatement怎么用?TypeScript isExpressionStatement使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isExpressionStatement函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should move static apis under "Taro"', function () {
const code = `
import { noop } from '@tarojs/taro-h5';
noop;
noop();
`
const result = babel.transform(code, { plugins: [pluginOptions] })
expect(result.code).toMatchSnapshot();
const ast = result.ast as t.File
const body = ast.program.body as [t.ImportDeclaration, t.ExpressionStatement]
expect(t.isImportDeclaration(body[0])).toBeTruthy()
expect(t.isExpressionStatement(body[1])).toBeTruthy()
const defaultImport = body[0].specifiers.find(v => t.isImportDefaultSpecifier(v))
expect(defaultImport).toBeTruthy()
const taroName = defaultImport!.local.name
let memberExpression = body[1].expression
if (t.isCallExpression(body[1])) {
memberExpression = (body[1].expression as t.CallExpression).callee
}
expect(memberExpression).toMatchObject(t.memberExpression(
t.identifier(taroName),
t.identifier('noop')
))
})
开发者ID:YangShaoQun,项目名称:taro,代码行数:27,代码来源:index-test.ts
示例2: resetTSClassProperty
export function resetTSClassProperty (body) {
for (const method of body) {
if (t.isClassMethod(method) && method.kind === 'constructor') {
for (const statement of cloneDeep(method.body.body)) {
if (t.isExpressionStatement(statement) && t.isAssignmentExpression(statement.expression)) {
const expr = statement.expression
const { left, right } = expr
if (
t.isMemberExpression(left) &&
t.isThisExpression(left.object) &&
t.isIdentifier(left.property)
) {
if (
(t.isArrowFunctionExpression(right) || t.isFunctionExpression(right)) ||
(left.property.name === 'config' && t.isObjectExpression(right))
) {
body.push(
t.classProperty(left.property, right)
)
remove(method.body.body, statement)
}
}
}
}
}
}
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:27,代码来源:helper.ts
示例3: hydrate
function hydrate (file: t.File) {
const ast = file.program.body[0]
if (ast && t.isExpressionStatement(ast) && t.isJSXElement(ast.expression)) {
const jsx = ast.expression
if (jsx.children.length === 1) {
const children = jsx.children[0]
return t.isJSXExpressionContainer(children)
? children.expression
: children
} else {
return jsx
}
}
}
开发者ID:topud,项目名称:taro,代码行数:14,代码来源:wxml.ts
示例4: handleThirdPartyComponent
method.body.body = method.body.body.filter(statement => {
if (t.isExpressionStatement(statement) && t.isAssignmentExpression(statement.expression)) {
const expr = statement.expression
const { left, right } = expr
if (
t.isMemberExpression(left) &&
t.isThisExpression(left.object) &&
t.isIdentifier(left.property)
) {
if (
(t.isArrowFunctionExpression(right) || t.isFunctionExpression(right))
||
(left.property.name === 'config' && t.isObjectExpression(right))
) {
const classProp = t.classProperty(left.property, right)
body.push(classProp)
handleThirdPartyComponent(classProp)
return false
}
}
}
return true
})
开发者ID:topud,项目名称:taro,代码行数:23,代码来源:index.ts
注:本文中的babel-types.isExpressionStatement函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论