-
Notifications
You must be signed in to change notification settings - Fork 231
Closed
Closed
Copy link
Description
Describe the bug
Version: 25.0.0
It's a very specific scenario, but I'm reporting just in case there's something underlying that's more concerning. If you enable useTrailingCommas, adding a method to an object literal with a template string of the form ${p}/* will add an extra comma to the template string ${p},/*.
I might have time to try to dig deeper but figured I'd report it in case anything obvious sprung to mind for the root cause. (since it seems oddly specific for repro)
To Reproduce
import { Node, Project, SyntaxKind } from 'ts-morph';
const project = new Project({
manipulationSettings: {
useTrailingCommas: true,
},
});
const sourceFile = project.createSourceFile('example.ts', 'func({});');
const callExpressions = sourceFile.getDescendantsOfKind(
SyntaxKind.CallExpression,
);
const objectLiteral = callExpressions[0].getArguments()[0];
if (!Node.isObjectLiteralExpression(objectLiteral)) {
throw new Error('Object literal expected');
}
objectLiteral.addMethod({
name: 'logTemplate',
statements: ['`${p}/*`;'],
parameters: [{ name: 'p', type: 'string' }],
});
console.info(sourceFile.getFullText());Expected behavior
func({
logTemplate(p: string) {
`${p}/*`;
}
});
Actual behavior
func({
logTemplate(p: string) {
`${p},/*`;
}
});
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels