当前位置: 首页>>代码示例>>TypeScript>>正文


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

本文整理汇总了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;未经允许,请勿转载。