private boolean canDecomposeSimply ( Node classNode ) { Node enclosingStatement = checkNotNull ( NodeUtil . getEnclosingStatement ( classNode ) , classNode ) ; if ( enclosingStatement == classNode ) { // `class Foo extends some_expression {}` // can always be converted to // ``` // const tmpvar = some_expression; // class Foo extends tmpvar {} // ``` return true ; } else { Node classNodeParent = classNode . getParent ( ) ; if ( NodeUtil . isNameDeclaration ( enclosingStatement ) && classNodeParent . isName ( ) && classNodeParent . isFirstChildOf ( enclosingStatement ) ) { // `const Foo = class extends some_expression {}, maybe_other_var;` // can always be converted to // ``` // const tmpvar = some_expression; // const Foo = class extends tmpvar {}, maybe_other_var; // ``` return true ; } else if ( enclosingStatement . isExprResult ( ) && classNodeParent . isOnlyChildOf ( enclosingStatement ) && classNodeParent . isAssign ( ) && classNode . isSecondChildOf ( classNodeParent ) ) { // `lhs = class extends some_expression {};` Node lhsNode = classNodeParent . getFirstChild ( ) ; // We can extract a temporary variable for some_expression as long as lhs expression // has no side effects. return ! NodeUtil . mayHaveSideEffects ( lhsNode , compiler ) ; } else { return false ; } } }
Find common cases where we can safely decompose class extends expressions which are not qualified names . Enables transpilation of complex extends expressions .