ng generate module produce wrong code for specific code pattern

Đang mở
#15,923 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
angular, typescript
Lĩnh vực
cli, tooling

Hướng nghiên cứu

Tái hiện vấn đề bằng các lệnh ng new, ng g c và ng g module được liệt kê, sau đó kiểm tra src/app/app-routing.module.ts trước và sau khi tạo. Hoàn tất khi route được tải lazy được chèn vào mà không có dấu phẩy không hợp lệ hoặc dấu phân cách bị mất, đồng thời route1 hiện có vẫn hợp lệ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
16 giờ 35 phút
Pull request đã merge (30 ngày)
176

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angular-cli

Tất cả issue của angular/angular-cli

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.