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
45 changes: 45 additions & 0 deletions packages/core/schematics/test/standalone_migration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,51 @@ describe('standalone migration', () => {
`));
});

it('should use the generated alias if a conflicting symbol already exists', async () => {
writeFile('module.ts', `
import {NgModule} from '@angular/core';
import {MyComp} from './comp';
import {MyButton} from './button';

@NgModule({declarations: [MyComp, MyButton], exports: [MyComp]})
export class Mod {}
`);

writeFile('comp.ts', `
import {Component} from '@angular/core';
import {MyButton} from '@external/button';

MyButton.sayHello();

@Component({selector: 'my-comp', template: '<my-button>Hello</my-button>'})
export class MyComp {}
`);

writeFile('button.ts', `
import {Component} from '@angular/core';

@Component({selector: 'my-button', template: '<ng-content></ng-content>'})
export class MyButton {}
`);

await runMigration('convert-to-standalone');

expect(stripWhitespace(tree.readContent('comp.ts'))).toBe(stripWhitespace(`
import {Component} from '@angular/core';
import {MyButton} from '@external/button';
import {MyButton as MyButton_1} from './button';

MyButton.sayHello();

@Component({
selector: 'my-comp', template: '<my-button>Hello</my-button>',
standalone: true,
imports: [MyButton_1]
})
export class MyComp {}
`));
});

it('should remove a module that only has imports and exports', async () => {
writeFile('app.module.ts', `
import {NgModule} from '@angular/core';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/schematics/utils/import_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class ImportManager {
if (symbolName) {
const {propertyName, name} = this._getImportParts(sourceFile, symbolName, alias);
const importMap = this.newImports.get(sourceFile)!.namedImports;
identifier = propertyName || name;
identifier = name;

if (!importMap.has(moduleName)) {
importMap.set(moduleName, []);
Expand Down