當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript babel-types.isNumericLiteral函數代碼示例

本文整理匯總了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}`)
}
開發者ID:topud,項目名稱:taro,代碼行數:14,代碼來源:utils.ts

示例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);
開發者ID:Ashwinie,項目名稱:inceptionEngine,代碼行數:67,代碼來源:index.ts


注:本文中的babel-types.isNumericLiteral函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。