@vxrn/compiler 1.25.13 → 1.25.16-1788753284749
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cache.cjs +3 -1
- package/dist/cjs/configure.cjs +9 -1
- package/dist/cjs/index.cjs +82 -4
- package/dist/cjs/reactNativeCodegen.cjs +140 -0
- package/dist/cjs/reactNativeViewConfig.cjs +489 -0
- package/dist/cjs/transformBabel.cjs +15 -20
- package/dist/cjs/transformBabel.test.cjs +260 -0
- package/dist/cjs/transformHermesLoops.cjs +317 -0
- package/dist/cjs/transformHermesLoops.test.cjs +220 -0
- package/dist/cjs/transformSWC.cjs +102 -137
- package/dist/cjs/transformSWC.test.cjs +74 -0
- package/dist/cjs/transformWorklets.cjs +121 -0
- package/dist/cjs/transformWorklets.test.cjs +604 -0
- package/dist/cjs/worklets/autoworklet.cjs +265 -0
- package/dist/cjs/worklets/globals.cjs +71 -0
- package/dist/cjs/worklets/hash.cjs +38 -0
- package/dist/cjs/worklets/scope.cjs +370 -0
- package/dist/cjs/worklets/serialize.cjs +101 -0
- package/dist/cjs/worklets/transform.cjs +232 -0
- package/dist/cjs/worklets/types.cjs +18 -0
- package/dist/esm/cache.mjs +4 -2
- package/dist/esm/cache.mjs.map +1 -1
- package/dist/esm/configure.mjs +8 -1
- package/dist/esm/configure.mjs.map +1 -1
- package/dist/esm/index.js +72 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +72 -5
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/reactNativeCodegen.mjs +104 -0
- package/dist/esm/reactNativeCodegen.mjs.map +1 -0
- package/dist/esm/reactNativeViewConfig.mjs +460 -0
- package/dist/esm/reactNativeViewConfig.mjs.map +1 -0
- package/dist/esm/transformBabel.mjs +14 -19
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/dist/esm/transformBabel.test.mjs +261 -1
- package/dist/esm/transformBabel.test.mjs.map +1 -1
- package/dist/esm/transformHermesLoops.mjs +281 -0
- package/dist/esm/transformHermesLoops.mjs.map +1 -0
- package/dist/esm/transformHermesLoops.test.mjs +197 -0
- package/dist/esm/transformHermesLoops.test.mjs.map +1 -0
- package/dist/esm/transformSWC.mjs +89 -138
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/dist/esm/transformSWC.test.mjs +75 -0
- package/dist/esm/transformSWC.test.mjs.map +1 -0
- package/dist/esm/transformWorklets.mjs +81 -0
- package/dist/esm/transformWorklets.mjs.map +1 -0
- package/dist/esm/transformWorklets.test.mjs +581 -0
- package/dist/esm/transformWorklets.test.mjs.map +1 -0
- package/dist/esm/worklets/autoworklet.mjs +234 -0
- package/dist/esm/worklets/autoworklet.mjs.map +1 -0
- package/dist/esm/worklets/globals.mjs +45 -0
- package/dist/esm/worklets/globals.mjs.map +1 -0
- package/dist/esm/worklets/hash.mjs +13 -0
- package/dist/esm/worklets/hash.mjs.map +1 -0
- package/dist/esm/worklets/scope.mjs +345 -0
- package/dist/esm/worklets/scope.mjs.map +1 -0
- package/dist/esm/worklets/serialize.mjs +75 -0
- package/dist/esm/worklets/serialize.mjs.map +1 -0
- package/dist/esm/worklets/transform.mjs +196 -0
- package/dist/esm/worklets/transform.mjs.map +1 -0
- package/dist/esm/worklets/types.mjs +2 -0
- package/dist/esm/worklets/types.mjs.map +1 -0
- package/package.json +10 -6
- package/src/cache.ts +9 -2
- package/src/configure.ts +12 -0
- package/src/index.ts +93 -13
- package/src/reactNativeCodegen.ts +181 -0
- package/src/reactNativeViewConfig.ts +593 -0
- package/src/transformBabel.test.ts +268 -1
- package/src/transformBabel.ts +21 -31
- package/src/transformHermesLoops.test.ts +282 -0
- package/src/transformHermesLoops.ts +433 -0
- package/src/transformSWC.test.ts +88 -0
- package/src/transformSWC.ts +109 -160
- package/src/transformWorklets.test.ts +708 -0
- package/src/transformWorklets.ts +160 -0
- package/src/types.ts +4 -4
- package/src/worklets/autoworklet.ts +391 -0
- package/src/worklets/globals.ts +125 -0
- package/src/worklets/hash.ts +14 -0
- package/src/worklets/scope.ts +401 -0
- package/src/worklets/serialize.ts +114 -0
- package/src/worklets/transform.ts +282 -0
- package/src/worklets/types.ts +26 -0
- package/types/cache.d.ts +1 -0
- package/types/cache.d.ts.map +1 -1
- package/types/configure.d.ts +2 -0
- package/types/configure.d.ts.map +1 -1
- package/types/index.d.ts +3 -0
- package/types/index.d.ts.map +1 -1
- package/types/reactNativeCodegen.d.ts +5 -0
- package/types/reactNativeCodegen.d.ts.map +1 -0
- package/types/reactNativeViewConfig.d.ts +35 -0
- package/types/reactNativeViewConfig.d.ts.map +1 -0
- package/types/transformBabel.d.ts +3 -3
- package/types/transformBabel.d.ts.map +1 -1
- package/types/transformHermesLoops.d.ts +5 -0
- package/types/transformHermesLoops.d.ts.map +1 -0
- package/types/transformHermesLoops.test.d.ts +2 -0
- package/types/transformHermesLoops.test.d.ts.map +1 -0
- package/types/transformSWC.d.ts +12 -3
- package/types/transformSWC.d.ts.map +1 -1
- package/types/transformSWC.test.d.ts +2 -0
- package/types/transformSWC.test.d.ts.map +1 -0
- package/types/transformWorklets.d.ts +22 -0
- package/types/transformWorklets.d.ts.map +1 -0
- package/types/transformWorklets.test.d.ts +2 -0
- package/types/transformWorklets.test.d.ts.map +1 -0
- package/types/types.d.ts +4 -4
- package/types/types.d.ts.map +1 -1
- package/types/worklets/autoworklet.d.ts +14 -0
- package/types/worklets/autoworklet.d.ts.map +1 -0
- package/types/worklets/globals.d.ts +3 -0
- package/types/worklets/globals.d.ts.map +1 -0
- package/types/worklets/hash.d.ts +5 -0
- package/types/worklets/hash.d.ts.map +1 -0
- package/types/worklets/scope.d.ts +7 -0
- package/types/worklets/scope.d.ts.map +1 -0
- package/types/worklets/serialize.d.ts +12 -0
- package/types/worklets/serialize.d.ts.map +1 -0
- package/types/worklets/transform.d.ts +6 -0
- package/types/worklets/transform.d.ts.map +1 -0
- package/types/worklets/types.d.ts +21 -0
- package/types/worklets/types.d.ts.map +1 -0
package/src/transformSWC.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { extname } from 'node:path'
|
|
2
|
-
import {
|
|
3
|
-
type Output,
|
|
4
|
-
type ParserConfig,
|
|
5
|
-
type Options as SWCOptions,
|
|
6
|
-
type TransformConfig,
|
|
7
|
-
transform,
|
|
8
|
-
} from '@swc/core'
|
|
9
|
-
import { merge } from 'ts-deepmerge'
|
|
10
2
|
import { normalizePath } from 'vite'
|
|
11
3
|
import { configuration } from './configure'
|
|
12
|
-
import { asyncGeneratorRegex, debug,
|
|
4
|
+
import { asyncGeneratorRegex, debug, runtimePublicPath } from './constants'
|
|
13
5
|
import type { Options } from './types'
|
|
14
6
|
|
|
7
|
+
export interface Output {
|
|
8
|
+
code: string
|
|
9
|
+
map?: any
|
|
10
|
+
}
|
|
11
|
+
|
|
15
12
|
// posix-only — id is normalized below
|
|
16
13
|
const ignoreId = /node_modules\/(\.vite|vite)\//
|
|
17
14
|
|
|
@@ -19,8 +16,8 @@ export async function transformSWC(
|
|
|
19
16
|
id: string,
|
|
20
17
|
code: string,
|
|
21
18
|
options: Options & { es5?: boolean },
|
|
22
|
-
swcOptions?:
|
|
23
|
-
) {
|
|
19
|
+
swcOptions?: any
|
|
20
|
+
): Promise<Output | undefined> {
|
|
24
21
|
// unify caller contracts (Vite plugin: POSIX id; patches.ts: native id)
|
|
25
22
|
id = normalizePath(id.split('?')[0]).replace(normalizePath(process.cwd()), '')
|
|
26
23
|
|
|
@@ -32,9 +29,8 @@ export async function transformSWC(
|
|
|
32
29
|
return
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
if (!parser) {
|
|
32
|
+
const lang = getLang(id, options.forceJSX)
|
|
33
|
+
if (!lang) {
|
|
38
34
|
return
|
|
39
35
|
}
|
|
40
36
|
|
|
@@ -45,108 +41,62 @@ export async function transformSWC(
|
|
|
45
41
|
!options.forceJSX &&
|
|
46
42
|
!id.includes('node_modules')
|
|
47
43
|
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
target: 'es2020',
|
|
70
|
-
parser,
|
|
71
|
-
transform: {
|
|
72
|
-
useDefineForClassFields: true,
|
|
73
|
-
react: reactConfig,
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const shouldEs5Transform =
|
|
80
|
-
options.es5 ||
|
|
81
|
-
(!process.env.VXRN_USE_BABEL_FOR_GENERATORS && asyncGeneratorRegex.test(code))
|
|
82
|
-
|
|
83
|
-
const opts: SWCOptions = shouldEs5Transform
|
|
84
|
-
? {
|
|
85
|
-
jsc: {
|
|
86
|
-
parser,
|
|
87
|
-
target: 'es5',
|
|
88
|
-
transform: {
|
|
89
|
-
useDefineForClassFields: true,
|
|
90
|
-
react: reactConfig,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
: {
|
|
95
|
-
...(!options.forceJSX && { env: SWC_ENV }),
|
|
96
|
-
jsc: {
|
|
97
|
-
...(options.forceJSX && { target: 'esnext' }),
|
|
98
|
-
parser,
|
|
99
|
-
transform: {
|
|
100
|
-
useDefineForClassFields: true,
|
|
101
|
-
react: reactConfig,
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
sourceMaps: shouldSourceMap(),
|
|
108
|
-
module: {
|
|
109
|
-
importInterop: 'none',
|
|
110
|
-
type: 'nodenext',
|
|
111
|
-
},
|
|
112
|
-
...(options.mode === 'serve-cjs' && {
|
|
113
|
-
module: {
|
|
114
|
-
importInterop: 'none',
|
|
115
|
-
type: 'commonjs',
|
|
116
|
-
strict: true,
|
|
117
|
-
},
|
|
118
|
-
}),
|
|
119
|
-
...opts,
|
|
120
|
-
}
|
|
121
|
-
})()
|
|
122
|
-
|
|
123
|
-
const finalOptions = merge(
|
|
124
|
-
{
|
|
125
|
-
filename: id,
|
|
126
|
-
swcrc: false,
|
|
127
|
-
configFile: false,
|
|
128
|
-
...transformOptions,
|
|
44
|
+
const importSource =
|
|
45
|
+
configuration.enableNativewind && !id.includes('node_modules')
|
|
46
|
+
? 'nativewind'
|
|
47
|
+
: 'react'
|
|
48
|
+
|
|
49
|
+
const shouldEs5Transform =
|
|
50
|
+
options.es5 ||
|
|
51
|
+
(!process.env.VXRN_USE_BABEL_FOR_GENERATORS && asyncGeneratorRegex.test(code))
|
|
52
|
+
|
|
53
|
+
const target = shouldEs5Transform ? 'es2015' : 'es2020'
|
|
54
|
+
const sourceMaps =
|
|
55
|
+
swcOptions?.sourceMaps !== undefined
|
|
56
|
+
? Boolean(swcOptions.sourceMaps)
|
|
57
|
+
: shouldSourceMap()
|
|
58
|
+
|
|
59
|
+
const oxcOptions: import('oxc-transform').TransformOptions = {
|
|
60
|
+
lang,
|
|
61
|
+
target,
|
|
62
|
+
assumptions: {
|
|
63
|
+
setPublicClassFields: true,
|
|
64
|
+
...(swcOptions?.assumptions || {}),
|
|
129
65
|
},
|
|
130
|
-
|
|
131
|
-
|
|
66
|
+
sourcemap: sourceMaps,
|
|
67
|
+
jsx: {
|
|
68
|
+
runtime: 'automatic',
|
|
69
|
+
development: !options.forceJSX && !options.production,
|
|
70
|
+
refresh: Boolean(refresh),
|
|
71
|
+
importSource,
|
|
72
|
+
},
|
|
73
|
+
}
|
|
132
74
|
|
|
133
|
-
const
|
|
75
|
+
const { transformSync } = await import('oxc-transform')
|
|
76
|
+
|
|
77
|
+
const result: Output = (() => {
|
|
134
78
|
try {
|
|
135
79
|
debug?.(
|
|
136
|
-
`transformSWC ${id} using options:\n${JSON.stringify(
|
|
80
|
+
`transformSWC (oxc) ${id} using options:\n${JSON.stringify(oxcOptions, null, 2)}`
|
|
137
81
|
)
|
|
138
82
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
|
|
83
|
+
const res = transformSync(id, code, oxcOptions)
|
|
84
|
+
if (res.errors?.length) {
|
|
85
|
+
const err = res.errors[0]
|
|
86
|
+
const error: any = new Error(
|
|
87
|
+
err.message + (err.codeframe ? `\n${err.codeframe}` : '')
|
|
88
|
+
)
|
|
89
|
+
if (err.labels?.[0]) {
|
|
90
|
+
error.start = err.labels[0].start
|
|
91
|
+
error.end = err.labels[0].end
|
|
148
92
|
}
|
|
93
|
+
throw error
|
|
149
94
|
}
|
|
95
|
+
return {
|
|
96
|
+
code: res.code,
|
|
97
|
+
map: res.map,
|
|
98
|
+
}
|
|
99
|
+
} catch (e: any) {
|
|
150
100
|
throw e
|
|
151
101
|
}
|
|
152
102
|
})()
|
|
@@ -163,7 +113,7 @@ export async function transformSWC(
|
|
|
163
113
|
// fix for node_modules that ship tsx but don't use type-specific imports
|
|
164
114
|
if (
|
|
165
115
|
options.fixNonTypeSpecificImports ||
|
|
166
|
-
(id.includes('node_modules') &&
|
|
116
|
+
(id.includes('node_modules') && (lang === 'ts' || lang === 'tsx'))
|
|
167
117
|
) {
|
|
168
118
|
// we need to keep fake objects for type exports
|
|
169
119
|
const typeExportsMatch = code.match(/^\s*export\s+type\s+([^\s]+)/gi)
|
|
@@ -199,6 +149,8 @@ export async function transformSWC(
|
|
|
199
149
|
return result
|
|
200
150
|
}
|
|
201
151
|
|
|
152
|
+
export const transformOxc = transformSWC
|
|
153
|
+
|
|
202
154
|
function wrapSourceInRefreshRuntime(
|
|
203
155
|
id: string,
|
|
204
156
|
result: Output,
|
|
@@ -219,7 +171,11 @@ function wrapSourceInRefreshRuntimeWeb(
|
|
|
219
171
|
result: Output,
|
|
220
172
|
hasRefreshRuntime: boolean
|
|
221
173
|
) {
|
|
222
|
-
const sourceMap = result.map
|
|
174
|
+
const sourceMap = result.map
|
|
175
|
+
? typeof result.map === 'string'
|
|
176
|
+
? JSON.parse(result.map)
|
|
177
|
+
: { ...result.map }
|
|
178
|
+
: undefined
|
|
223
179
|
if (sourceMap) {
|
|
224
180
|
sourceMap.mappings = ';;' + sourceMap.mappings
|
|
225
181
|
}
|
|
@@ -286,7 +242,11 @@ globalThis.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
|
286
242
|
module.url = '${id}'
|
|
287
243
|
module.hot = createHotContext(module.url)`
|
|
288
244
|
|
|
289
|
-
const sourceMap = result.map
|
|
245
|
+
const sourceMap = result.map
|
|
246
|
+
? typeof result.map === 'string'
|
|
247
|
+
? JSON.parse(result.map)
|
|
248
|
+
: { ...result.map }
|
|
249
|
+
: undefined
|
|
290
250
|
|
|
291
251
|
if (sourceMap) {
|
|
292
252
|
// we need ";" equal to number of lines added to the top
|
|
@@ -314,72 +274,61 @@ ${postfixCode}
|
|
|
314
274
|
return result
|
|
315
275
|
}
|
|
316
276
|
|
|
317
|
-
const SWC_ENV = {
|
|
318
|
-
targets: {
|
|
319
|
-
node: '4',
|
|
320
|
-
},
|
|
321
|
-
// debug: true,
|
|
322
|
-
include: [],
|
|
323
|
-
// this breaks the uniswap app for any file with a ...spread
|
|
324
|
-
exclude: [
|
|
325
|
-
'transform-spread',
|
|
326
|
-
'transform-destructuring',
|
|
327
|
-
'transform-object-rest-spread',
|
|
328
|
-
// `transform-async-to-generator` is relying on `transform-destructuring`.
|
|
329
|
-
// If we exclude `transform-destructuring` but not `transform-async-to-generator`, the SWC binary will panic
|
|
330
|
-
// with error: `called `Option::unwrap()` on a `None` value`.
|
|
331
|
-
// See: https://github.com/swc-project/swc/blob/v1.7.14/crates/swc_ecma_compat_es2015/src/generator.rs#L703-L705
|
|
332
|
-
'transform-async-to-generator',
|
|
333
|
-
'transform-regenerator', // Similar to above
|
|
334
|
-
],
|
|
335
|
-
} satisfies SWCOptions['env']
|
|
336
|
-
|
|
337
277
|
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/
|
|
338
278
|
|
|
339
|
-
function shouldSourceMap() {
|
|
279
|
+
export function shouldSourceMap() {
|
|
340
280
|
return process.env.VXRN_ENABLE_SOURCE_MAP === '1'
|
|
341
281
|
}
|
|
342
282
|
|
|
343
|
-
function
|
|
283
|
+
function getLang(id: string, forceJSX = false): 'js' | 'jsx' | 'ts' | 'tsx' | undefined {
|
|
344
284
|
if (id.endsWith('one-entry-native')) {
|
|
345
|
-
return
|
|
285
|
+
return 'tsx'
|
|
346
286
|
}
|
|
347
287
|
|
|
348
288
|
const extension = extname(id)
|
|
349
|
-
let parser: ParserConfig = !extension ? parsers['.js'] : parsers[extension]
|
|
350
289
|
|
|
351
|
-
if (extension === '.
|
|
352
|
-
|
|
353
|
-
|
|
290
|
+
if (extension === '.tsx') return 'tsx'
|
|
291
|
+
if (extension === '.ts') return 'ts'
|
|
292
|
+
if (extension === '.jsx' || extension === '.mdx') return 'jsx'
|
|
293
|
+
if (extension === '.js' || extension === '.mjs' || extension === '.cjs') {
|
|
294
|
+
if (forceJSX || id.includes('expo-modules-core')) {
|
|
295
|
+
return 'jsx'
|
|
354
296
|
}
|
|
297
|
+
return 'js'
|
|
298
|
+
}
|
|
355
299
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}
|
|
300
|
+
if (!extension) {
|
|
301
|
+
return forceJSX ? 'jsx' : 'js'
|
|
359
302
|
}
|
|
360
303
|
|
|
361
|
-
return
|
|
304
|
+
return undefined
|
|
362
305
|
}
|
|
363
306
|
|
|
364
307
|
export const transformSWCStripJSX = async (id: string, code: string) => {
|
|
365
|
-
const
|
|
366
|
-
if (!
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
refresh: false,
|
|
381
|
-
},
|
|
382
|
-
},
|
|
308
|
+
const lang = getLang(id)
|
|
309
|
+
if (!lang) return
|
|
310
|
+
|
|
311
|
+
const { transformSync } = await import('oxc-transform')
|
|
312
|
+
const res = transformSync(id, code, {
|
|
313
|
+
lang,
|
|
314
|
+
target: 'es2020',
|
|
315
|
+
assumptions: {
|
|
316
|
+
setPublicClassFields: true,
|
|
317
|
+
},
|
|
318
|
+
sourcemap: shouldSourceMap(),
|
|
319
|
+
jsx: {
|
|
320
|
+
runtime: 'automatic',
|
|
321
|
+
development: true,
|
|
322
|
+
refresh: false,
|
|
383
323
|
},
|
|
384
324
|
})
|
|
325
|
+
|
|
326
|
+
if (res.errors?.length) {
|
|
327
|
+
const err = res.errors[0]
|
|
328
|
+
throw new Error(err.message + (err.codeframe ? `\n${err.codeframe}` : ''))
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return { code: res.code, map: res.map as any }
|
|
385
332
|
}
|
|
333
|
+
|
|
334
|
+
export const transformOxcStripJSX = transformSWCStripJSX
|