當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。