本文整理匯總了TypeScript中path.scope.hasBinding方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript scope.hasBinding方法的具體用法?TypeScript scope.hasBinding怎麽用?TypeScript scope.hasBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類path.scope
的用法示例。
在下文中一共展示了scope.hasBinding方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
}
}
};
}]