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


TypeScript babel-generator.default函数代码示例

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


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

示例1: if

    scannedMethod.params = (value.params || []).map((nodeParam) => {
      let name;
      let defaultValue;
      let rest;

      if (babel.isIdentifier(nodeParam)) {
        // Basic parameter: method(param)
        name = nodeParam.name;

      } else if (
          babel.isRestElement(nodeParam) &&
          babel.isIdentifier(nodeParam.argument)) {
        // Rest parameter: method(...param)
        name = nodeParam.argument.name;
        rest = true;

      } else if (
          babel.isAssignmentPattern(nodeParam) &&
          babel.isIdentifier(nodeParam.left) &&
          babel.isLiteral(nodeParam.right)) {
        // Parameter with a default: method(param = "default")
        name = nodeParam.left.name;
        defaultValue = generate(nodeParam.right).code;

      } else {
        // Some AST pattern we don't recognize. Hope the code generator does
        // something reasonable.
        name = generate(nodeParam).code;
      }

      let type;
      let description;
      const tag = paramTags.get(name);
      if (tag) {
        if (tag.type) {
          type = doctrine.type.stringify(tag.type);
        }
        if (tag.description) {
          description = tag.description;
        }
      }

      const param: MethodParam = {name, type, defaultValue, rest, description};
      return param;
    });
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:45,代码来源:esutil.ts

示例2: parseJSXElement

 .reduce((str, child) => {
   if (t.isJSXText(child)) {
     return str + child.value
   }
   if (t.isJSXElement(child)) {
     return str + parseJSXElement(child)
   }
   if (t.isJSXExpressionContainer(child)) {
     if (t.isJSXElement(child.expression)) {
       return str + parseJSXElement(child.expression)
     }
     return str + `{${
       decodeUnicode(
         generate(child, {
           quotes: 'single',
           jsonCompatibleStrings: true
         })
         .code
       )
       .replace(/(this\.props\.)|(this\.state\.)/g, '')
       .replace(/(props\.)|(state\.)/g, '')
       .replace(/this\./, '')
     }}`
   }
   return str
 }, '')
开发者ID:topud,项目名称:taro,代码行数:26,代码来源:jsx.ts

示例3: 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

示例4: prepareBundleModule

/**
 * Generate code containing import statements to all bundled modules and
 * export statements to re-export their namespaces and exports.
 *
 * Example: a bundle containing files `module-a.js` and `module-b.js` would
 * result in a prepareBundleModule result like:
 *
 *     import * as $moduleA from './module-a.js';
 *     import * as $moduleB from './module-b.js';
 *     import $moduleBDefault from './module-b.js';
 *     export {thing1, thing2} from './module-a.js';
 *     export {thing3} from './module-b.js';
 *     export {$moduleA, $moduleB, $moduleBDefault};
 */
async function prepareBundleModule(
    bundler: Bundler, manifest: BundleManifest, assignedBundle: AssignedBundle):
    Promise<string> {
      let bundleSource = babel.program([]);
      const sourceAnalysis =
          await bundler.analyzer.analyze([...assignedBundle.bundle.files]);
      for (const sourceUrl of [...assignedBundle.bundle.files].sort()) {
        const rebasedSourceUrl =
            ensureLeadingDot(bundler.analyzer.urlResolver.relative(
                stripUrlFileSearchAndHash(assignedBundle.url), sourceUrl));
        const moduleDocument = getAnalysisDocument(sourceAnalysis, sourceUrl);
        const moduleExports = getModuleExportNames(moduleDocument);
        const starExportName =
            getOrSetBundleModuleExportName(assignedBundle, sourceUrl, '*');
        bundleSource.body.push(babel.importDeclaration(
            [babel.importNamespaceSpecifier(babel.identifier(starExportName))],
            babel.stringLiteral(rebasedSourceUrl)));
        if (moduleExports.size > 0) {
          bundleSource.body.push(babel.exportNamedDeclaration(
              undefined, [babel.exportSpecifier(
                             babel.identifier(starExportName),
                             babel.identifier(starExportName))]));
          bundleSource.body.push(babel.exportNamedDeclaration(
              undefined,
              [...moduleExports].map(
                  (e) => babel.exportSpecifier(
                      babel.identifier(e),
                      babel.identifier(getOrSetBundleModuleExportName(
                          assignedBundle, sourceUrl, e)))),
              babel.stringLiteral(rebasedSourceUrl)));
        }
      }
      const {code} = generate(bundleSource);
      return code;
    }
开发者ID:Polymer,项目名称:vulcanize,代码行数:49,代码来源:es6-module-bundler.ts

