Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7715955

Browse files
authored
Fix helpers emit for .cjs files in ESM module mode (microsoft#61814)
1 parentfa2a0fc commit7715955

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

‎src/compiler/factory/utilities.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,10 @@ export function createExternalHelpersImportDeclarationIfNeeded(nodeFactory: Node
700700
constimpliedModuleKind=getImpliedNodeFormatForEmitWorker(sourceFile,compilerOptions);
701701
consthelpers=getImportedHelpers(sourceFile);
702702
if(
703-
(moduleKind>=ModuleKind.ES2015&&moduleKind<=ModuleKind.ESNext)||
704-
impliedModuleKind===ModuleKind.ESNext||
705-
impliedModuleKind===undefined&&moduleKind===ModuleKind.Preserve
703+
impliedModuleKind!==ModuleKind.CommonJS&&
704+
((moduleKind>=ModuleKind.ES2015&&moduleKind<=ModuleKind.ESNext)||
705+
impliedModuleKind===ModuleKind.ESNext||
706+
impliedModuleKind===undefined&&moduleKind===ModuleKind.Preserve)
706707
){
707708
// When we emit as an ES module, generate an `import` declaration that uses named imports for helpers.
708709
// If we cannot determine the implied module kind under `module: preserve` we assume ESM.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
notmodule.cts(1,23): error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
2+
3+
4+
==== notmodule.cts (1 errors) ====
5+
export async function foo() {
6+
~~~
7+
!!! error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
8+
await 0;
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/compiler/ctsFileInEsnextHelpers.ts] ////
2+
3+
//// [notmodule.cts]
4+
exportasyncfunctionfoo(){
5+
await0;
6+
}
7+
8+
//// [notmodule.cjs]
9+
"use strict";
10+
Object.defineProperty(exports,"__esModule",{value:true});
11+
exports.foo=foo;
12+
vartslib_1=require("tslib");
13+
functionfoo(){
14+
returntslib_1.__awaiter(this,void0,void0,function(){
15+
returntslib_1.__generator(this,function(_a){
16+
switch(_a.label){
17+
case0:return[4/*yield*/,0];
18+
case1:
19+
_a.sent();
20+
return[2/*return*/];
21+
}
22+
});
23+
});
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@module: es2015
2+
//@importHelpers: true
3+
//@noTypesAndSymbols: true
4+
5+
//@Filename: notmodule.cts
6+
exportasyncfunctionfoo(){
7+
await0;
8+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp