Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const callingMethodParamsInNode = (callee, node: t.BaseNode): t.BaseNode[] => {
let foundParams = [];
if (t.isFunctionDeclaration(node)) {
foundParams = node.params;
} else if (t.isVariableDeclarator(node)) {
if (t.isFunctionExpression(node.init) || t.isArrowFunctionExpression(node.init)) {
foundParams = node.init.params;
} else if (t.isObjectExpression(node.init)) {
let calleName = null;
if (t.isMemberExpression(callee) && t.isIdentifier(callee.property)) {
//call-6
calleName = callee.property.name;
} else if (t.isIdentifier(callee)) {
// attribute-call-1
calleName = callee.name;
}
// else throw 'ERROR: not implemented in callingMethodParams -> ' + callee.type;
calleName &&
node.init.properties.every((prop) => {
if (
t.isObjectProperty(prop) &&
t.isIdentifier(prop.key) &&
prop.key.name === calleName &&
export function findComponentOptions(
body: t.Statement[]
): t.ObjectExpression | undefined {
const exported = body.find(
(n): n is t.ExportDefaultDeclaration => t.isExportDefaultDeclaration(n)
)
if (!exported) return undefined
// TODO: support class style component
const dec = exported.declaration
if (t.isObjectExpression(dec)) {
// Using object literal definition
// export default {
// ...
// }
return dec
} else if (isVueExtend(dec) && t.isObjectExpression(dec.arguments[0])) {
// Using Vue.extend with object literal
// export default Vue.extend({
// ...
// })
return dec.arguments[0] as t.ObjectExpression
}
return undefined
}
const typeTag = jsdoc.getTag(prop.jsdoc, 'type');
if (typeTag) {
prop.type =
typeTag.type ? doctrine.type.stringify(typeTag.type) : undefined;
}
prop.published = true;
let isComputed = false;
const value = property.value;
if (babel.isIdentifier(value)) {
// Polymer supports this simple syntax, where only the attribute
// deserializer is specified.
prop.attributeType = value.name;
} else if (!babel.isObjectExpression(value)) {
continue;
} else {
/**
* Parse the expression inside a property object block. e.g.
* property: {
* key: {
* type: String,
* notify: true,
* value: -1,
* readOnly: true,
* reflectToAttribute: true
* }
* }
*/
for (const propertyArg of esutil.getSimpleObjectProperties(value)) {
public mutate(node: types.Node): Array<[types.Node, types.Node | { raw: string }]> {
return types.isObjectExpression(node) && node.properties.length > 0
? [[node, { raw: '{}' }]] // raw string replacement
: [];
}
}
throw new Error('Invalid value is included.')
}
return value
}
if (isNullLiteral(node)) {
return null
}
if (isArrayExpression(node)) {
const { elements } = node
return elements.map(node => converter(node))
}
if (isObjectExpression(node)) {
if (!isObjectExpressionWithOnlyObjectProperties(node)) {
throw new Error('Invalid syntax is included.')
}
const { properties } = node
if (!isConvertibleObjectProperty(properties)) {
throw new Error('Invalid syntax is included.')
}
return properties.reduce((acc, cur) => {
const key = cur.key.name || cur.key.value
// see issues#10
if (typeof key === 'number' && !Number.isSafeInteger(key)) {
throw new Error('Invalid syntax is included.')
}
const value = converter(cur.value)
);
}
}
// target is object destructuring pattern?
else if (T.isObjectPattern(targetNode)) {
if (exprNode) {
let sourceType = nodeTypes.get(sourceRefNode);
if (sourceType) {
markNodeType(exprNode,{ ...sourceType, });
}
else {
markNodeType(exprNode,{ inferred: "object", });
}
}
if (T.isObjectExpression(sourceRefNode)) {
for (let [idx,targetProp,] of targetNode.properties.entries()) {
let targetPropName = targetProp.key.name;
targetProp = targetProp.value;
let targetPropExprNode = null;
// target is identifier with a default = value assignment?
if (T.isAssignmentPattern(targetProp)) {
targetPropExprNode = targetProp;
targetProp = targetProp.left;
}
let sourceProp = sourceRefNode.properties.find(function matchProp(prop){
return (
T.isIdentifier(prop.key,{ name: targetPropName, }) ||
T.isLiteral(prop.key,{ value: targetPropName, })
);
function getMixinsVariableNames(compDef: NodePath): string[] {
const varNames: string[] = []
if (bt.isObjectExpression(compDef.node)) {
const mixinProp = compDef
.get('properties')
.filter((p: NodePath) => p.node.key.name === 'mixins')
const mixinPath = mixinProp.length ? (mixinProp[0] as NodePath) : undefined
if (mixinPath) {
const mixinPropertyValue =
mixinPath.node.value && bt.isArrayExpression(mixinPath.node.value)
? mixinPath.node.value.elements
: []
mixinPropertyValue.forEach((e: bt.Node | null) => {
if (e && bt.isIdentifier(e)) {
varNames.push(e.name)
}
})
}
function normalizeComponentPath(path: NodePath): NodePath {
if (bt.isObjectExpression(path.node)) {
return path
} else if (bt.isCallExpression(path.node)) {
return path.get('arguments', 0)
} else if (bt.isVariableDeclarator(path.node)) {
return path.get('init')
}
return path
}
const valuesObjectNode = [...traverseNodes(ast.program.body)].find(node =>
isObjectExpression(node)
);