本文整理汇总了TypeScript中@babel/types.isArrayExpression函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isArrayExpression函数的具体用法?TypeScript isArrayExpression怎么用?TypeScript isArrayExpression使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isArrayExpression函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: extractObservers
export function extractObservers(
observersArray: babel.Node, document: JavaScriptDocument): undefined|
{observers: Observer[], warnings: Warning[]} {
if (!babel.isArrayExpression(observersArray)) {
return;
}
let warnings: Warning[] = [];
const observers = [];
for (const element of observersArray.elements) {
let v = astValue.expressionToValue(element);
if (v === undefined) {
v = astValue.CANT_CONVERT;
}
const parseResult =
parseExpressionInJsStringLiteral(document, element, 'callExpression');
warnings = warnings.concat(parseResult.warnings);
observers.push({
javascriptNode: element,
expression: v,
parsedExpression: parseResult.databinding
});
}
return {observers, warnings};
}
示例2: declarationPropertyHandlers
export function declarationPropertyHandlers(
declaration: ScannedPolymerElement,
document: JavaScriptDocument,
path: NodePath): PropertyHandlers {
return {
is(node: babel.Node) {
if (babel.isLiteral(node)) {
declaration.tagName = '' + astValue.expressionToValue(node);
}
},
properties(node: babel.Node) {
for (const prop of analyzeProperties(node, document)) {
declaration.addProperty(prop);
}
},
behaviors(node: babel.Node) {
if (!babel.isArrayExpression(node)) {
return;
}
for (const element of node.elements) {
const result = getBehaviorReference(element, document, path);
if (result.successful === false) {
declaration.warnings.push(result.error);
} else {
declaration.behaviorAssignments.push(result.value);
}
}
},
observers(node: babel.Node) {
const observers = extractObservers(node, document);
if (!observers) {
return;
}
declaration.warnings = declaration.warnings.concat(observers.warnings);
declaration.observers = declaration.observers.concat(observers.observers);
},
listeners(node: babel.Node) {
if (!babel.isObjectExpression(node)) {
declaration.warnings.push(new Warning({
code: 'invalid-listeners-declaration',
message: '`listeners` property should be an object expression',
severity: Severity.WARNING,
sourceRange: document.sourceRangeForNode(node)!,
parsedDocument: document
}));
return;
}
for (const p of getSimpleObjectProperties(node)) {
const evtName =
babel.isLiteral(p.key) && astValue.expressionToValue(p.key) ||
babel.isIdentifier(p.key) && p.key.name;
const handler =
!babel.isLiteral(p.value) || astValue.expressionToValue(p.value);
if (typeof evtName !== 'string' || typeof handler !== 'string') {
// TODO (maklesoft): Notifiy the user somehow that a listener entry
// was not extracted
// because the event or handler namecould not be statically analyzed.
// E.g. add a low-severity
// warning once opting out of rules is supported.
continue;
}
declaration.listeners.push({event: evtName, handler: handler});
}
}
};
}