Calling `replaceWithText` on private static property with no spaces to be non-private leads to error
See original GitHub issueDescribe the bug
Version: 15.1.0
I have a class with a private static property that I would like to make public by renaming it. The weird thing is, that the issue only happens if the file is in minified form.
To Reproduce
import { Project, SyntaxKind } from "ts-morph";
// This works
const content1 = `
class Test{
static #t = 23;
}`;
// This fails
const content2 = "class Test{static#t=23;}";
const project = new Project();
const file = project.createSourceFile("test.ts", content2);
const classNode = file.getFirstChildByKindOrThrow(SyntaxKind.ClassDeclaration);
const property = classNode.getFirstChildByKindOrThrow(SyntaxKind.PropertyDeclaration);
const privateIdentifier = property.getFirstChildByKindOrThrow(SyntaxKind.PrivateIdentifier);
// remove # from the beginning of the name
const publicName = privateIdentifier.getText().substring(1);
privateIdentifier.replaceWithText(publicName);
console.log(file.getText());
If I use the minified input (content2), then the following error is thrown:
Stack: Error: Error replacing tree! Perhaps a syntax error was inserted (Current: SyntaxList -- New: Identifier).
Expected behavior
It should work with the minified version as well.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Private property changing it's value, without it's setter being ...
The problem is the fact that this variable is static and hence when one user logs in and the value is set, another...
Read more >Strict mode static property is undefined (no compiler error)
For the type check on the getProps() side, this is somewhat a working-as-intended: the variable is not declared optional, so they "cannot" be ......
Read more >Static properties and methods - The Modern JavaScript Tutorial
staticMethod () call is the class constructor User itself (the “object before dot” rule). Usually, static methods are used to implement functions ...
Read more >java.util Class Properties
A property list that contains default values for any keys not found in this property list. private static char[], hexDigit. A table of...
Read more >MapBasic v2021 User Guide - Precisely Help
Trademarked names are used editorially, to the benefit of the trademark owner, with no intent to infringe on the trademark. 4. MapBasic 2021....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, I started working on it, but it’s a decent amount of additional code. I’m going to close this one as “wont do” and recommend adding some conditional logic like the following to tell if a space should be added:
This is clever, thank you!