Skip to content

Commit 3803e0c

Browse files
committed
chore: convert string to numeric props
1 parent 9a27bb7 commit 3803e0c

26 files changed

+423
-240
lines changed

packages/qwik/src/core/api.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ export class _EffectData {
231231
data: NodePropData;
232232
}
233233

234+
// Warning: (ae-forgotten-export) The symbol "NumericPropKey" needs to be exported by the entry point index.d.ts
235+
//
234236
// @internal (undocumented)
235237
export type _ElementVNode = [
236238
_VNodeFlags.Element,
@@ -247,7 +249,7 @@ _VNode | null | undefined,
247249
Element,
248250
//////////////////// 6 - Element
249251
string | undefined,
250-
(string | null)[]
252+
(NumericPropKey | string | null)[]
251253
] & {
252254
__brand__: 'ElementVNode';
253255
};
@@ -416,11 +418,11 @@ export interface JSXNode<T extends string | FunctionComponent | unknown = unknow
416418
// @internal
417419
export interface JSXNodeInternal<T extends string | FunctionComponent | unknown = unknown> extends JSXNode<T> {
418420
// (undocumented)
419-
constProps: Record<any, unknown> | null;
421+
constProps: Record<NumericPropKey, unknown> | null;
420422
// (undocumented)
421423
flags: number;
422424
// (undocumented)
423-
varProps: Record<any, unknown>;
425+
varProps: Record<NumericPropKey, unknown>;
424426
}
425427

426428
// @public
@@ -1712,7 +1714,7 @@ _VNode | null,
17121714
_VNode | null,
17131715
/////////////// 4 - First child
17141716
_VNode | null,
1715-
(string | null | boolean)[]
1717+
(NumericPropKey | string | null | boolean)[]
17161718
] & {
17171719
__brand__: 'FragmentNode' & 'HostElement';
17181720
};

packages/qwik/src/core/client/dom-container.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
QLocaleAttr,
3333
} from '../shared/utils/markers';
3434
import { isPromise } from '../shared/utils/promises';
35-
import { isSlotProp } from '../shared/utils/prop';
35+
import { getPropId, isSlotProp, type NumericPropKey } from '../shared/utils/prop';
3636
import { qDev } from '../shared/utils/qdev';
3737
import {
3838
convertScopedStyleIdsToArray,
@@ -228,14 +228,14 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
228228
if (!ctx) {
229229
this.setHostProp(host, QCtxAttr, (ctx = []));
230230
}
231-
mapArray_set(ctx, context.id, value, 0);
231+
mapArray_set(ctx, getPropId(context.id), value, 0);
232232
}
233233

