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

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

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

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



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

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


示例2: buildRefTemplate

export function buildRefTemplate (name: string, refName?: string, loop?: boolean) {
  return t.jSXElement(
    t.jSXOpeningElement(t.jSXIdentifier('template'), [
      t.jSXAttribute(t.jSXIdentifier('is'), t.stringLiteral(name)),
      t.jSXAttribute(t.jSXIdentifier('data'), t.stringLiteral(`{{...${refName ? `${loop ? '' : '$$'}${refName}` : '__data'}}}`))
    ]),
    t.jSXClosingElement(t.jSXIdentifier('template')),
    []
  )
}
开发者ID:teachat8,项目名称:taro,代码行数:10,代码来源:jsx.ts


示例3: transformLoop

function transformLoop (
  name: string,
  attr: NodePath<t.JSXAttribute>,
  jsx: NodePath<t.JSXElement>,
  value: AttrValue
) {
  if (name !== WX_FOR) {
    return
  }
  if (!value || !t.isJSXExpressionContainer(value)) {
    throw new Error('wx:for 的值必须使用 "{{}}"  包裹')
  }
  attr.remove()
  let item = t.stringLiteral('item')
  let index = t.stringLiteral('index')
  jsx
    .get('openingElement')
    .get('attributes')
    .forEach(p => {
      const node = p.node
      if (node.name.name === WX_FOR_ITEM) {
        if (!node.value || !t.isStringLiteral(node.value)) {
          throw new Error(WX_FOR_ITEM + ' 的值必须是一个字符串')
        }
        item = node.value
        p.remove()
      }
      if (node.name.name === WX_FOR_INDEX) {
        if (!node.value || !t.isStringLiteral(node.value)) {
          throw new Error(WX_FOR_INDEX + ' 的值必须是一个字符串')
        }
        index = node.value
        p.remove()
      }
      if (node.name.name === WX_KEY) {
        p.get('name').replaceWith(t.jSXIdentifier('key'))
      }
    })

  const replacement = t.jSXExpressionContainer(
    t.callExpression(
      t.memberExpression(value.expression, t.identifier('map')),
      [
        t.arrowFunctionExpression(
          [t.identifier(item.value), t.identifier(index.value)],
          t.blockStatement([t.returnStatement(jsx.node)])
        )
      ]
    )
  )

  const block = buildBlockElement()
  block.children = [replacement]
  jsx.replaceWith(block)
}
开发者ID:topud,项目名称:taro,代码行数:55,代码来源:wxml.ts


示例4: buildRefTemplate

export function buildRefTemplate (name: string, refName?: string, loop?: boolean, key?: t.JSXAttribute) {
  const attrs = [
    t.jSXAttribute(t.jSXIdentifier('is'), t.stringLiteral(name)),
    t.jSXAttribute(t.jSXIdentifier('data'), t.stringLiteral(`{{...${refName ? `${loop ? '' : '$$'}${refName}` : '__data'}}}`))
  ]
  if (key) {
    attrs.push(key)
  }
  return t.jSXElement(
    t.jSXOpeningElement(t.jSXIdentifier('template'), attrs),
    t.jSXClosingElement(t.jSXIdentifier('template')),
    []
  )
}
开发者ID:AlloyTeam,项目名称:Nuclear,代码行数:14,代码来源:jsx.ts


示例5: rewriteExportAllToNamedExports

 rewriteExportAllToNamedExports(node: babel.Node, analysis: Analysis) {
   traverse(node, {
     noScope: true,
     ExportAllDeclaration: {
       enter(path: NodePath<babel.ExportAllDeclaration>) {
         const exportAllDeclaration = path.node;
         const sourceUrl =
             babel.isStringLiteral(exportAllDeclaration.source) &&
             exportAllDeclaration.source.value;
         if (!sourceUrl) {
           return;
         }
         const sourceDocument = getAnalysisDocument(analysis, sourceUrl);
         const documentExports = sourceDocument.getFeatures({kind: 'export'});
         const specifiers: babel.ExportSpecifier[] = [];
         for (const documentExport of documentExports) {
           for (const exportIdentifier of documentExport.identifiers) {
             const identifierValue = exportIdentifier.valueOf();
             // It does not appear that `export * from` should re-export
             // the default module export of a module.
             if (identifierValue !== 'default') {
               specifiers.push(babel.exportSpecifier(
                   babel.identifier(identifierValue),
                   babel.identifier(identifierValue)));
             }
           }
         }
         const namedExportDeclaration = babel.exportNamedDeclaration(
             undefined, specifiers, babel.stringLiteral(sourceUrl));
         rewriteObject(exportAllDeclaration, namedExportDeclaration);
       }
     }
   });
 }
