Skip to content

Instantly share code, notes, and snippets.

@roytouw7
Created August 20, 2020 12:53
Show Gist options
  • Save roytouw7/b0ee0cba7bb3e672c5453ff9503d9b45 to your computer and use it in GitHub Desktop.
Save roytouw7/b0ee0cba7bb3e672c5453ff9503d9b45 to your computer and use it in GitHub Desktop.
export const isObjectOrSubjectConstructor: Classifier = classifierTemplate((node) => {
if (ts.isNewExpression(node) && ts.isIdentifier(node.expression)) {
if ([...rxjsObjectKinds, ...rxjsSubjectKinds].some(operator => operator === node.expression.getText())) {
return true;
}
}
return false;
});
// Classify node by set of classifiers, if classified return true.
export const classify = (node: Touched<ts.Node>): RxJSPart => {
const classifiers: [Classifier, RxJSPart][] = [
[isRxJSCreationOperator, RxJSPart.observable],
[isRxJSJoinCreationOperator, RxJSPart.observable],
[isObjectOrSubjectConstructor, RxJSPart.observable],
[isSubscribe, RxJSPart.subscriber],
[isPipeOperator, RxJSPart.pipeOperator]
];
const classification = classifiers
.filter(tuple => tuple[0](node))
.map(tuple => tuple[1])
.pop();
return classification ? classification : RxJSPart.unclassified;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment