ng generate module produce wrong code for specific code pattern

Aperta
#15,923 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
angular, typescript
Ambito
cli, tooling

Direzione di ricerca

Riproduci il problema con i comandi ng new, ng g c e ng g module elencati, quindi ispeziona src/app/app-routing.module.ts prima e dopo la generazione. L'attività è completata quando la route caricata lazy viene inserita senza virgole non valide o separatori rimossi, mentre la route1 esistente rimane valida.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: @schematics/angular freq1: low severity3: broken type: bug/fix

🐞 Bug report

Command (mark with an x)
- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [x] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc
Is this a regression?

No.

Description

The ng generate module produce wrong code.

🔬 Minimal Reproduction

ng new demo1 --routing --style css
cd demo1
ng g c test1

Add route config in src/app/app-routing.module.ts just like below:

const route1 = { path: 'test1', component: Test1Component };
const routes: Routes = [
  route1
];

Then I creating an lazy-loaded module named test.

ng g module test --route test --module app

Then the route config will turn into this. And this is wrong.

const route1 = { path: 'test1', component: Test1Component };
const routes: Routes = [,
  { path: 'test', loadChildren: () => import('./test/test.module').then(m => m.TestModule) }
  route1
];

🔥 Exception or Error


ERROR in Cannot read property 'loadChildren' of undefined

🌍 Your Environment


Angular CLI: 8.3.13
Node: 10.16.3
OS: win32 x64
Angular: 8.2.11
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.13
@angular-devkit/build-angular     0.803.13
@angular-devkit/build-optimizer   0.803.13
@angular-devkit/build-webpack     0.803.13
@angular-devkit/core              8.3.13
@angular-devkit/schematics        8.3.13
@angular/cli                      8.3.13
@ngtools/webpack                  8.3.13
@schematics/angular               8.3.13
@schematics/update                0.803.13
rxjs                              6.4.0
typescript                        3.5.3
webpack                           4.39.2

Anything else relevant?

Lingua principale
TypeScript
Stelle
27k
Fork
11.8k
Merge medio
16h 35m
PR unite (30g)
176

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di angular/angular-cli

Tutte le issue di angular/angular-cli

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.