MCPcopy Index your code
hub / github.com/TypeStrong/ts-node / createSwcOptions

Function createSwcOptions

src/transpilers/swc.ts:126–270  ·  view source on GitHub ↗
(
  compilerOptions: ts.CompilerOptions,
  nodeModuleEmitKind: NodeModuleEmitKind | undefined,
  swcInstance: SwcInstance,
  swcDepName: string
)

Source from the content-addressed store, hash-verified

124 * @internal exported for testing
125 */
126export function createSwcOptions(
127 compilerOptions: ts.CompilerOptions,
128 nodeModuleEmitKind: NodeModuleEmitKind | undefined,
129 swcInstance: SwcInstance,
130 swcDepName: string
131) {
132 const {
133 esModuleInterop,
134 sourceMap,
135 importHelpers,
136 experimentalDecorators,
137 emitDecoratorMetadata,
138 target,
139 module,
140 jsx,
141 jsxFactory,
142 jsxFragmentFactory,
143 strict,
144 alwaysStrict,
145 noImplicitUseStrict,
146 jsxImportSource,
147 } = compilerOptions;
148
149 let swcTarget = targetMapping.get(target!) ?? 'es3';
150 // Downgrade to lower target if swc does not support the selected target.
151 // Perhaps project has an older version of swc.
152 // TODO cache the results of this; slightly faster
153 let swcTargetIndex = swcTargets.indexOf(swcTarget);
154 for (; swcTargetIndex >= 0; swcTargetIndex--) {
155 try {
156 swcInstance.transformSync('', {
157 jsc: { target: swcTargets[swcTargetIndex] as swcWasm.JscTarget },
158 });
159 break;
160 } catch (e) {}
161 }
162 swcTarget = swcTargets[swcTargetIndex];
163 const keepClassNames = target! >= /* ts.ScriptTarget.ES2016 */ 3;
164 const isNodeModuleKind = module === ModuleKind.Node16 || module === ModuleKind.NodeNext;
165 // swc only supports these 4x module options [MUST_UPDATE_FOR_NEW_MODULEKIND]
166 const moduleType =
167 module === ModuleKind.CommonJS
168 ? 'commonjs'
169 : module === ModuleKind.AMD
170 ? 'amd'
171 : module === ModuleKind.UMD
172 ? 'umd'
173 : isNodeModuleKind && nodeModuleEmitKind === 'nodecjs'
174 ? 'commonjs'
175 : isNodeModuleKind && nodeModuleEmitKind === 'nodeesm'
176 ? 'es6'
177 : 'es6';
178 // In swc:
179 // strictMode means `"use strict"` is *always* emitted for non-ES module, *never* for ES module where it is assumed it can be omitted.
180 // (this assumption is invalid, but that's the way swc behaves)
181 // tsc is a bit more complex:
182 // alwaysStrict will force emitting it always unless `import`/`export` syntax is emitted which implies it per the JS spec.
183 // if not alwaysStrict, will emit implicitly whenever module target is non-ES *and* transformed module syntax is emitted.

Callers 2

createFunction · 0.85

Calls 3

createVariantFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…