Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getDeclarationName(node) {
var declaration = node.declarations[0];
if (jscs.Identifier.check(declaration.id)) {
return declaration.id.name;
}
// Order by the first property name in the object pattern.
if (jscs.ObjectPattern.check(declaration.id)) {
return declaration.id.properties[0].key.name;
}
// Order by the first element name in the array pattern.
if (jscs.ArrayPattern.check(declaration.id)) {
return declaration.id.elements[0].name;
}
return '';
}
this.find(j.ClassDeclaration).forEach(path => {
const superClass = path.node.superClass;
if (superClass) {
if (
// TODO: 处理 Component 和 React.Component 的来源信赖问题
// class A extends Component {}
(j.Identifier.check(superClass) && superClass.name === 'Component') ||
// class A extends React.Component {}
(j.MemberExpression.check(superClass) && isReactComponent(superClass))
) {
pathes.push(path);
}
}
});
element => jscs.Identifier.check(element)
);
function isDvaInstance(identifierName, path) {
const scope = path.scope.lookup(identifierName);
if (scope) {
const declaratorPath = scope.getBindings()[identifierName][0].parent;
const declaratorNode = declaratorPath.value;
if (j.VariableDeclarator.check(declaratorNode)) {
const { init } = declaratorNode;
if (j.CallExpression.check(init) && j.Identifier.check(init.callee)) {
return getImportRequirePath(init.callee.name, path) === 'dva';
}
}
}
}
export default function getExportedObjectKeys({fileContent}) {
return j(fileContent)
.find(j.ExportDefaultDeclaration)
.find(j.Identifier)
.nodes()
.map(prop => prop.name)
}
function isValidRequireDeclaration(node) {
if (!hasOneRequireDeclaration(node)) {
return false;
}
var declaration = node.declarations[0];
if (jscs.Identifier.check(declaration.id)) {
return true;
}
if (jscs.ObjectPattern.check(declaration.id)) {
return declaration.id.properties.every(
prop => prop.shorthand && jscs.Identifier.check(prop.key)
);
}
if (jscs.ArrayPattern.check(declaration.id)) {
return declaration.id.elements.every(
element => jscs.Identifier.check(element)
);
}
return false;
}
findIdentifier(name) {
const result = this.find(j.Identifier);
if(name) {
return result.filter(i => i.value.name === name);
}
return result;
},
if (typeof a.key.name === 'number' && typeof b.key.name === 'number') {
return b.key.name - a.key.name;
}
return a.key.name.localeCompare(b.key.name);
});
};
const jsSorted = j(file.source)
.find(j.ObjectExpression)
.forEach(naturalSortObject)
.toSource();
return j(jsSorted)
.find(jscodeshift.Identifier, {name: 'Vue'})
.filter((path) => path.parentPath.value.type === 'NewExpression')
.map((path) => {
if (!path.parentPath.value.arguments[0] || !path.parentPath.value.arguments[0].properties) {
return path;
}
path.parentPath.value.arguments[0].properties = path.parentPath.value.arguments[0].properties.sort((a, b) => {
if (a.type.match(/^Spread/)) {
return -1;
}
if (b.type.match(/^Spread/)) {
return 1;
}
if (!a.key || !b.key) {
function wrap(node){
const token = options().placeholder ? 'process.env.IOPIPE_TOKEN' : `\'${options().token || 'DEFAULT_TOKEN'}\'`;
const str = `require('iopipe')({clientId: ${token}, installMethod: 'plugin-sls'})(REPLACE)`;
return j(str)
.find(j.Identifier, {
name: 'REPLACE'
})
.replaceWith(node.right)
.toSource({quote: options().quote});
}
export function getPropertyName({key, computed}) {
if (computed) { return null; }
return j.Identifier.check(key) ? key.name : key.value;
}