mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
fix(migrations): duplicated comments on migrated classes (#48966)
Fixes that the migration was duplicating the comments on class nodes that were being converted to standalone. Fixes #48943. PR Close #48966
This commit is contained in:
parent
2de6dae16d
commit
759db12e0b
2 changed files with 33 additions and 5 deletions
|
|
@ -286,11 +286,11 @@ function addPropertyToAngularDecorator(
|
|||
return node;
|
||||
}
|
||||
|
||||
return ts.factory.updateDecorator(
|
||||
node,
|
||||
ts.factory.createCallExpression(node.expression.expression, node.expression.typeArguments, [
|
||||
ts.factory.createObjectLiteralExpression(literalProperties, literalProperties.length > 1)
|
||||
]));
|
||||
// Use `createDecorator` instead of `updateDecorator`, because
|
||||
// the latter ends up duplicating the node's leading comment.
|
||||
return ts.factory.createDecorator(ts.factory.createCallExpression(
|
||||
node.expression.expression, node.expression.typeArguments,
|
||||
[ts.factory.createObjectLiteralExpression(literalProperties, literalProperties.length > 1)]));
|
||||
}
|
||||
|
||||
/** Checks if a node is a `PropertyAssignment` with a name. */
|
||||
|
|
|
|||
|
|
@ -1294,6 +1294,34 @@ describe('standalone migration', () => {
|
|||
`));
|
||||
});
|
||||
|
||||
it('should not duplicate doc strings', async () => {
|
||||
writeFile('module.ts', `
|
||||
import {NgModule, Directive} from '@angular/core';
|
||||
|
||||
/** Directive used for testing. */
|
||||
@Directive({selector: '[dir]'})
|
||||
export class MyDir {}
|
||||
|
||||
/** Module used for testing. */
|
||||
@NgModule({declarations: [MyDir]})
|
||||
export class Mod {}
|
||||
`);
|
||||
|
||||
await runMigration('convert-to-standalone');
|
||||
|
||||
expect(stripWhitespace(tree.readContent('module.ts'))).toBe(stripWhitespace(`
|
||||
import {NgModule, Directive} from '@angular/core';
|
||||
|
||||
/** Directive used for testing. */
|
||||
@Directive({selector: '[dir]', standalone: true})
|
||||
export class MyDir {}
|
||||
|
||||
/** Module used for testing. */
|
||||
@NgModule({imports: [MyDir]})
|
||||
export class Mod {}
|
||||
`));
|
||||
});
|
||||
|
||||
it('should remove a module that only has imports and exports', async () => {
|
||||
writeFile('app.module.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
|
|
|
|||
Loading…
Reference in a new issue