本文整理汇总了TypeScript中babel-types.isArrayExpression函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isArrayExpression函数的具体用法?TypeScript isArrayExpression怎么用?TypeScript isArrayExpression使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isArrayExpression函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: convertAstExpressionToVariable
export function convertAstExpressionToVariable (node) {
if (t.isObjectExpression(node)) {
const obj = {}
const properties = node.properties
properties.forEach(property => {
if (property.type === 'ObjectProperty' || property.type === 'ObjectMethod') {
const key = convertAstExpressionToVariable(property.key)
const value = convertAstExpressionToVariable(property.value)
obj[key] = value
}
})
return obj
} else if (t.isArrayExpression(node)) {
return node.elements.map(convertAstExpressionToVariable)
} else if (t.isLiteral(node)) {
return node['value']
} else if (t.isIdentifier(node) || t.isJSXIdentifier(node)) {
const name = node.name
return name === 'undefined'
? undefined
: name
} else if (t.isJSXExpressionContainer(node)) {
return convertAstExpressionToVariable(node.expression)
}
}
示例2: 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};
}
示例3: toConstant
function toConstant(expression: b.Expression): any {
if (!constant) return;
if (b.isArrayExpression(expression)) {
const result = [];
for (let i = 0; constant && i < expression.elements.length; i++) {
const element = expression.elements[i];
if (b.isSpreadElement(element)) {
const spread = toConstant(element.argument);
if (!(isSpreadable(spread) && constant)) {
constant = false;
} else {
result.push(...spread);
}
} else {
result.push(toConstant(element));
}
}
return result;
}
if (b.isBinaryExpression(expression)) {
const left = toConstant(expression.left);
const right = toConstant(expression.right);
return constant && binaryOperation(expression.operator, left, right);
}
if (b.isBooleanLiteral(expression)) {
return expression.value;
}
if (b.isCallExpression(expression)) {
const args = [];
for (let i = 0; constant && i < expression.arguments.length; i++) {
const arg = expression.arguments[i];
if (b.isSpreadElement(arg)) {
const spread = toConstant(arg.argument);
if (!(isSpreadable(spread) && constant)) {
constant = false;
} else {
args.push(...spread);
}
} else {
args.push(toConstant(arg));
}
}
if (!constant) return;
if (b.isMemberExpression(expression.callee)) {
const object = toConstant(expression.callee.object);
if (!object || !constant) {
constant = false;
return;
}
const member = expression.callee.computed
? toConstant(expression.callee.property)
: b.isIdentifier(expression.callee.property)
? expression.callee.property.name
: undefined;
if (member === undefined && !expression.callee.computed) {
constant = false;
}
if (!constant) return;
if (canCallMethod(object, '' + member)) {
return object[member].apply(object, args);
}
} else {
const callee = toConstant(expression.callee);
if (!constant) return;
return callee.apply(null, args);
}
}
if (b.isConditionalExpression(expression)) {
const test = toConstant(expression.test);
return test
? toConstant(expression.consequent)
: toConstant(expression.alternate);
}
if (b.isIdentifier(expression)) {
if (
options.constants &&
{}.hasOwnProperty.call(options.constants, expression.name)
) {
return options.constants[expression.name];
}
}
if (b.isLogicalExpression(expression)) {
const left = toConstant(expression.left);
const right = toConstant(expression.right);
if (constant && expression.operator === '&&') {
return left && right;
}
if (constant && expression.operator === '||') {
return left || right;
}
}
if (b.isMemberExpression(expression)) {
const object = toConstant(expression.object);
if (!object || !constant) {
constant = false;
return;
}
const member = expression.computed
? toConstant(expression.property)
: b.isIdentifier(expression.property)
//.........这里部分代码省略.........
示例4:
if (elements.some(el => t.isObjectExpression(el as any) || t.isArrayExpression(el))) {
示例5: return
return (astPath) => {
const node = astPath.node
const key = node.key
const value = node.value
if (key.name !== 'config' || !t.isObjectExpression(value)) return
// 入口文件的 config ,与页面的分开处理
if (isEntryFile) {
// 读取 config 配置
astPath.traverse({
ObjectProperty (astPath) {
const node = astPath.node
const key = node.key
const value = node.value
// if (key.name !== 'pages' || !t.isArrayExpression(value)) return
if (key.name === 'pages' && t.isArrayExpression(value)) {
// 分包
let root = ''
const rootNode = astPath.parent.properties.find(v => {
return v.key.name === 'root'
})
root = rootNode ? rootNode.value.value : ''
value.elements.forEach(v => {
if (t.isStringLiteral(v)) {
const pagePath = `${root}/${v.value}`.replace(/\/{2,}/g, '/')
pages.push(pagePath.replace(/^\//, ''))
}
})
astPath.remove()
}
// window
if (key.name === 'window' && t.isObjectExpression(value)) {
return
}
if (key.name === 'tabBar' && t.isObjectExpression(value)) {
astPath.traverse({
ObjectProperty (astPath) {
const node = astPath.node as any
const value = node.value.value
if (node.key.name === 'iconPath' ||
node.key.value === 'iconPath' ||
node.key.name === 'selectedIconPath' ||
node.key.value === 'selectedIconPath'
) {
if (typeof value !== 'string') return
const iconName = _.camelCase(value)
if (iconPaths.indexOf(value) === -1) {
iconPaths.push(value)
}
astPath.insertAfter(t.objectProperty(
t.identifier(node.key.name || node.key.value),
t.identifier(iconName)
))
astPath.remove()
}
}
})
}
}
})
}
astPath.node.static = 'true'
}
示例6: declarationPropertyHandlers
export function declarationPropertyHandlers(
declaration: ScannedPolymerElement,
document: JavaScriptDocument): 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 = getBehaviorAssignmentOrWarning(element, document);
if (result.kind === 'warning') {
declaration.warnings.push(result.warning);
} else {
declaration.behaviorAssignments.push(result.assignment);
}
}
},
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 node.properties) {
if (babel.isSpreadProperty(p)) {
continue;
}
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});
}
}
};
}