@@ -1074,10 +1074,24 @@ export class ASTNodeFactory {
1074
1074
return node ;
1075
1075
}
1076
1076
1077
+ /**
1078
+ * Return a copy of the given `node`, along with all its children.
1079
+ * Optionally pass in a `remapping` from ids in the old context, to ids of
1080
+ * the old context of any sibling nodes that may be referred in node (e.g.
1081
+ * by `referencedDeclaration` fields).
1082
+ */
1077
1083
copy < T extends ASTNode > ( node : T , remappings ?: IDMap ) : T {
1078
1084
return this . copyWithMapping ( node , remappings ) [ 0 ] ;
1079
1085
}
1080
1086
1087
+ /**
1088
+ * Return a tuple containing a copy of the given `node` and all its
1089
+ * children, and a mapping of ids between the old nodes and the new nodes.
1090
+ *
1091
+ * Optionally pass in a `remapping` from ids in the old context, to ids of
1092
+ * the old context of any sibling nodes that may be referred in node (e.g.
1093
+ * by `referencedDeclaration` fields).
1094
+ */
1081
1095
copyWithMapping < T extends ASTNode > ( node : T , remappings ?: IDMap ) : [ T , IDMap ] {
1082
1096
const cache = new Map < number , number > ( remappings ? remappings . entries ( ) : [ ] ) ;
1083
1097
const clone = this . copyHelper ( node , cache ) ;
@@ -1166,6 +1180,21 @@ export class ASTNodeFactory {
1166
1180
return clone ;
1167
1181
}
1168
1182
1183
+ /**
1184
+ * Return the list of arguments (after `id` and `src`) that need to be
1185
+ * passed to `node`'s constructor to recreate `node`.
1186
+ */
1187
+ getNodeConstructorArgs < T extends ASTNode > ( node : T ) : any [ ] {
1188
+ const ctor = node . constructor as ASTNodeConstructor < T > ;
1189
+ const extractor = argExtractionMapping . get ( ctor ) ;
1190
+
1191
+ if ( extractor === undefined ) {
1192
+ throw new Error ( `Unable to find extractor for node constructor ${ ctor . name } ` ) ;
1193
+ }
1194
+
1195
+ return extractor ( node ) ;
1196
+ }
1197
+
1169
1198
private copyValue ( value : any , cache : IDMap ) : any {
1170
1199
if ( value === null || value === undefined ) {
1171
1200
return value ;
0 commit comments