开发者ID:Polymer,项目名称:tools,代码行数:34,代码来源:es6-rewriter.ts


示例6:

 observeProps.map(p => t.objectExpression([
   t.objectProperty(
     t.identifier('name'),
     t.stringLiteral(p.name)
   ),
   t.objectProperty(
     t.identifier('observer'),
     p.observer
   )
 ]))
开发者ID:YangShaoQun,项目名称:taro,代码行数:10,代码来源:script.ts


示例7: buildImportStatement

export function buildImportStatement (source: string, specifiers: string[] = [], defaultSpec?: string) {
  return t.importDeclaration(
    defaultSpec ? [defaultSpec, ...specifiers].map((spec, index) => {
      if (index === 0) {
        return t.importDefaultSpecifier(t.identifier(defaultSpec))
      }
      return t.importSpecifier(t.identifier(spec), t.identifier(spec))
    }) : specifiers.map(s => t.importSpecifier(t.identifier(s), t.identifier(s))),
    t.stringLiteral(source)
  )
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:11,代码来源:utils.ts


示例8: templateLiterals

export function templateLiterals (path, state) {

  let nodes: Array<Object> = []

  const expressions = path.get('expressions')

  for (const elem of (path.node.quasis)) {
    nodes.push(t.stringLiteral(elem.value.cooked))

    const expr = expressions.shift()
    if (expr) {
      // tslint:disable-next-line:no-multi-spaces
      if (state.opts.spec && !expr.isBaseType('string') && !expr.isBaseType('number'))  {
        nodes.push(t.callExpression(t.identifier('String'), [expr.node]))
      } else {
        nodes.push(expr.node)
      }
    }
  }

  // filter out empty string literals
  nodes = nodes.filter((n) => !t.isLiteral(n, { value: '' }))

  // since `+` is left-to-right associative
  // ensure the first node is a string if first/second isn't
  if (!isString(nodes[0]) && !isString(nodes[1])) {
    nodes.unshift(t.stringLiteral(''))
  }

  if (nodes.length > 1) {
    let root = buildBinaryExpression(nodes.shift(), nodes.shift())

    for (const node of nodes) {
      root = buildBinaryExpression(root, node)
    }

    path.replaceWith(root)
  } else {
    path.replaceWith(nodes[0])
  }
}
开发者ID:AlloyTeam,项目名称:Nuclear,代码行数:41,代码来源:plugins.ts


示例9: convertArrayToAstExpression

 return arr.map(value => {
   if (typeof value === 'string') {
     return t.stringLiteral(value)
   }
   if (typeof value === 'number') {
     return t.numericLiteral(value)
   }
   if (typeof value === 'boolean') {
     return t.booleanLiteral(value)
   }
   if (Array.isArray(value)) {
     return convertArrayToAstExpression(value)
   }
   if (typeof value === 'object') {
     return t.objectExpression(convertObjectToAstExpression(value))
   }
   return t.nullLiteral()
 })
开发者ID:YangShaoQun,项目名称:taro,代码行数:18,代码来源:astConvert.ts


示例10: parseAttribute

function parseAttribute (attr: Attribute) {
  const { key, value } = attr

  let jsxValue: null | t.JSXExpressionContainer | t.StringLiteral = null

  if (value) {
    const { type, content } = parseContent(value)
    jsxValue =
      type === 'raw'
        ? t.stringLiteral(content)
        : t.jSXExpressionContainer(buildTemplate(content))
  }

  const jsxKey = handleAttrKey(key)
  if (/^on[A-Z]/.test(jsxKey) && jsxValue && t.isStringLiteral(jsxValue)) {
    jsxValue = t.jSXExpressionContainer(
      t.memberExpression(t.thisExpression(), t.identifier(jsxValue.value))
    )
  }
  return t.jSXAttribute(t.jSXIdentifier(jsxKey), jsxValue)
}
开发者ID:topud,项目名称:taro,代码行数:21,代码来源:wxml.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript babel-types.thisExpression函数代码示例发布时间:2022-05-25
下一篇:
TypeScript babel-types.returnStatement函数代码示例发布时间: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