Skip to content

Commit eb3e1cc

Browse files
authored
Merge pull request #7381 from QwikDev/v2-small-cleanup
chore: cleanup and fix types
2 parents 66037b5 + 9e19b34 commit eb3e1cc

File tree

13 files changed

+23
-123
lines changed

13 files changed

+23
-123
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ export interface QDocument extends Document {
5353
qVNodeData: WeakMap<Element, string>;
5454
}
5555

56-
export interface QNode extends Node {
57-
qVNode?: VNode;
58-
}
59-
6056
/**
6157
* Flags for VNode.
6258
*

packages/qwik/src/core/client/vnode-diff.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
QDefaultSlot,
2727
QSlot,
2828
QSlotParent,
29-
QStyle,
3029
QBackRefs,
3130
QTemplate,
3231
Q_PREFIX,
@@ -59,7 +58,6 @@ import {
5958
} from './types';
6059
import {
6160
vnode_ensureElementInflated,
62-
vnode_getAttr,
6361
vnode_getDomParentVNode,
6462
vnode_getElementName,
6563
vnode_getFirstChild,
@@ -102,8 +100,6 @@ import { serializeAttribute } from '../shared/utils/styles';
102100
import { QError, qError } from '../shared/error/error';
103101
import { getFileLocationFromJsx } from '../shared/utils/jsx-filename';
104102

105-
export type ComponentQueue = Array<VNode>;
106-
107103
export const vnode_diff = (
108104
container: ClientContainer,
109105
jsxNode: JSXOutput,
@@ -806,7 +802,7 @@ export const vnode_diff = (
806802
}
807803
}
808804

809-
/** @param tag Returns true if `qDispatchEvent` needs patching */
805+
/** @returns True if `qDispatchEvent` needs patching */
810806
function setBulkProps(
811807
vnode: ElementVNode,
812808
srcAttrs: ClientAttrs,
@@ -974,6 +970,7 @@ export const vnode_diff = (
974970
* By retrieving the child with the given key we are effectively removing it from the list (hence
975971
* we need to splice the `vSiblings` array).
976972
*
973+
* @param nodeName
977974
* @param key
978975
* @returns Array where: (see: `SiblingsArray`)
979976
*
@@ -1202,14 +1199,6 @@ export const vnode_diff = (
12021199
}
12031200
};
12041201

1205-
export const isQStyleVNode = (vNode: VNode): boolean => {
1206-
return (
1207-
vnode_isElementVNode(vNode) &&
1208-
vnode_getElementName(vNode) === 'style' &&
1209-
vnode_getAttr(vNode, QStyle) !== null
1210-
);
1211-
};
1212-
12131202
/**
12141203
* Retrieve the key from the VNode.
12151204
*

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

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,14 @@ import { QError, qError } from '../shared/error/error';
124124
import { DEBUG_TYPE, QContainerValue, VirtualType, VirtualTypeName } from '../shared/types';
125125
import { isText } from '../shared/utils/element';
126126
import {
127+
dangerouslySetInnerHTML,
127128
ELEMENT_ID,
128129
ELEMENT_KEY,
129130
ELEMENT_PROPS,
130131
ELEMENT_SEQ,
131132
ELEMENT_SEQ_IDX,
132133
OnRenderProp,
134+
Q_PROPS_SEPARATOR,
133135
QContainerAttr,
134136
QContainerAttrEnd,
135137
QContainerIsland,
@@ -142,27 +144,25 @@ import {
142144
QSlotParent,
143145
QStyle,
144146
QStylesAllSelector,
145-
Q_PROPS_SEPARATOR,
146-
dangerouslySetInnerHTML,
147147
} from '../shared/utils/markers';
148148
import { isHtmlElement } from '../shared/utils/types';
149149
import { VNodeDataChar } from '../shared/vnode-data-types';
150150
import { getDomContainer } from './dom-container';
151151
import { mapApp_findIndx, mapArray_get, mapArray_set } from './util-mapArray';
152152
import {
153-
ElementVNodeProps,
154-
TextVNodeProps,
155-
VNodeFlags,
156-
VNodeFlagsIndex,
157-
VNodeProps,
158-
VirtualVNodeProps,
159153
type ClientContainer,
160154
type ContainerElement,
161155
type ElementVNode,
156+
ElementVNodeProps,
162157
type QDocument,
163158
type TextVNode,
164-
type VNode,
159+
TextVNodeProps,
165160
type VirtualVNode,
161+
VirtualVNodeProps,
162+
type VNode,
163+
VNodeFlags,
164+
VNodeFlagsIndex,
165+
VNodeProps,
166166
} from './types';
167167
import {
168168
vnode_getDomChildrenWithCorrectNamespacesToInsert,
@@ -1131,17 +1131,6 @@ export const vnode_truncate = (
11311131
vParent[ElementVNodeProps.lastChild] = vPrevious;
11321132
};
11331133

1134-
export const vnode_isChildOf = (vParent: VNode, vChild: VNode): boolean => {
1135-
let vNode = vChild;
1136-
while (vNode) {
1137-
if (vNode === vParent) {
1138-
return true;
1139-
}
1140-
vNode = vnode_getParent(vNode)!;
1141-
}
1142-
return false;
1143-
};
1144-
11451134
//////////////////////////////////////////////////////////////////////////////////////////////////////
11461135

11471136
export const vnode_getElementName = (vnode: ElementVNode): string => {
@@ -1888,7 +1877,7 @@ const isElement = (node: any): node is Element =>
18881877
* parents.
18891878
*
18901879
* However, if during traversal we encounter a projection, than we have to follow the projection,
1891-
* and nod weth the projection component is further away (it is the parent's parent of the
1880+
* and node with the projection component is further away (it is the parent's parent of the
18921881
* projection's)
18931882
*
18941883
* So in general we have to go up as many parent components as there are projections nestings.
@@ -1899,7 +1888,7 @@ const isElement = (node: any): node is Element =>
18991888
* - And so on.
19001889
*
19011890
* @param vHost
1902-
* @param getObjectById
1891+
* @param rootVNode
19031892
* @returns
19041893
*/
19051894
export const vnode_getProjectionParentComponent = (
@@ -1929,7 +1918,7 @@ export const vnode_getProjectionParentComponent = (
19291918
return vHost as VirtualVNode | null;
19301919
};
19311920

1932-
const VNodeArray = class VNode extends Array {
1921+
const VNodeArray = class VNode extends Array<any> {
19331922
static createElement(
19341923
flags: VNodeFlags,
19351924
parent: VNode | null,
@@ -1940,7 +1929,7 @@ const VNodeArray = class VNode extends Array {
19401929
element: Element,
19411930
elementName: string | undefined
19421931
) {
1943-
const vnode = new VNode(
1932+
return new VNode(
19441933
flags,
19451934
parent,
19461935
previousSibling,
@@ -1950,8 +1939,7 @@ const VNodeArray = class VNode extends Array {
19501939
element,
19511940
elementName,
19521941
[]
1953-
) as any;
1954-
return vnode;
1942+
) as ElementVNode;
19551943
}
19561944

19571945
static createText(
@@ -1962,8 +1950,7 @@ const VNodeArray = class VNode extends Array {
19621950
textNode: Text | null,
19631951
text: string | undefined
19641952
) {
1965-
const vnode = new VNode(flags, parent, previousSibling, nextSibling, textNode, text) as any;
1966-
return vnode;
1953+
return new VNode(flags, parent, previousSibling, nextSibling, textNode, text) as TextVNode;
19671954
}
19681955

19691956
static createVirtual(
@@ -1974,16 +1961,15 @@ const VNodeArray = class VNode extends Array {
19741961
firstChild: VNode | null,
19751962
lastChild: VNode | null
19761963
) {
1977-
const vnode = new VNode(
1964+
return new VNode(
19781965
flags,
19791966
parent,
19801967
previousSibling,
19811968
nextSibling,
19821969
firstChild,
19831970
lastChild,
19841971
[]
1985-
) as any;
1986-
return vnode;
1972+
) as VirtualVNode;
19871973
}
19881974

19891975
constructor(
@@ -1993,7 +1979,6 @@ const VNodeArray = class VNode extends Array {
19931979
nextSibling: VNode | null | undefined,
19941980
...rest: (VNode | Element | Text | string | null | undefined)[]
19951981
) {
1996-
// @ts-expect-error
19971982
super(flags, parent, previousSibling, nextSibling, ...rest);
19981983
if (isDev) {
19991984
this.toString = vnode_toString;

packages/qwik/src/core/debug.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ export const pad = (text: string, prefix: string) => {
6464

6565
export const jsxToString = (value: any): string => {
6666
if (isJSXNode(value)) {
67-
let type = value.type;
68-
if (typeof type === 'function') {
69-
type = type.name || 'Component';
70-
}
7167
let str = '<' + value.type;
7268
if (value.props) {
7369
for (const [key, val] of Object.entries(value.props)) {

packages/qwik/src/core/shared/component.public.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
QRLEventHandlerMulti,
88
} from './jsx/types/jsx-qwik-attributes';
99
import type { FunctionComponent } from './jsx/types/jsx-node';
10-
import { _CONST_PROPS, _VAR_PROPS, _jsxSorted, _jsxSplit } from '../internal';
10+
import { _jsxSplit } from '../internal';
1111
import type { QwikIntrinsicElements } from './jsx/types/jsx-qwik-elements';
1212
import { assertNumber } from './error/assert';
1313
import { qTest } from './utils/qdev';
@@ -212,8 +212,3 @@ export const component$ = <PROPS = unknown>(onMount: OnRenderFn<PROPS>): Compone
212212

213213
/** @public */
214214
export type OnRenderFn<PROPS> = (props: PROPS) => JSXOutput;
215-
216-
export interface RenderFactoryOutput<PROPS> {
217-
renderQRL: QRL<OnRenderFn<PROPS>>;
218-
waitOn: any[];
219-
}

packages/qwik/src/core/shared/jsx/jsx-runtime.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ export function h<TYPE extends string | FunctionComponent<PROPS>, PROPS extends
197197
return _jsxSplit(type, props!, null, normalizedProps.children, 0, key);
198198
}
199199

200-
export const SKIP_RENDER_TYPE = ':skipRender';
201-
202200
export const isPropsProxy = (obj: any): obj is PropsProxy => {
203201
return obj && obj[_VAR_PROPS] !== undefined;
204202
};
@@ -317,19 +315,6 @@ export const jsxDEV = <T extends string | FunctionComponent<Props>>(
317315

318316
export type { QwikJSX as JSX };
319317

320-
export const createJSXError = (message: string, node: JSXNodeInternal) => {
321-
const error = new Error(message);
322-
if (!node.dev) {
323-
return error;
324-
}
325-
error.stack = `JSXError: ${message}\n${filterStack(node.dev.stack!, 1)}`;
326-
return error;
327-
};
328-
329-
const filterStack = (stack: string, offset: number = 0) => {
330-
return stack.split('\n').slice(offset).join('\n');
331-
};
332-
333318
export function createPropsProxy(
334319
varProps: Props,
335320
constProps: Props | null,
@@ -402,7 +387,7 @@ class PropsProxyHandler implements ProxyHandler<any> {
402387
(this.$constProps$ ? prop in this.$constProps$ : false);
403388
return hasProp;
404389
}
405-
getOwnPropertyDescriptor(target: any, p: string | symbol): PropertyDescriptor | undefined {
390+
getOwnPropertyDescriptor(_: any, p: string | symbol): PropertyDescriptor | undefined {
406391
const value =
407392
p === 'children' && this.$children$ != null
408393
? this.$children$

packages/qwik/src/core/shared/shared-serialization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ export function _deserialize(rawStateData: string | null, element?: unknown): un
14411441
return [];
14421442
}
14431443

1444-
let container: DeserializeContainer | undefined = undefined;
1444+
let container: DeserializeContainer | undefined;
14451445
if (isNode(element) && isElement(element)) {
14461446
container = _createDeserializeContainer(stateData, element as HTMLElement);
14471447
} else {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ export type qWindow = Window & {
6767

6868
export type QwikLoaderEventScope = '-document' | '-window' | '';
6969

70-
export const isContainer = (container: any): container is Container => {
71-
return container && typeof container === 'object' && typeof container.setHostProp === 'function';
72-
};
73-
7470
/**
7571
* A friendly name tag for a VirtualVNode.
7672
*

packages/qwik/src/core/shared/utils/promises.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import type { ValueOrPromise } from './types';
33

44
export const MAX_RETRY_ON_PROMISE_COUNT = 100;
55

6-
export type PromiseTree<T> = T | Promise<T> | Promise<T[]> | Array<PromiseTree<T>>;
7-
86
export const isPromise = (value: any): value is Promise<any> => {
97
// not using "value instanceof Promise" to have zone.js support
108
return !!value && typeof value == 'object' && typeof value.then === 'function';
@@ -36,15 +34,6 @@ export const maybeThen = <T, B>(
3634
: thenFn(valueOrPromise as any);
3735
};
3836

39-
export const maybeThenPassError = <T, B>(
40-
valueOrPromise: ValueOrPromise<T>,
41-
thenFn: (arg: Awaited<T>) => ValueOrPromise<B>
42-
): ValueOrPromise<B> => {
43-
return isPromise(valueOrPromise)
44-
? valueOrPromise.then(thenFn as any)
45-
: thenFn(valueOrPromise as any);
46-
};
47-
4837
export const shouldNotError = (reason: any): any => {
4938
throwErrorAndStop(reason);
5039
};

packages/qwik/src/core/shared/utils/serialize-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const _verifySerializable = <T>(
6868
case 'number':
6969
return value;
7070
}
71-
let message = '';
71+
let message: string;
7272
if (preMessage) {
7373
message = preMessage;
7474
} else {

0 commit comments

Comments
 (0)