本文整理汇总了TypeScript中babel-types.isBinaryExpression函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isBinaryExpression函数的具体用法?TypeScript isBinaryExpression怎么用?TypeScript isBinaryExpression使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isBinaryExpression函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: toConstant
function toConstant(expression: b.Expression): any {
if (!constant) return;
if (b.isArrayExpression(expression)) {
const result = [];
for (let i = 0; constant && i < expression.elements.length; i++) {
const element = expression.elements[i];
if (b.isSpreadElement(element)) {
const spread = toConstant(element.argument);
if (!(isSpreadable(spread) && constant)) {
constant = false;
} else {
result.push(...spread);
}
} else {
result.push(toConstant(element));
}
}
return result;
}
if (b.isBinaryExpression(expression)) {
const left = toConstant(expression.left);
const right = toConstant(expression.right);
return constant && binaryOperation(expression.operator, left, right);
}
if (b.isBooleanLiteral(expression)) {
return expression.value;
}
if (b.isCallExpression(expression)) {
const args = [];
for (let i = 0; constant && i < expression.arguments.length; i++) {
const arg = expression.arguments[i];
if (b.isSpreadElement(arg)) {
const spread = toConstant(arg.argument);
if (!(isSpreadable(spread) && constant)) {
constant = false;
} else {
args.push(...spread);
}
} else {
args.push(toConstant(arg));
}
}
if (!constant) return;
if (b.isMemberExpression(expression.callee)) {
const object = toConstant(expression.callee.object);
if (!object || !constant) {
constant = false;
return;
}
const member = expression.callee.computed
? toConstant(expression.callee.property)
: b.isIdentifier(expression.callee.property)
? expression.callee.property.name
: undefined;
if (member === undefined && !expression.callee.computed) {
constant = false;
}
if (!constant) return;
if (canCallMethod(object, '' + member)) {
return object[member].apply(object, args);
}
} else {
const callee = toConstant(expression.callee);
if (!constant) return;
return callee.apply(null, args);
}
}
if (b.isConditionalExpression(expression)) {
const test = toConstant(expression.test);
return test
? toConstant(expression.consequent)
: toConstant(expression.alternate);
}
if (b.isIdentifier(expression)) {
if (
options.constants &&
{}.hasOwnProperty.call(options.constants, expression.name)
) {
return options.constants[expression.name];
}
}
if (b.isLogicalExpression(expression)) {
const left = toConstant(expression.left);
const right = toConstant(expression.right);
if (constant && expression.operator === '&&') {
return left && right;
}
if (constant && expression.operator === '||') {
return left || right;
}
}
if (b.isMemberExpression(expression)) {
const object = toConstant(expression.object);
if (!object || !constant) {
constant = false;
return;
}
const member = expression.computed
? toConstant(expression.property)
: b.isIdentifier(expression.property)
//.........这里部分代码省略.........
开发者ID:Ashwinie,项目名称:inceptionEngine,代码行数:101,代码来源:index.ts
示例2: transform
//.........这里部分代码省略.........
path.node.name = t.jSXIdentifier('View')
const store = path.node.attributes.find(attr => attr.name.name === 'store')
if (store && t.isJSXExpressionContainer(store.value) && t.isIdentifier(store.value.expression)) {
storeName = store.value.expression.name
}
path.node.attributes = []
}
}
if (IMAGE_COMPONENTS.has(name)) {
for (const attr of path.node.attributes) {
if (
attr.name.name === 'src'
) {
if (t.isStringLiteral(attr.value)) {
imageSource.add(attr.value.value)
} else if (t.isJSXExpressionContainer(attr.value)) {
if (t.isStringLiteral(attr.value.expression)) {
imageSource.add(attr.value.expression.value)
}
}
}
}
}
},
JSXAttribute (path) {
const { name, value } = path.node
if (!t.isJSXIdentifier(name) || value === null || t.isStringLiteral(value) || t.isJSXElement(value)) {
return
}
const expr = value.expression as any
const exprPath = path.get('value.expression')
if (!t.isBinaryExpression(expr, { operator: '+' }) && !t.isLiteral(expr) && name.name === 'style') {
const jsxID = path.findParent(p => p.isJSXOpeningElement()).get('name')
if (jsxID && jsxID.isJSXIdentifier() && DEFAULT_Component_SET.has(jsxID.node.name)) {
exprPath.replaceWith(
t.callExpression(t.identifier(INTERNAL_INLINE_STYLE), [expr])
)
}
}
if (name.name.startsWith('on')) {
if (exprPath.isReferencedIdentifier()) {
const ids = [expr.name]
const fullPath = buildFullPathThisPropsRef(expr, ids, path)
if (fullPath) {
exprPath.replaceWith(fullPath)
}
}
if (exprPath.isReferencedMemberExpression()) {
const id = findFirstIdentifierFromMemberExpression(expr)
const ids = getIdsFromMemberProps(expr)
if (t.isIdentifier(id)) {
const fullPath = buildFullPathThisPropsRef(id, ids, path)
if (fullPath) {
exprPath.replaceWith(fullPath)
}
}
}
// @TODO: bind 的处理待定
}
},
ImportDeclaration (path) {
开发者ID:topud,项目名称:taro,代码行数:67,代码来源:index.ts
示例3: traverse
declare const ast: t.Node;
traverse(ast, {
enter(path) {
const node = path.node;
if (t.isIdentifier(node, { name: "n" })) {
node.name = "x";
}
if (t.isFunctionExpression(node)) {
node.params = [t.identifier('param')];
}
}
});
if (t.isBinaryExpression(ast)) {
ast.left;
ast.right;
ast.operator;
}
t.assertBinaryExpression(ast);
t.assertBinaryExpression(ast, { operator: "*" });
const exp: t.Expression = t.nullLiteral();
// React examples:
// https://github.com/babel/babel/blob/4e50b2d9d9c376cee7a2cbf56553fe5b982ea53c/packages/babel-plugin-transform-react-inline-elements/src/index.js#L61
traverse(ast, {
JSXElement(path, file) {
const { node } = path;
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:30,代码来源:babel-types-tests.ts
示例4: transform
//.........这里部分代码省略.........
path.node.name = t.jSXIdentifier('View')
const store = path.node.attributes.find(attr => attr.name.name === 'store')
if (store && t.isJSXExpressionContainer(store.value) && t.isIdentifier(store.value.expression)) {
storeName = store.value.expression.name
}
path.node.attributes = []
}
}
if (IMAGE_COMPONENTS.has(name)) {
for (const attr of path.node.attributes) {
if (
t.isIdentifier(attr) &&
attr.name.name === 'src'
) {
if (t.isStringLiteral(attr.value)) {
imageSource.add(attr.value.value)
} else if (t.isJSXExpressionContainer(attr.value)) {
if (t.isStringLiteral(attr.value.expression)) {
imageSource.add(attr.value.expression.value)
}
}
}
}
}
},
JSXAttribute (path) {
const { name, value } = path.node
if (!t.isJSXIdentifier(name) || value === null || t.isStringLiteral(value) || t.isJSXElement(value)) {
return
}
const expr = value.expression
if (t.isBinaryExpression(expr, { operator: '+' }) || t.isLiteral(expr) || name.name !== 'style') {
return
}
path.get('value.expression').replaceWith(
t.callExpression(t.identifier(INTERNAL_INLINE_STYLE), [expr])
)
},
ImportDeclaration (path) {
const source = path.node.source.value
const names: string[] = []
if (source === TARO_PACKAGE_NAME) {
path.node.specifiers.push(
t.importSpecifier(t.identifier(INTERNAL_SAFE_GET), t.identifier(INTERNAL_SAFE_GET)),
t.importSpecifier(t.identifier(INTERNAL_DYNAMIC), t.identifier(INTERNAL_DYNAMIC)),
t.importSpecifier(t.identifier(INTERNAL_INLINE_STYLE), t.identifier(INTERNAL_INLINE_STYLE))
)
}
if (
source === REDUX_PACKAGE_NAME
) {
path.node.specifiers.forEach((s, index, specs) => {
if (s.local.name === 'Provider') {
specs.splice(index, 1)
specs.push(
t.importSpecifier(t.identifier('setStore'), t.identifier('setStore'))
)
}
})
}
path.traverse({
ImportDefaultSpecifier (path) {
const name = path.node.local.name
开发者ID:ApolloRobot,项目名称:taro,代码行数:67,代码来源:index.ts
注:本文中的babel-types.isBinaryExpression函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论