本文整理汇总了TypeScript中babel-types.isNumericLiteral函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isNumericLiteral函数的具体用法?TypeScript isNumericLiteral怎么用?TypeScript isNumericLiteral使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isNumericLiteral函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getArgumentName
export function getArgumentName (arg) {
if (t.isThisExpression(arg)) {
return 'this'
} else if (t.isNullLiteral(arg)) {
return 'null'
} else if (t.isStringLiteral(arg) || t.isNumericLiteral(arg)) {
return arg.value
} else if (t.isIdentifier(arg)) {
return arg.name
} else {
return generate(arg).code
}
throw new Error(`bind 不支持传入该参数: ${arg}`)
}
示例2: toConstant
//.........这里部分代码省略.........
}
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)
? expression.property.name
: undefined;
if (member === undefined && !expression.computed) {
constant = false;
}
if (!constant) return;
if ({}.hasOwnProperty.call(object, '' + member) && member[0] !== '_') {
return object[member];
}
}
if (b.isNullLiteral(expression)) {
return null;
}
if (b.isNumericLiteral(expression)) {
return expression.value;
}
if (b.isObjectExpression(expression)) {
const result: any = {};
for (let i = 0; constant && i < expression.properties.length; i++) {
const property = expression.properties[i];
if (b.isObjectProperty(property)) {
if (property.shorthand) {
constant = false;
return;
}
const key = property.computed
? toConstant(property.key)
: b.isIdentifier(property.key)
? property.key.name
: b.isStringLiteral(property.key)
? property.key.value
: undefined;
if (!key || key[0] === '_') {
constant = false;
}
if (!constant) return;
const value = toConstant(property.value);
if (!constant) return;
result[key] = value;
} else if (b.isObjectMethod(property)) {
constant = false;
} else if (b.isSpreadProperty(property)) {
const argument = toConstant(property.argument);
if (!argument) constant = false;
if (!constant) return;
Object.assign(result, argument);