當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript path.scope類代碼示例

本文整理匯總了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;未經允許,請勿轉載。