@hewel/zgui-build 0.1.4 → 0.1.6
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/README.md +2 -2
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +1 -1
- package/sdk/Cargo.lock +97 -45
- package/sdk/THIRD_PARTY_NOTICES.md +1 -1
- package/sdk/bun.lock +7 -7
- package/sdk/package.json +2 -1
- package/src/build.ts +108 -31
- package/src/compiler.ts +22 -1
- package/src/dev.ts +12 -2
- package/src/host.ts +54 -3
- package/src/identity.ts +4 -2
- package/src/internal.ts +1 -0
- package/src/manifest-policy.ts +71 -4
- package/src/package-app.ts +18 -5
- package/src/preview.ts +9 -1
- package/src/public-api.d.ts +17 -0
- package/src/publication.ts +2 -0
- package/src/sdk-packages.ts +36 -20
- package/src/sync-ui-resources.ts +1 -1
- package/src/validate.ts +91 -49
- package/src/watch.ts +8 -0
package/src/package-app.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import { chmod, copyFile, cp, mkdir, realpath, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { buildWithResolvedHost } from "./build.ts";
|
|
6
|
+
import { preflightBundle } from "./host.ts";
|
|
6
7
|
import { packagedSdkRoot, workspaceRoot } from "./sdk.ts";
|
|
7
8
|
|
|
8
9
|
const DISTRIBUTED_LICENSE_FILES = ["LICENSE", "NOTICE", "THIRD_PARTY_NOTICES.md"] as const;
|
|
@@ -23,8 +24,14 @@ function sanitizeDesktopField(value: string): string {
|
|
|
23
24
|
return value.replace(/[\r\n]+/g, " ").trim();
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
function buildLauncherScript({
|
|
27
|
-
|
|
27
|
+
function buildLauncherScript({
|
|
28
|
+
pureShell = false,
|
|
29
|
+
headless = false,
|
|
30
|
+
}: {
|
|
31
|
+
pureShell?: boolean;
|
|
32
|
+
headless?: boolean;
|
|
33
|
+
}): string {
|
|
34
|
+
const extraFlags = `${pureShell ? " --pure-shell" : ""}${headless ? " --headless" : ""}`;
|
|
28
35
|
return `#!/usr/bin/env sh
|
|
29
36
|
set -eu
|
|
30
37
|
DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
@@ -77,6 +84,7 @@ export async function packageApplication(
|
|
|
77
84
|
appDirectory = path.join(root, "apps/examples", app),
|
|
78
85
|
out = path.join(appDirectory, "dist-package"),
|
|
79
86
|
bytecode = false,
|
|
87
|
+
preflight = "auto",
|
|
80
88
|
hostRoot,
|
|
81
89
|
hostExecutable,
|
|
82
90
|
hostSearchFrom,
|
|
@@ -85,18 +93,20 @@ export async function packageApplication(
|
|
|
85
93
|
cssModuleInclude,
|
|
86
94
|
desktopEntry = false,
|
|
87
95
|
pureShell = false,
|
|
96
|
+
headless = false,
|
|
88
97
|
signal,
|
|
89
98
|
}: PackageApplicationOptions = {},
|
|
90
99
|
): Promise<PackagedApplication> {
|
|
91
100
|
signal?.throwIfAborted();
|
|
92
101
|
const resolvedAppDir = path.resolve(appDirectory);
|
|
93
102
|
const outputDir = path.resolve(out);
|
|
94
|
-
const { application, resolveHost } = await buildWithResolvedHost(
|
|
103
|
+
const { application, resolveHost, preflightedDirectory } = await buildWithResolvedHost(
|
|
95
104
|
app,
|
|
96
105
|
{
|
|
97
106
|
root,
|
|
98
107
|
appDirectory: resolvedAppDir,
|
|
99
108
|
bytecode,
|
|
109
|
+
preflight,
|
|
100
110
|
hostSearchFrom,
|
|
101
111
|
extraCapabilities,
|
|
102
112
|
capabilitiesFile,
|
|
@@ -113,12 +123,15 @@ export async function packageApplication(
|
|
|
113
123
|
);
|
|
114
124
|
}
|
|
115
125
|
|
|
126
|
+
const bundleSource = preflightedDirectory ?? (await realpath(dist));
|
|
116
127
|
const host = await resolveHost();
|
|
117
128
|
const abi = host.abi;
|
|
118
129
|
if (!abi) throw new Error("Resolved zgui-host did not report ABI metadata");
|
|
119
130
|
signal?.throwIfAborted();
|
|
131
|
+
if (preflight === "auto" && preflightedDirectory === undefined && abi.preflight === true) {
|
|
132
|
+
await preflightBundle(host, bundleSource, { signal });
|
|
133
|
+
}
|
|
120
134
|
|
|
121
|
-
const bundleSource = await realpath(dist);
|
|
122
135
|
const stagingDir = `${outputDir}.staging-${process.pid}-${Date.now()}`;
|
|
123
136
|
const binDir = path.join(stagingDir, "bin");
|
|
124
137
|
const bundleDir = path.join(stagingDir, "bundle");
|
|
@@ -139,7 +152,7 @@ export async function packageApplication(
|
|
|
139
152
|
await copyFile(source, path.join(licensesDir, filename));
|
|
140
153
|
licensePaths.push(`licenses/${filename}`);
|
|
141
154
|
}
|
|
142
|
-
await writeFile(launcherPath, buildLauncherScript({ pureShell }), "utf8");
|
|
155
|
+
await writeFile(launcherPath, buildLauncherScript({ pureShell, headless }), "utf8");
|
|
143
156
|
await chmod(launcherPath, 0o755);
|
|
144
157
|
|
|
145
158
|
if (desktopEntry) {
|
package/src/preview.ts
CHANGED
|
@@ -25,6 +25,9 @@ export async function previewApplication(
|
|
|
25
25
|
signal,
|
|
26
26
|
onOutput,
|
|
27
27
|
bytecode = false,
|
|
28
|
+
preflight,
|
|
29
|
+
maxJsHeapUsedBytes,
|
|
30
|
+
maxJsHeapPostDisposeBytes,
|
|
28
31
|
...buildOptions
|
|
29
32
|
}: PreviewApplicationOptions = {},
|
|
30
33
|
): Promise<number> {
|
|
@@ -41,12 +44,17 @@ export async function previewApplication(
|
|
|
41
44
|
"--out",
|
|
42
45
|
output,
|
|
43
46
|
];
|
|
47
|
+
if (maxJsHeapUsedBytes !== undefined)
|
|
48
|
+
args.push("--max-js-heap-used-bytes", String(maxJsHeapUsedBytes));
|
|
49
|
+
if (maxJsHeapPostDisposeBytes !== undefined)
|
|
50
|
+
args.push("--max-js-heap-post-dispose-bytes", String(maxJsHeapPostDisposeBytes));
|
|
44
51
|
onOutput?.(output);
|
|
45
52
|
if (watch)
|
|
46
53
|
return devApplication(app, {
|
|
47
54
|
...buildOptions,
|
|
48
55
|
root,
|
|
49
56
|
appDirectory,
|
|
57
|
+
preflight,
|
|
50
58
|
...(explicitHostRoot === undefined ? {} : { hostRoot: explicitHostRoot }),
|
|
51
59
|
hostExecutable,
|
|
52
60
|
mode: "preview",
|
|
@@ -58,7 +66,7 @@ export async function previewApplication(
|
|
|
58
66
|
resolveHost,
|
|
59
67
|
} = await buildWithResolvedHost(
|
|
60
68
|
app,
|
|
61
|
-
{ ...buildOptions, root, appDirectory, bytecode },
|
|
69
|
+
{ ...buildOptions, root, appDirectory, bytecode, preflight },
|
|
62
70
|
{ hostRoot: explicitHostRoot, hostExecutable, signal },
|
|
63
71
|
);
|
|
64
72
|
const host = await resolveHost();
|
package/src/public-api.d.ts
CHANGED
|
@@ -42,13 +42,22 @@ export type NetworkCapabilities = {
|
|
|
42
42
|
allowPrivateNetworks?: boolean;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
export interface DescriptorHandoffCapabilities {
|
|
46
|
+
readonly unixSockets?: readonly string[];
|
|
47
|
+
readonly namedSockets?: readonly string[];
|
|
48
|
+
readonly commands?: readonly string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
export type Capabilities = {
|
|
46
52
|
shellSurfaces?: boolean;
|
|
47
53
|
sessionLock?: boolean;
|
|
54
|
+
offscreenCapture?: boolean;
|
|
48
55
|
imagePrefixes?: string[];
|
|
56
|
+
namedImagePrefixes?: string[];
|
|
49
57
|
unixSockets?: string[];
|
|
50
58
|
namedSockets?: string[];
|
|
51
59
|
commands?: string[];
|
|
60
|
+
descriptorHandoff?: Readonly<DescriptorHandoffCapabilities>;
|
|
52
61
|
controlChannel?: boolean;
|
|
53
62
|
/** Base package launch policy; overlays cannot enable this. */
|
|
54
63
|
singleInstance?: boolean;
|
|
@@ -70,6 +79,7 @@ export type WindowDeclaration = {
|
|
|
70
79
|
minHeight?: number;
|
|
71
80
|
resizable?: boolean;
|
|
72
81
|
};
|
|
82
|
+
export type ResourceProfile = "standard" | "extended";
|
|
73
83
|
export type ResolvedApplication = { app: string; appDirectory: string; root: string };
|
|
74
84
|
export type PublishedApplication = { dist: string; manifest: Manifest };
|
|
75
85
|
|
|
@@ -87,6 +97,7 @@ export type Manifest = {
|
|
|
87
97
|
assets: string[];
|
|
88
98
|
fonts: FontDeclaration[];
|
|
89
99
|
window?: WindowDeclaration;
|
|
100
|
+
resourceProfile?: ResourceProfile;
|
|
90
101
|
capabilities?: Capabilities;
|
|
91
102
|
styleSystem: {
|
|
92
103
|
name: "lightningcss";
|
|
@@ -132,6 +143,7 @@ export interface BuildApplicationOptions {
|
|
|
132
143
|
appDirectory?: string;
|
|
133
144
|
development?: boolean;
|
|
134
145
|
bytecode?: boolean;
|
|
146
|
+
preflight?: boolean | "auto" | undefined;
|
|
135
147
|
hostRoot?: string;
|
|
136
148
|
hostExecutable?: string;
|
|
137
149
|
hostSearchFrom?: readonly string[] | undefined;
|
|
@@ -167,6 +179,7 @@ export type DevMode = "desktop" | "preview";
|
|
|
167
179
|
|
|
168
180
|
export interface DevApplicationOptions extends Omit<BuildApplicationOptions, "development"> {
|
|
169
181
|
strictTypecheck?: boolean | undefined;
|
|
182
|
+
headless?: boolean | undefined;
|
|
170
183
|
hostArgs?: string[];
|
|
171
184
|
/** Working directory for the native process, independent of bundle and Cargo paths. */
|
|
172
185
|
hostCwd?: string;
|
|
@@ -185,6 +198,8 @@ export interface PreviewApplicationOptions extends Omit<
|
|
|
185
198
|
fixture?: string;
|
|
186
199
|
scenario?: string;
|
|
187
200
|
out?: string;
|
|
201
|
+
maxJsHeapUsedBytes?: number | undefined;
|
|
202
|
+
maxJsHeapPostDisposeBytes?: number | undefined;
|
|
188
203
|
onOutput?: (directory: string) => void;
|
|
189
204
|
}
|
|
190
205
|
|
|
@@ -209,6 +224,7 @@ export interface NativeHostAbi {
|
|
|
209
224
|
bytecodeFormat?: string | undefined;
|
|
210
225
|
quickjsAbi?: string | undefined;
|
|
211
226
|
styleProfile?: string | undefined;
|
|
227
|
+
preflight?: boolean | undefined;
|
|
212
228
|
}
|
|
213
229
|
|
|
214
230
|
export interface ResolveNativeHostOptions {
|
|
@@ -242,6 +258,7 @@ export interface PackageApplicationOptions extends Omit<BuildApplicationOptions,
|
|
|
242
258
|
hostExecutable?: string | undefined;
|
|
243
259
|
desktopEntry?: boolean | undefined;
|
|
244
260
|
pureShell?: boolean | undefined;
|
|
261
|
+
headless?: boolean | undefined;
|
|
245
262
|
signal?: AbortSignal | undefined;
|
|
246
263
|
}
|
|
247
264
|
|
package/src/publication.ts
CHANGED
|
@@ -70,6 +70,7 @@ export async function activatePublication(
|
|
|
70
70
|
export async function publishGeneration(
|
|
71
71
|
appDirectory: string,
|
|
72
72
|
files: ReadonlyMap<string, Uint8Array>,
|
|
73
|
+
options?: { verify?: (packageDirectory: string) => Promise<void> },
|
|
73
74
|
): Promise<string> {
|
|
74
75
|
const generations = path.join(appDirectory, ".zgui-generations");
|
|
75
76
|
await mkdir(generations, { recursive: true });
|
|
@@ -86,6 +87,7 @@ export async function publishGeneration(
|
|
|
86
87
|
await writeFile(destination, bytes, { flag: "wx" });
|
|
87
88
|
}
|
|
88
89
|
await rename(staging, generation);
|
|
90
|
+
await options?.verify?.(generation);
|
|
89
91
|
const dist = await activatePublication(appDirectory, generation);
|
|
90
92
|
published = true;
|
|
91
93
|
return dist;
|
package/src/sdk-packages.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { existsSync, type Dirent } from "node:fs";
|
|
2
|
+
import { existsSync, readdirSync, type Dirent } from "node:fs";
|
|
3
3
|
import {
|
|
4
4
|
copyFile,
|
|
5
5
|
mkdir,
|
|
@@ -44,13 +44,32 @@ const SDK_PACKAGE_SPECS: Readonly<Record<SdkPackageName, SdkPackageSpec>> = {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const ALL_SDK_PACKAGES: readonly SdkPackageName[] = ["ui", "services"];
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"oxlint/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
|
|
48
|
+
/** Derive sorted `oxlint/**\/*.js` outputs from `oxlint/src/**\/*.ts` (excluding `.d.ts`). */
|
|
49
|
+
export function listOxlintOutputFiles(pkgDir: string): readonly string[] {
|
|
50
|
+
const oxlintSrcDir = path.join(pkgDir, "oxlint/src");
|
|
51
|
+
if (!existsSync(oxlintSrcDir)) {
|
|
52
|
+
throw new Error(`Missing oxlint source directory: ${oxlintSrcDir}`);
|
|
53
|
+
}
|
|
54
|
+
const outputs: string[] = [];
|
|
55
|
+
const walk = (dir: string, prefix: string): void => {
|
|
56
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
57
|
+
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
58
|
+
const full = path.join(dir, entry.name);
|
|
59
|
+
if (entry.isDirectory()) {
|
|
60
|
+
walk(full, rel);
|
|
61
|
+
} else if (entry.isFile() && entry.name.endsWith(".ts") && !entry.name.endsWith(".d.ts")) {
|
|
62
|
+
outputs.push(`oxlint/${rel.slice(0, -3)}.js`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
walk(oxlintSrcDir, "");
|
|
67
|
+
outputs.sort();
|
|
68
|
+
if (outputs.length === 0) {
|
|
69
|
+
throw new Error(`No TypeScript sources found under ${oxlintSrcDir}`);
|
|
70
|
+
}
|
|
71
|
+
return outputs;
|
|
72
|
+
}
|
|
54
73
|
|
|
55
74
|
const compilerCli = path.join(
|
|
56
75
|
path.dirname(createRequire(import.meta.url).resolve("tsrs/package.json")),
|
|
@@ -109,22 +128,14 @@ async function newestInputMtimeMs(pkgDir: string): Promise<number> {
|
|
|
109
128
|
async function isPackageDistFresh(pkgDir: string, spec: SdkPackageSpec): Promise<boolean> {
|
|
110
129
|
const distDir = path.join(pkgDir, "dist");
|
|
111
130
|
const hasOxlintBuild = existsSync(path.join(pkgDir, "tsconfig.oxlint.json"));
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
"index.d.ts",
|
|
115
|
-
...spec.handwrittenDts,
|
|
116
|
-
...(hasOxlintBuild ? OXLINT_OUTPUT_FILES : []),
|
|
117
|
-
];
|
|
131
|
+
const oxlintOutputs = hasOxlintBuild ? listOxlintOutputFiles(pkgDir) : [];
|
|
132
|
+
const required = ["index.js", "index.d.ts", ...spec.handwrittenDts, ...oxlintOutputs];
|
|
118
133
|
let stampMtime = Number.POSITIVE_INFINITY;
|
|
119
134
|
for (const rel of required) {
|
|
120
135
|
const full = path.join(distDir, rel);
|
|
121
136
|
try {
|
|
122
137
|
const info = await stat(full);
|
|
123
|
-
if (
|
|
124
|
-
rel === "index.js" ||
|
|
125
|
-
rel === "index.d.ts" ||
|
|
126
|
-
(hasOxlintBuild && (OXLINT_OUTPUT_FILES as readonly string[]).includes(rel))
|
|
127
|
-
) {
|
|
138
|
+
if (rel === "index.js" || rel === "index.d.ts" || oxlintOutputs.includes(rel)) {
|
|
128
139
|
stampMtime = Math.min(stampMtime, info.mtimeMs);
|
|
129
140
|
}
|
|
130
141
|
} catch {
|
|
@@ -201,7 +212,12 @@ async function syncDirectoryInPlace(stagingDir: string, distDir: string): Promis
|
|
|
201
212
|
await removeEmptyDirs(distDir);
|
|
202
213
|
|
|
203
214
|
const now = new Date();
|
|
204
|
-
|
|
215
|
+
const sentinels = [
|
|
216
|
+
"index.js",
|
|
217
|
+
"index.d.ts",
|
|
218
|
+
...stagedFiles.filter(rel => rel.startsWith("oxlint/") && rel.endsWith(".js")),
|
|
219
|
+
];
|
|
220
|
+
for (const sentinel of sentinels) {
|
|
205
221
|
const target = path.join(distDir, sentinel);
|
|
206
222
|
if (existsSync(target)) {
|
|
207
223
|
await utimes(target, now, now).catch(() => {});
|
package/src/sync-ui-resources.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { mkdir } from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
|
-
const REVISION = "
|
|
5
|
+
const REVISION = "b985e19296b625f6f9ee1b66d6a5ff09d9de7ff6";
|
|
6
6
|
const workspaceRoot = fileURLToPath(new URL("../../../", import.meta.url));
|
|
7
7
|
|
|
8
8
|
export interface ResourceSnapshot {
|
package/src/validate.ts
CHANGED
|
@@ -13,6 +13,8 @@ const globals = new Set([
|
|
|
13
13
|
"performance",
|
|
14
14
|
"setTimeout",
|
|
15
15
|
"clearTimeout",
|
|
16
|
+
"setInterval",
|
|
17
|
+
"clearInterval",
|
|
16
18
|
"requestAnimationFrame",
|
|
17
19
|
"cancelAnimationFrame",
|
|
18
20
|
"queueMicrotask",
|
|
@@ -22,6 +24,7 @@ const globals = new Set([
|
|
|
22
24
|
"Symbol",
|
|
23
25
|
"Error",
|
|
24
26
|
"AggregateError",
|
|
27
|
+
"DOMException",
|
|
25
28
|
"EvalError",
|
|
26
29
|
"RangeError",
|
|
27
30
|
"ReferenceError",
|
|
@@ -57,6 +60,12 @@ const globals = new Set([
|
|
|
57
60
|
"URLSearchParams",
|
|
58
61
|
"TextEncoder",
|
|
59
62
|
"TextDecoder",
|
|
63
|
+
"Event",
|
|
64
|
+
"CustomEvent",
|
|
65
|
+
"EventTarget",
|
|
66
|
+
"AbortController",
|
|
67
|
+
"AbortSignal",
|
|
68
|
+
"crypto",
|
|
60
69
|
"Atomics",
|
|
61
70
|
"JSON",
|
|
62
71
|
"Promise",
|
|
@@ -82,6 +91,8 @@ const workerDisallowedGlobals = new Set([
|
|
|
82
91
|
"performance",
|
|
83
92
|
"setTimeout",
|
|
84
93
|
"clearTimeout",
|
|
94
|
+
"setInterval",
|
|
95
|
+
"clearInterval",
|
|
85
96
|
"requestAnimationFrame",
|
|
86
97
|
"cancelAnimationFrame",
|
|
87
98
|
]);
|
|
@@ -339,41 +350,73 @@ function hasArgumentsBinding(ancestors: readonly AncestorFrame[]): boolean {
|
|
|
339
350
|
return false;
|
|
340
351
|
}
|
|
341
352
|
|
|
342
|
-
|
|
353
|
+
const definedTypeofValues = new Set([
|
|
354
|
+
"object",
|
|
355
|
+
"function",
|
|
356
|
+
"string",
|
|
357
|
+
"number",
|
|
358
|
+
"boolean",
|
|
359
|
+
"symbol",
|
|
360
|
+
"bigint",
|
|
361
|
+
]);
|
|
362
|
+
|
|
363
|
+
function isTypeofIdentifier(node: unknown, name: string): boolean {
|
|
364
|
+
return (
|
|
365
|
+
isAstNode(node) &&
|
|
366
|
+
node.type === "UnaryExpression" &&
|
|
367
|
+
node.operator === "typeof" &&
|
|
368
|
+
isAstNode(node.argument) &&
|
|
369
|
+
node.argument.type === "Identifier" &&
|
|
370
|
+
node.argument.name === name
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function matchTypeofComparison(
|
|
375
|
+
expr: AstNode,
|
|
376
|
+
name: string,
|
|
377
|
+
): { equal: boolean; literal: string } | null {
|
|
378
|
+
if (expr.type !== "BinaryExpression") return null;
|
|
379
|
+
const op = expr.operator;
|
|
380
|
+
const equal = op === "===" || op === "==";
|
|
381
|
+
const notEqual = op === "!==" || op === "!=";
|
|
382
|
+
if (!equal && !notEqual) return null;
|
|
383
|
+
if (isTypeofIdentifier(expr.left, name) && isStringLiteral(expr.right)) {
|
|
384
|
+
return { equal, literal: expr.right.value };
|
|
385
|
+
}
|
|
386
|
+
if (isTypeofIdentifier(expr.right, name) && isStringLiteral(expr.left)) {
|
|
387
|
+
return { equal, literal: expr.left.value };
|
|
388
|
+
}
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// True when `expr` evaluating to `whenTruthy` guarantees `typeof <name> !== "undefined"`.
|
|
393
|
+
function provesDefinedWhen(expr: unknown, name: string, whenTruthy: boolean): boolean {
|
|
343
394
|
if (!isAstNode(expr)) return false;
|
|
344
395
|
if (expr.type === "ParenthesizedExpression") {
|
|
345
|
-
return
|
|
396
|
+
return provesDefinedWhen(expr.expression, name, whenTruthy);
|
|
397
|
+
}
|
|
398
|
+
if (expr.type === "UnaryExpression" && expr.operator === "!") {
|
|
399
|
+
return provesDefinedWhen(expr.argument, name, !whenTruthy);
|
|
346
400
|
}
|
|
347
|
-
if (expr.type === "LogicalExpression"
|
|
348
|
-
|
|
401
|
+
if (expr.type === "LogicalExpression") {
|
|
402
|
+
if (expr.operator === "&&") {
|
|
403
|
+
return whenTruthy
|
|
404
|
+
? provesDefinedWhen(expr.left, name, true) || provesDefinedWhen(expr.right, name, true)
|
|
405
|
+
: provesDefinedWhen(expr.left, name, false) && provesDefinedWhen(expr.right, name, false);
|
|
406
|
+
}
|
|
407
|
+
if (expr.operator === "||") {
|
|
408
|
+
return whenTruthy
|
|
409
|
+
? provesDefinedWhen(expr.left, name, true) && provesDefinedWhen(expr.right, name, true)
|
|
410
|
+
: provesDefinedWhen(expr.left, name, false) || provesDefinedWhen(expr.right, name, false);
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
349
413
|
}
|
|
350
|
-
|
|
351
|
-
|
|
414
|
+
const cmp = matchTypeofComparison(expr, name);
|
|
415
|
+
if (!cmp) return false;
|
|
416
|
+
if (whenTruthy) {
|
|
417
|
+
return cmp.equal ? definedTypeofValues.has(cmp.literal) : cmp.literal === "undefined";
|
|
352
418
|
}
|
|
353
|
-
|
|
354
|
-
const op = expr.operator;
|
|
355
|
-
const matches = expectedUndefined ? op === "===" || op === "==" : op === "!==" || op === "!=";
|
|
356
|
-
if (!matches) return false;
|
|
357
|
-
const left = expr.left;
|
|
358
|
-
const right = expr.right;
|
|
359
|
-
return (
|
|
360
|
-
(isAstNode(left) &&
|
|
361
|
-
left.type === "UnaryExpression" &&
|
|
362
|
-
left.operator === "typeof" &&
|
|
363
|
-
isAstNode(left.argument) &&
|
|
364
|
-
left.argument.type === "Identifier" &&
|
|
365
|
-
left.argument.name === name &&
|
|
366
|
-
isStringLiteral(right) &&
|
|
367
|
-
right.value === "undefined") ||
|
|
368
|
-
(isAstNode(right) &&
|
|
369
|
-
right.type === "UnaryExpression" &&
|
|
370
|
-
right.operator === "typeof" &&
|
|
371
|
-
isAstNode(right.argument) &&
|
|
372
|
-
right.argument.type === "Identifier" &&
|
|
373
|
-
right.argument.name === name &&
|
|
374
|
-
isStringLiteral(left) &&
|
|
375
|
-
left.value === "undefined")
|
|
376
|
-
);
|
|
419
|
+
return cmp.equal && cmp.literal === "undefined";
|
|
377
420
|
}
|
|
378
421
|
|
|
379
422
|
function isTypeofGuarded(name: string, ancestors: readonly AncestorFrame[]): boolean {
|
|
@@ -388,23 +431,25 @@ function isTypeofGuarded(name: string, ancestors: readonly AncestorFrame[]): boo
|
|
|
388
431
|
}
|
|
389
432
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
390
433
|
const frame = ancestors[i]!;
|
|
391
|
-
if (frame.node.type === "LogicalExpression") {
|
|
392
|
-
if (
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
(frame.node.operator === "&&" &&
|
|
397
|
-
frame.key === "right" &&
|
|
398
|
-
hasTypeofCheck(frame.node.left, name, false))
|
|
399
|
-
) {
|
|
434
|
+
if (frame.node.type === "LogicalExpression" && frame.key === "right") {
|
|
435
|
+
if (frame.node.operator === "&&" && provesDefinedWhen(frame.node.left, name, true)) {
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
if (frame.node.operator === "||" && provesDefinedWhen(frame.node.left, name, false)) {
|
|
400
439
|
return true;
|
|
401
440
|
}
|
|
402
441
|
}
|
|
403
442
|
if (frame.node.type === "IfStatement" || frame.node.type === "ConditionalExpression") {
|
|
404
|
-
if (frame.key === "consequent" &&
|
|
405
|
-
if (frame.key === "alternate" &&
|
|
443
|
+
if (frame.key === "consequent" && provesDefinedWhen(frame.node.test, name, true)) return true;
|
|
444
|
+
if (frame.key === "alternate" && provesDefinedWhen(frame.node.test, name, false)) return true;
|
|
445
|
+
}
|
|
446
|
+
if (
|
|
447
|
+
isFunctionNode(frame.node) ||
|
|
448
|
+
frame.node.type === "StaticBlock" ||
|
|
449
|
+
frame.node.type === "Program"
|
|
450
|
+
) {
|
|
451
|
+
break;
|
|
406
452
|
}
|
|
407
|
-
if (isFunctionNode(frame.node) || frame.node.type === "Program") break;
|
|
408
453
|
}
|
|
409
454
|
return false;
|
|
410
455
|
}
|
|
@@ -516,8 +561,8 @@ export function validateModule(
|
|
|
516
561
|
}
|
|
517
562
|
};
|
|
518
563
|
|
|
519
|
-
function checkIdentifierReference(name: string, scope: Scope): void {
|
|
520
|
-
if (isTypeofGuarded(name, ancestors)) return;
|
|
564
|
+
function checkIdentifierReference(name: string, scope: Scope, allowTypeofGuard = true): void {
|
|
565
|
+
if (allowTypeofGuard && isTypeofGuarded(name, ancestors)) return;
|
|
521
566
|
if (
|
|
522
567
|
bundled &&
|
|
523
568
|
!hasBinding(scope, name) &&
|
|
@@ -558,7 +603,7 @@ export function validateModule(
|
|
|
558
603
|
if (isAssignmentTarget) {
|
|
559
604
|
const name = pattern.name as string;
|
|
560
605
|
markWrite(name, scope);
|
|
561
|
-
checkIdentifierReference(name, scope);
|
|
606
|
+
checkIdentifierReference(name, scope, false);
|
|
562
607
|
}
|
|
563
608
|
break;
|
|
564
609
|
case "MemberExpression":
|
|
@@ -867,10 +912,7 @@ export function validateModule(
|
|
|
867
912
|
pushAndWalk(node, "right", node.right, scope);
|
|
868
913
|
break;
|
|
869
914
|
case "UpdateExpression":
|
|
870
|
-
|
|
871
|
-
markWrite(node.argument.name as string, scope);
|
|
872
|
-
}
|
|
873
|
-
pushAndWalk(node, "argument", node.argument, scope);
|
|
915
|
+
walkPattern(node, "argument", node.argument, scope, true);
|
|
874
916
|
break;
|
|
875
917
|
case "MemberExpression":
|
|
876
918
|
pushAndWalk(node, "object", node.object, scope);
|
package/src/watch.ts
CHANGED
|
@@ -105,6 +105,10 @@ export function watchApplication(
|
|
|
105
105
|
appDirectory = path.join(root, "apps/examples", app),
|
|
106
106
|
development = false,
|
|
107
107
|
strictTypecheck = false,
|
|
108
|
+
preflight,
|
|
109
|
+
hostRoot,
|
|
110
|
+
hostExecutable,
|
|
111
|
+
hostSearchFrom,
|
|
108
112
|
extraCapabilities,
|
|
109
113
|
capabilitiesFile,
|
|
110
114
|
cssModuleInclude,
|
|
@@ -305,6 +309,10 @@ export function watchApplication(
|
|
|
305
309
|
root,
|
|
306
310
|
appDirectory,
|
|
307
311
|
development,
|
|
312
|
+
preflight,
|
|
313
|
+
hostRoot,
|
|
314
|
+
hostExecutable,
|
|
315
|
+
hostSearchFrom,
|
|
308
316
|
extraCapabilities,
|
|
309
317
|
capabilitiesFile,
|
|
310
318
|
signal: controller.signal,
|