• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript babel-types.isJSXSpreadAttribute函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中babel-types.isJSXSpreadAttribute函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isJSXSpreadAttribute函数的具体用法?TypeScript isJSXSpreadAttribute怎么用?TypeScript isJSXSpreadAttribute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了isJSXSpreadAttribute函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: codeFrameError

 attributes: attributes.reduce((obj, attr) => {
   if (t.isJSXSpreadAttribute(attr)) {
     throw codeFrameError(attr.loc, 'JSX 参数暂不支持 ...spread 表达式')
   }
   const name = attr.name.name === 'className' ? 'class' : attr.name.name
   let value: string | boolean = true
   let attrValue = attr.value
   if (typeof name === 'string') {
     if (t.isStringLiteral(attrValue)) {
       value = attrValue.value
     } else if (t.isJSXExpressionContainer(attrValue)) {
       const isBindEvent =
         name.startsWith('bind') || name.startsWith('catch')
       let { code } = generate(attrValue.expression)
       code = code
         .replace(/(this\.props\.)|(this\.state\.)/, '')
         .replace(/this\./, '')
       value = isBindEvent ? code : `{{${code}}}`
       if (t.isStringLiteral(attrValue.expression)) {
         value = attrValue.expression.value
       }
     }
     if (
       componentSpecialProps &&
       componentSpecialProps.has(name)
     ) {
       obj[name] = value
     } else {
       obj[isDefaultComponent && !name.includes('-') && !name.includes(':') ? kebabCase(name) : name] = value
     }
   }
   return obj
 }, {}),
开发者ID:teachat8,项目名称:taro,代码行数:33,代码来源:jsx.ts


示例2: codeFrameError

 attributesTrans = attributes.reduce((obj, attr) => {
   if (t.isJSXSpreadAttribute(attr)) {
     throw codeFrameError(attr.loc, 'JSX 参数暂不支持 ...spread 表达式')
   }
   let name = attr.name.name
   if (DEFAULT_Component_SET.has(componentName)) {
     if (name === 'className') {
       name = 'class'
     }
   }
   let value: string | boolean = true
   let attrValue = attr.value
   if (typeof name === 'string') {
     const isAlipayEvent = Adapter.type === Adapters.alipay && /(^on[A-Z_])|(^catch[A-Z_])/.test(name)
     if (t.isStringLiteral(attrValue)) {
       value = attrValue.value
     } else if (t.isJSXExpressionContainer(attrValue)) {
       let isBindEvent =
         (name.startsWith('bind') && name !== 'bind') || (name.startsWith('catch') && name !== 'catch')
       const code = decodeUnicode(generate(attrValue.expression, {
           quotes: 'single',
           concise: true
         }).code)
         .replace(/"/g, "'")
         .replace(/(this\.props\.)|(this\.state\.)/g, '')
         .replace(/this\./g, '')
       value = isBindEvent || isAlipayEvent ? code : `{{${code}}}`
       if (Adapter.type === Adapters.swan && name === Adapter.for) {
         value = code
       }
       if (t.isStringLiteral(attrValue.expression)) {
         value = attrValue.expression.value
       }
     } else if (attrValue === null && name !== Adapter.else) {
       value = `{{true}}`
     }
     if ((componentName === 'Input' || componentName === 'input') && name === 'maxLength') {
       obj['maxlength'] = value
     } else if (
       componentSpecialProps && componentSpecialProps.has(name) ||
       name.startsWith('__fn_') ||
       isAlipayEvent
     ) {
       obj[name] = value
     } else {
       obj[isDefaultComponent && !name.includes('-') && !name.includes(':') ? kebabCase(name) : name] = value
     }
   }
   if (!isDefaultComponent && !specialComponentName.includes(componentName)) {
     obj[TRIGGER_OBSERER] = '{{ _triggerObserer }}'
   }
   return obj
 }, {})
开发者ID:topud,项目名称:taro,代码行数:53,代码来源:jsx.ts


示例3: codeFrameError

 attributesTrans = attributes.reduce((obj, attr) => {
   if (t.isJSXSpreadAttribute(attr)) {
     throw codeFrameError(attr.loc, 'JSX 参数暂不支持 ...spread 表达式')
   }
   let name = attr.name.name
   if (DEFAULT_Component_SET.has(componentName)) {
     if (name === 'className') {
       name = 'class'
     }
   }
   let value: string | boolean = true
   let attrValue = attr.value
   if (typeof name === 'string') {
     const isAlipayEvent = Adapter.type === Adapters.alipay && /(^on[A-Z_])|(^catch[A-Z_])/.test(name)
     if (t.isStringLiteral(attrValue)) {
       value = attrValue.value
     } else if (t.isJSXExpressionContainer(attrValue)) {
       let isBindEvent =
         (name.startsWith('bind') && name !== 'bind') || (name.startsWith('catch') && name !== 'catch')
       let code = decodeUnicode(generate(attrValue.expression, {
           quotes: 'single',
           concise: true
         }).code)
         .replace(/"/g, "'")
         .replace(/(this\.props\.)|(this\.data\.)/g, '')
         .replace(/this\./g, '')
       if (
         Adapters.swan === Adapter.type &&
         code !== 'true' &&
         code !== 'false' &&
         swanSpecialAttrs[componentName] &&
         swanSpecialAttrs[componentName].includes(name)
       ) {
         value = `{= ${code} =}`
       } else {
         if (Adapter.key === name) {
           const splitCode = code.split('.')
           if (splitCode.length > 1) {
             value = splitCode.slice(1).join('.')
           } else {
             value = code
           }
         } else {
           value = isBindEvent || isAlipayEvent ? code : `{{${code}}}`
         }
       }
       if (Adapter.type === Adapters.swan && name === Adapter.for) {
         value = code
       }
       if (t.isStringLiteral(attrValue.expression)) {
         value = attrValue.expression.value
       }
     } else if (attrValue === null && name !== Adapter.else) {
       value = `{{true}}`
     }
     if (THIRD_PARTY_COMPONENTS.has(componentName) && /^bind/.test(name) && name.includes('-')) {
       name = name.replace(/^bind/, 'bind:')
     }
     if (componentTransfromProps && componentTransfromProps[componentName]) {
       const transfromProps = componentTransfromProps[componentName]
       Object.keys(transfromProps).forEach(oriName => {
         if (transfromProps.hasOwnProperty(name as string)) {
           name = transfromProps[oriName]
         }
       })
     }
     if ((componentName === 'Input' || componentName === 'input') && name === 'maxLength') {
       obj['maxlength'] = value
     } else if (
       componentSpecialProps && componentSpecialProps.has(name) ||
       name.startsWith('__fn_') ||
       isAlipayEvent
     ) {
       obj[name] = value
     } else {
       obj[isDefaultComponent && !name.includes('-') && !name.includes(':') ? kebabCase(name) : name] = value
     }
   }
   if (!isDefaultComponent && !specialComponentName.includes(componentName)) {
     //@fix
     //obj[TRIGGER_OBSERER] = '{{ _triggerObserer }}'
   }
   return obj
 }, {})
开发者ID:AlloyTeam,项目名称:Nuclear,代码行数:84,代码来源:jsx.ts



注:本文中的babel-types.isJSXSpreadAttribute函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript babel-types.isJSXText函数代码示例发布时间:2022-05-25
下一篇:
TypeScript babel-types.isJSXMemberExpression函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap