Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.visitMethod(node, symbol.getName());
} else if (ts.isFunctionTypeNode(node)) {
log("- FunctionTypeNode.. ?");
} else if (ts.isFunctionExpression(node)) {
const sym = this.checker.getSymbolAtLocation(node.name);
const name = sym ? sym.getName() : "";
log("- FunctionExpression", name);
} else if (ts.isInterfaceDeclaration(node)) {
this.visitClass(node);
} else if (ts.isObjectLiteralExpression(node)) {
// TODO Ignoring for now.
log("- ObjectLiteralExpression");
} else if (ts.isTypeLiteralNode(node)) {
// TODO Ignoring for now.
log("- TypeLiteral");
} else if (ts.isPropertyAccessExpression(node)) {
log("- PropertyAccessExpression");
//const symbol = this.checker.getSymbolAtLocation(node.name);
//this.visitMethod(node, symbol.getName());
} else if (ts.isEnumDeclaration(node)) {
const sym = this.checker.getSymbolAtLocation(node.name);
const name = sym ? sym.getName() : "";
log("- EnumDeclaration", name);
const docstr = this.getFlatDocstr(sym);
this.output.push({
name,
kind: "enum",
docstr
});
for (let m of node.members) {
const sym = this.checker.getSymbolAtLocation(m.name);
const memberName = sym ? sym.getName() : "";
function classElementName(m: ts.ClassElement | ts.TypeElement): string {
if (m.name) {
if (ts.isIdentifier(m.name)) {
return ts.idText(m.name);
}
if (ts.isComputedPropertyName(m.name)) {
const e = m.name.expression;
if (ts.isPropertyAccessExpression(e)) {
// This is for [Symbol.iterator]() { }
assert(ts.isIdentifier(e.name));
return `[Symbol.${e.name.text}]`;
}
}
}
return "";
}
function getDecoratorOrigin(
decorator: ts.Decorator,
typeChecker: ts.TypeChecker,
): DecoratorOrigin | null {
if (!ts.isCallExpression(decorator.expression)) {
return null;
}
let identifier: ts.Node;
let name = '';
if (ts.isPropertyAccessExpression(decorator.expression.expression)) {
identifier = decorator.expression.expression.expression;
name = decorator.expression.expression.name.text;
} else if (ts.isIdentifier(decorator.expression.expression)) {
identifier = decorator.expression.expression;
} else {
return null;
}
// NOTE: resolver.getReferencedImportDeclaration would work as well but is internal
const symbol = typeChecker.getSymbolAtLocation(identifier);
if (symbol && symbol.declarations && symbol.declarations.length > 0) {
const declaration = symbol.declarations[0];
let module: string;
if (ts.isImportSpecifier(declaration)) {
name = (declaration.propertyName || declaration.name).text;
export function isHookCall(
{ expression }: CallExpression,
ruleOptions: RuleOptions,
) {
if (isIdentifier(expression) && isHookIdentifier(expression)) {
return true;
} else if (
isPropertyAccessExpression(expression) &&
isHookIdentifier(expression.name)
) {
if (ruleOptions[detectHooksFromNonReactNamespaceOptionName]) {
return true;
}
/**
* The expression from which the property is accessed.
*
* @example for `React.useState`, this would be the `React` identifier
*/
const sourceExpression = expression.expression;
return isReactIdentifier(sourceExpression);
}
public readonly substituteNode = (_hint: ts.EmitHint, node: ts.Node) => {
if (ts.isIdentifier(node)) {
const parent = tsUtils.node.getParent(node) as ts.Node | undefined;
if (parent !== undefined && ts.isPropertyAccessExpression(parent) && tsUtils.node.getNameNode(parent) === node) {
return node;
}
return this.getIdentifierForIdentifier(node);
}
if (ts.isImportDeclaration(node)) {
if (this.isExternalFileImportExport(node)) {
return this.getCombinedImport(node);
}
const importFile = tsUtils.importExport.getModuleSpecifierSourceFile(this.context.typeChecker, node);
const namespaceIdentifier = tsUtils.importDeclaration.getNamespaceImportIdentifier(node);
if (importFile !== undefined && namespaceIdentifier !== undefined) {
const exportedSymbols = tsUtils.file.getExportedSymbols(this.context.typeChecker, importFile);
function isPropertyAccess(node: ts.Node, parent: string, child: string): boolean {
if (!ts.isPropertyAccessExpression(node)) return false;
return ts.isIdentifier(node.expression) && node.expression.escapedText === parent &&
node.name.escapedText === child;
}
function visitor(node: ts.Node): ts.Node {
if (ts.isPropertyAccessExpression(node)
&& ts.isIdentifier(node.expression)
&& controllerVars.indexOf(node.expression.text) >= 0) {
node = node.name;
}
if (ts.isElementAccessExpression(node)
&& ts.isIdentifier(node.expression)
&& controllerVars.indexOf(node.expression.text) >= 0
&& node.argumentExpression
&& ts.isStringLiteral(node.argumentExpression)) {
node = ts.createIdentifier(node.argumentExpression.text);
}
return ts.visitEachChild(node, visitor, context);
}
return ts.visitNode(root, visitor);
shouldIgnoreNode(node) {
if (this.shouldIgnoreCurrentFile(node)) {
return true;
}
if (!ts.isPropertyAccessExpression(node.expression)) {
return true;
}
const prop = node.expression;
if (methodNames.indexOf(prop.name.text) < 0) {
return true;
}
return false;
}
}
private parentUsesNode(parent?: ts.Node) {
return (
parent &&
(ts.isPropertyAccessExpression(parent) ||
ts.isPropertyDeclaration(parent) ||
ts.isReturnStatement(parent) ||
ts.isCallOrNewExpression(parent) ||
ts.isSpreadElement(parent) ||
ts.isJsxExpression(parent) ||
ts.isConditionalExpression(parent) ||
ts.isArrayLiteralExpression(parent) ||
ts.isBinaryExpression(parent) ||
ts.isArrowFunction(parent))
);
}
}
effects.forEach(effect => {
if (
ts.isCallExpression(effect.initializer) &&
ts.isPropertyAccessExpression(effect.initializer.expression) &&
effect.initializer.expression.name.text === 'pipe' &&
ts.isCallExpression(effect.initializer.expression.expression) &&
ts.isPropertyAccessExpression(
effect.initializer.expression.expression.expression
) &&
effect.initializer.expression.expression.expression.name.text === 'ofType'
) {
const originalText = effect.initializer.getText(sourceFile);
const ofTypeExpression = ts.createCall(
ts.createIdentifier('ofType'),
effect.initializer.expression.expression.typeArguments,
effect.initializer.expression.expression.arguments
);
const node = ts.createCall(
ts.createPropertyAccess(
effect.initializer.expression.expression.expression.expression,
'pipe'