示例5: evalClass

export function evalClass (ast: t.File, props = '', isRequire = false) {
  let mainClass!: t.ClassDeclaration
  const statements = new Set<t.ExpressionStatement>([
    template('Current.inst = this;')() as any
  ])

  traverse(ast, {
    ClassDeclaration (path) {
      mainClass = path.node
    },
    /**
     * 目前 node 的版本支持不了 class-properties
     * 但 babel 又有 bug,某些情况竟然把转换后的 class-properties 编译到 super 之前
     * 不然用 babel.transformFromAst 就完事了
     * 现在只能自己实现这个 feature 的部分功能了,真 tm 麻烦
     * @TODO 有空再给他们提 PR 吧
     */
    ClassProperty (path) {
      const { key, value } = path.node
      statements.add(t.expressionStatement(t.assignmentExpression(
        '=',
        t.memberExpression(
          t.thisExpression(),
          key
        ),
        value
      )))
      path.remove()
    }
  })

  for (const method of mainClass.body.body) {
    // constructor 即便没有被定义也会被加上
    if (t.isClassMethod(method) && method.kind === 'constructor') {
      const index = method.body.body.findIndex(node => t.isSuper(node))
      method.body.body.push(
        t.expressionStatement(t.assignmentExpression(
          '=',
          t.memberExpression(
            t.thisExpression(),
            t.identifier('state')
          ),
          t.callExpression(t.memberExpression(t.thisExpression(), t.identifier('_createData')), [])
        ))
      )
      method.body.body.splice(index, 0, ...statements)
    }
  }

  let code = `function f() {};` +
    generate(t.classDeclaration(t.identifier('Test'), t.identifier('f'), mainClass.body, [])).code +
    ';' + `var classInst =  new Test(${props});classInst`

  code = internalFunction + code

  // tslint:disable-next-line
  return eval(code)
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:58,代码来源:utils.ts

示例6: 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

示例7: generateJSXAttr

export function generateJSXAttr (ast: t.Node) {
  return decodeUnicode(
    generate(ast, {
      quotes: 'single',
      jsonCompatibleStrings: true
    })
    .code
  )
  .replace(/(this\.props\.)|(this\.state\.)/g, '')
  .replace(/(props\.)|(state\.)/g, '')
  .replace(/this\./g, '')
  .replace(/</g, lessThanSignPlacehold)
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:13,代码来源:jsx.ts

示例8: 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

示例9: parseJSXElement

 .reduce((str, child) => {
   if (t.isJSXText(child)) {
     return str + child.value
   }
   if (t.isJSXElement(child)) {
     return str + parseJSXElement(child)
   }
   if (t.isJSXExpressionContainer(child)) {
     if (t.isJSXElement(child.expression)) {
       return str + parseJSXElement(child.expression)
     }
     return str + `{${
       generate(child)
       .code
       .replace(/(this\.props\.)|(this\.state\.)/, '')
       .replace(/this\./, '')
     }}`
   }
   return str
 }, '')
开发者ID:teachat8,项目名称:taro,代码行数:20,代码来源:jsx.ts

示例10: findMethodName

export function findMethodName (expression: t.Expression): string {
  let methodName
  if (
    t.isIdentifier(expression) ||
    t.isJSXIdentifier(expression)
  ) {
    methodName = expression.name
  } else if (t.isStringLiteral(expression)) {
    methodName = expression.value
  } else if (
    t.isMemberExpression(expression) &&
    t.isIdentifier(expression.property)
  ) {
    const { code } = generate(expression)
    const ids = code.split('.')
    if (ids[0] === 'this' && ids[1] === 'props' && ids[2]) {
      methodName = code.replace('this.props.', '')
    } else {
      methodName = expression.property.name
    }
  } else if (
    t.isCallExpression(expression) &&
    t.isMemberExpression(expression.callee) &&
    t.isIdentifier(expression.callee.object)
  ) {
    methodName = expression.callee.object.name
  } else if (
    t.isCallExpression(expression) &&
    t.isMemberExpression(expression.callee) &&
    t.isMemberExpression(expression.callee.object) &&
    t.isIdentifier(expression.callee.property) &&
    expression.callee.property.name === 'bind' &&
    t.isIdentifier(expression.callee.object.property)
  ) {
    methodName = expression.callee.object.property.name
  } else {
    throw codeFrameError(expression.loc, '当 props 为事件时(props name 以 `on` 开头),只能传入一个 this 作用域下的函数。')
  }
  return methodName
}
开发者ID:topud,项目名称:taro,代码行数:40,代码来源:utils.ts


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