234234
resolveContext<T>(host: HostElement, contextId: ContextId<T>): T | undefined {
235235
while (host) {
236236
const ctx = this.getHostProp<Array<string | unknown>>(host, QCtxAttr);
237237
if (ctx) {
238-
const value = mapArray_get(ctx, contextId.id, 0) as T;
238+
const value = mapArray_get(ctx, getPropId(contextId.id), 0) as T;
239239
if (value) {
240240
return value as T;
241241
}
@@ -319,7 +319,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
319319
vNode[VNodeProps.flags] |= VNodeFlags.Resolved;
320320
const props = vnode_getProps(vNode);
321321
for (let i = 0; i < props.length; i = i + 2) {
322-
const prop = props[i] as string;
322+
const prop = props[i] as NumericPropKey;
323323
if (isSlotProp(prop)) {
324324
const value = props[i + 1];
325325
if (typeof value == 'string') {

packages/qwik/src/core/client/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import type { QRL } from '../shared/qrl/qrl.public';
44
import type { Container } from '../shared/types';
5+
import type { NumericPropKey } from '../shared/utils/prop';
56
import type { VNodeJournal } from './vnode';
67

7-
export type ClientAttrKey = string;
8-
export type ClientAttrValue = string | null;
9-
export type ClientAttrs = Array<ClientAttrKey | ClientAttrValue>;
8+
export type ClientAttrValue = unknown | null;
9+
export type ClientAttrs = Array<NumericPropKey | ClientAttrValue>;
1010

1111
/** @internal */
1212
export interface ClientContainer extends Container {
@@ -128,7 +128,7 @@ export type ElementVNode = [
128128
Element, //////////////////// 6 - Element
129129
string | undefined, ///////// 7 - tag
130130
/// Props
131-
(string | null)[], /////// 8 - attrs
131+
(NumericPropKey | string | null)[], /////// 8 - attrs
132132
] & { __brand__: 'ElementVNode' };
133133

134134
export const enum TextVNodeProps {
@@ -165,7 +165,7 @@ export type VirtualVNode = [
165165
VNode | null, /////////////// 4 - First child
166166
VNode | null, /////////////// 5 - Last child
167167
/// Props
168-
(string | null | boolean)[], /////// 6 - attrs
168+
(NumericPropKey | string | null | boolean)[], /////// 6 - attrs
169169
] & { __brand__: 'FragmentNode' & 'HostElement' };
170170

171171
/** @internal */

packages/qwik/src/core/client/util-mapArray.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { assertTrue } from '../shared/error/assert';
2+
import type { NumericPropKey } from '../shared/utils/prop';
23

3-
export const mapApp_findIndx = <T>(array: (T | null)[], key: string, start: number): number => {
4+
export const mapApp_findIndx = <T>(
5+
array: (T | null)[],
6+
key: NumericPropKey,
7+
start: number = 0
8+
): number => {
49
assertTrue(start % 2 === 0, 'Expecting even number.');
510
let bottom = (start as number) >> 1;
611
let top = (array.length - 2) >> 1;
712
while (bottom <= top) {
813
const mid = bottom + ((top - bottom) >> 1);
9-
const midKey = array[mid << 1] as string;
14+
const midKey = array[mid << 1] as NumericPropKey;
1015
if (midKey === key) {
1116
return mid << 1;
1217
}
@@ -21,23 +26,27 @@ export const mapApp_findIndx = <T>(array: (T | null)[], key: string, start: numb
2126

2227
export const mapArray_set = <T>(
2328
array: (T | null)[],
24-
key: string,
25-
value: T | null,
26-
start: number
29+
key: NumericPropKey,
30+
value: unknown | null,
31+
start: number = 0
2732
) => {
2833
const indx = mapApp_findIndx(array, key, start);
2934
if (indx >= 0) {
3035
if (value == null) {
3136
array.splice(indx, 2);
3237
} else {
33-
array[indx + 1] = value;
38+
array[indx + 1] = value as T;
3439
}
3540
} else if (value != null) {
36-
array.splice(indx ^ -1, 0, key as any, value);
41+
array.splice(indx ^ -1, 0, key as any, value as T);
3742
}
3843
};
3944

40-
export const mapApp_remove = <T>(array: (T | null)[], key: string, start: number): T | null => {
45+
export const mapApp_remove = <T>(
46+
array: (T | null)[],
47+
key: NumericPropKey,
48+
start: number = 0
49+
): T | null => {
4150
const indx = mapApp_findIndx(array, key, start);
4251
let value: T | null = null;
4352
if (indx >= 0) {
@@ -48,7 +57,11 @@ export const mapApp_remove = <T>(array: (T | null)[], key: string, start: number
4857
return value;
4958
};
5059

51-
export const mapArray_get = <T>(array: (T | null)[], key: string, start: number): T | null => {
60+
export const mapArray_get = <T>(
61+
array: (T | null)[],
62+
key: NumericPropKey,
63+
start: number = 0
64+
): T | null => {
5265
const indx = mapApp_findIndx(array, key, start);
5366
if (indx >= 0) {
5467
return array[indx + 1] as T | null;
@@ -57,6 +70,10 @@ export const mapArray_get = <T>(array: (T | null)[], key: string, start: number)
5770
}
5871
};
5972

60-
export const mapArray_has = <T>(array: (T | null)[], key: string, start: number): boolean => {
73+
export const mapArray_has = <T>(
74+
array: (T | null)[],
75+
key: NumericPropKey,
76+
start: number = 0
77+
): boolean => {
6178
return mapApp_findIndx(array, key, start) >= 0;
6279
};

0 commit comments

Comments
 (0)