bippy 0.6.1-dev.61475ed → 0.6.1-dev.b88fcb4
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/LICENSE +1 -1
- package/README.md +32 -48
- package/dist/core.cjs +1 -1
- package/dist/core.d.cts +45 -59
- package/dist/core.d.ts +45 -59
- package/dist/core.js +1 -1
- package/dist/core2.cjs +9 -0
- package/dist/core2.d.cts +11 -3
- package/dist/core2.d.ts +11 -3
- package/dist/core2.js +9 -0
- package/dist/errors.d.cts +465 -0
- package/dist/errors.d.ts +465 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.iife.js +1 -1
- package/dist/index.js +1 -1
- package/dist/install-hook-only.cjs +1 -1
- package/dist/install-hook-only.d.cts +9 -1
- package/dist/install-hook-only.d.ts +9 -1
- package/dist/install-hook-only.iife.js +1 -1
- package/dist/rdt-hook.cjs +1 -1
- package/dist/rdt-hook.js +1 -1
- package/dist/source.cjs +14 -4
- package/dist/source.d.cts +27 -9
- package/dist/source.d.ts +27 -9
- package/dist/source.js +14 -4
- package/package.json +22 -16
- package/src/core.ts +412 -316
- package/src/errors.ts +99 -0
- package/src/rdt-hook.ts +163 -151
- package/src/react-internals/generated/react-work-tags.ts +314 -0
- package/src/react-internals/index.ts +67 -0
- package/src/react-internals/semver.ts +78 -0
- package/src/react-internals/types.ts +269 -0
- package/src/source/constants.ts +1 -1
- package/src/source/error-stack.ts +11 -0
- package/src/source/get-display-name-from-source.ts +1 -1
- package/src/source/get-source.ts +4 -3
- package/src/source/index.ts +9 -1
- package/src/source/inspect-hooks.ts +199 -165
- package/src/source/owner-stack.ts +87 -113
- package/src/source/parse-debug-stack.ts +4 -4
- package/src/source/parse-hook-names.ts +1 -1
- package/src/source/parse-stack.ts +1 -1
- package/src/source/symbolication.ts +476 -88
- package/dist/get-source.cjs +0 -19
- package/dist/get-source.js +0 -19
- package/dist/react-refresh.cjs +0 -9
- package/dist/react-refresh.d.cts +0 -66
- package/dist/react-refresh.d.ts +0 -66
- package/dist/react-refresh.js +0 -9
- package/dist/unsubscribe.d.cts +0 -298
- package/dist/unsubscribe.d.ts +0 -298
- package/src/react-refresh/constants.ts +0 -9
- package/src/react-refresh/detect-hmr-transport.ts +0 -33
- package/src/react-refresh/index.ts +0 -173
- package/src/react-refresh/metro-hmr-transport.ts +0 -188
- package/src/react-refresh/next-webpack-hmr-transport.ts +0 -72
- package/src/react-refresh/normalize-hmr-file-path.ts +0 -24
- package/src/react-refresh/types.ts +0 -7
- package/src/react-refresh/vite-hmr-transport.ts +0 -116
- package/src/types.ts +0 -438
- package/src/unsubscribe.ts +0 -17
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { compareSemver } from "../semver.js";
|
|
2
|
+
|
|
3
|
+
export const ReactBuildType = {
|
|
4
|
+
Development: 1,
|
|
5
|
+
Production: 0,
|
|
6
|
+
} as const;
|
|
7
|
+
|
|
8
|
+
export const ReactFiberFlags = {
|
|
9
|
+
ChildDeletion: 16,
|
|
10
|
+
Cloned: 8,
|
|
11
|
+
ContentReset: 32,
|
|
12
|
+
Hydrating: 4096,
|
|
13
|
+
PerformedWork: 1,
|
|
14
|
+
Placement: 2,
|
|
15
|
+
Snapshot: 1024,
|
|
16
|
+
Update: 4,
|
|
17
|
+
Visibility: 8192,
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
export const ReactSymbols = {
|
|
21
|
+
CONCURRENT_MODE_NUMBER: 60111,
|
|
22
|
+
CONCURRENT_MODE_SYMBOL_DESCRIPTION: "react.concurrent_mode",
|
|
23
|
+
CONCURRENT_MODE_SYMBOL_STRING: "Symbol(react.concurrent_mode)",
|
|
24
|
+
DEPRECATED_ASYNC_MODE_SYMBOL_DESCRIPTION: "react.async_mode",
|
|
25
|
+
DEPRECATED_ASYNC_MODE_SYMBOL_STRING: "Symbol(react.async_mode)",
|
|
26
|
+
ELEMENT_SYMBOL_STRING: "Symbol(react.transitional.element)",
|
|
27
|
+
LEGACY_ELEMENT_SYMBOL_STRING: "Symbol(react.element)",
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
export interface ReactWorkTagMap {
|
|
31
|
+
ActivityComponent: number;
|
|
32
|
+
CacheComponent: number;
|
|
33
|
+
ClassComponent: number;
|
|
34
|
+
ContextConsumer: number;
|
|
35
|
+
ContextProvider: number;
|
|
36
|
+
CoroutineComponent: number;
|
|
37
|
+
CoroutineHandlerPhase: number;
|
|
38
|
+
DehydratedSuspenseComponent: number;
|
|
39
|
+
ForwardRef: number;
|
|
40
|
+
Fragment: number;
|
|
41
|
+
FunctionComponent: number;
|
|
42
|
+
HostComponent: number;
|
|
43
|
+
HostHoistable: number;
|
|
44
|
+
HostPortal: number;
|
|
45
|
+
HostRoot: number;
|
|
46
|
+
HostSingleton: number;
|
|
47
|
+
HostText: number;
|
|
48
|
+
IncompleteClassComponent: number;
|
|
49
|
+
IncompleteFunctionComponent: number;
|
|
50
|
+
IndeterminateComponent: number;
|
|
51
|
+
LazyComponent: number;
|
|
52
|
+
LegacyHiddenComponent: number;
|
|
53
|
+
MemoComponent: number;
|
|
54
|
+
Mode: number;
|
|
55
|
+
OffscreenComponent: number;
|
|
56
|
+
Profiler: number;
|
|
57
|
+
ScopeComponent: number;
|
|
58
|
+
SimpleMemoComponent: number;
|
|
59
|
+
SuspenseComponent: number;
|
|
60
|
+
SuspenseListComponent: number;
|
|
61
|
+
Throw: number;
|
|
62
|
+
TracingMarkerComponent: number;
|
|
63
|
+
ViewTransitionComponent: number;
|
|
64
|
+
YieldComponent: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const defineReactWorkTags = <const VersionedWorkTags extends Record<string, ReactWorkTagMap>>(
|
|
68
|
+
workTags: VersionedWorkTags,
|
|
69
|
+
): VersionedWorkTags => workTags;
|
|
70
|
+
|
|
71
|
+
const reactWorkTagsByVersion = defineReactWorkTags({
|
|
72
|
+
"16.0.0": {
|
|
73
|
+
ActivityComponent: -1,
|
|
74
|
+
CacheComponent: -1,
|
|
75
|
+
ClassComponent: 2,
|
|
76
|
+
ContextConsumer: 12,
|
|
77
|
+
ContextProvider: 13,
|
|
78
|
+
CoroutineComponent: 7,
|
|
79
|
+
CoroutineHandlerPhase: 8,
|
|
80
|
+
DehydratedSuspenseComponent: -1,
|
|
81
|
+
ForwardRef: 14,
|
|
82
|
+
Fragment: 10,
|
|
83
|
+
FunctionComponent: 1,
|
|
84
|
+
HostComponent: 5,
|
|
85
|
+
HostHoistable: -1,
|
|
86
|
+
HostPortal: 4,
|
|
87
|
+
HostRoot: 3,
|
|
88
|
+
HostSingleton: -1,
|
|
89
|
+
HostText: 6,
|
|
90
|
+
IncompleteClassComponent: -1,
|
|
91
|
+
IncompleteFunctionComponent: -1,
|
|
92
|
+
IndeterminateComponent: 0,
|
|
93
|
+
LazyComponent: -1,
|
|
94
|
+
LegacyHiddenComponent: -1,
|
|
95
|
+
MemoComponent: -1,
|
|
96
|
+
Mode: 11,
|
|
97
|
+
OffscreenComponent: -1,
|
|
98
|
+
Profiler: 15,
|
|
99
|
+
ScopeComponent: -1,
|
|
100
|
+
SimpleMemoComponent: -1,
|
|
101
|
+
SuspenseComponent: 16,
|
|
102
|
+
SuspenseListComponent: -1,
|
|
103
|
+
Throw: -1,
|
|
104
|
+
TracingMarkerComponent: -1,
|
|
105
|
+
ViewTransitionComponent: -1,
|
|
106
|
+
YieldComponent: 9,
|
|
107
|
+
},
|
|
108
|
+
"16.4.3-alpha": {
|
|
109
|
+
ActivityComponent: -1,
|
|
110
|
+
CacheComponent: -1,
|
|
111
|
+
ClassComponent: 2,
|
|
112
|
+
ContextConsumer: 11,
|
|
113
|
+
ContextProvider: 12,
|
|
114
|
+
CoroutineComponent: -1,
|
|
115
|
+
CoroutineHandlerPhase: -1,
|
|
116
|
+
DehydratedSuspenseComponent: -1,
|
|
117
|
+
ForwardRef: 13,
|
|
118
|
+
Fragment: 9,
|
|
119
|
+
FunctionComponent: 0,
|
|
120
|
+
HostComponent: 7,
|
|
121
|
+
HostHoistable: -1,
|
|
122
|
+
HostPortal: 6,
|
|
123
|
+
HostRoot: 5,
|
|
124
|
+
HostSingleton: -1,
|
|
125
|
+
HostText: 8,
|
|
126
|
+
IncompleteClassComponent: -1,
|
|
127
|
+
IncompleteFunctionComponent: -1,
|
|
128
|
+
IndeterminateComponent: 4,
|
|
129
|
+
LazyComponent: -1,
|
|
130
|
+
LegacyHiddenComponent: -1,
|
|
131
|
+
MemoComponent: -1,
|
|
132
|
+
Mode: 10,
|
|
133
|
+
OffscreenComponent: -1,
|
|
134
|
+
Profiler: 15,
|
|
135
|
+
ScopeComponent: -1,
|
|
136
|
+
SimpleMemoComponent: -1,
|
|
137
|
+
SuspenseComponent: 16,
|
|
138
|
+
SuspenseListComponent: -1,
|
|
139
|
+
Throw: -1,
|
|
140
|
+
TracingMarkerComponent: -1,
|
|
141
|
+
ViewTransitionComponent: -1,
|
|
142
|
+
YieldComponent: -1,
|
|
143
|
+
},
|
|
144
|
+
"16.6.0-beta.0": {
|
|
145
|
+
ActivityComponent: -1,
|
|
146
|
+
CacheComponent: -1,
|
|
147
|
+
ClassComponent: 1,
|
|
148
|
+
ContextConsumer: 9,
|
|
149
|
+
ContextProvider: 10,
|
|
150
|
+
CoroutineComponent: -1,
|
|
151
|
+
CoroutineHandlerPhase: -1,
|
|
152
|
+
DehydratedSuspenseComponent: 18,
|
|
153
|
+
ForwardRef: 11,
|
|
154
|
+
Fragment: 7,
|
|
155
|
+
FunctionComponent: 0,
|
|
156
|
+
HostComponent: 5,
|
|
157
|
+
HostHoistable: -1,
|
|
158
|
+
HostPortal: 4,
|
|
159
|
+
HostRoot: 3,
|
|
160
|
+
HostSingleton: -1,
|
|
161
|
+
HostText: 6,
|
|
162
|
+
IncompleteClassComponent: 17,
|
|
163
|
+
IncompleteFunctionComponent: -1,
|
|
164
|
+
IndeterminateComponent: 2,
|
|
165
|
+
LazyComponent: 16,
|
|
166
|
+
LegacyHiddenComponent: -1,
|
|
167
|
+
MemoComponent: 14,
|
|
168
|
+
Mode: 8,
|
|
169
|
+
OffscreenComponent: -1,
|
|
170
|
+
Profiler: 12,
|
|
171
|
+
ScopeComponent: -1,
|
|
172
|
+
SimpleMemoComponent: 15,
|
|
173
|
+
SuspenseComponent: 13,
|
|
174
|
+
SuspenseListComponent: 19,
|
|
175
|
+
Throw: -1,
|
|
176
|
+
TracingMarkerComponent: -1,
|
|
177
|
+
ViewTransitionComponent: -1,
|
|
178
|
+
YieldComponent: -1,
|
|
179
|
+
},
|
|
180
|
+
"17.0.0-alpha": {
|
|
181
|
+
ActivityComponent: -1,
|
|
182
|
+
CacheComponent: -1,
|
|
183
|
+
ClassComponent: 1,
|
|
184
|
+
ContextConsumer: 9,
|
|
185
|
+
ContextProvider: 10,
|
|
186
|
+
CoroutineComponent: -1,
|
|
187
|
+
CoroutineHandlerPhase: -1,
|
|
188
|
+
DehydratedSuspenseComponent: 18,
|
|
189
|
+
ForwardRef: 11,
|
|
190
|
+
Fragment: 7,
|
|
191
|
+
FunctionComponent: 0,
|
|
192
|
+
HostComponent: 5,
|
|
193
|
+
HostHoistable: -1,
|
|
194
|
+
HostPortal: 4,
|
|
195
|
+
HostRoot: 3,
|
|
196
|
+
HostSingleton: -1,
|
|
197
|
+
HostText: 6,
|
|
198
|
+
IncompleteClassComponent: 17,
|
|
199
|
+
IncompleteFunctionComponent: -1,
|
|
200
|
+
IndeterminateComponent: 2,
|
|
201
|
+
LazyComponent: 16,
|
|
202
|
+
LegacyHiddenComponent: 24,
|
|
203
|
+
MemoComponent: 14,
|
|
204
|
+
Mode: 8,
|
|
205
|
+
OffscreenComponent: 23,
|
|
206
|
+
Profiler: 12,
|
|
207
|
+
ScopeComponent: 21,
|
|
208
|
+
SimpleMemoComponent: 15,
|
|
209
|
+
SuspenseComponent: 13,
|
|
210
|
+
SuspenseListComponent: 19,
|
|
211
|
+
Throw: -1,
|
|
212
|
+
TracingMarkerComponent: -1,
|
|
213
|
+
ViewTransitionComponent: -1,
|
|
214
|
+
YieldComponent: -1,
|
|
215
|
+
},
|
|
216
|
+
"17.0.2": {
|
|
217
|
+
ActivityComponent: 31,
|
|
218
|
+
CacheComponent: 24,
|
|
219
|
+
ClassComponent: 1,
|
|
220
|
+
ContextConsumer: 9,
|
|
221
|
+
ContextProvider: 10,
|
|
222
|
+
CoroutineComponent: -1,
|
|
223
|
+
CoroutineHandlerPhase: -1,
|
|
224
|
+
DehydratedSuspenseComponent: 18,
|
|
225
|
+
ForwardRef: 11,
|
|
226
|
+
Fragment: 7,
|
|
227
|
+
FunctionComponent: 0,
|
|
228
|
+
HostComponent: 5,
|
|
229
|
+
HostHoistable: 26,
|
|
230
|
+
HostPortal: 4,
|
|
231
|
+
HostRoot: 3,
|
|
232
|
+
HostSingleton: 27,
|
|
233
|
+
HostText: 6,
|
|
234
|
+
IncompleteClassComponent: 17,
|
|
235
|
+
IncompleteFunctionComponent: 28,
|
|
236
|
+
IndeterminateComponent: 2,
|
|
237
|
+
LazyComponent: 16,
|
|
238
|
+
LegacyHiddenComponent: 23,
|
|
239
|
+
MemoComponent: 14,
|
|
240
|
+
Mode: 8,
|
|
241
|
+
OffscreenComponent: 22,
|
|
242
|
+
Profiler: 12,
|
|
243
|
+
ScopeComponent: 21,
|
|
244
|
+
SimpleMemoComponent: 15,
|
|
245
|
+
SuspenseComponent: 13,
|
|
246
|
+
SuspenseListComponent: 19,
|
|
247
|
+
Throw: 29,
|
|
248
|
+
TracingMarkerComponent: 25,
|
|
249
|
+
ViewTransitionComponent: 30,
|
|
250
|
+
YieldComponent: -1,
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
export type ReactWorkTagVersion = keyof typeof reactWorkTagsByVersion;
|
|
255
|
+
|
|
256
|
+
export interface GetReactWorkTags {
|
|
257
|
+
<Version extends ReactWorkTagVersion>(
|
|
258
|
+
reactVersion: Version,
|
|
259
|
+
): Readonly<(typeof reactWorkTagsByVersion)[Version]>;
|
|
260
|
+
(reactVersion: string): Readonly<ReactWorkTagMap>;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export type ReactWorkTag = Exclude<
|
|
264
|
+
(typeof reactWorkTagsByVersion)[ReactWorkTagVersion][keyof ReactWorkTagMap],
|
|
265
|
+
-1
|
|
266
|
+
>;
|
|
267
|
+
|
|
268
|
+
export type HostWorkTag = Exclude<
|
|
269
|
+
| (typeof reactWorkTagsByVersion)[ReactWorkTagVersion]["HostComponent"]
|
|
270
|
+
| (typeof reactWorkTagsByVersion)[ReactWorkTagVersion]["HostHoistable"]
|
|
271
|
+
| (typeof reactWorkTagsByVersion)[ReactWorkTagVersion]["HostSingleton"]
|
|
272
|
+
| (typeof reactWorkTagsByVersion)[ReactWorkTagVersion]["HostText"],
|
|
273
|
+
-1
|
|
274
|
+
>;
|
|
275
|
+
|
|
276
|
+
interface ReactWorkTagRange {
|
|
277
|
+
isMinimumExcluded: boolean;
|
|
278
|
+
minimumVersion: string;
|
|
279
|
+
workTags: Readonly<ReactWorkTagMap>;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const reactWorkTagRanges: ReactWorkTagRange[] = [
|
|
283
|
+
{
|
|
284
|
+
isMinimumExcluded: true,
|
|
285
|
+
minimumVersion: "17.0.1",
|
|
286
|
+
workTags: reactWorkTagsByVersion["17.0.2"],
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
isMinimumExcluded: false,
|
|
290
|
+
minimumVersion: "17.0.0-alpha",
|
|
291
|
+
workTags: reactWorkTagsByVersion["17.0.0-alpha"],
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
isMinimumExcluded: false,
|
|
295
|
+
minimumVersion: "16.6.0-beta.0",
|
|
296
|
+
workTags: reactWorkTagsByVersion["16.6.0-beta.0"],
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
isMinimumExcluded: false,
|
|
300
|
+
minimumVersion: "16.4.3-alpha",
|
|
301
|
+
workTags: reactWorkTagsByVersion["16.4.3-alpha"],
|
|
302
|
+
},
|
|
303
|
+
];
|
|
304
|
+
|
|
305
|
+
export const getReactWorkTags: GetReactWorkTags = (reactVersion: string) => {
|
|
306
|
+
for (const range of reactWorkTagRanges) {
|
|
307
|
+
const comparison = compareSemver(reactVersion, range.minimumVersion);
|
|
308
|
+
if (comparison === null) return reactWorkTagsByVersion["17.0.2"];
|
|
309
|
+
if (comparison === 1 || (comparison === 0 && !range.isMinimumExcluded)) {
|
|
310
|
+
return range.workTags;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return reactWorkTagsByVersion["16.0.0"];
|
|
314
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getReactWorkTags, ReactFiberFlags } from "./generated/react-work-tags.js";
|
|
2
|
+
import type { ReactWorkTagMap } from "./generated/react-work-tags.js";
|
|
3
|
+
import { compareSemver } from "./semver.js";
|
|
4
|
+
import type { Fiber, ReactRenderer } from "./types.js";
|
|
5
|
+
|
|
6
|
+
export { compareSemver } from "./semver.js";
|
|
7
|
+
export {
|
|
8
|
+
getReactWorkTags,
|
|
9
|
+
ReactBuildType,
|
|
10
|
+
ReactFiberFlags,
|
|
11
|
+
ReactSymbols,
|
|
12
|
+
} from "./generated/react-work-tags.js";
|
|
13
|
+
export type {
|
|
14
|
+
HostWorkTag,
|
|
15
|
+
ReactWorkTag,
|
|
16
|
+
ReactWorkTagMap,
|
|
17
|
+
ReactWorkTagVersion,
|
|
18
|
+
} from "./generated/react-work-tags.js";
|
|
19
|
+
export * from "./types.js";
|
|
20
|
+
|
|
21
|
+
const defaultReactWorkTags = getReactWorkTags("");
|
|
22
|
+
const fiberReactWorkTags = new WeakMap<Fiber, Readonly<ReactWorkTagMap>>();
|
|
23
|
+
|
|
24
|
+
export const getReactWorkTagsForRenderer = (
|
|
25
|
+
renderer?: ReactRenderer | null,
|
|
26
|
+
): Readonly<ReactWorkTagMap> => {
|
|
27
|
+
const reconcilerVersion = renderer?.reconcilerVersion;
|
|
28
|
+
if (reconcilerVersion && compareSemver(reconcilerVersion, reconcilerVersion) === 0) {
|
|
29
|
+
return getReactWorkTags(reconcilerVersion);
|
|
30
|
+
}
|
|
31
|
+
return getReactWorkTags(renderer?.version ?? "");
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const setReactWorkTagsForFiber = (fiber: Fiber, renderer?: ReactRenderer): void => {
|
|
35
|
+
const workTags = getReactWorkTagsForRenderer(renderer);
|
|
36
|
+
fiberReactWorkTags.set(fiber, workTags);
|
|
37
|
+
if (fiber.alternate) fiberReactWorkTags.set(fiber.alternate, workTags);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const getReactWorkTagsForFiber = (fiber: Fiber): Readonly<ReactWorkTagMap> => {
|
|
41
|
+
const cachedWorkTags = fiberReactWorkTags.get(fiber);
|
|
42
|
+
if (cachedWorkTags) return cachedWorkTags;
|
|
43
|
+
|
|
44
|
+
const traversedFibers: Fiber[] = [fiber];
|
|
45
|
+
let rootFiber = fiber;
|
|
46
|
+
while (rootFiber.return) {
|
|
47
|
+
rootFiber = rootFiber.return;
|
|
48
|
+
traversedFibers.push(rootFiber);
|
|
49
|
+
}
|
|
50
|
+
const workTags = fiberReactWorkTags.get(rootFiber) ?? defaultReactWorkTags;
|
|
51
|
+
for (const traversedFiber of traversedFibers) {
|
|
52
|
+
fiberReactWorkTags.set(traversedFiber, workTags);
|
|
53
|
+
if (traversedFiber.alternate) {
|
|
54
|
+
fiberReactWorkTags.set(traversedFiber.alternate, workTags);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return workTags;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const MutationMask =
|
|
61
|
+
ReactFiberFlags.Placement |
|
|
62
|
+
ReactFiberFlags.Update |
|
|
63
|
+
ReactFiberFlags.ChildDeletion |
|
|
64
|
+
ReactFiberFlags.ContentReset |
|
|
65
|
+
ReactFiberFlags.Hydrating |
|
|
66
|
+
ReactFiberFlags.Visibility |
|
|
67
|
+
ReactFiberFlags.Snapshot;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
interface SemanticVersion {
|
|
2
|
+
major: string;
|
|
3
|
+
minor: string;
|
|
4
|
+
patch: string;
|
|
5
|
+
prerelease: string[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const SEMVER_PATTERN =
|
|
9
|
+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
10
|
+
const NUMERIC_IDENTIFIER_PATTERN = /^\d+$/;
|
|
11
|
+
|
|
12
|
+
const parseSemver = (version: string): SemanticVersion | null => {
|
|
13
|
+
const match = SEMVER_PATTERN.exec(version);
|
|
14
|
+
if (!match) return null;
|
|
15
|
+
const prerelease = match[4]?.split(".") ?? [];
|
|
16
|
+
if (
|
|
17
|
+
prerelease.some(
|
|
18
|
+
(identifier) =>
|
|
19
|
+
NUMERIC_IDENTIFIER_PATTERN.test(identifier) &&
|
|
20
|
+
identifier.length > 1 &&
|
|
21
|
+
identifier.startsWith("0"),
|
|
22
|
+
)
|
|
23
|
+
) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
major: match[1],
|
|
28
|
+
minor: match[2],
|
|
29
|
+
patch: match[3],
|
|
30
|
+
prerelease,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const compareNumericIdentifiers = (left: string, right: string): -1 | 0 | 1 => {
|
|
35
|
+
if (left.length !== right.length) return left.length < right.length ? -1 : 1;
|
|
36
|
+
if (left === right) return 0;
|
|
37
|
+
return left < right ? -1 : 1;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const comparePrereleaseIdentifiers = (left: string, right: string): -1 | 0 | 1 => {
|
|
41
|
+
const isLeftNumeric = NUMERIC_IDENTIFIER_PATTERN.test(left);
|
|
42
|
+
const isRightNumeric = NUMERIC_IDENTIFIER_PATTERN.test(right);
|
|
43
|
+
if (isLeftNumeric && isRightNumeric) return compareNumericIdentifiers(left, right);
|
|
44
|
+
if (isLeftNumeric !== isRightNumeric) return isLeftNumeric ? -1 : 1;
|
|
45
|
+
if (left === right) return 0;
|
|
46
|
+
return left < right ? -1 : 1;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const comparePrerelease = (left: string[], right: string[]): -1 | 0 | 1 => {
|
|
50
|
+
if (left.length === 0 || right.length === 0) {
|
|
51
|
+
if (left.length === right.length) return 0;
|
|
52
|
+
return left.length === 0 ? 1 : -1;
|
|
53
|
+
}
|
|
54
|
+
const identifierCount = Math.max(left.length, right.length);
|
|
55
|
+
for (let identifierIndex = 0; identifierIndex < identifierCount; identifierIndex++) {
|
|
56
|
+
const leftIdentifier = left[identifierIndex];
|
|
57
|
+
const rightIdentifier = right[identifierIndex];
|
|
58
|
+
if (leftIdentifier === undefined || rightIdentifier === undefined) {
|
|
59
|
+
return leftIdentifier === undefined ? -1 : 1;
|
|
60
|
+
}
|
|
61
|
+
const comparison = comparePrereleaseIdentifiers(leftIdentifier, rightIdentifier);
|
|
62
|
+
if (comparison !== 0) return comparison;
|
|
63
|
+
}
|
|
64
|
+
return 0;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const compareSemver = (leftVersion: string, rightVersion: string): -1 | 0 | 1 | null => {
|
|
68
|
+
const left = parseSemver(leftVersion);
|
|
69
|
+
const right = parseSemver(rightVersion);
|
|
70
|
+
if (!left || !right) return null;
|
|
71
|
+
const majorComparison = compareNumericIdentifiers(left.major, right.major);
|
|
72
|
+
if (majorComparison !== 0) return majorComparison;
|
|
73
|
+
const minorComparison = compareNumericIdentifiers(left.minor, right.minor);
|
|
74
|
+
if (minorComparison !== 0) return minorComparison;
|
|
75
|
+
const patchComparison = compareNumericIdentifiers(left.patch, right.patch);
|
|
76
|
+
if (patchComparison !== 0) return patchComparison;
|
|
77
|
+
return comparePrerelease(left.prerelease, right.prerelease);
|
|
78
|
+
};
|