peachsim 0.1.822 → 0.1.824
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-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.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 +15 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +169 -44
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +169 -44
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +200 -77
- package/dist-lib/host/fetch-proxy-handler.cjs +24 -34
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +33 -3
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +1 -1
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.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 +1 -1
- package/dist-lib/skills.cjs +200 -77
- package/dist-lib/swift-compile.cjs +169 -44
- package/dist-lib/swift-compile.mjs +169 -44
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +169 -44
- package/dist-lib/vite.cjs +1 -1
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/package.json +1 -1
- package/src/backend-origin.ts +27 -0
- package/src/host/bridge-host.ts +8 -3
- package/src/host/fetch-proxy-handler.ts +20 -37
- package/src/host/fetch-proxy-transport.ts +4 -8
- package/src/host/websocket-proxy.ts +12 -0
- package/src/swift-compile.ts +183 -48
package/src/host/bridge-host.ts
CHANGED
|
@@ -49,8 +49,8 @@ import { rnxRuntime } from '../runtime-delivery.ts'
|
|
|
49
49
|
import { AgentHost, type AgentHostOptions } from './agent-host.ts'
|
|
50
50
|
import {
|
|
51
51
|
handleAppApiRequest,
|
|
52
|
-
handleBundleProxyRequest,
|
|
53
52
|
handleFetchProxyRequest,
|
|
53
|
+
rejectUntrustedBridgeOrigin,
|
|
54
54
|
isAppApiRequestUrl,
|
|
55
55
|
isFetchProxyRequestUrl,
|
|
56
56
|
} from './fetch-proxy-handler.ts'
|
|
@@ -62,7 +62,10 @@ import {
|
|
|
62
62
|
handleReplacementModuleRequest,
|
|
63
63
|
isReplacementModuleRequestUrl,
|
|
64
64
|
} from './replacement-module-handler.ts'
|
|
65
|
-
import {
|
|
65
|
+
import {
|
|
66
|
+
handleWebSocketProxyUpgrade,
|
|
67
|
+
rejectUntrustedBridgeUpgrade,
|
|
68
|
+
} from './websocket-proxy.ts'
|
|
66
69
|
import type { WsCommand } from '../bridge-contract.ts'
|
|
67
70
|
|
|
68
71
|
const SOOTSIM_CROSS_ORIGIN_EMBEDDER_POLICY = 'require-corp'
|
|
@@ -571,6 +574,7 @@ export class SootSimBridgeHost {
|
|
|
571
574
|
this.wss = new WebSocketServer({ noServer: true })
|
|
572
575
|
this.wireWebSocketServer()
|
|
573
576
|
server.on('upgrade', (req, socket, head) => {
|
|
577
|
+
if (rejectUntrustedBridgeUpgrade(req, socket)) return
|
|
574
578
|
if (handleWebSocketProxyUpgrade(req, socket, head)) return
|
|
575
579
|
this.wss?.handleUpgrade(req, socket, head, (ws) => {
|
|
576
580
|
this.wss?.emit('connection', ws, req)
|
|
@@ -1499,6 +1503,7 @@ export class SootSimBridgeHost {
|
|
|
1499
1503
|
* non-upgrade routes that don't match serve index.html (SPA behavior) so
|
|
1500
1504
|
* electron's webContents can navigate freely inside the runtime. */
|
|
1501
1505
|
private handleHttpRequest(req: IncomingMessage, res: ServerResponse) {
|
|
1506
|
+
if (rejectUntrustedBridgeOrigin(req, res)) return
|
|
1502
1507
|
if (req.url === '/__peach/fetch-transport') {
|
|
1503
1508
|
res.writeHead(200, {
|
|
1504
1509
|
'Content-Type': 'application/json',
|
|
@@ -1733,7 +1738,7 @@ export class SootSimBridgeHost {
|
|
|
1733
1738
|
// cross-origin URL without CORS headers, and metro doesn't set them.
|
|
1734
1739
|
// we proxy the request and stream the response back.
|
|
1735
1740
|
if (url.pathname === '/__bundle-proxy') {
|
|
1736
|
-
void
|
|
1741
|
+
void handleFetchProxyRequest(req, res)
|
|
1737
1742
|
return
|
|
1738
1743
|
}
|
|
1739
1744
|
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// routes implemented here:
|
|
17
17
|
// /__fetch-proxy?url=… — generic CORS-bypassing proxy
|
|
18
18
|
// /__proxy?url=… — alias of /__fetch-proxy (demo-gateway path)
|
|
19
|
+
// /__bundle-proxy?url=… — alias of /__fetch-proxy (bundles and assets)
|
|
19
20
|
// /__app-api?origin=…&path=… — tenant API reverse proxy, stateless
|
|
20
21
|
// (bundle origin carried in the query string)
|
|
21
22
|
// /__app-api/<path> — legacy form for callers that registered an
|
|
@@ -27,7 +28,11 @@ import http, { type IncomingMessage, type ServerResponse } from 'http'
|
|
|
27
28
|
import https from 'https'
|
|
28
29
|
import { Http2ServerRequest, type Http2ServerResponse } from 'node:http2'
|
|
29
30
|
import { finished, pipeline } from 'stream/promises'
|
|
30
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
isLoopbackHost,
|
|
33
|
+
isTrustedBridgeRequest,
|
|
34
|
+
normalizeHostname,
|
|
35
|
+
} from '../backend-origin.ts'
|
|
31
36
|
import {
|
|
32
37
|
buildFetchProxyUpstreamHeaders,
|
|
33
38
|
nodeRequestHeaderEntries,
|
|
@@ -131,6 +136,20 @@ export function buildAppApiProxyHeaders(
|
|
|
131
136
|
return headers
|
|
132
137
|
}
|
|
133
138
|
|
|
139
|
+
// every bridge http surface (the daemon server, its http/2 fetch transport,
|
|
140
|
+
// the shell dev server's proxies) answers only pages isTrustedBridgeRequest
|
|
141
|
+
// admits.
|
|
142
|
+
export function rejectUntrustedBridgeOrigin(
|
|
143
|
+
req: FetchProxyRequest,
|
|
144
|
+
res: FetchProxyResponse,
|
|
145
|
+
): boolean {
|
|
146
|
+
if (isTrustedBridgeRequest(req.headers)) return false
|
|
147
|
+
res.statusCode = 403
|
|
148
|
+
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
|
|
149
|
+
res.end(`peach bridge: origin ${req.headers.origin} may not use this bridge`)
|
|
150
|
+
return true
|
|
151
|
+
}
|
|
152
|
+
|
|
134
153
|
export function isFetchProxyRequestUrl(rawUrl: string | undefined): boolean {
|
|
135
154
|
return rawUrl?.startsWith('/__fetch-proxy?') || rawUrl?.startsWith('/__proxy?') || false
|
|
136
155
|
}
|
|
@@ -327,42 +346,6 @@ export async function handleFetchProxyRequest(
|
|
|
327
346
|
}
|
|
328
347
|
}
|
|
329
348
|
|
|
330
|
-
export async function handleBundleProxyRequest(
|
|
331
|
-
req: FetchProxyRequest,
|
|
332
|
-
res: FetchProxyResponse,
|
|
333
|
-
): Promise<void> {
|
|
334
|
-
const params = new URLSearchParams((req.url || '').split('?')[1] || '')
|
|
335
|
-
const target = params.get('url')
|
|
336
|
-
if (!target) {
|
|
337
|
-
applyFetchProxyCors(req, res)
|
|
338
|
-
res.statusCode = 400
|
|
339
|
-
res.setHeader('Content-Type', 'text/plain')
|
|
340
|
-
res.end('bundle-proxy: missing url query param')
|
|
341
|
-
return
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
let targetUrl: URL
|
|
345
|
-
try {
|
|
346
|
-
targetUrl = new URL(target)
|
|
347
|
-
} catch {
|
|
348
|
-
applyFetchProxyCors(req, res)
|
|
349
|
-
res.statusCode = 400
|
|
350
|
-
res.setHeader('Content-Type', 'text/plain')
|
|
351
|
-
res.end('bundle-proxy: invalid url')
|
|
352
|
-
return
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
if (!isLoopbackHost(targetUrl.hostname)) {
|
|
356
|
-
applyFetchProxyCors(req, res)
|
|
357
|
-
res.statusCode = 403
|
|
358
|
-
res.setHeader('Content-Type', 'text/plain')
|
|
359
|
-
res.end('bundle-proxy: only loopback targets allowed')
|
|
360
|
-
return
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
await handleFetchProxyRequest(req, res)
|
|
364
|
-
}
|
|
365
|
-
|
|
366
349
|
export function handleAppApiRequest(req: IncomingMessage, res: ServerResponse): boolean {
|
|
367
350
|
// returns true if it handled the request, false if it is not an /__app-api
|
|
368
351
|
// request. the proxy is stateless: a request without an `origin` query
|
|
@@ -2,10 +2,10 @@ import { createHash, randomBytes } from 'node:crypto'
|
|
|
2
2
|
import { createSecureServer, type ServerHttp2Session } from 'node:http2'
|
|
3
3
|
import { SubjectAlternativeNameExtension, X509CertificateGenerator } from '@peculiar/x509'
|
|
4
4
|
import {
|
|
5
|
-
handleBundleProxyRequest,
|
|
6
5
|
handleFetchProxyRequest,
|
|
7
6
|
isBundleProxyRequestUrl,
|
|
8
7
|
isFetchProxyRequestUrl,
|
|
8
|
+
rejectUntrustedBridgeOrigin,
|
|
9
9
|
} from './fetch-proxy-handler.ts'
|
|
10
10
|
|
|
11
11
|
// image bytes use multiplexed tls streams. the websocket control server keeps
|
|
@@ -42,19 +42,15 @@ export async function startFetchProxyTransport() {
|
|
|
42
42
|
settings: { maxConcurrentStreams: 256 },
|
|
43
43
|
},
|
|
44
44
|
(req, res) => {
|
|
45
|
+
if (rejectUntrustedBridgeOrigin(req, res)) return
|
|
45
46
|
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin')
|
|
46
47
|
res.setHeader('Timing-Allow-Origin', '*')
|
|
47
|
-
|
|
48
|
-
? handleBundleProxyRequest
|
|
49
|
-
: isFetchProxyRequestUrl(req.url)
|
|
50
|
-
? handleFetchProxyRequest
|
|
51
|
-
: null
|
|
52
|
-
if (!handler) {
|
|
48
|
+
if (!isBundleProxyRequestUrl(req.url) && !isFetchProxyRequestUrl(req.url)) {
|
|
53
49
|
res.writeHead(404)
|
|
54
50
|
res.end()
|
|
55
51
|
return
|
|
56
52
|
}
|
|
57
|
-
void
|
|
53
|
+
void handleFetchProxyRequest(req, res).catch(() => res.destroy())
|
|
58
54
|
},
|
|
59
55
|
)
|
|
60
56
|
server.on('session', (session) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'crypto'
|
|
2
2
|
import { request as requestHttp, type IncomingMessage } from 'http'
|
|
3
3
|
import { request as requestHttps } from 'https'
|
|
4
|
+
import { isTrustedBridgeRequest } from '../backend-origin.ts'
|
|
4
5
|
import type { Duplex } from 'stream'
|
|
5
6
|
|
|
6
7
|
export const WEBSOCKET_PROXY_PATH = '/__websocket-proxy'
|
|
@@ -45,6 +46,17 @@ function rejectUpgrade(
|
|
|
45
46
|
socket.destroy()
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
// the bridge's websocket upgrade admits browser pages by the same rule as its
|
|
50
|
+
// http routes (rejectUntrustedBridgeOrigin)
|
|
51
|
+
export function rejectUntrustedBridgeUpgrade(
|
|
52
|
+
req: IncomingMessage,
|
|
53
|
+
socket: Duplex,
|
|
54
|
+
): boolean {
|
|
55
|
+
if (isTrustedBridgeRequest(req.headers)) return false
|
|
56
|
+
rejectUpgrade(socket, 403, 'forbidden bridge origin')
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
|
|
48
60
|
function hasHeaderToken(value: string | undefined, token: string): boolean {
|
|
49
61
|
return (value || '').split(',').some((part) => part.trim().toLowerCase() === token)
|
|
50
62
|
}
|
package/src/swift-compile.ts
CHANGED
|
@@ -1427,10 +1427,29 @@ export function tableProtocolConformances(sources: string[]): Map<string, Set<st
|
|
|
1427
1427
|
for (const source of sources) {
|
|
1428
1428
|
const code = swiftCodeMask(source)
|
|
1429
1429
|
for (const owner of code.matchAll(
|
|
1430
|
-
/\b(?:class|extension)\s+([A-Za-z_]\w*)
|
|
1430
|
+
/\b(?:class|extension|protocol)\s+(?!(?:func|var)\b)([A-Za-z_]\w*)([^{}]*)\{/g,
|
|
1431
1431
|
)) {
|
|
1432
|
+
// generic constraints are not inheritance. find the colon outside <...>.
|
|
1433
|
+
const header = owner[2]!
|
|
1434
|
+
let depth = 0
|
|
1435
|
+
let colon = -1
|
|
1436
|
+
for (let at = 0; at < header.length; at++) {
|
|
1437
|
+
if (header[at] === '<') depth++
|
|
1438
|
+
else if (header[at] === '>') depth--
|
|
1439
|
+
else if (header[at] === ':' && depth === 0) {
|
|
1440
|
+
colon = at
|
|
1441
|
+
break
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
if (colon === -1) continue
|
|
1432
1445
|
const inherited = parents.get(owner[1]!) ?? new Set<string>()
|
|
1433
|
-
for (const type of
|
|
1446
|
+
for (const type of splitTopLevel(header.slice(colon + 1).split(/\bwhere\b/)[0]!)) {
|
|
1447
|
+
const name = /^\s*(?:[A-Za-z_]\w*\.)*([A-Za-z_]\w*)/.exec(type)?.[1]
|
|
1448
|
+
// Swift does not infer optional Objective-C witnesses through a
|
|
1449
|
+
// specialized generic superclass. explicit @objc remains exposed by
|
|
1450
|
+
// the normal attribute lowering below.
|
|
1451
|
+
if (name && !type.includes('<')) inherited.add(name)
|
|
1452
|
+
}
|
|
1434
1453
|
parents.set(owner[1]!, inherited)
|
|
1435
1454
|
}
|
|
1436
1455
|
}
|
|
@@ -1457,51 +1476,151 @@ function lowerTableProtocolMethods(
|
|
|
1457
1476
|
conformances: Map<string, Set<string>>,
|
|
1458
1477
|
): string {
|
|
1459
1478
|
const code = swiftCodeMask(source)
|
|
1460
|
-
const dataSource: Record<string, string> = {
|
|
1461
|
-
numberOfRowsInSection:
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1479
|
+
const dataSource: Record<string, readonly [string, string]> = {
|
|
1480
|
+
numberOfRowsInSection: [
|
|
1481
|
+
'tableView:numberOfRowsInSection:',
|
|
1482
|
+
'_:UITableView,numberOfRowsInSection:Int->Int',
|
|
1483
|
+
],
|
|
1484
|
+
cellForRowAt: [
|
|
1485
|
+
'tableView:cellForRowAtIndexPath:',
|
|
1486
|
+
'_:UITableView,cellForRowAt:IndexPath->UITableViewCell',
|
|
1487
|
+
],
|
|
1488
|
+
titleForHeaderInSection: [
|
|
1489
|
+
'tableView:titleForHeaderInSection:',
|
|
1490
|
+
'_:UITableView,titleForHeaderInSection:Int->String?',
|
|
1491
|
+
],
|
|
1492
|
+
titleForFooterInSection: [
|
|
1493
|
+
'tableView:titleForFooterInSection:',
|
|
1494
|
+
'_:UITableView,titleForFooterInSection:Int->String?',
|
|
1495
|
+
],
|
|
1496
|
+
canEditRowAt: [
|
|
1497
|
+
'tableView:canEditRowAtIndexPath:',
|
|
1498
|
+
'_:UITableView,canEditRowAt:IndexPath->Bool',
|
|
1499
|
+
],
|
|
1500
|
+
commit: [
|
|
1501
|
+
'tableView:commitEditingStyle:forRowAtIndexPath:',
|
|
1502
|
+
'_:UITableView,commit:UITableViewCell.EditingStyle,forRowAt:IndexPath->Void',
|
|
1503
|
+
],
|
|
1504
|
+
}
|
|
1505
|
+
const delegate: Record<string, readonly [string, string]> = {
|
|
1506
|
+
willDisplay: [
|
|
1507
|
+
'tableView:willDisplayCell:forRowAtIndexPath:',
|
|
1508
|
+
'_:UITableView,willDisplay:UITableViewCell,forRowAt:IndexPath->Void',
|
|
1509
|
+
],
|
|
1510
|
+
didEndDisplaying: [
|
|
1511
|
+
'tableView:didEndDisplayingCell:forRowAtIndexPath:',
|
|
1512
|
+
'_:UITableView,didEndDisplaying:UITableViewCell,forRowAt:IndexPath->Void',
|
|
1513
|
+
],
|
|
1514
|
+
heightForRowAt: [
|
|
1515
|
+
'tableView:heightForRowAtIndexPath:',
|
|
1516
|
+
'_:UITableView,heightForRowAt:IndexPath->CGFloat',
|
|
1517
|
+
],
|
|
1518
|
+
estimatedHeightForRowAt: [
|
|
1519
|
+
'tableView:estimatedHeightForRowAtIndexPath:',
|
|
1520
|
+
'_:UITableView,estimatedHeightForRowAt:IndexPath->CGFloat',
|
|
1521
|
+
],
|
|
1522
|
+
heightForHeaderInSection: [
|
|
1523
|
+
'tableView:heightForHeaderInSection:',
|
|
1524
|
+
'_:UITableView,heightForHeaderInSection:Int->CGFloat',
|
|
1525
|
+
],
|
|
1526
|
+
heightForFooterInSection: [
|
|
1527
|
+
'tableView:heightForFooterInSection:',
|
|
1528
|
+
'_:UITableView,heightForFooterInSection:Int->CGFloat',
|
|
1529
|
+
],
|
|
1530
|
+
estimatedHeightForHeaderInSection: [
|
|
1531
|
+
'tableView:estimatedHeightForHeaderInSection:',
|
|
1532
|
+
'_:UITableView,estimatedHeightForHeaderInSection:Int->CGFloat',
|
|
1533
|
+
],
|
|
1534
|
+
estimatedHeightForFooterInSection: [
|
|
1535
|
+
'tableView:estimatedHeightForFooterInSection:',
|
|
1536
|
+
'_:UITableView,estimatedHeightForFooterInSection:Int->CGFloat',
|
|
1537
|
+
],
|
|
1538
|
+
viewForHeaderInSection: [
|
|
1539
|
+
'tableView:viewForHeaderInSection:',
|
|
1540
|
+
'_:UITableView,viewForHeaderInSection:Int->UIView?',
|
|
1541
|
+
],
|
|
1542
|
+
viewForFooterInSection: [
|
|
1543
|
+
'tableView:viewForFooterInSection:',
|
|
1544
|
+
'_:UITableView,viewForFooterInSection:Int->UIView?',
|
|
1545
|
+
],
|
|
1546
|
+
willDisplayHeaderView: [
|
|
1547
|
+
'tableView:willDisplayHeaderView:forSection:',
|
|
1548
|
+
'_:UITableView,willDisplayHeaderView:UIView,forSection:Int->Void',
|
|
1549
|
+
],
|
|
1550
|
+
willDisplayFooterView: [
|
|
1551
|
+
'tableView:willDisplayFooterView:forSection:',
|
|
1552
|
+
'_:UITableView,willDisplayFooterView:UIView,forSection:Int->Void',
|
|
1553
|
+
],
|
|
1554
|
+
didEndDisplayingHeaderView: [
|
|
1555
|
+
'tableView:didEndDisplayingHeaderView:forSection:',
|
|
1556
|
+
'_:UITableView,didEndDisplayingHeaderView:UIView,forSection:Int->Void',
|
|
1557
|
+
],
|
|
1558
|
+
didEndDisplayingFooterView: [
|
|
1559
|
+
'tableView:didEndDisplayingFooterView:forSection:',
|
|
1560
|
+
'_:UITableView,didEndDisplayingFooterView:UIView,forSection:Int->Void',
|
|
1561
|
+
],
|
|
1562
|
+
shouldHighlightRowAt: [
|
|
1563
|
+
'tableView:shouldHighlightRowAtIndexPath:',
|
|
1564
|
+
'_:UITableView,shouldHighlightRowAt:IndexPath->Bool',
|
|
1565
|
+
],
|
|
1566
|
+
didHighlightRowAt: [
|
|
1567
|
+
'tableView:didHighlightRowAtIndexPath:',
|
|
1568
|
+
'_:UITableView,didHighlightRowAt:IndexPath->Void',
|
|
1569
|
+
],
|
|
1570
|
+
didUnhighlightRowAt: [
|
|
1571
|
+
'tableView:didUnhighlightRowAtIndexPath:',
|
|
1572
|
+
'_:UITableView,didUnhighlightRowAt:IndexPath->Void',
|
|
1573
|
+
],
|
|
1574
|
+
willSelectRowAt: [
|
|
1575
|
+
'tableView:willSelectRowAtIndexPath:',
|
|
1576
|
+
'_:UITableView,willSelectRowAt:IndexPath->IndexPath?',
|
|
1577
|
+
],
|
|
1578
|
+
willDeselectRowAt: [
|
|
1579
|
+
'tableView:willDeselectRowAtIndexPath:',
|
|
1580
|
+
'_:UITableView,willDeselectRowAt:IndexPath->IndexPath?',
|
|
1581
|
+
],
|
|
1582
|
+
didSelectRowAt: [
|
|
1583
|
+
'tableView:didSelectRowAtIndexPath:',
|
|
1584
|
+
'_:UITableView,didSelectRowAt:IndexPath->Void',
|
|
1585
|
+
],
|
|
1586
|
+
didDeselectRowAt: [
|
|
1587
|
+
'tableView:didDeselectRowAtIndexPath:',
|
|
1588
|
+
'_:UITableView,didDeselectRowAt:IndexPath->Void',
|
|
1589
|
+
],
|
|
1590
|
+
accessoryButtonTappedForRowWith: [
|
|
1491
1591
|
'tableView:accessoryButtonTappedForRowWithIndexPath:',
|
|
1492
|
-
|
|
1493
|
-
|
|
1592
|
+
'_:UITableView,accessoryButtonTappedForRowWith:IndexPath->Void',
|
|
1593
|
+
],
|
|
1594
|
+
editingStyleForRowAt: [
|
|
1595
|
+
'tableView:editingStyleForRowAtIndexPath:',
|
|
1596
|
+
'_:UITableView,editingStyleForRowAt:IndexPath->UITableViewCell.EditingStyle',
|
|
1597
|
+
],
|
|
1598
|
+
leadingSwipeActionsConfigurationForRowAt: [
|
|
1494
1599
|
'tableView:leadingSwipeActionsConfigurationForRowAtIndexPath:',
|
|
1495
|
-
|
|
1600
|
+
'_:UITableView,leadingSwipeActionsConfigurationForRowAt:IndexPath->UISwipeActionsConfiguration?',
|
|
1601
|
+
],
|
|
1602
|
+
trailingSwipeActionsConfigurationForRowAt: [
|
|
1496
1603
|
'tableView:trailingSwipeActionsConfigurationForRowAtIndexPath:',
|
|
1497
|
-
|
|
1498
|
-
|
|
1604
|
+
'_:UITableView,trailingSwipeActionsConfigurationForRowAt:IndexPath->UISwipeActionsConfiguration?',
|
|
1605
|
+
],
|
|
1606
|
+
willBeginEditingRowAt: [
|
|
1607
|
+
'tableView:willBeginEditingRowAtIndexPath:',
|
|
1608
|
+
'_:UITableView,willBeginEditingRowAt:IndexPath->Void',
|
|
1609
|
+
],
|
|
1610
|
+
didEndEditingRowAt: [
|
|
1611
|
+
'tableView:didEndEditingRowAtIndexPath:',
|
|
1612
|
+
'_:UITableView,didEndEditingRowAt:IndexPath?->Void',
|
|
1613
|
+
],
|
|
1499
1614
|
}
|
|
1500
1615
|
const braces = [...code.matchAll(/[{}]/g)].map((match) => match.index)
|
|
1501
1616
|
const edits: [number, string][] = []
|
|
1502
1617
|
for (const owner of code.matchAll(/\b(?:class|extension)\s+([A-Za-z_]\w*)[^{}]*\{/g)) {
|
|
1503
1618
|
const conforms = conformances.get(owner[1]!)
|
|
1504
1619
|
if (!conforms) continue
|
|
1620
|
+
// direct generic conformances dispatch through their Swift witness;
|
|
1621
|
+
// inferred selector records apply to nongeneric class declarations.
|
|
1622
|
+
if (/^\s*</.test(owner[0].slice(owner[0].indexOf(owner[1]!) + owner[1]!.length)))
|
|
1623
|
+
continue
|
|
1505
1624
|
const selectors = {
|
|
1506
1625
|
...(conforms.has('UITableViewDataSource') ? dataSource : {}),
|
|
1507
1626
|
...(conforms.has('UITableViewDelegate') ? delegate : {}),
|
|
@@ -1527,19 +1646,35 @@ function lowerTableProtocolMethods(
|
|
|
1527
1646
|
if (/\b(?:override|static|class)\b|@(?:objc|ObjC|IBAction)\b/.test(attributes))
|
|
1528
1647
|
continue
|
|
1529
1648
|
let selector: string | undefined
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
/^func\s+numberOfSections\s*\(\s*in\s+\w+\s*:\s*(?:UIKit\.)?UITableView\s*\)/.test(
|
|
1649
|
+
const method =
|
|
1650
|
+
/^func\s+(tableView|numberOfSections)\s*\(([^()]*)\)\s*(?:->\s*([\w.?!]+|\(\s*\)))?\s*$/.exec(
|
|
1533
1651
|
signature,
|
|
1534
1652
|
)
|
|
1535
|
-
)
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1653
|
+
if (method) {
|
|
1654
|
+
const parameters = splitTopLevel(method[2]!)
|
|
1655
|
+
.map((parameter) => {
|
|
1656
|
+
const match = /^(?:(\w+)\s+)?(\w+)\s*:\s*([\w.?]+)\s*$/.exec(parameter)
|
|
1657
|
+
return match ? `${match[1] ?? match[2]}:${match[3]}` : ''
|
|
1658
|
+
})
|
|
1659
|
+
.join(',')
|
|
1660
|
+
.replace(/\b(?:UIKit|UIKitCore|Foundation|CoreGraphics|Swift)\./g, '')
|
|
1661
|
+
const result = (method[3] ?? 'Void')
|
|
1662
|
+
.replace(/\(\s*\)/, 'Void')
|
|
1663
|
+
.replaceAll('!', '?')
|
|
1664
|
+
.replace(/\b(?:UIKit|UIKitCore|Foundation|CoreGraphics|Swift)\./g, '')
|
|
1665
|
+
if (method[1] === 'numberOfSections') {
|
|
1666
|
+
if (
|
|
1667
|
+
conforms.has('UITableViewDataSource') &&
|
|
1668
|
+
parameters === 'in:UITableView' &&
|
|
1669
|
+
result === 'Int'
|
|
1541
1670
|
)
|
|
1542
|
-
|
|
1671
|
+
selector = 'numberOfSectionsInTableView:'
|
|
1672
|
+
} else {
|
|
1673
|
+
const label = /^_:UITableView,(\w+):/.exec(parameters)?.[1]
|
|
1674
|
+
const requirement = label ? selectors[label] : undefined
|
|
1675
|
+
if (requirement && `${parameters}->${result}` === requirement[1])
|
|
1676
|
+
selector = requirement[0]
|
|
1677
|
+
}
|
|
1543
1678
|
}
|
|
1544
1679
|
if (selector)
|
|
1545
1680
|
edits.push([
|