peachsim 0.1.2441 → 0.1.2457
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/README.md +4 -49
- package/cli/app-catalog.ts +8 -7
- package/cli/app-stubs.ts +98 -70
- package/cli/cloud-box-artifact.ts +2 -5
- package/cli/cloud-client.ts +12 -1
- package/cli/commands/box.ts +41 -2
- package/cli/commands/compat.ts +5 -3
- package/cli/commands/cpu-profile.ts +11 -14
- package/cli/commands/diagnose.ts +5 -18
- package/cli/commands/inspect/describe.ts +4 -8
- package/cli/commands/maestro-generate.ts +4 -8
- package/cli/commands/mode.ts +3 -19
- package/cli/commands/perf.ts +3 -19
- package/cli/commands/permissions.ts +2 -6
- package/cli/commands/platform.ts +22 -14
- package/cli/commands/react.ts +7 -21
- package/cli/commands/record-three.ts +6 -10
- package/cli/commands/record.ts +38 -62
- package/cli/commands/screenshot-command.ts +8 -25
- package/cli/commands/storage.ts +4 -16
- package/cli/commands/three-mode.ts +6 -10
- package/cli/outbound-endpoints.ts +4 -5
- package/cli/parse-args.ts +45 -0
- package/cli/remote-metro.ts +1 -1
- package/cli/remote-simulators.ts +5 -1
- package/cli/send-to-box.ts +3 -1
- package/detox/index.ts +20 -1
- package/dist-lib/agent-daemon-client.cjs +2 -2
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +2 -2
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +5 -5
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +3 -3
- package/dist-lib/bundle-channel.cjs +240 -316
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +3 -3
- package/dist-lib/cloud-contract.cjs +14 -1
- package/dist-lib/cloud-contract.mjs +5 -3
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +2 -2
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +7 -7
- package/dist-lib/config.cjs +1 -6
- package/dist-lib/config.mjs +5 -9
- package/dist-lib/detox/index.cjs +17 -5
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-FRQNHKFC.mjs → acorn-73XUBXBT.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-IRMC5BCX.mjs → chunk-7V2QJGVI.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-PMGJ7FLI.mjs → chunk-BHQEYJAF.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-BAYRN7ZL.mjs → chunk-DSPFMVBM.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-4HEUXQGM.mjs → chunk-GA73RJSG.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-ABMB3G7I.mjs → chunk-IGBAFWZ3.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-ZCMAKWHN.mjs → chunk-IKZDUGT6.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-VAQJQDWI.mjs → chunk-IP5ZV36U.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-O4EOBXAP.mjs → chunk-KGHQ4GK2.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-4BZ3Z3IQ.mjs → chunk-KY63O76W.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-QYYJESMK.mjs → chunk-LJ74MO6Y.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-DJMWTW2B.mjs → chunk-LJX42YVT.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-XO5GX4PI.mjs → chunk-O4KAW2JJ.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-6A6JEVIF.mjs → chunk-OIFM356B.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-NPLEBOWJ.mjs → chunk-P63DPATT.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-VCAJFWZD.mjs → chunk-SCCOZKCP.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-QUBR7LHU.mjs → chunk-TAZL253K.mjs} +41 -15
- package/dist-lib/esm-chunks/{chunk-ORYS5CC4.mjs → chunk-UBXCWZL3.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-4ZRMJ5YO.mjs → chunk-ZQWWO33G.mjs} +14 -2
- package/dist-lib/esm-chunks/{metro-layout-parser-AUAVE5VL.mjs → metro-layout-parser-HNQRTPVE.mjs} +3 -3
- package/dist-lib/expo-swift-bundle.cjs +197 -336
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +7 -7
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +276 -381
- package/dist-lib/host/fetch-proxy-handler.cjs +35 -43
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +4 -2
- package/dist-lib/index.cjs +2 -105
- package/dist-lib/kotlin-host.cjs +6 -4
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +3 -3
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +3 -3
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +4 -4
- package/dist-lib/native-app-identity-project.cjs +2 -2
- package/dist-lib/native-app-identity-project.mjs +12 -12
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +6 -6
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +3 -3
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +2 -2
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +3 -3
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +64 -64
- package/dist-lib/public-origins-lib-static.json +1 -1
- package/dist-lib/public-origins-lib.json +107 -85
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +2 -2
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +7 -7
- package/dist-lib/skills.cjs +310 -310
- package/dist-lib/swift-compile.cjs +37 -11
- package/dist-lib/swift-compile.mjs +8 -8
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +3 -3
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +5 -5
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +14770 -0
- package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +2790 -0
- package/dist-lib/vendor/acorn.cjs +1 -1
- package/dist-lib/vendor/bplist-parser.cjs +1 -1
- package/dist-lib/vendor/ignore.cjs +1 -1
- package/dist-lib/vendor/magic-string.cjs +1 -1
- package/dist-lib/vendor/plist.cjs +1 -1
- package/dist-lib/vendor/prism.wasm +0 -0
- package/dist-lib/vendor/smol-toml.cjs +1 -1
- package/dist-lib/vendor/stream-json.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
- package/dist-lib/vendor/sucrase.cjs +1 -1
- package/dist-lib/vendor/terser.cjs +1 -1
- package/dist-lib/vendor/valibot.cjs +1 -1
- package/dist-lib/vendor/ws.cjs +3710 -0
- package/dist-lib/vendor/zod.cjs +1 -1
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +3 -3
- package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-gesture-handler.d.ts +0 -3
- package/dist-types/packages/peach-engine/src/config.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/engine/scene-table.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/text-line-break.d.ts +3 -1
- package/dist-types/packages/peach-engine/src/engine/text-paint.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/text-runs.d.ts +6 -1
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +22 -14
- package/skills/peach-setup/references/native-config.md +3 -3
- package/src/app-config.ts +7 -15
- package/src/cloud-contract.ts +35 -0
- package/src/config.ts +2 -6
- package/src/estree-walk.ts +13 -0
- package/src/host/network-policy.ts +4 -1
- package/src/index.ts +0 -1
- package/src/one-native-app-config.ts +14 -15
- package/src/podspec-prism.ts +7 -1
- package/src/process-group.ts +4 -1
- package/src/process-table.ts +6 -1
- package/src/swift-compile.ts +38 -8
- package/src/swift-host.ts +10 -4
- package/cli/commands/box/bundle-plane.ts +0 -154
- package/dist-lib/jump-to-source-babel.cjs +0 -131
- package/dist-lib/jump-to-source-native.cjs +0 -235
- package/src/java-static-imports.ts +0 -68
- package/src/jump-to-source-babel.ts +0 -143
- package/src/jump-to-source-native.ts +0 -200
- package/src/kotlin-jvm-sources.ts +0 -35
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import type { PluginObj, types } from '@babel/core'
|
|
2
|
-
|
|
3
|
-
export interface SootsimJumpToSourceBabelOptions {
|
|
4
|
-
enabled?: boolean
|
|
5
|
-
attrName?: string
|
|
6
|
-
include?: readonly SourcePathMatcher[]
|
|
7
|
-
exclude?: readonly SourcePathMatcher[]
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
type SourcePathMatcher = string | RegExp
|
|
11
|
-
|
|
12
|
-
function normalizeSourcePath(path: string): string {
|
|
13
|
-
const queryStart = path.indexOf('?')
|
|
14
|
-
const clean = queryStart >= 0 ? path.slice(0, queryStart) : path
|
|
15
|
-
return clean.replace(/\\/g, '/')
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function matchesPath(path: string, matcher: SourcePathMatcher): boolean {
|
|
19
|
-
return typeof matcher === 'string' ? path.includes(matcher) : matcher.test(path)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function shouldStampFile(
|
|
23
|
-
filename: string,
|
|
24
|
-
options: SootsimJumpToSourceBabelOptions,
|
|
25
|
-
): boolean {
|
|
26
|
-
const normalized = normalizeSourcePath(filename)
|
|
27
|
-
if (normalized.includes('/node_modules/')) return false
|
|
28
|
-
if (normalized.includes('/dist/') || normalized.includes('/build/')) return false
|
|
29
|
-
if (options.exclude?.some((matcher) => matchesPath(normalized, matcher))) return false
|
|
30
|
-
if (options.include?.length) {
|
|
31
|
-
return options.include.some((matcher) => matchesPath(normalized, matcher))
|
|
32
|
-
}
|
|
33
|
-
return true
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default function sootsimJumpToSourceBabelPlugin(
|
|
37
|
-
api: { types: typeof types },
|
|
38
|
-
options: SootsimJumpToSourceBabelOptions = {},
|
|
39
|
-
): PluginObj {
|
|
40
|
-
const t = api.types
|
|
41
|
-
const attrName = options.attrName || 'srcloc'
|
|
42
|
-
const stamped = new WeakSet<types.JSXElement>()
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
name: 'sootsim-jump-to-source',
|
|
46
|
-
visitor: {
|
|
47
|
-
JSXElement: {
|
|
48
|
-
exit(path, state) {
|
|
49
|
-
if (options.enabled === false) return
|
|
50
|
-
const filename = state.filename
|
|
51
|
-
if (!filename || !shouldStampFile(filename, options)) return
|
|
52
|
-
|
|
53
|
-
const node = path.node
|
|
54
|
-
if (stamped.has(node)) return
|
|
55
|
-
stamped.add(node)
|
|
56
|
-
const opening = node.openingElement
|
|
57
|
-
const name = opening.name
|
|
58
|
-
if (t.isJSXNamespacedName(name)) return
|
|
59
|
-
if (
|
|
60
|
-
opening.attributes.some(
|
|
61
|
-
(attr) =>
|
|
62
|
-
t.isJSXAttribute(attr) &&
|
|
63
|
-
t.isJSXIdentifier(attr.name, { name: attrName }),
|
|
64
|
-
)
|
|
65
|
-
)
|
|
66
|
-
return
|
|
67
|
-
const loc = opening.loc?.start
|
|
68
|
-
if (!loc) return
|
|
69
|
-
const source = `${normalizeSourcePath(filename)}:${loc.line}:${loc.column + 1}`
|
|
70
|
-
if (t.isJSXIdentifier(name) && /^[a-z]/.test(name.name)) {
|
|
71
|
-
opening.attributes.push(
|
|
72
|
-
t.jsxAttribute(t.jsxIdentifier(attrName), t.stringLiteral(source)),
|
|
73
|
-
)
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// capture the type once, before props and children. names and member
|
|
78
|
-
// getters can resolve to fragment at runtime; no symbol accepts srcloc.
|
|
79
|
-
const fn = path.getFunctionParent()
|
|
80
|
-
const parameterDefault = Boolean(
|
|
81
|
-
fn &&
|
|
82
|
-
opening.start != null &&
|
|
83
|
-
fn.node.body.start != null &&
|
|
84
|
-
opening.start < fn.node.body.start,
|
|
85
|
-
)
|
|
86
|
-
const type = path.scope.generateUidIdentifier('PeachSourceType')
|
|
87
|
-
if (!parameterDefault) path.scope.push({ id: type })
|
|
88
|
-
// jsx member names have the same object/property shape as expressions.
|
|
89
|
-
function expression(
|
|
90
|
-
tag: types.JSXIdentifier | types.JSXMemberExpression,
|
|
91
|
-
): types.Expression {
|
|
92
|
-
return t.isJSXIdentifier(tag)
|
|
93
|
-
? t.identifier(tag.name)
|
|
94
|
-
: t.memberExpression(
|
|
95
|
-
expression(tag.object),
|
|
96
|
-
t.identifier(tag.property.name),
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
const originalType = expression(name)
|
|
100
|
-
const alias = t.jsxIdentifier(type.name)
|
|
101
|
-
opening.name = alias
|
|
102
|
-
if (node.closingElement) node.closingElement.name = alias
|
|
103
|
-
opening.attributes.push(
|
|
104
|
-
t.jsxSpreadAttribute(
|
|
105
|
-
t.conditionalExpression(
|
|
106
|
-
t.binaryExpression(
|
|
107
|
-
'===',
|
|
108
|
-
t.unaryExpression('typeof', type),
|
|
109
|
-
t.stringLiteral('symbol'),
|
|
110
|
-
),
|
|
111
|
-
t.nullLiteral(),
|
|
112
|
-
t.objectExpression([
|
|
113
|
-
t.objectProperty(t.stringLiteral(attrName), t.stringLiteral(source)),
|
|
114
|
-
]),
|
|
115
|
-
),
|
|
116
|
-
),
|
|
117
|
-
)
|
|
118
|
-
// defaults execute outside the function body. their own parameter
|
|
119
|
-
// binding preserves lexical this and arguments without a shared temp.
|
|
120
|
-
// the always-truthy capture avoids sequence expressions inside jsx.
|
|
121
|
-
const replacement = parameterDefault
|
|
122
|
-
? t.callExpression(t.arrowFunctionExpression([type], node), [originalType])
|
|
123
|
-
: t.logicalExpression(
|
|
124
|
-
'&&',
|
|
125
|
-
t.logicalExpression(
|
|
126
|
-
'||',
|
|
127
|
-
t.assignmentExpression('=', type, originalType),
|
|
128
|
-
t.booleanLiteral(true),
|
|
129
|
-
),
|
|
130
|
-
node,
|
|
131
|
-
)
|
|
132
|
-
if (path.parentPath.isJSXElement() || path.parentPath.isJSXFragment()) {
|
|
133
|
-
path.replaceWith(t.jsxExpressionContainer(replacement))
|
|
134
|
-
} else {
|
|
135
|
-
path.replaceWith(replacement)
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export { sootsimJumpToSourceBabelPlugin }
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import MagicString from 'magic-string'
|
|
2
|
-
import {
|
|
3
|
-
parseSync,
|
|
4
|
-
type Program,
|
|
5
|
-
type BlockStatement,
|
|
6
|
-
type Expression,
|
|
7
|
-
type JSXElement,
|
|
8
|
-
type JSXFragment,
|
|
9
|
-
} from 'oxc-parser'
|
|
10
|
-
import { visitParsedProgram } from './visit-parsed-program'
|
|
11
|
-
import type { SootsimJumpToSourceBabelOptions } from './jump-to-source-babel.ts'
|
|
12
|
-
|
|
13
|
-
export type JumpToSourceNativeOptions = SootsimJumpToSourceBabelOptions
|
|
14
|
-
|
|
15
|
-
function matchesPath(path: string, matcher: string | RegExp): boolean {
|
|
16
|
-
return typeof matcher === 'string' ? path.includes(matcher) : matcher.test(path)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// stamp the same one-based source locations as the babel plugin before native
|
|
20
|
-
// jsx compilation, without running babel in the native bundle pipeline.
|
|
21
|
-
export function stampJsxSourceLocations(
|
|
22
|
-
code: string,
|
|
23
|
-
filename: string,
|
|
24
|
-
options: JumpToSourceNativeOptions = {},
|
|
25
|
-
): string | null {
|
|
26
|
-
if (options.enabled === false || !filename || !code.includes('<')) return null
|
|
27
|
-
const source = filename.split('?')[0].replace(/\\/g, '/')
|
|
28
|
-
if (
|
|
29
|
-
source.includes('/node_modules/') ||
|
|
30
|
-
source.includes('/dist/') ||
|
|
31
|
-
source.includes('/build/')
|
|
32
|
-
)
|
|
33
|
-
return null
|
|
34
|
-
if (options.exclude?.some((matcher) => matchesPath(source, matcher))) return null
|
|
35
|
-
if (
|
|
36
|
-
options.include?.length &&
|
|
37
|
-
!options.include.some((matcher) => matchesPath(source, matcher))
|
|
38
|
-
)
|
|
39
|
-
return null
|
|
40
|
-
|
|
41
|
-
const { program, errors } = parseSync(source, code, {
|
|
42
|
-
lang: source.endsWith('.tsx') ? 'tsx' : source.endsWith('.ts') ? 'ts' : 'jsx',
|
|
43
|
-
})
|
|
44
|
-
if (errors.length) return null
|
|
45
|
-
|
|
46
|
-
const attrName = options.attrName || 'srcloc'
|
|
47
|
-
const lineStarts = [0]
|
|
48
|
-
for (let i = 0; i < code.length; i++) {
|
|
49
|
-
if (code.charCodeAt(i) === 10) lineStarts.push(i + 1)
|
|
50
|
-
}
|
|
51
|
-
const magic = new MagicString(code)
|
|
52
|
-
let stamped = false
|
|
53
|
-
let nextType = 0
|
|
54
|
-
const usedTypeNames = new Set(code.match(/\b_PeachSourceType\d+\b/g) ?? [])
|
|
55
|
-
type Scope = { body: Program | BlockStatement | Expression; names: string[] }
|
|
56
|
-
const scopes: Scope[] = [{ body: program, names: [] }]
|
|
57
|
-
const allScopes = [...scopes]
|
|
58
|
-
const elements: (JSXElement | JSXFragment)[] = []
|
|
59
|
-
const childElements = new WeakSet<JSXElement>()
|
|
60
|
-
const enterElement = (node: JSXElement | JSXFragment) => {
|
|
61
|
-
elements.push(node)
|
|
62
|
-
for (const child of node.children) {
|
|
63
|
-
if (child.type === 'JSXElement') childElements.add(child)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const enterFunction = (node: { body?: BlockStatement | Expression | null }) => {
|
|
67
|
-
const scope: Scope = { body: node.body ?? program, names: [] }
|
|
68
|
-
scopes.push(scope)
|
|
69
|
-
allScopes.push(scope)
|
|
70
|
-
}
|
|
71
|
-
const exitFunction = () => {
|
|
72
|
-
scopes.pop()
|
|
73
|
-
}
|
|
74
|
-
visitParsedProgram(program, {
|
|
75
|
-
FunctionDeclaration: enterFunction,
|
|
76
|
-
'FunctionDeclaration:exit': exitFunction,
|
|
77
|
-
FunctionExpression: enterFunction,
|
|
78
|
-
'FunctionExpression:exit': exitFunction,
|
|
79
|
-
ArrowFunctionExpression: enterFunction,
|
|
80
|
-
'ArrowFunctionExpression:exit': exitFunction,
|
|
81
|
-
JSXElement: enterElement,
|
|
82
|
-
'JSXElement:exit'() {
|
|
83
|
-
elements.pop()
|
|
84
|
-
},
|
|
85
|
-
JSXFragment: enterElement,
|
|
86
|
-
'JSXFragment:exit'() {
|
|
87
|
-
elements.pop()
|
|
88
|
-
},
|
|
89
|
-
JSXOpeningElement(node) {
|
|
90
|
-
const name = node.name
|
|
91
|
-
if (name.type === 'JSXNamespacedName') return
|
|
92
|
-
if (
|
|
93
|
-
node.attributes.some(
|
|
94
|
-
(attr) =>
|
|
95
|
-
attr.type === 'JSXAttribute' &&
|
|
96
|
-
attr.name.type === 'JSXIdentifier' &&
|
|
97
|
-
attr.name.name === attrName,
|
|
98
|
-
)
|
|
99
|
-
)
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
// binary search keeps location lookup logarithmic for large source files.
|
|
103
|
-
let lo = 0
|
|
104
|
-
let hi = lineStarts.length - 1
|
|
105
|
-
while (lo < hi) {
|
|
106
|
-
const mid = (lo + hi + 1) >> 1
|
|
107
|
-
if (lineStarts[mid] <= node.start) lo = mid
|
|
108
|
-
else hi = mid - 1
|
|
109
|
-
}
|
|
110
|
-
const location = `${source}:${lo + 1}:${node.start - lineStarts[lo] + 1}`
|
|
111
|
-
if (name.type === 'JSXIdentifier' && /^[a-z]/.test(name.name)) {
|
|
112
|
-
magic.appendLeft(
|
|
113
|
-
node.end - (node.selfClosing ? 2 : 1),
|
|
114
|
-
` ${attrName}={${JSON.stringify(location)}}`,
|
|
115
|
-
)
|
|
116
|
-
} else {
|
|
117
|
-
const scope = scopes[scopes.length - 1]
|
|
118
|
-
// parameter defaults have their own environment outside the body.
|
|
119
|
-
const parameterDefault =
|
|
120
|
-
node.start < scope.body.start || node.end > scope.body.end
|
|
121
|
-
const element = elements[elements.length - 1]
|
|
122
|
-
if (element.type !== 'JSXElement') return
|
|
123
|
-
const isChild = childElements.has(element)
|
|
124
|
-
let type: string
|
|
125
|
-
do {
|
|
126
|
-
type = `_PeachSourceType${nextType++}`
|
|
127
|
-
} while (usedTypeNames.has(type))
|
|
128
|
-
if (!parameterDefault) scope.names.push(type)
|
|
129
|
-
const originalType = code.slice(name.start, name.end)
|
|
130
|
-
// keep the capture before props without a sequence inside jsx children.
|
|
131
|
-
magic.appendLeft(
|
|
132
|
-
element.start,
|
|
133
|
-
`${isChild ? '{' : ''}${parameterDefault ? `((${type}) => ` : `(((${type} = ${originalType}) || true) && `}`,
|
|
134
|
-
)
|
|
135
|
-
magic.appendLeft(
|
|
136
|
-
element.end,
|
|
137
|
-
`${parameterDefault ? `)(${originalType})` : ')'}${isChild ? '}' : ''}`,
|
|
138
|
-
)
|
|
139
|
-
magic.overwrite(name.start, name.end, type)
|
|
140
|
-
if (element.closingElement) {
|
|
141
|
-
const closing = element.closingElement.name
|
|
142
|
-
magic.overwrite(closing.start, closing.end, type)
|
|
143
|
-
}
|
|
144
|
-
magic.appendLeft(
|
|
145
|
-
node.end - (node.selfClosing ? 2 : 1),
|
|
146
|
-
` {...(typeof ${type} === "symbol" ? null : {${JSON.stringify(attrName)}: ${JSON.stringify(location)}})}`,
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
stamped = true
|
|
150
|
-
},
|
|
151
|
-
})
|
|
152
|
-
for (const { body, names } of allScopes) {
|
|
153
|
-
if (!names.length) continue
|
|
154
|
-
const declaration = `var ${names.join(', ')};`
|
|
155
|
-
if (body.type === 'Program' || body.type === 'BlockStatement') {
|
|
156
|
-
let start =
|
|
157
|
-
body.type === 'Program'
|
|
158
|
-
? program.hashbang
|
|
159
|
-
? code.indexOf('\n', program.hashbang.end) + 1
|
|
160
|
-
: 0
|
|
161
|
-
: body.start + 1
|
|
162
|
-
for (const statement of body.body) {
|
|
163
|
-
if (
|
|
164
|
-
statement.type !== 'ExpressionStatement' ||
|
|
165
|
-
statement.expression.type !== 'Literal' ||
|
|
166
|
-
typeof statement.expression.value !== 'string'
|
|
167
|
-
)
|
|
168
|
-
break
|
|
169
|
-
start = statement.end
|
|
170
|
-
}
|
|
171
|
-
magic.prependLeft(start, declaration)
|
|
172
|
-
} else {
|
|
173
|
-
magic.prependLeft(body.start, `{${declaration} return (`)
|
|
174
|
-
magic.appendLeft(body.end, ');}')
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return stamped ? magic.toString() : null
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// metro's nativeTransformModules accepts module ids; consumers can export an
|
|
181
|
-
// instance of this transform from a module to supply their include filters.
|
|
182
|
-
export function createJumpToSourceNativeTransform(
|
|
183
|
-
options: JumpToSourceNativeOptions = {},
|
|
184
|
-
) {
|
|
185
|
-
return function jumpToSourceNativeTransform(code: string, ctx: { filename: string }) {
|
|
186
|
-
return stampJsxSourceLocations(code, ctx.filename, options)
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export function jumpToSourceNativePlugin(options: JumpToSourceNativeOptions = {}) {
|
|
191
|
-
return {
|
|
192
|
-
name: 'sootsim-jump-to-source',
|
|
193
|
-
transform(code: string, id: string) {
|
|
194
|
-
const stamped = stampJsxSourceLocations(code, id, options)
|
|
195
|
-
return stamped == null ? null : { code: stamped, map: null }
|
|
196
|
-
},
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export default createJumpToSourceNativeTransform()
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// Kotlin/JVM's kotlin.collections classes that are typealiases of java.util's,
|
|
2
|
-
// so a Kotlin/JVM source naming one means the Java class
|
|
3
|
-
const JVM_COLLECTION_ALIASES = [
|
|
4
|
-
'ArrayList',
|
|
5
|
-
'HashMap',
|
|
6
|
-
'HashSet',
|
|
7
|
-
'LinkedHashMap',
|
|
8
|
-
'LinkedHashSet',
|
|
9
|
-
]
|
|
10
|
-
|
|
11
|
-
export function importJvmCollectionAliases(source: string): string {
|
|
12
|
-
const names = JVM_COLLECTION_ALIASES.filter(
|
|
13
|
-
(name) =>
|
|
14
|
-
new RegExp(`(?<![\\w.])${name}\\b`).test(source.replace(/^\s*import\s.*$/gm, '')) &&
|
|
15
|
-
!new RegExp(
|
|
16
|
-
`^\\s*import\\s+[\\w.]+(\\.${name}|\\s+as\\s+${name})\\s*$|\\b(class|typealias|interface)\\s+${name}\\b`,
|
|
17
|
-
'm',
|
|
18
|
-
).test(source),
|
|
19
|
-
)
|
|
20
|
-
if (!names.length) return source
|
|
21
|
-
const imports = names.map((name) => `import java.util.${name}`).join('\n')
|
|
22
|
-
const header = /^package\s.*$/m.exec(source)
|
|
23
|
-
if (!header) return `${imports}\n${source}`
|
|
24
|
-
const end = header.index + header[0].length
|
|
25
|
-
return `${source.slice(0, end)}\n${imports}${source.slice(end)}`
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Kotlin/JVM alone takes a class literal with type arguments, for an array:
|
|
29
|
-
// the Java class of that array
|
|
30
|
-
export function arrayClassLiterals(source: string): string {
|
|
31
|
-
return source.replace(
|
|
32
|
-
/(?<![\w.])Array<([\w.]+)>::class\.java\b/g,
|
|
33
|
-
(_, component) => `${component}::class.java.arrayType()`,
|
|
34
|
-
)
|
|
35
|
-
}
|