Skip to content

Commit

Permalink
fix(v2): repl examples (#6897)
Browse files Browse the repository at this point in the history
* throw error using qwik utils

* fix repl examples

* fix api
  • Loading branch information
Varixo committed Sep 22, 2024
1 parent a789e32 commit cf77a1f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
6 changes: 5 additions & 1 deletion packages/docs/src/repl/monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ const checkDiagnostics = async (
) => {
if (!monacoCtx.tsWorker) {
const getTsWorker = await monaco.languages.typescript.getTypeScriptWorker();
monacoCtx.tsWorker = await getTsWorker(editor.getModel()!.uri);
const uri = editor.getModel()?.uri;
if (!uri) {
return;
}
monacoCtx.tsWorker = await getTsWorker(uri);
}
const tsWorker = monacoCtx.tsWorker;

Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/repl/worker/repl-request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ const injectDevHtml = (clientId: string, html?: string) => {
}, true);
})();`;

return `<script>${s}</script>${html || ''}`;
return `<script :>${s}</script>${html || ''}`;
};
2 changes: 1 addition & 1 deletion packages/qwik/src/core/v2/client/dom-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
);
this.qContainer = element.getAttribute(QContainerAttr)!;
if (!this.qContainer) {
throw new Error("Element must have 'q:container' attribute.");
throwErrorAndStop("Element must have 'q:container' attribute.");
}
this.$journal$ = [
// The first time we render we need to hoist the styles.
Expand Down
7 changes: 4 additions & 3 deletions packages/qwik/src/core/v2/client/process-vnode-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// NOTE: we want to move this function to qwikloader, and therefore this function should not have any external dependencies
import { throwErrorAndStop } from '../../util/log';
import { VNodeDataChar, VNodeDataSeparator } from '../shared/vnode-data-types';
import type { ContainerElement, ElementVNode, QDocument } from './types';

Expand Down Expand Up @@ -265,7 +266,7 @@ export function processVNodeData(document: Document) {
do {
islandNode = walker.nextNode();
if (!islandNode) {
throw new Error(`Island inside <!--${node?.nodeValue}--> not found!`);
return throwErrorAndStop(`Island inside <!--${node?.nodeValue}--> not found!`);
}
} while (getFastNodeType(islandNode) !== NodeType.COMMENT_ISLAND_START);
nextNode = null;
Expand All @@ -274,7 +275,7 @@ export function processVNodeData(document: Document) {
do {
nextNode = walker.nextNode();
if (!nextNode) {
throw new Error(`Ignore block not closed!`);
return throwErrorAndStop(`Ignore block not closed!`);
}
} while (getFastNodeType(nextNode) !== NodeType.COMMENT_IGNORE_END);
nextNode = null;
Expand All @@ -284,7 +285,7 @@ export function processVNodeData(document: Document) {
do {
nextNode = nextSibling(nextNode);
if (!nextNode) {
throw new Error(`<!--${node?.nodeValue}--> not closed!`);
return throwErrorAndStop(`<!--${node?.nodeValue}--> not closed!`);
}
} while (getFastNodeType(nextNode) !== NodeType.COMMENT_SKIP_END);
// console.log('EXIT', nextNode?.outerHTML);
Expand Down
3 changes: 2 additions & 1 deletion packages/qwik/src/core/v2/client/vnode-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import {
clearSubscriberEffectDependencies,
clearVNodeEffectDependencies,
} from '../signal/v2-subscriber';
import { throwErrorAndStop } from '../../util/log';

export type ComponentQueue = Array<VNode>;

Expand Down Expand Up @@ -651,7 +652,7 @@ export const vnode_diff = (
if (elementName === 'textarea' && key === 'value') {
if (typeof value !== 'string') {
if (isDev) {
throw new Error('The value of the textarea must be a string');
throwErrorAndStop('The value of the textarea must be a string');
}
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/v2/shared/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import {
type ResourceDescriptor,
type TaskFn,
} from '../../use/use-task';
import { logWarn } from '../../util/log';
import { logWarn, throwErrorAndStop } from '../../util/log';
import { isPromise, maybeThen, maybeThenPassError, safeCall } from '../../util/promises';
import type { ValueOrPromise } from '../../util/types';
import { isDomContainer } from '../client/dom-container';
Expand Down Expand Up @@ -470,7 +470,7 @@ function choreComparator(a: Chore, b: Chore, shouldThrowOnHostMismatch: boolean)
const errorMessage =
'SERVER: during HTML streaming, it is not possible to cause a re-run of tasks on a different host';
if (shouldThrowOnHostMismatch) {
throw new Error(errorMessage);
throwErrorAndStop(errorMessage);
}
logWarn(errorMessage);
return null;
Expand Down
14 changes: 7 additions & 7 deletions packages/qwik/src/core/v2/shared/shared-serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ const inflate = (container: DeserializeContainer, target: any, needsInflationDat
: undefined;
break;
case SerializationConstant.Resource_VALUE:
throw new Error('Not implemented');
return throwErrorAndStop('Not implemented');
case SerializationConstant.Component_VALUE:
inflateQRL(container, target[SERIALIZABLE_STATE][0]);
break;
Expand Down Expand Up @@ -378,7 +378,7 @@ const inflate = (container: DeserializeContainer, target: any, needsInflationDat
propsProxy[_CONST_PROPS] = container.$getObjectById$(restInt()) as any;
break;
default:
throw new Error('Not implemented');
return throwErrorAndStop('Not implemented');
}
restIdx = restStack.pop() as number;
rest = restStack.pop() as string;
Expand All @@ -393,7 +393,7 @@ const allocate = <T>(value: string): any => {
case SerializationConstant.Task_VALUE:
return new Task(-1, -1, null!, null!, null!, null);
case SerializationConstant.Resource_VALUE:
throw new Error('Not implemented');
return throwErrorAndStop('Not implemented');
case SerializationConstant.URL_VALUE:
return new URL(value.substring(1));
case SerializationConstant.Date_VALUE:
Expand Down Expand Up @@ -453,7 +453,7 @@ const allocate = <T>(value: string): any => {
case SerializationConstant.PropsProxy_VALUE:
return createPropsProxy(null!, null);
default:
throw new Error('unknown allocate type: ' + value.charCodeAt(0));
return throwErrorAndStop('unknown allocate type: ' + value.charCodeAt(0));
}
};

Expand Down Expand Up @@ -761,7 +761,7 @@ export const createSerializationContext = (
}
}
} else {
throw new Error('Unknown type: ' + obj);
return throwErrorAndStop('Unknown type: ' + obj);
}
} else if (id === Number.MIN_SAFE_INTEGER) {
// We are seeing this object second time => promoted it.
Expand Down Expand Up @@ -841,7 +841,7 @@ function serialize(serializationContext: SerializationContext): void {
} else if (typeof value === 'undefined') {
writeString(SerializationConstant.UNDEFINED_CHAR);
} else {
throw new Error('Unknown type: ' + typeof value);
return throwErrorAndStop('Unknown type: ' + typeof value);
}
};

Expand Down Expand Up @@ -996,7 +996,7 @@ function serialize(serializationContext: SerializationContext): void {
const out = btoa(buf).replace(/=+$/, '');
writeString(SerializationConstant.Uint8Array_CHAR + out);
} else {
throw new Error('implement');
return throwErrorAndStop('implement');
}
};

Expand Down
8 changes: 4 additions & 4 deletions packages/qwik/src/core/v2/signal/v2-signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { type QRLInternal } from '../../qrl/qrl-class';
import type { QRL } from '../../qrl/qrl.public';
import { trackSignal, tryGetInvokeContext } from '../../use/use-core';
import { Task, TaskFlags, isTask } from '../../use/use-task';
import { logError } from '../../util/log';
import { logError, throwErrorAndStop } from '../../util/log';
import { ELEMENT_PROPS, OnRenderProp, QSubscribers } from '../../util/markers';
import { isPromise } from '../../util/promises';
import { qDev } from '../../util/qdev';
Expand Down Expand Up @@ -222,7 +222,7 @@ export class Signal<T = any> extends Subscriber implements ISignal<T> {
// prevent accidental use as value
valueOf() {
if (qDev) {
throw new TypeError('Cannot coerce a Signal, use `.value` instead');
return throwErrorAndStop('Cannot coerce a Signal, use `.value` instead');
}
}

Expand Down Expand Up @@ -476,7 +476,7 @@ export class ComputedSignal<T> extends Signal<T> {
}

set value(_: any) {
throw new TypeError('ComputedSignal is read-only');
throwErrorAndStop('ComputedSignal is read-only');
}
}

Expand Down Expand Up @@ -548,6 +548,6 @@ export class WrappedSignal<T> extends Signal<T> {
}

set value(_: any) {
throw new TypeError('WrappedSignal is read-only');
throwErrorAndStop('WrappedSignal is read-only');
}
}

0 comments on commit cf77a1f

Please sign in to comment.