@scriptc/compiler 0.1.3 → 0.1.5
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 +275 -62
- 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 +15 -1
- package/dist/backend/c/c-emitter.js +36 -11
- package/dist/backend/c/c-emitter.js.map +1 -1
- package/dist/backend/c/exprs.d.ts +2 -2
- package/dist/backend/c/exprs.js +556 -71
- package/dist/backend/c/exprs.js.map +1 -1
- package/dist/backend/c/stmts.js +5 -3
- package/dist/backend/c/stmts.js.map +1 -1
- package/dist/backend/c/types.d.ts +2 -3
- package/dist/backend/c/types.js +10 -1
- package/dist/backend/c/types.js.map +1 -1
- package/dist/backend/c/walkers.js +1 -1
- package/dist/backend/c/walkers.js.map +1 -1
- package/dist/backend/link-plan.d.ts +3 -1
- package/dist/backend/link-plan.js +3 -1
- package/dist/backend/link-plan.js.map +1 -1
- package/dist/backend/llvm/dyn.js +1 -1
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.js +42 -12
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/expr-bytes.d.ts +1 -2
- package/dist/backend/llvm/expr-bytes.js +28 -23
- 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-containers.d.ts +1 -0
- package/dist/backend/llvm/expr-containers.js +32 -4
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-context.d.ts +19 -3
- 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 +49 -13
- 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 +80 -10
- package/dist/backend/llvm/lib-filesystem.js.map +1 -1
- package/dist/backend/llvm/lib-network.js +69 -10
- 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 +100 -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 +5 -0
- package/dist/backend/native-toolchain.js +4 -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 +7 -0
- package/dist/backend/targets.js +26 -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 +14 -4
- 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 +4 -0
- package/dist/executable/executable-cache.js +6 -1
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/executable/executable-cache.test.js +3 -3
- package/dist/executable/executable-cache.test.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/containers/bytes.d.ts +1 -1
- package/dist/frontend/lowering/containers/bytes.js +6 -5
- package/dist/frontend/lowering/containers/bytes.js.map +1 -1
- package/dist/frontend/lowering/containers/string-and-regexp.d.ts +7 -6
- package/dist/frontend/lowering/containers/string-and-regexp.js +237 -28
- package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
- package/dist/frontend/lowering/expressions/object-literals.js +8 -0
- package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
- 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 +54 -28
- package/dist/frontend/lowering/lower-builtins.js +957 -116
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.d.ts +32 -23
- package/dist/frontend/lowering/lower-calls.js +835 -206
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.js +41 -10
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.d.ts +7 -9
- package/dist/frontend/lowering/lower-containers.js +293 -51
- 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.d.ts +12 -0
- package/dist/frontend/lowering/lower-exprs.js +263 -93
- 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 +182 -12
- 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 +3 -5
- package/dist/frontend/lowering/lower-server.js +413 -54
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.js +122 -19
- 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 +449 -74
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/optional-arguments.d.ts +9 -1
- package/dist/frontend/lowering/optional-arguments.js +67 -1
- package/dist/frontend/lowering/optional-arguments.js.map +1 -1
- package/dist/frontend/lowering/pairs-snapshot.d.ts +3 -1
- package/dist/frontend/lowering/pairs-snapshot.js +12 -4
- package/dist/frontend/lowering/pairs-snapshot.js.map +1 -1
- package/dist/frontend/lowering/surfaces.d.ts +34 -14
- package/dist/frontend/lowering/surfaces.js +177 -104
- 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-prune.d.ts +6 -0
- package/dist/frontend/npm-static-prune.js +203 -0
- package/dist/frontend/npm-static-prune.js.map +1 -0
- package/dist/frontend/npm-static-prune.test.d.ts +1 -0
- package/dist/frontend/npm-static-prune.test.js +48 -0
- package/dist/frontend/npm-static-prune.test.js.map +1 -0
- 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 +87 -14
- 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 +107 -14
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/provenance.js +8 -3
- package/dist/frontend/provenance.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 +80 -29
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +34 -41
- package/dist/index.js.map +1 -1
- package/dist/ir/analysis.d.ts +5 -3
- package/dist/ir/analysis.js +25 -11
- package/dist/ir/analysis.js.map +1 -1
- package/dist/ir/analysis.test.js +50 -2
- package/dist/ir/analysis.test.js.map +1 -1
- package/dist/ir/constant-tables.d.ts +17 -0
- package/dist/ir/constant-tables.js +99 -0
- package/dist/ir/constant-tables.js.map +1 -0
- package/dist/ir/constant-tables.test.d.ts +1 -0
- package/dist/ir/constant-tables.test.js +78 -0
- package/dist/ir/constant-tables.test.js.map +1 -0
- package/dist/ir/integer-ranges.d.ts +13 -0
- package/dist/ir/integer-ranges.js +122 -0
- package/dist/ir/integer-ranges.js.map +1 -0
- package/dist/ir/integer-ranges.test.d.ts +1 -0
- package/dist/ir/integer-ranges.test.js +63 -0
- package/dist/ir/integer-ranges.test.js.map +1 -0
- package/dist/ir/ir.d.ts +130 -76
- package/dist/ir/ir.js +69 -4
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/ir.test.js +20 -1
- package/dist/ir/ir.test.js.map +1 -1
- package/dist/ir/scalar-records.d.ts +8 -0
- package/dist/ir/scalar-records.js +216 -0
- package/dist/ir/scalar-records.js.map +1 -0
- package/dist/ir/scalar-records.test.d.ts +1 -0
- package/dist/ir/scalar-records.test.js +142 -0
- package/dist/ir/scalar-records.test.js.map +1 -0
- 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 +256 -20
- package/dist/ir/validate.js.map +1 -1
- package/dist/ir/validate.test.d.ts +1 -0
- package/dist/ir/validate.test.js +31 -0
- package/dist/ir/validate.test.js.map +1 -0
- package/dist/library/cache-primitives.d.ts +1 -1
- package/dist/library/cache-primitives.js +3 -3
- package/dist/library/cache-primitives.js.map +1 -1
- package/dist/library/fence-eval.js +11 -4
- package/dist/library/fence-eval.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.js +0 -1
- package/dist/library/library-cache.js.map +1 -1
- package/dist/library/library-cache.test.js +8 -8
- package/dist/library/library-cache.test.js.map +1 -1
- package/package.json +17 -17
- package/surface-manifest.json +186 -79
package/dist/frontend/program.js
CHANGED
|
@@ -45,6 +45,7 @@ import { commonJsModuleSyntaxDiag, invalidPackageConfigDiag, strictNullChecksFlo
|
|
|
45
45
|
import { isNodeModulesPath, nearestInvalidPackageJsonPath, nearestPackageType, nearestPkgJsonPath, projectDtsRuntimeSibling, resolveBareModule, resolveProjectModule, resolveTypeDirective, setProjectPathMappings, setProjectRealm } from "./resolve.js";
|
|
46
46
|
import { probeNodeImportRefusal, probeNodeRequireRefusal } from "./npm.js";
|
|
47
47
|
import { isNpmStaticPackage, npmStaticActive, npmStaticFsShadow, npmStaticPackageOfPath, reportNpmStaticOffender, setNpmStaticDeclarationOverloads, setNpmStaticPackages } from "./npm-static.js";
|
|
48
|
+
import { isPrunedNpmReexport, planNpmStaticReexports } from "./npm-static-prune.js";
|
|
48
49
|
import { npmStaticDeclarationReexports, npmStaticRuntimeClassTargets, parseNpmStaticDeclarationOverloads, parseNpmStaticDeclarationProperties } from "./npm-static-declarations.js";
|
|
49
50
|
import { provenanceEntryFor, provenancePaths } from "./provenance-registry.js";
|
|
50
51
|
import { cjsLexerVisibleNames } from "./cjs-lexer.js";
|
|
@@ -53,6 +54,7 @@ import { builtinDefaultImportModule, canonicalBuiltinModule, SUPPORTED_NODE_MODU
|
|
|
53
54
|
import { clearWorkspacePackages, isRelativeSpecifier, isWorkspacePackageName, npmPackageNameOf, registerWorkspacePackage, workspacePackageOfPath, } from "./workspace-registry.js";
|
|
54
55
|
import { ADOPTED_OPTIONS, isJsSourceFileName, JS_ANY_OPERATOR_CODES, JS_RELAXED_TSC_CODES, } from "./tsc-codes.js";
|
|
55
56
|
import { trackedFileExists, trackedReadFile, trackedRealpath } from "./input-tracker.js";
|
|
57
|
+
import { forkTargetPaths } from "./fork-target.js";
|
|
56
58
|
const BASE_OPTIONS = {
|
|
57
59
|
strict: true,
|
|
58
60
|
};
|
|
@@ -344,6 +346,44 @@ function externalTypeFileClosure7(program, externalTypes) {
|
|
|
344
346
|
}
|
|
345
347
|
return new Map([...ownersByFile].map(([file, owners]) => [file, [...owners]]));
|
|
346
348
|
}
|
|
349
|
+
/** Program roots hidden behind canonical createRequire bindings. tsgo
|
|
350
|
+
* discovers ordinary import/require edges itself, but a source binding
|
|
351
|
+
* returned by createRequire is intentionally just a function to the type
|
|
352
|
+
* checker. Rebuild the native program with each literal project target as
|
|
353
|
+
* an explicit root, to a fixpoint, so the same TS 7 AST/checker world owns
|
|
354
|
+
* their exports and transitive graph. */
|
|
355
|
+
function createRequireProgramRoots7(program) {
|
|
356
|
+
const known = new Set(program.getSourceFiles().map((sf) => tsgoPath(resolve(sf.fileName))));
|
|
357
|
+
const roots = new Set();
|
|
358
|
+
for (const sf of program.getSourceFiles()) {
|
|
359
|
+
if (sf.isDeclarationFile || sf.fileName.endsWith(".json"))
|
|
360
|
+
continue;
|
|
361
|
+
ts.walkPreorder(sf, (node) => {
|
|
362
|
+
if (!ts.isCallExpression(node) || node.questionDotToken !== undefined ||
|
|
363
|
+
node.arguments.length !== 1 || !ts.isStringLiteralLike(node.arguments[0]) ||
|
|
364
|
+
!ts.isIdentifier(node.expression) || !isCreateRequireBinding7(program, node.expression)) {
|
|
365
|
+
return undefined;
|
|
366
|
+
}
|
|
367
|
+
const spec = node.arguments[0].text;
|
|
368
|
+
if (canonicalBuiltinModule(spec) !== null)
|
|
369
|
+
return "skip";
|
|
370
|
+
let target = resolveProjectModule(sf.fileName, spec);
|
|
371
|
+
if (target === null && !spec.startsWith("#")) {
|
|
372
|
+
const npm = resolveNpmImport7(sf.fileName, spec);
|
|
373
|
+
if (npm !== null && isNpmStaticPackage(npm.packageName) && isJsSourceFileName(npm.typesFile)) {
|
|
374
|
+
target = npm.typesFile;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (target === null || target.endsWith(".json"))
|
|
378
|
+
return "skip";
|
|
379
|
+
const normalized = tsgoPath(resolve(target));
|
|
380
|
+
if (!known.has(normalized))
|
|
381
|
+
roots.add(normalized);
|
|
382
|
+
return "skip";
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
return [...roots].sort();
|
|
386
|
+
}
|
|
347
387
|
function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
348
388
|
const config = adoptProjectConfig7(host, entryPath);
|
|
349
389
|
const configuredPaths = config.options["paths"];
|
|
@@ -361,8 +401,10 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
361
401
|
// just resolved) — without maxNodeModuleJsDepth, node_modules JS types as
|
|
362
402
|
// an implicit-any module (TS7016) and nothing infers. Only flagged
|
|
363
403
|
// compiles pay this; flagless builds keep the exact historical options.
|
|
404
|
+
// Eight levels retain package-internal re-export chains such as Effect's;
|
|
405
|
+
// the former four-level cap left valid bindings outside the checker graph.
|
|
364
406
|
if (npmStaticActive())
|
|
365
|
-
options.maxNodeModuleJsDepth =
|
|
407
|
+
options.maxNodeModuleJsDepth = 8;
|
|
366
408
|
// --provenance-sources: the registered entries become tsconfig "paths"
|
|
367
409
|
// so tsgo's OWN resolution of the bare specifiers lands on the same
|
|
368
410
|
// source files the preflight resolver answers — the checker types the
|
|
@@ -379,7 +421,22 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
379
421
|
options = { ...options, paths };
|
|
380
422
|
}
|
|
381
423
|
const coreRoots = [entryPath, ambientDtsPath(), nodeTypes ?? fallbackDtsPath()];
|
|
382
|
-
const
|
|
424
|
+
const programRoots = [...coreRoots];
|
|
425
|
+
let program = ts.createProgram([...programRoots, overridesDtsPath()], options, host);
|
|
426
|
+
for (let pass = 0; pass < 32; pass++) {
|
|
427
|
+
const candidates = [
|
|
428
|
+
...createRequireProgramRoots7(program),
|
|
429
|
+
...forkTargetPaths(program, program.getSourceFiles()),
|
|
430
|
+
];
|
|
431
|
+
const extraRoots = candidates.filter((root, index) => !programRoots.includes(root) && candidates.indexOf(root) === index);
|
|
432
|
+
if (extraRoots.length === 0)
|
|
433
|
+
break;
|
|
434
|
+
program.dispose();
|
|
435
|
+
programRoots.push(...extraRoots);
|
|
436
|
+
program = ts.createProgram([...programRoots, overridesDtsPath()], options, host);
|
|
437
|
+
if (pass === 31)
|
|
438
|
+
throw new Error("static program-root discovery did not converge");
|
|
439
|
+
}
|
|
383
440
|
const entry = program.getSourceFile(entryPath);
|
|
384
441
|
if (!entry)
|
|
385
442
|
throw new Error(`could not load ${entryPath}`);
|
|
@@ -392,7 +449,7 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
392
449
|
configDiags: config.diags,
|
|
393
450
|
externalTypes,
|
|
394
451
|
externalTypeSpecifiersByFile,
|
|
395
|
-
projectWorld: () => (projectWorld ??= ts.createProgram(
|
|
452
|
+
projectWorld: () => (projectWorld ??= ts.createProgram(programRoots, options, host)),
|
|
396
453
|
disposeAll: () => {
|
|
397
454
|
projectWorld?.dispose();
|
|
398
455
|
program.dispose();
|
|
@@ -562,13 +619,18 @@ function suppressedJsStrictness7(d) {
|
|
|
562
619
|
* share — anything require-shaped it does NOT match (computed specifiers,
|
|
563
620
|
* extra arguments) is not a module edge and fences at its use site. */
|
|
564
621
|
function requireSpecOf7(node) {
|
|
565
|
-
|
|
622
|
+
let value = node;
|
|
623
|
+
while (ts.isParenthesizedExpression(value) || ts.isAsExpression(value) ||
|
|
624
|
+
ts.isTypeAssertion(value) || ts.isNonNullExpression(value)) {
|
|
625
|
+
value = value.expression;
|
|
626
|
+
}
|
|
627
|
+
if (!ts.isCallExpression(value))
|
|
566
628
|
return null;
|
|
567
|
-
if (!ts.isIdentifier(
|
|
629
|
+
if (!ts.isIdentifier(value.expression) || value.expression.text !== "require")
|
|
568
630
|
return null;
|
|
569
|
-
if (
|
|
631
|
+
if (value.arguments.length !== 1)
|
|
570
632
|
return null;
|
|
571
|
-
const arg =
|
|
633
|
+
const arg = value.arguments[0];
|
|
572
634
|
return ts.isStringLiteral(arg) ? arg.text : null;
|
|
573
635
|
}
|
|
574
636
|
/** True for statements that are CommonJS require IMPORTS at a module's top
|
|
@@ -806,7 +868,8 @@ function isCreateRequireBinding7(program, callee) {
|
|
|
806
868
|
* module edges; other source bindings get a pointed fence before lowering
|
|
807
869
|
* can mistake them for module syntax. */
|
|
808
870
|
function requireCallBindingKind7(program, node) {
|
|
809
|
-
const
|
|
871
|
+
const raw = ts.isVariableDeclaration(node) ? node.initializer : node;
|
|
872
|
+
const call = raw && ts.isExpression(raw) ? stripRequireCasts7(raw) : raw;
|
|
810
873
|
if (!call || !ts.isCallExpression(call) || !ts.isIdentifier(call.expression))
|
|
811
874
|
return "ambient";
|
|
812
875
|
const checker = program.getTypeChecker();
|
|
@@ -1853,13 +1916,15 @@ function preflight7(load) {
|
|
|
1853
1916
|
!sf.fileName.endsWith(".json") &&
|
|
1854
1917
|
(!isNodeModulesPath(sf.fileName) || npmStaticPackageOfPath(sf.fileName) !== null) &&
|
|
1855
1918
|
!islandJsFile(sf.fileName));
|
|
1856
|
-
|
|
1919
|
+
const userFiles = npmStaticActive()
|
|
1920
|
+
? planNpmStaticReexports(program, entry, programFiles, [...createRequireProgramRoots7(program), ...forkTargetPaths(program, program.getSourceFiles())], (sf, spec) => resolveImport7(program, sf, spec) ?? npmStaticDepSf7(program, sf, spec))
|
|
1921
|
+
: programFiles;
|
|
1922
|
+
program.getTypeChecker().prefetchSourceFileStructures(userFiles);
|
|
1857
1923
|
// node_modules JS that no --npm-static opt-in claims is NOT program
|
|
1858
1924
|
// source even when maxNodeModuleJsDepth pulled it into the checker's
|
|
1859
1925
|
// program (see nodeModulesJsSuppressed above): its execution home is the
|
|
1860
1926
|
// island, so preflight's statement walks skip it — no import fences, no
|
|
1861
1927
|
// module edges, no statement counts from files the lowering never lowers.
|
|
1862
|
-
const userFiles = programFiles;
|
|
1863
1928
|
// Node stops at the nearest package.json even when it is malformed, and
|
|
1864
1929
|
// an explicit CommonJS scope (or .cjs/.cts extension) disables ambiguous-
|
|
1865
1930
|
// file syntax detection entirely. TypeScript's bundler checker models
|
|
@@ -1963,7 +2028,7 @@ function preflight7(load) {
|
|
|
1963
2028
|
continue;
|
|
1964
2029
|
}
|
|
1965
2030
|
if (ts.isExportDeclaration(stmt)) {
|
|
1966
|
-
if (stmt.isTypeOnly || erasedTypeOnlyReexport(stmt))
|
|
2031
|
+
if (stmt.isTypeOnly || erasedTypeOnlyReexport(stmt) || isPrunedNpmReexport(program, stmt))
|
|
1967
2032
|
continue;
|
|
1968
2033
|
if (!stmt.moduleSpecifier)
|
|
1969
2034
|
continue;
|
|
@@ -2234,7 +2299,8 @@ function preflight7(load) {
|
|
|
2234
2299
|
depPositions.get(sf).push({ dep, pos: stmt.getStart(sf) });
|
|
2235
2300
|
}
|
|
2236
2301
|
}
|
|
2237
|
-
|
|
2302
|
+
{
|
|
2303
|
+
const jsRequireFile = isJsSourceFileName(sf.fileName);
|
|
2238
2304
|
const stmts = sf.statements;
|
|
2239
2305
|
let firstRunnable = -1;
|
|
2240
2306
|
stmts.forEach((s, i) => {
|
|
@@ -2245,8 +2311,14 @@ function preflight7(load) {
|
|
|
2245
2311
|
const stmt = stmts[k];
|
|
2246
2312
|
for (const req of requiresOf7(stmt)) {
|
|
2247
2313
|
const loc = { file: sf.fileName, start: req.node.getStart(sf), end: req.node.getEnd() };
|
|
2314
|
+
const bindingKind = requireCallBindingKind7(program, req.node);
|
|
2315
|
+
// TypeScript source files join this scan only through the
|
|
2316
|
+
// canonical createRequire bridge. Their ordinary require-shaped
|
|
2317
|
+
// calls retain the existing checker/lowering diagnostics; JS
|
|
2318
|
+
// files keep the full CommonJS scan.
|
|
2319
|
+
if (!jsRequireFile && bindingKind !== "createRequire")
|
|
2320
|
+
continue;
|
|
2248
2321
|
if (isNodeEsmFile7(sf)) {
|
|
2249
|
-
const bindingKind = requireCallBindingKind7(program, req.node);
|
|
2250
2322
|
if (bindingKind !== "createRequire") {
|
|
2251
2323
|
diags.push(unsupportedDiag("SC1013", loc, esmRequireFeature7(bindingKind)));
|
|
2252
2324
|
continue;
|
|
@@ -2281,6 +2353,13 @@ function preflight7(load) {
|
|
|
2281
2353
|
continue; // offender recorded — the fallback loop reloads
|
|
2282
2354
|
}
|
|
2283
2355
|
else {
|
|
2356
|
+
// createRequire's non-program targets belong to its own
|
|
2357
|
+
// lowering: installed packages select static-vs-island
|
|
2358
|
+
// there, and missing packages become catchable
|
|
2359
|
+
// MODULE_NOT_FOUND throws. Only resolved program targets are
|
|
2360
|
+
// module-order edges in this preflight walk.
|
|
2361
|
+
if (bindingKind === "createRequire")
|
|
2362
|
+
continue;
|
|
2284
2363
|
if (canonicalBuiltinModule(req.spec) === null &&
|
|
2285
2364
|
!processModuleAliasRequire7(req.spec, req.decl)) {
|
|
2286
2365
|
// A binding-less require of a package NOTHING resolves:
|
|
@@ -2297,6 +2376,8 @@ function preflight7(load) {
|
|
|
2297
2376
|
}
|
|
2298
2377
|
}
|
|
2299
2378
|
if (dep && dep.fileName.endsWith(".json")) {
|
|
2379
|
+
if (bindingKind === "createRequire")
|
|
2380
|
+
continue;
|
|
2300
2381
|
diags.push(unsupportedDiag("SC1012", loc, "require() of JSON modules"));
|
|
2301
2382
|
continue;
|
|
2302
2383
|
}
|
|
@@ -2316,8 +2397,10 @@ function preflight7(load) {
|
|
|
2316
2397
|
for (const call of nestedBareRequires) {
|
|
2317
2398
|
const spec = requireSpecOf7(call);
|
|
2318
2399
|
const loc = { file: sf.fileName, start: call.getStart(sf), end: call.getEnd() };
|
|
2400
|
+
const bindingKind = requireCallBindingKind7(program, call);
|
|
2401
|
+
if (!jsRequireFile && bindingKind !== "createRequire")
|
|
2402
|
+
continue;
|
|
2319
2403
|
if (isNodeEsmFile7(sf)) {
|
|
2320
|
-
const bindingKind = requireCallBindingKind7(program, call);
|
|
2321
2404
|
if (bindingKind !== "createRequire") {
|
|
2322
2405
|
diags.push(unsupportedDiag("SC1013", loc, esmRequireFeature7(bindingKind)));
|
|
2323
2406
|
continue;
|
|
@@ -2329,6 +2412,8 @@ function preflight7(load) {
|
|
|
2329
2412
|
const projectDep = resolveImport7(program, sf, spec);
|
|
2330
2413
|
if (projectDep !== null) {
|
|
2331
2414
|
if (projectDep.fileName.endsWith(".json")) {
|
|
2415
|
+
if (bindingKind === "createRequire")
|
|
2416
|
+
continue;
|
|
2332
2417
|
diags.push(unsupportedDiag("SC1012", loc, "require() of JSON modules"));
|
|
2333
2418
|
continue;
|
|
2334
2419
|
}
|
|
@@ -2345,6 +2430,8 @@ function preflight7(load) {
|
|
|
2345
2430
|
deps.push({ dep: nDep });
|
|
2346
2431
|
continue;
|
|
2347
2432
|
}
|
|
2433
|
+
if (bindingKind === "createRequire")
|
|
2434
|
+
continue;
|
|
2348
2435
|
if (canonicalBuiltinModule(spec) === null && !processModuleAliasRequire7(spec, null)) {
|
|
2349
2436
|
// Binding-less by construction — same require-site throw
|
|
2350
2437
|
// channel as the statement-level form above.
|
|
@@ -2561,6 +2648,8 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
2561
2648
|
for (const stmt of sf.statements) {
|
|
2562
2649
|
if (!ts.isImportDeclaration(stmt) && !(ts.isExportDeclaration(stmt) && !stmt.isTypeOnly))
|
|
2563
2650
|
continue;
|
|
2651
|
+
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
2652
|
+
continue;
|
|
2564
2653
|
if (ts.isImportDeclaration(stmt) && stmt.importClause?.phaseModifier === ts.SyntaxKind.TypeKeyword)
|
|
2565
2654
|
continue;
|
|
2566
2655
|
const specNode = stmt.moduleSpecifier;
|
|
@@ -2787,6 +2876,8 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
2787
2876
|
for (const stmt of sf.statements) {
|
|
2788
2877
|
if (!ts.isImportDeclaration(stmt) && !(ts.isExportDeclaration(stmt) && !stmt.isTypeOnly))
|
|
2789
2878
|
continue;
|
|
2879
|
+
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
2880
|
+
continue;
|
|
2790
2881
|
if (ts.isImportDeclaration(stmt) && stmt.importClause?.phaseModifier === ts.SyntaxKind.TypeKeyword)
|
|
2791
2882
|
continue;
|
|
2792
2883
|
const moduleSpecifier = stmt.moduleSpecifier;
|
|
@@ -2973,6 +3064,8 @@ function erasedTypeOnlyReexport(stmt) {
|
|
|
2973
3064
|
export function orderedImportsOf(program, sf) {
|
|
2974
3065
|
const out = [];
|
|
2975
3066
|
for (const stmt of sf.statements) {
|
|
3067
|
+
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
3068
|
+
continue;
|
|
2976
3069
|
if (ts.isExportDeclaration(stmt) && (stmt.isTypeOnly || erasedTypeOnlyReexport(stmt) || !stmt.moduleSpecifier))
|
|
2977
3070
|
continue;
|
|
2978
3071
|
if (!ts.isImportDeclaration(stmt) && !ts.isExportDeclaration(stmt))
|