Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem is that updateNode does not use getFullStart and getFullWidth. The printer seems to print the "full node". If that's not causing other problems with the way the migration is built, then that might be worth doing instead

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That ended up breaking some other tests because we were deleting too much text. I think it's okay to recreate the node, given that we aren't reusing the AST after we print it anyway and we aren't guaranteeing for the formatting to stay the same.

@devversion devversion Feb 6, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I approved because I assumed the migration relies on full start not being used, but in general that's a good thing to note (I didn't remember of this caveat)

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. */
Expand Down
28 changes: 28 additions & 0 deletions packages/core/schematics/test/standalone_migration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down