You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to remove all nodes from a source file except a function and it's ascendants.
The original sourceFile looks like this:
`
export class PDVModalitiesCardsSearchModalLookupFieldComponent {
protected get ngModelValue() {
return this.keys.codigoModalidadeCard;
}
protected set ngModelValue(newValue: any) {
this.keys.codigoModalidadeCard = newValue;
}
// #region Fields from xx
/**
* Número de Meses
*/
public get numeroMeses() { return this.result.numeroMeses; }
public set numeroMeses(value: number) {
if (value !== this.result.numeroMeses) {
this.result.numeroMeses = value;
this.numeroMesesChange.emit(this.result.numeroMeses);
}
}
public numeroMesesChange = new EventEmitter();
/**
* Taxa (%)
*/
public get taxa() { return this.result.taxa; }
public set taxa(value: number) {
if (value !== this.result.taxa) {
this.result.taxa = value;
this.taxaChange.emit(this.result.taxa);
}
}
public taxaChange = new EventEmitter();
return this.http.get<models.PDVModalitiesCardsSearchResultVM>(
'api/PDV/PDVModalitiesCardsSearchModal/GetCurrent'
, {
params: this.keys as any
}
);
}
}
`
I'm trying to leave the class only with loadAutoComplete method so the code I'm using is:
`
function composeDeltaTree(relevantNode: Node<ts.Node>) {
const parents = relevantNode.getAncestors();
const sourceFile = relevantNode.getSourceFile();
sourceFile.forEachDescendant((node, traversal) => {
if (node === relevantNode) {
console.debug("node: ", node.getKindName(), (node.compilerNode as ts.NamedDeclaration).name?.getText(), " is our relevantNode, returning it");
traversal.skip();
}
else if (!parents.includes(node) && (node as any).remove) {
console.debug("node: ", node.getKindName(), (node.compilerNode as ts.NamedDeclaration).name?.getText(), " is not in parents and is removable, cleaning it up. leading trivia", node.getLeadingCommentRanges().map(c => c.getKind() + "->" + c.getText()));
(node as any).remove();
traversal.skip();
}
else {
console.debug("node: ", node.getKindName(), (node.compilerNode as ts.NamedDeclaration).name?.getText(), " is in parents or is not removable, returning it");
}
});
return sourceFile;
}
`
Unfortunatelly the output is:
`
export class PDVModalitiesCardsSearchModalLookupFieldComponent {
// #region Fields from PDVModalitiesCardsSearchResultVM
// #endregion Fields from PDVModalitiesCardsSearchResultVM
the call to remove nodes is leaving the // #region trivia, any idea why? Am I missing something? Can you help me please?
Thanks and best regards
POFerro
PS: Thanks and congrats for the lib it's amazing at making ast manipulation easy :)
PS2: Sorry for the bad formating of source code, I can't seem to get it right :D
The text was updated successfully, but these errors were encountered:
Hi :),
I'm trying to remove all nodes from a source file except a function and it's ascendants.
The original sourceFile looks like this:
`
export class PDVModalitiesCardsSearchModalLookupFieldComponent {
protected get ngModelValue() {
return this.keys.codigoModalidadeCard;
}
protected set ngModelValue(newValue: any) {
this.keys.codigoModalidadeCard = newValue;
}
// #region Fields from xx
/**
* Número de Meses
*/
public get numeroMeses() { return this.result.numeroMeses; }
public set numeroMeses(value: number) {
if (value !== this.result.numeroMeses) {
this.result.numeroMeses = value;
this.numeroMesesChange.emit(this.result.numeroMeses);
}
}
public numeroMesesChange = new EventEmitter();
/**
* Taxa (%)
*/
public get taxa() { return this.result.taxa; }
public set taxa(value: number) {
if (value !== this.result.taxa) {
this.result.taxa = value;
this.taxaChange.emit(this.result.taxa);
}
}
public taxaChange = new EventEmitter();
// #endregion Fields from xx
constructor(
announcer: LiveAnnouncer
, private dialog: MatDialog
, private http: HttpClient
, @self() @optional() autocomplete?: MatAutoCompleteTriggerLcfExtension<models.PDVModalitiesCardsSearchResultVM>
, @optional() @self() ngModel?: NgModel
) {
super(announcer, (searchString) => this.loadAutoComplete(searchString), autocomplete, ngModel);
}
private loadAutoComplete(searchString: string) {
return this.http.get<models.PDVModalitiesCardsSearchResultVM[]>(
'api/PDV/PDVModalitiesCardsSearchModal/AutoCompleteSearch'
, { params: { searchString: searchString } }
)
;
}
protected performLoad() {
console.log("[PDVModalitiesCardsSearchModalLookupFieldComponent][load] codigoModalidadeCard: ", this.ngModelValue);
}
}
`
I'm trying to leave the class only with loadAutoComplete method so the code I'm using is:
`
function composeDeltaTree(relevantNode: Node<ts.Node>) {
const parents = relevantNode.getAncestors();
const sourceFile = relevantNode.getSourceFile();
sourceFile.forEachDescendant((node, traversal) => {
if (node === relevantNode) {
console.debug("node: ", node.getKindName(), (node.compilerNode as ts.NamedDeclaration).name?.getText(), " is our relevantNode, returning it");
traversal.skip();
}
else if (!parents.includes(node) && (node as any).remove) {
console.debug("node: ", node.getKindName(), (node.compilerNode as ts.NamedDeclaration).name?.getText(), " is not in parents and is removable, cleaning it up. leading trivia", node.getLeadingCommentRanges().map(c => c.getKind() + "->" + c.getText()));
(node as any).remove();
traversal.skip();
}
else {
console.debug("node: ", node.getKindName(), (node.compilerNode as ts.NamedDeclaration).name?.getText(), " is in parents or is not removable, returning it");
}
});
return sourceFile;
}
`
Unfortunatelly the output is:
`
export class PDVModalitiesCardsSearchModalLookupFieldComponent {
// #region Fields from PDVModalitiesCardsSearchResultVM
// #endregion Fields from PDVModalitiesCardsSearchResultVM
private loadAutoComplete(searchString: string) {
return this.http.get<models.PDVModalitiesCardsSearchResultVM[]>(
'api/PDV/PDVModalitiesCardsSearchModal/AutoCompleteSearch'
, { params: { searchString: searchString } }
)
;
}
}
`
the call to remove nodes is leaving the // #region trivia, any idea why? Am I missing something? Can you help me please?
Thanks and best regards
POFerro
PS: Thanks and congrats for the lib it's amazing at making ast manipulation easy :)
PS2: Sorry for the bad formating of source code, I can't seem to get it right :D
The text was updated successfully, but these errors were encountered: