// REVIEW: I would prefer to not expose CloneAsRoot and make the functionality // internal to CaaS layer, to ensure that for a given SyntaxTree there can not // be multiple trees claiming to be its children. // // However, as long as we provide GetRoot extensibility point on SyntaxTree // the guarantee above cannot be implemented and we have to provide some way for // creating root nodes. // // Therefore I place CloneAsRoot API on SyntaxTree and make it protected to // at least limit its visibility to SyntaxTree extenders. /// <summary> /// Produces a clone of a <see cref="LuaSyntaxNode"/> which will have current syntax tree as its parent. /// /// Caller must guarantee that if the same instance of <see cref="LuaSyntaxNode"/> makes multiple calls /// to this function, only one result is observable. /// </summary> /// <typeparam name="T">Type of the syntax node.</typeparam> /// <param name="node">The original syntax node.</param> /// <returns>A clone of the original syntax node that has current <see cref="LuaSyntaxTree"/> as its parent.</returns> protected T CloneNodeAsRoot <T>(T node) where T : LuaSyntaxNode => SyntaxNode.CloneNodeAsRoot(node, this);