microsoft / microsoft/TypeScript

tsc does not use amd-module name when emitting dynamic imports

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

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

Awaiting More Feedback Domain: JS Emit Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

TypeScript Version: 3.3.0-dev.20190118

Search Terms: amd-module, optional, dynamic, directive

Code

Scripts/foo.ts

///<amd-module name="customNameFoo" />

export function hello() {
    console.log('hello world');
}

Scripts/bar.ts

///<amd-module name="customNameBar" />

async function myFunction(): Promise<void> {
	//Dynamically import foo
        var fooModule = await import('./foo');

	fooModule.hello();
}

tsconfig.json

{
	"compileOnSave": true,
	"compilerOptions": {
		"target": "es5",
		"outDir": "GeneratedScripts",
		"module": "amd",
		"lib": [
			"es2015.promise",
			"dom",
			"es5",
			"scripthost"
		]
	},
	"include": [
		"Scripts/**/*"
	],
	"exclude": [
		"GeneratedScripts"
	]
}

would expect that the call to require would use the amd-module name for foo ("customNameFoo") and not "./foo". (If we non-dynamically imported foo, then the generated 'define' would refer to foo by it's amd-module name)
GeneratedScripts/bar.js

//...

return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, new Promise(function (resolve_1, reject_1) { require(['./foo'], resolve_1, reject_1); })];
                    case 1:
                        fooModule = _a.sent();
                        fooModule.hello();
                        return [2 /*return*/];
                }
            });

Expected behavior: The generated amd code for a dynamic import should use the name of the module specified in the amd-module directive

Actual behavior: The generated code for the dynamic import uses relative path to the module

Related Issues:
https://github.com/Microsoft/TypeScript/pull/1158
https://github.com/Microsoft/TypeScript/issues/28760

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.

Hướng nghiên cứu

Tái hiện vấn đề với Scripts/foo.ts, Scripts/bar.ts và tsconfig.json, sau đó kiểm tra điểm vào của compiler cho việc phát sinh dynamic-import AMD. So sánh GeneratedScripts/bar.js với đầu ra mong đợi; hoàn tất khi lệnh gọi require được tạo sử dụng tên module AMD tùy chỉnh customNameFoo của foo thay vì './foo'.

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

Đánh giá

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

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.