@@ -52,6 +52,9 @@ export function create(createOptions: SwcTranspilerOptions): Transpiler {
52
52
module,
53
53
jsxFactory,
54
54
jsxFragmentFactory,
55
+ strict,
56
+ alwaysStrict,
57
+ noImplicitUseStrict,
55
58
} = compilerOptions ;
56
59
const nonTsxOptions = createSwcOptions ( false ) ;
57
60
const tsxOptions = createSwcOptions ( true ) ;
@@ -71,21 +74,39 @@ export function create(createOptions: SwcTranspilerOptions): Transpiler {
71
74
}
72
75
swcTarget = swcTargets [ swcTargetIndex ] ;
73
76
const keepClassNames = target ! >= /* ts.ScriptTarget.ES2016 */ 3 ;
77
+ // swc only supports these 4x module options
74
78
const moduleType =
75
79
module === ModuleKind . CommonJS
76
80
? 'commonjs'
77
81
: module === ModuleKind . AMD
78
82
? 'amd'
79
83
: module === ModuleKind . UMD
80
84
? 'umd'
81
- : undefined ;
85
+ : 'es6' ;
86
+ // In swc:
87
+ // strictMode means `"use strict"` is *always* emitted for non-ES module, *never* for ES module where it is assumed it can be omitted.
88
+ // (this assumption is invalid, but that's the way swc behaves)
89
+ // tsc is a bit more complex:
90
+ // alwaysStrict will force emitting it always unless `import`/`export` syntax is emitted which implies it per the JS spec.
91
+ // if not alwaysStrict, will emit implicitly whenever module target is non-ES *and* transformed module syntax is emitted.
92
+ // For node, best option is to assume that all scripts are modules (commonjs or esm) and thus should get tsc's implicit strict behavior.
93
+
94
+ // Always set strictMode, *unless* alwaysStrict is disabled and noImplicitUseStrict is enabled
95
+ const strictMode =
96
+ // if `alwaysStrict` is disabled, remembering that `strict` defaults `alwaysStrict` to true
97
+ ( alwaysStrict === false || ( alwaysStrict !== true && strict !== true ) ) &&
98
+ // if noImplicitUseStrict is enabled
99
+ noImplicitUseStrict === true
100
+ ? false
101
+ : true ;
82
102
return {
83
103
sourceMaps : sourceMap ,
84
104
// isModule: true,
85
105
module : moduleType
86
106
? ( {
87
107
noInterop : ! esModuleInterop ,
88
108
type : moduleType ,
109
+ strictMode,
89
110
} as swcTypes . ModuleConfig )
90
111
: undefined ,
91
112
swcrc : false ,
0 commit comments