@scriptc/compiler 0.1.3 → 0.1.4
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/ambient/scriptc-node-fallback.d.ts +200 -51
- package/dist/backend/c/async.d.ts +25 -0
- package/dist/backend/c/async.js +167 -0
- package/dist/backend/c/async.js.map +1 -1
- package/dist/backend/c/c-emitter.d.ts +10 -0
- package/dist/backend/c/c-emitter.js +14 -2
- package/dist/backend/c/c-emitter.js.map +1 -1
- package/dist/backend/c/exprs.js +293 -51
- package/dist/backend/c/exprs.js.map +1 -1
- package/dist/backend/c/types.js +2 -0
- package/dist/backend/c/types.js.map +1 -1
- package/dist/backend/link-plan.d.ts +2 -1
- package/dist/backend/link-plan.js +2 -1
- package/dist/backend/link-plan.js.map +1 -1
- package/dist/backend/llvm/emitter.js +20 -6
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/expr-bytes.d.ts +1 -1
- package/dist/backend/llvm/expr-bytes.js +8 -8
- package/dist/backend/llvm/expr-bytes.js.map +1 -1
- package/dist/backend/llvm/expr-callbacks.d.ts +9 -0
- package/dist/backend/llvm/expr-callbacks.js +125 -0
- package/dist/backend/llvm/expr-callbacks.js.map +1 -1
- package/dist/backend/llvm/expr-context.d.ts +14 -2
- package/dist/backend/llvm/expr-dispatch.js +1 -0
- package/dist/backend/llvm/expr-dispatch.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.d.ts +1 -1
- package/dist/backend/llvm/expr-primitives.js +30 -9
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.test.d.ts +1 -0
- package/dist/backend/llvm/expr-primitives.test.js +38 -0
- package/dist/backend/llvm/expr-primitives.test.js.map +1 -0
- package/dist/backend/llvm/expr-stream-callbacks.d.ts +3 -0
- package/dist/backend/llvm/expr-stream-callbacks.js +69 -0
- package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
- package/dist/backend/llvm/lib-filesystem.js +68 -10
- package/dist/backend/llvm/lib-filesystem.js.map +1 -1
- package/dist/backend/llvm/lib-network.js +18 -2
- package/dist/backend/llvm/lib-network.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +156 -6
- package/dist/backend/llvm/lib-process.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +36 -0
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/lib-stream.js +23 -0
- package/dist/backend/llvm/lib-stream.js.map +1 -1
- package/dist/backend/native-toolchain.d.ts +3 -0
- package/dist/backend/native-toolchain.js +3 -1
- package/dist/backend/native-toolchain.js.map +1 -1
- package/dist/backend/runtime-pack.test.js +28 -10
- package/dist/backend/runtime-pack.test.js.map +1 -1
- package/dist/backend/targets.d.ts +4 -0
- package/dist/backend/targets.js +13 -0
- package/dist/backend/targets.js.map +1 -1
- package/dist/backend/targets.test.js +8 -1
- package/dist/backend/targets.test.js.map +1 -1
- package/dist/coverage/surface-manifest.js +8 -0
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/diagnostics/diagnostic.js +1 -1
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/executable/executable-cache.d.ts +2 -0
- package/dist/executable/executable-cache.js +3 -0
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/frontend/fork-target.d.ts +17 -0
- package/dist/frontend/fork-target.js +256 -0
- package/dist/frontend/fork-target.js.map +1 -0
- package/dist/frontend/lowering/abstract-equality.d.ts +6 -0
- package/dist/frontend/lowering/abstract-equality.js +250 -0
- package/dist/frontend/lowering/abstract-equality.js.map +1 -0
- package/dist/frontend/lowering/lower-assert.js +71 -2
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-builtins.d.ts +50 -23
- package/dist/frontend/lowering/lower-builtins.js +939 -106
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.d.ts +29 -21
- package/dist/frontend/lowering/lower-calls.js +573 -121
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.js +39 -8
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.js +150 -0
- package/dist/frontend/lowering/lower-containers.js.map +1 -1
- package/dist/frontend/lowering/lower-event-emitter.js +212 -21
- package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.js +135 -83
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.d.ts +4 -0
- package/dist/frontend/lowering/lower-inspect.js +1 -1
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-island.d.ts +6 -3
- package/dist/frontend/lowering/lower-island.js +165 -6
- package/dist/frontend/lowering/lower-island.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.d.ts +6 -0
- package/dist/frontend/lowering/lower-modules.js +184 -38
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-namespaces.js +7 -0
- package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
- package/dist/frontend/lowering/lower-server.d.ts +1 -1
- package/dist/frontend/lowering/lower-server.js +130 -27
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.js +118 -15
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.d.ts +3 -0
- package/dist/frontend/lowering/lower-stream.js +7 -0
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +86 -9
- package/dist/frontend/lowering/lowerer.js +412 -72
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/surfaces.d.ts +26 -0
- package/dist/frontend/lowering/surfaces.js +140 -77
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/npm-static-declarations.d.ts +4 -0
- package/dist/frontend/npm-static-declarations.js +56 -0
- package/dist/frontend/npm-static-declarations.js.map +1 -1
- package/dist/frontend/npm-static-declarations.test.js +23 -2
- package/dist/frontend/npm-static-declarations.test.js.map +1 -1
- package/dist/frontend/npm-static.js +6 -5
- package/dist/frontend/npm-static.js.map +1 -1
- package/dist/frontend/npm.d.ts +15 -3
- package/dist/frontend/npm.js +80 -8
- package/dist/frontend/npm.js.map +1 -1
- package/dist/frontend/npm.test.js +76 -9
- package/dist/frontend/npm.test.js.map +1 -1
- package/dist/frontend/program.js +92 -10
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/resolve.d.ts +6 -0
- package/dist/frontend/resolve.js +7 -4
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/type-mapper.d.ts +5 -0
- package/dist/frontend/type-mapper.js +64 -24
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +24 -3
- package/dist/index.js.map +1 -1
- package/dist/ir/ir.d.ts +93 -47
- package/dist/ir/ir.js +63 -4
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/ir.test.js +14 -1
- package/dist/ir/ir.test.js.map +1 -1
- package/dist/ir/serialize.d.ts +1 -1
- package/dist/ir/serialize.js +1 -1
- package/dist/ir/serialize.js.map +1 -1
- package/dist/ir/validate.js +165 -13
- package/dist/ir/validate.js.map +1 -1
- package/dist/library/int-infer.test.js +4 -4
- package/dist/library/int-infer.test.js.map +1 -1
- package/dist/library/library-cache.test.js +5 -5
- package/dist/library/library-cache.test.js.map +1 -1
- package/package.json +17 -17
- package/surface-manifest.json +132 -38
package/dist/frontend/program.js
CHANGED
|
@@ -53,6 +53,7 @@ import { builtinDefaultImportModule, canonicalBuiltinModule, SUPPORTED_NODE_MODU
|
|
|
53
53
|
import { clearWorkspacePackages, isRelativeSpecifier, isWorkspacePackageName, npmPackageNameOf, registerWorkspacePackage, workspacePackageOfPath, } from "./workspace-registry.js";
|
|
54
54
|
import { ADOPTED_OPTIONS, isJsSourceFileName, JS_ANY_OPERATOR_CODES, JS_RELAXED_TSC_CODES, } from "./tsc-codes.js";
|
|
55
55
|
import { trackedFileExists, trackedReadFile, trackedRealpath } from "./input-tracker.js";
|
|
56
|
+
import { forkTargetPaths } from "./fork-target.js";
|
|
56
57
|
const BASE_OPTIONS = {
|
|
57
58
|
strict: true,
|
|
58
59
|
};
|
|
@@ -344,6 +345,44 @@ function externalTypeFileClosure7(program, externalTypes) {
|
|
|
344
345
|
}
|
|
345
346
|
return new Map([...ownersByFile].map(([file, owners]) => [file, [...owners]]));
|
|
346
347
|
}
|
|
348
|
+
/** Program roots hidden behind canonical createRequire bindings. tsgo
|
|
349
|
+
* discovers ordinary import/require edges itself, but a source binding
|
|
350
|
+
* returned by createRequire is intentionally just a function to the type
|
|
351
|
+
* checker. Rebuild the native program with each literal project target as
|
|
352
|
+
* an explicit root, to a fixpoint, so the same TS 7 AST/checker world owns
|
|
353
|
+
* their exports and transitive graph. */
|
|
354
|
+
function createRequireProgramRoots7(program) {
|
|
355
|
+
const known = new Set(program.getSourceFiles().map((sf) => tsgoPath(resolve(sf.fileName))));
|
|
356
|
+
const roots = new Set();
|
|
357
|
+
for (const sf of program.getSourceFiles()) {
|
|
358
|
+
if (sf.isDeclarationFile || sf.fileName.endsWith(".json"))
|
|
359
|
+
continue;
|
|
360
|
+
ts.walkPreorder(sf, (node) => {
|
|
361
|
+
if (!ts.isCallExpression(node) || node.questionDotToken !== undefined ||
|
|
362
|
+
node.arguments.length !== 1 || !ts.isStringLiteralLike(node.arguments[0]) ||
|
|
363
|
+
!ts.isIdentifier(node.expression) || !isCreateRequireBinding7(program, node.expression)) {
|
|
364
|
+
return undefined;
|
|
365
|
+
}
|
|
366
|
+
const spec = node.arguments[0].text;
|
|
367
|
+
if (canonicalBuiltinModule(spec) !== null)
|
|
368
|
+
return "skip";
|
|
369
|
+
let target = resolveProjectModule(sf.fileName, spec);
|
|
370
|
+
if (target === null && !spec.startsWith("#")) {
|
|
371
|
+
const npm = resolveNpmImport7(sf.fileName, spec);
|
|
372
|
+
if (npm !== null && isNpmStaticPackage(npm.packageName) && isJsSourceFileName(npm.typesFile)) {
|
|
373
|
+
target = npm.typesFile;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (target === null || target.endsWith(".json"))
|
|
377
|
+
return "skip";
|
|
378
|
+
const normalized = tsgoPath(resolve(target));
|
|
379
|
+
if (!known.has(normalized))
|
|
380
|
+
roots.add(normalized);
|
|
381
|
+
return "skip";
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
return [...roots].sort();
|
|
385
|
+
}
|
|
347
386
|
function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
348
387
|
const config = adoptProjectConfig7(host, entryPath);
|
|
349
388
|
const configuredPaths = config.options["paths"];
|
|
@@ -379,7 +418,22 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
379
418
|
options = { ...options, paths };
|
|
380
419
|
}
|
|
381
420
|
const coreRoots = [entryPath, ambientDtsPath(), nodeTypes ?? fallbackDtsPath()];
|
|
382
|
-
const
|
|
421
|
+
const programRoots = [...coreRoots];
|
|
422
|
+
let program = ts.createProgram([...programRoots, overridesDtsPath()], options, host);
|
|
423
|
+
for (let pass = 0; pass < 32; pass++) {
|
|
424
|
+
const candidates = [
|
|
425
|
+
...createRequireProgramRoots7(program),
|
|
426
|
+
...forkTargetPaths(program, program.getSourceFiles()),
|
|
427
|
+
];
|
|
428
|
+
const extraRoots = candidates.filter((root, index) => !programRoots.includes(root) && candidates.indexOf(root) === index);
|
|
429
|
+
if (extraRoots.length === 0)
|
|
430
|
+
break;
|
|
431
|
+
program.dispose();
|
|
432
|
+
programRoots.push(...extraRoots);
|
|
433
|
+
program = ts.createProgram([...programRoots, overridesDtsPath()], options, host);
|
|
434
|
+
if (pass === 31)
|
|
435
|
+
throw new Error("static program-root discovery did not converge");
|
|
436
|
+
}
|
|
383
437
|
const entry = program.getSourceFile(entryPath);
|
|
384
438
|
if (!entry)
|
|
385
439
|
throw new Error(`could not load ${entryPath}`);
|
|
@@ -392,7 +446,7 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
392
446
|
configDiags: config.diags,
|
|
393
447
|
externalTypes,
|
|
394
448
|
externalTypeSpecifiersByFile,
|
|
395
|
-
projectWorld: () => (projectWorld ??= ts.createProgram(
|
|
449
|
+
projectWorld: () => (projectWorld ??= ts.createProgram(programRoots, options, host)),
|
|
396
450
|
disposeAll: () => {
|
|
397
451
|
projectWorld?.dispose();
|
|
398
452
|
program.dispose();
|
|
@@ -562,13 +616,18 @@ function suppressedJsStrictness7(d) {
|
|
|
562
616
|
* share — anything require-shaped it does NOT match (computed specifiers,
|
|
563
617
|
* extra arguments) is not a module edge and fences at its use site. */
|
|
564
618
|
function requireSpecOf7(node) {
|
|
565
|
-
|
|
619
|
+
let value = node;
|
|
620
|
+
while (ts.isParenthesizedExpression(value) || ts.isAsExpression(value) ||
|
|
621
|
+
ts.isTypeAssertion(value) || ts.isNonNullExpression(value)) {
|
|
622
|
+
value = value.expression;
|
|
623
|
+
}
|
|
624
|
+
if (!ts.isCallExpression(value))
|
|
566
625
|
return null;
|
|
567
|
-
if (!ts.isIdentifier(
|
|
626
|
+
if (!ts.isIdentifier(value.expression) || value.expression.text !== "require")
|
|
568
627
|
return null;
|
|
569
|
-
if (
|
|
628
|
+
if (value.arguments.length !== 1)
|
|
570
629
|
return null;
|
|
571
|
-
const arg =
|
|
630
|
+
const arg = value.arguments[0];
|
|
572
631
|
return ts.isStringLiteral(arg) ? arg.text : null;
|
|
573
632
|
}
|
|
574
633
|
/** True for statements that are CommonJS require IMPORTS at a module's top
|
|
@@ -806,7 +865,8 @@ function isCreateRequireBinding7(program, callee) {
|
|
|
806
865
|
* module edges; other source bindings get a pointed fence before lowering
|
|
807
866
|
* can mistake them for module syntax. */
|
|
808
867
|
function requireCallBindingKind7(program, node) {
|
|
809
|
-
const
|
|
868
|
+
const raw = ts.isVariableDeclaration(node) ? node.initializer : node;
|
|
869
|
+
const call = raw && ts.isExpression(raw) ? stripRequireCasts7(raw) : raw;
|
|
810
870
|
if (!call || !ts.isCallExpression(call) || !ts.isIdentifier(call.expression))
|
|
811
871
|
return "ambient";
|
|
812
872
|
const checker = program.getTypeChecker();
|
|
@@ -2234,7 +2294,8 @@ function preflight7(load) {
|
|
|
2234
2294
|
depPositions.get(sf).push({ dep, pos: stmt.getStart(sf) });
|
|
2235
2295
|
}
|
|
2236
2296
|
}
|
|
2237
|
-
|
|
2297
|
+
{
|
|
2298
|
+
const jsRequireFile = isJsSourceFileName(sf.fileName);
|
|
2238
2299
|
const stmts = sf.statements;
|
|
2239
2300
|
let firstRunnable = -1;
|
|
2240
2301
|
stmts.forEach((s, i) => {
|
|
@@ -2245,8 +2306,14 @@ function preflight7(load) {
|
|
|
2245
2306
|
const stmt = stmts[k];
|
|
2246
2307
|
for (const req of requiresOf7(stmt)) {
|
|
2247
2308
|
const loc = { file: sf.fileName, start: req.node.getStart(sf), end: req.node.getEnd() };
|
|
2309
|
+
const bindingKind = requireCallBindingKind7(program, req.node);
|
|
2310
|
+
// TypeScript source files join this scan only through the
|
|
2311
|
+
// canonical createRequire bridge. Their ordinary require-shaped
|
|
2312
|
+
// calls retain the existing checker/lowering diagnostics; JS
|
|
2313
|
+
// files keep the full CommonJS scan.
|
|
2314
|
+
if (!jsRequireFile && bindingKind !== "createRequire")
|
|
2315
|
+
continue;
|
|
2248
2316
|
if (isNodeEsmFile7(sf)) {
|
|
2249
|
-
const bindingKind = requireCallBindingKind7(program, req.node);
|
|
2250
2317
|
if (bindingKind !== "createRequire") {
|
|
2251
2318
|
diags.push(unsupportedDiag("SC1013", loc, esmRequireFeature7(bindingKind)));
|
|
2252
2319
|
continue;
|
|
@@ -2281,6 +2348,13 @@ function preflight7(load) {
|
|
|
2281
2348
|
continue; // offender recorded — the fallback loop reloads
|
|
2282
2349
|
}
|
|
2283
2350
|
else {
|
|
2351
|
+
// createRequire's non-program targets belong to its own
|
|
2352
|
+
// lowering: installed packages select static-vs-island
|
|
2353
|
+
// there, and missing packages become catchable
|
|
2354
|
+
// MODULE_NOT_FOUND throws. Only resolved program targets are
|
|
2355
|
+
// module-order edges in this preflight walk.
|
|
2356
|
+
if (bindingKind === "createRequire")
|
|
2357
|
+
continue;
|
|
2284
2358
|
if (canonicalBuiltinModule(req.spec) === null &&
|
|
2285
2359
|
!processModuleAliasRequire7(req.spec, req.decl)) {
|
|
2286
2360
|
// A binding-less require of a package NOTHING resolves:
|
|
@@ -2297,6 +2371,8 @@ function preflight7(load) {
|
|
|
2297
2371
|
}
|
|
2298
2372
|
}
|
|
2299
2373
|
if (dep && dep.fileName.endsWith(".json")) {
|
|
2374
|
+
if (bindingKind === "createRequire")
|
|
2375
|
+
continue;
|
|
2300
2376
|
diags.push(unsupportedDiag("SC1012", loc, "require() of JSON modules"));
|
|
2301
2377
|
continue;
|
|
2302
2378
|
}
|
|
@@ -2316,8 +2392,10 @@ function preflight7(load) {
|
|
|
2316
2392
|
for (const call of nestedBareRequires) {
|
|
2317
2393
|
const spec = requireSpecOf7(call);
|
|
2318
2394
|
const loc = { file: sf.fileName, start: call.getStart(sf), end: call.getEnd() };
|
|
2395
|
+
const bindingKind = requireCallBindingKind7(program, call);
|
|
2396
|
+
if (!jsRequireFile && bindingKind !== "createRequire")
|
|
2397
|
+
continue;
|
|
2319
2398
|
if (isNodeEsmFile7(sf)) {
|
|
2320
|
-
const bindingKind = requireCallBindingKind7(program, call);
|
|
2321
2399
|
if (bindingKind !== "createRequire") {
|
|
2322
2400
|
diags.push(unsupportedDiag("SC1013", loc, esmRequireFeature7(bindingKind)));
|
|
2323
2401
|
continue;
|
|
@@ -2329,6 +2407,8 @@ function preflight7(load) {
|
|
|
2329
2407
|
const projectDep = resolveImport7(program, sf, spec);
|
|
2330
2408
|
if (projectDep !== null) {
|
|
2331
2409
|
if (projectDep.fileName.endsWith(".json")) {
|
|
2410
|
+
if (bindingKind === "createRequire")
|
|
2411
|
+
continue;
|
|
2332
2412
|
diags.push(unsupportedDiag("SC1012", loc, "require() of JSON modules"));
|
|
2333
2413
|
continue;
|
|
2334
2414
|
}
|
|
@@ -2345,6 +2425,8 @@ function preflight7(load) {
|
|
|
2345
2425
|
deps.push({ dep: nDep });
|
|
2346
2426
|
continue;
|
|
2347
2427
|
}
|
|
2428
|
+
if (bindingKind === "createRequire")
|
|
2429
|
+
continue;
|
|
2348
2430
|
if (canonicalBuiltinModule(spec) === null && !processModuleAliasRequire7(spec, null)) {
|
|
2349
2431
|
// Binding-less by construction — same require-site throw
|
|
2350
2432
|
// channel as the statement-level form above.
|