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

TypeScript path.scope类代码示例

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

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



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

示例1: resolvePartialWildcardString

    plugins: [({ types: t }) => {
      function resolvePartialWildcardString (node, lastIsWildcard) {
        if (t.isStringLiteral(node))
          return node.value;
        if (t.isTemplateLiteral(node)) {
          let str = '';
          for (let i = 0; i < node.quasis.length; i++) {
            const quasiStr = node.quasis[i].value.cooked;
            if (quasiStr.length) {
              str += quasiStr;
              lastIsWildcard = false;
            }
            const nextNode = node.expressions[i];
            if (nextNode) {
              const nextStr = resolvePartialWildcardString(nextNode, lastIsWildcard);
              if (nextStr.length) {
                lastIsWildcard = nextStr.endsWith('*');
                str += nextStr;
              }
            }
          }
          return str;
        }
        if (t.isBinaryExpression(node) && node.operator === '+') {
          const leftResolved = resolvePartialWildcardString(node.left, lastIsWildcard);
          if (leftResolved.length)
            lastIsWildcard = leftResolved.endsWith('*');
          const rightResolved = resolvePartialWildcardString(node.right, lastIsWildcard);
          return leftResolved + rightResolved;
        }
        return lastIsWildcard ? '' : '*';
      }

      return {
        visitor: {
          ReferencedIdentifier (path) {
            const identifierName = path.node.name;
            if (!hasProcess && identifierName === 'process' && !path.scope.hasBinding('process'))
              hasProcess = true;
            if (!hasBuffer && identifierName === 'Buffer' && !path.scope.hasBinding('Buffer'))
              hasBuffer = true;
          },
          CallExpression (path) {
            if (t.isIdentifier(path.node.callee, { name: 'require' })) {
              const req = resolvePartialWildcardString(path.node.arguments[0], false);
              if (req !== '*')
                requires.add(req);
            }
            else if (t.isMemberExpression(path.node.callee) &&
                     t.isIdentifier(path.node.callee.object, { name: 'require' }) &&
                     t.isIdentifier(path.node.callee.property, { name: 'resolve' })) {
              const req = resolvePartialWildcardString(path.node.arguments[0], false);
              if (req.indexOf('*') !== -1)
                requires.add(req);
            }
          }
        }
      };
    }]
开发者ID:jspm,项目名称:jspm-cli,代码行数:59,代码来源:dew-worker.ts


示例2: it

 it("should register typescript types with the scope", function() {  
   visit(ast, {
     visitProgram(path) {
       assert(path.scope.declaresType('Foo'));
       assert(path.scope.declaresType('Bar'));
       assert.equal(path.scope.lookupType('Foo').getTypes()['Foo'][0].parent.node.type, 'TSTypeAliasDeclaration');
       assert.equal(path.scope.lookupType('Bar').getTypes()['Bar'][0].parent.node.type, 'TSInterfaceDeclaration');
       return false;
     }
   });
 });
开发者ID:benjamn,项目名称:ast-types,代码行数:11,代码来源:typescript.ts


示例3: return

 return (path, state) => {
   const bindings: { [identifier: string]: Binding } = (path.scope.getAllBindings() as any);
   const camlExceptions = bindings["Caml_exceptions"];
   if (camlExceptions) {
     let referenceCount = camlExceptions.references;
     const modulePath: string = state.file.opts.filename;
     if (modulePath === "unknown")
       return;
     let json: BuckleScript.AttrsJSON;
     if ((json = (BuckleScript.Attrs.json(modulePath) as any)) == null)
       return;
     for (const name in bindings) {
       let replacement: string;
       if ((replacement = json[name]) != null) {
         const binding = bindings[name];
         binding.path.replaceWith(
           types.variableDeclarator(binding.identifier, types.stringLiteral(replacement))
         );
         referenceCount--;
       }
     }
     if (referenceCount < 1) {
       camlExceptions.path.remove();
     }
   }
 };
开发者ID:freebroccolo,项目名称:babel-plugin-transform-bucklescript,代码行数:26,代码来源:index.ts


示例4: getSuperClassCode

export function getSuperClassCode (path: NodePath<t.ClassDeclaration>) {
  const superClass = path.node.superClass
  if (t.isIdentifier(superClass)) {
    const binding = path.scope.getBinding(superClass.name)
    if (binding && binding.kind === 'module') {
      const bindingPath = binding.path.parentPath
      if (bindingPath.isImportDeclaration()) {
        const source = bindingPath.node.source
        if (source.value === TARO_PACKAGE_NAME) {
          return
        }
        try {
          const p = pathResolver(source.value, transformOptions.sourcePath) + (transformOptions.isTyped ? '.tsx' : '.js')
          const code = fs.readFileSync(p, 'utf8')
          return {
            code,
            sourcePath: source.value
          }
        } catch (error) {
          return
        }
      }
    }
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:25,代码来源:utils.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript path-sort.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript path.resolve类代码示例发布时间: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