@scriptc/compiler 0.0.22 → 0.0.24

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.
Files changed (93) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +139 -14
  2. package/dist/backend/cc.d.ts +13 -0
  3. package/dist/backend/cc.js +11 -0
  4. package/dist/backend/cc.js.map +1 -1
  5. package/dist/backend/emission/emit-async.d.ts +4 -0
  6. package/dist/backend/emission/emit-async.js +34 -2
  7. package/dist/backend/emission/emit-async.js.map +1 -1
  8. package/dist/backend/emission/emit-exprs.d.ts +10 -0
  9. package/dist/backend/emission/emit-exprs.js +272 -22
  10. package/dist/backend/emission/emit-exprs.js.map +1 -1
  11. package/dist/backend/emission/emit-shapes.js +1 -0
  12. package/dist/backend/emission/emit-shapes.js.map +1 -1
  13. package/dist/backend/emission/emit-stmts.js +36 -9
  14. package/dist/backend/emission/emit-stmts.js.map +1 -1
  15. package/dist/backend/emission/emit-types.js +14 -1
  16. package/dist/backend/emission/emit-types.js.map +1 -1
  17. package/dist/backend/emission/emitter.d.ts +19 -1
  18. package/dist/backend/emission/emitter.js +81 -2
  19. package/dist/backend/emission/emitter.js.map +1 -1
  20. package/dist/backend/llvm/emitter.js +578 -36
  21. package/dist/backend/llvm/emitter.js.map +1 -1
  22. package/dist/backend/llvm/shapes.js +12 -3
  23. package/dist/backend/llvm/shapes.js.map +1 -1
  24. package/dist/backend/mangle.d.ts +3 -0
  25. package/dist/backend/mangle.js +5 -0
  26. package/dist/backend/mangle.js.map +1 -1
  27. package/dist/compat/fetch-profile.d.ts +10 -0
  28. package/dist/compat/fetch-profile.js +55 -6
  29. package/dist/compat/fetch-profile.js.map +1 -1
  30. package/dist/coverage/surface-manifest.js +16 -1
  31. package/dist/coverage/surface-manifest.js.map +1 -1
  32. package/dist/diagnostics/diagnostic.d.ts +10 -0
  33. package/dist/diagnostics/diagnostic.js +27 -1
  34. package/dist/diagnostics/diagnostic.js.map +1 -1
  35. package/dist/frontend/lowering/lower-builtins.d.ts +17 -16
  36. package/dist/frontend/lowering/lower-builtins.js +817 -117
  37. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  38. package/dist/frontend/lowering/lower-calls.js +3 -1
  39. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  40. package/dist/frontend/lowering/lower-classes.js +28 -8
  41. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  42. package/dist/frontend/lowering/lower-containers.d.ts +2 -1
  43. package/dist/frontend/lowering/lower-containers.js +99 -32
  44. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  45. package/dist/frontend/lowering/lower-exprs.d.ts +1 -1
  46. package/dist/frontend/lowering/lower-exprs.js +78 -6
  47. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  48. package/dist/frontend/lowering/lower-generators.js +7 -1
  49. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  50. package/dist/frontend/lowering/lower-inspect.js +59 -1
  51. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  52. package/dist/frontend/lowering/lower-island.d.ts +21 -0
  53. package/dist/frontend/lowering/lower-island.js +284 -10
  54. package/dist/frontend/lowering/lower-island.js.map +1 -1
  55. package/dist/frontend/lowering/lower-server.d.ts +5 -0
  56. package/dist/frontend/lowering/lower-server.js +1 -1
  57. package/dist/frontend/lowering/lower-server.js.map +1 -1
  58. package/dist/frontend/lowering/lower-stmts.d.ts +6 -2
  59. package/dist/frontend/lowering/lower-stmts.js +53 -14
  60. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  61. package/dist/frontend/lowering/lowerer.d.ts +3 -2
  62. package/dist/frontend/lowering/lowerer.js +17 -8
  63. package/dist/frontend/lowering/lowerer.js.map +1 -1
  64. package/dist/frontend/lowering/surfaces.js +108 -25
  65. package/dist/frontend/lowering/surfaces.js.map +1 -1
  66. package/dist/frontend/program.d.ts +4 -4
  67. package/dist/frontend/program.js +264 -46
  68. package/dist/frontend/program.js.map +1 -1
  69. package/dist/frontend/resolve.d.ts +10 -0
  70. package/dist/frontend/resolve.js +37 -0
  71. package/dist/frontend/resolve.js.map +1 -1
  72. package/dist/frontend/ts7/enums.d.ts +9 -0
  73. package/dist/frontend/ts7/enums.js +8 -6
  74. package/dist/frontend/ts7/enums.js.map +1 -1
  75. package/dist/frontend/ts7/program.js +4 -1
  76. package/dist/frontend/ts7/program.js.map +1 -1
  77. package/dist/frontend/types.d.ts +7 -4
  78. package/dist/frontend/types.js +103 -8
  79. package/dist/frontend/types.js.map +1 -1
  80. package/dist/index.js +8 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/ir/integer-loops.d.ts +23 -0
  83. package/dist/ir/integer-loops.js +82 -0
  84. package/dist/ir/integer-loops.js.map +1 -0
  85. package/dist/ir/nodes.d.ts +104 -28
  86. package/dist/ir/nodes.js +89 -1
  87. package/dist/ir/nodes.js.map +1 -1
  88. package/dist/ir/validate.js +136 -25
  89. package/dist/ir/validate.js.map +1 -1
  90. package/dist/library/fence-eval.js +4 -3
  91. package/dist/library/fence-eval.js.map +1 -1
  92. package/package.json +2 -2
  93. package/surface-manifest.json +186 -29
@@ -28,11 +28,10 @@
28
28
  * in tsc codes at all: cjsExportDiscardReason (lowering) names every
29
29
  * genuinely discarded export, so relaxing the checker's stricter
30
30
  * modeling loses nothing.
31
- * - isNodeEsmFile: 5.9.3 under bundler sets impliedNodeFormat ONLY for
32
- * .mjs/.cjs-family files (probed) and falls back to syntactic module
33
- * detection for .js/.ts; 7's client SourceFile has no impliedNodeFormat,
34
- * so this lane spells exactly that observed behavior: extensions first,
35
- * then externalModuleIndicator.
31
+ * - isNodeEsmFile: 7's client SourceFile has no impliedNodeFormat, so this
32
+ * lane spells Node's format decision directly: fixed extensions first,
33
+ * then an explicit nearest-package `type`, then syntax detection for
34
+ * ambiguous .js/.ts files.
36
35
  * - Malformed tsconfig.json: tsgo's parseConfigFile swallows JSONC syntax
37
36
  * errors (recovers to empty options) where 5.9.3 reported a passthrough
38
37
  * diagnostic, so this lane validates the config's JSONC syntax itself
@@ -43,8 +42,8 @@ import { builtinModules } from "node:module";
43
42
  import { statSync } from "node:fs";
44
43
  import { dirname, resolve } from "node:path";
45
44
  import * as ts from "./ts7/adapter.js";
46
- import { strictNullChecksFloorDiag, tscPassthroughDiag, unsupportedDiag, } from "../diagnostics/diagnostic.js";
47
- import { isNodeModulesPath, nearestPkgJsonPath, projectDtsRuntimeSibling, resolveBareModule, resolveProjectImport, resolveRelativeModule, resolveTypeDirective, setProjectRealm } from "./resolve.js";
45
+ import { commonJsModuleSyntaxDiag, invalidPackageConfigDiag, strictNullChecksFloorDiag, tscPassthroughDiag, unsupportedDiag, } from "../diagnostics/diagnostic.js";
46
+ import { isNodeModulesPath, nearestInvalidPackageJsonPath, nearestPackageType, nearestPkgJsonPath, projectDtsRuntimeSibling, resolveBareModule, resolveProjectImport, resolveRelativeModule, resolveTypeDirective, setProjectRealm } from "./resolve.js";
48
47
  import { probeNodeImportRefusal, probeNodeRequireRefusal } from "./npm.js";
49
48
  import { isNpmStaticPackage, npmStaticActive, npmStaticFsShadow, npmStaticPackageOfPath, reportNpmStaticOffender, setNpmStaticPackages } from "./npm-static.js";
50
49
  import { provenanceEntryFor, provenancePaths } from "./provenance-registry.js";
@@ -57,6 +56,14 @@ const FORCED_OPTIONS = {
57
56
  target: ts.ScriptTarget.ESNext,
58
57
  module: ts.ModuleKind.ESNext,
59
58
  moduleResolution: ts.ModuleResolutionKind.Bundler,
59
+ // Every file Node executes has its own lexical module wrapper: ESM has a
60
+ // module environment and CommonJS has the per-file function wrapper. In
61
+ // particular, an ambiguous file whose ONLY ESM marker is top-level await
62
+ // must not remain a TypeScript global script (otherwise declarations in
63
+ // sibling files merge and reads cross module boundaries). Runtime format
64
+ // classification is intentionally independent below; this option is only
65
+ // the binder's scope decision.
66
+ moduleDetection: ts.ModuleDetectionKind.Force,
60
67
  lib: ["lib.es2025.d.ts"],
61
68
  types: [],
62
69
  allowImportingTsExtensions: true,
@@ -540,17 +547,198 @@ function nestedBareRequiresOf7(sf) {
540
547
  });
541
548
  return out;
542
549
  }
543
- /** True when Node would treat this file as an ES MODULE (never defining
544
- * require/__dirname there): .mjs always, .cjs never, and .js/.ts by
545
- * syntactic module detection — spelled to 5.9.3's OBSERVED bundler-mode
546
- * behavior (it set impliedNodeFormat only for the mjs/cjs families; 7's
547
- * client SourceFile has no impliedNodeFormat at all). */
548
- function isNodeEsmFile7(sf) {
549
- if (sf.fileName.endsWith(".cjs") || sf.fileName.endsWith(".cts"))
550
+ function stripRequireCasts7(expr) {
551
+ let cur = expr;
552
+ while (ts.isParenthesizedExpression(cur) ||
553
+ ts.isAsExpression(cur) ||
554
+ ts.isTypeAssertion(cur) ||
555
+ ts.isNonNullExpression(cur)) {
556
+ cur = cur.expression;
557
+ }
558
+ return cur;
559
+ }
560
+ /** The supported-builtin provenance of an imported identifier, narrowed to
561
+ * the one member this preflight distinction needs. Mirrors the lowering's
562
+ * builtinImportOf alias handling so a re-export facade remains supported. */
563
+ function isCreateRequireImport7(program, ident) {
564
+ const checker = program.getTypeChecker();
565
+ const symbol = checker.getSymbolAtLocation(ident);
566
+ const decl = symbol ? checker.declarationsOf(symbol)[0] : undefined;
567
+ if (decl === undefined || !ts.isImportSpecifier(decl))
550
568
  return false;
551
- if (sf.fileName.endsWith(".mjs") || sf.fileName.endsWith(".mts"))
569
+ const importDecl = decl.parent.parent.parent;
570
+ if (ts.isImportDeclaration(importDecl) && ts.isStringLiteral(importDecl.moduleSpecifier)) {
571
+ const module = canonicalBuiltinModule(importDecl.moduleSpecifier.text);
572
+ const member = decl.propertyName?.text ?? decl.name.text;
573
+ if (module === "module" && member === "createRequire")
574
+ return true;
575
+ }
576
+ if (symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0) {
577
+ const target = checker.getAliasedSymbol(symbol);
578
+ const targetDecl = checker.declarationsOf(target)[0];
579
+ if (targetDecl !== undefined && targetDecl.getSourceFile().isDeclarationFile) {
580
+ for (let p = targetDecl.parent; p !== undefined && !ts.isSourceFile(p); p = p.parent) {
581
+ if (ts.isModuleDeclaration(p) && ts.isStringLiteral(p.name)) {
582
+ return canonicalBuiltinModule(p.name.text) === "module" && target.name === "createRequire";
583
+ }
584
+ }
585
+ }
586
+ }
587
+ return false;
588
+ }
589
+ /** True only for the createRequire binding shape the lowering recognizes:
590
+ * a const initialized from node:module's createRequire with a base naming
591
+ * the current file. Arbitrary source declarations named `require` must not
592
+ * ride the module-edge lowering, which would erase their calls. */
593
+ function isCreateRequireBinding7(program, callee) {
594
+ const checker = program.getTypeChecker();
595
+ const symbol = checker.getSymbolAtLocation(callee);
596
+ const decl = symbol
597
+ ? checker.declarationsOf(symbol).find((d) => ts.isVariableDeclaration(d))
598
+ : undefined;
599
+ if (decl === undefined ||
600
+ decl.initializer === undefined ||
601
+ !ts.isVariableDeclarationList(decl.parent) ||
602
+ (decl.parent.flags & ts.NodeFlags.Const) === 0) {
603
+ return false;
604
+ }
605
+ const init = stripRequireCasts7(decl.initializer);
606
+ if (!ts.isCallExpression(init) ||
607
+ init.questionDotToken !== undefined ||
608
+ !ts.isIdentifier(init.expression) ||
609
+ !isCreateRequireImport7(program, init.expression) ||
610
+ init.arguments.length !== 1) {
611
+ return false;
612
+ }
613
+ const base = stripRequireCasts7(init.arguments[0]);
614
+ if (ts.isIdentifier(base) && base.text === "__filename")
552
615
  return true;
553
- return ts.isExternalModule(sf);
616
+ return (ts.isPropertyAccessExpression(base) &&
617
+ base.questionDotToken === undefined &&
618
+ ts.isMetaProperty(base.expression) &&
619
+ base.expression.keywordToken === ts.SyntaxKind.ImportKeyword &&
620
+ (base.name.text === "url" || base.name.text === "filename"));
621
+ }
622
+ /** Classifies a require-shaped call as Node's ambient CommonJS global, the
623
+ * one supported createRequire source binding, or another source binding.
624
+ * The scanners still collect createRequire calls because they carry static
625
+ * module edges; other source bindings get a pointed fence before lowering
626
+ * can mistake them for module syntax. */
627
+ function requireCallBindingKind7(program, node) {
628
+ const call = ts.isVariableDeclaration(node) ? node.initializer : node;
629
+ if (!call || !ts.isCallExpression(call) || !ts.isIdentifier(call.expression))
630
+ return "ambient";
631
+ const checker = program.getTypeChecker();
632
+ const symbol = checker.getSymbolAtLocation(call.expression);
633
+ if (symbol === undefined)
634
+ return "ambient";
635
+ const decls = checker.declarationsOf(symbol);
636
+ if (decls.length === 0 || decls.every((d) => d.getSourceFile().isDeclarationFile))
637
+ return "ambient";
638
+ return isCreateRequireBinding7(program, call.expression) ? "createRequire" : "source";
639
+ }
640
+ function esmRequireFeature7(kind) {
641
+ return kind === "ambient"
642
+ ? "require() in an ES module (Node throws ReferenceError — use import)"
643
+ : "calls through a source binding named 'require' (this spelling is reserved for CommonJS/createRequire module edges — rename the binding)";
644
+ }
645
+ const CJS_WRAPPER_NAMES = new Set(["require", "module", "exports", "__dirname", "__filename"]);
646
+ function bindingDeclaresCjsWrapper7(name) {
647
+ if (ts.isIdentifier(name))
648
+ return CJS_WRAPPER_NAMES.has(name.text) ? name : null;
649
+ for (const el of name.elements) {
650
+ if (el.name === undefined)
651
+ continue;
652
+ const hit = bindingDeclaresCjsWrapper7(el.name);
653
+ if (hit !== null)
654
+ return hit;
655
+ }
656
+ return null;
657
+ }
658
+ function insideFunctionLike7(node) {
659
+ for (let p = node.parent; p !== undefined && !ts.isSourceFile(p); p = p.parent) {
660
+ if (ts.isFunctionLike(p))
661
+ return true;
662
+ }
663
+ return false;
664
+ }
665
+ /** The first syntax marker Node's ambiguous-file detector recognizes. This
666
+ * cannot use ts.isExternalModule: moduleDetection=force deliberately gives
667
+ * EVERY executable file module-local checker scope, including CommonJS.
668
+ * Runtime classification remains Node's own narrower question: value-level
669
+ * import/export forms, import.meta, top-level await/for-await, or a top-level
670
+ * lexical declaration that would redeclare a CommonJS wrapper binding. */
671
+ function nodeEsmSyntaxMarker7(sf) {
672
+ for (const stmt of sf.statements) {
673
+ if (ts.isImportDeclaration(stmt) && !erasedTypeOnlyImport(stmt))
674
+ return stmt;
675
+ if (ts.isExportDeclaration(stmt) &&
676
+ !stmt.isTypeOnly &&
677
+ !erasedTypeOnlyReexport(stmt)) {
678
+ return stmt;
679
+ }
680
+ if (ts.isExportAssignment(stmt))
681
+ return stmt;
682
+ if (ts.canHaveModifiers(stmt) &&
683
+ ts.getModifiers(stmt)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) === true) {
684
+ return stmt;
685
+ }
686
+ if (ts.isVariableStatement(stmt) &&
687
+ (stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0) {
688
+ for (const decl of stmt.declarationList.declarations) {
689
+ const hit = bindingDeclaresCjsWrapper7(decl.name);
690
+ if (hit !== null)
691
+ return hit;
692
+ }
693
+ }
694
+ if (ts.isClassDeclaration(stmt) && stmt.name !== undefined && CJS_WRAPPER_NAMES.has(stmt.name.text)) {
695
+ return stmt.name;
696
+ }
697
+ }
698
+ let found = null;
699
+ ts.walkPreorder(sf, (node) => {
700
+ if (ts.isMetaProperty(node) &&
701
+ node.keywordToken === ts.SyntaxKind.ImportKeyword) {
702
+ found = node;
703
+ return "stop";
704
+ }
705
+ if (!insideFunctionLike7(node) &&
706
+ (ts.isAwaitExpression(node) ||
707
+ (ts.isForOfStatement(node) && node.awaitModifier !== undefined))) {
708
+ found = node;
709
+ return "stop";
710
+ }
711
+ return undefined;
712
+ });
713
+ return found;
714
+ }
715
+ const nodeEsmFileCache7 = new WeakMap();
716
+ /** True when Node would treat this file as an ES MODULE (never defining
717
+ * require/__dirname there): fixed extensions first, then an explicit
718
+ * nearest-package type, then Node's syntax markers for ambiguous .js/.ts
719
+ * files. TypeScript's external-module bit is forced for checker scoping and
720
+ * therefore intentionally plays no part in this runtime decision. */
721
+ function isNodeEsmFile7(sf) {
722
+ const cached = nodeEsmFileCache7.get(sf);
723
+ if (cached !== undefined)
724
+ return cached;
725
+ let result;
726
+ if (sf.fileName.endsWith(".cjs") || sf.fileName.endsWith(".cts")) {
727
+ result = false;
728
+ }
729
+ else if (sf.fileName.endsWith(".mjs") || sf.fileName.endsWith(".mts")) {
730
+ result = true;
731
+ }
732
+ else {
733
+ const packageType = nearestPackageType(sf.fileName);
734
+ result = packageType === "module"
735
+ ? true
736
+ : packageType === "commonjs"
737
+ ? false
738
+ : nodeEsmSyntaxMarker7(sf) !== null;
739
+ }
740
+ nodeEsmFileCache7.set(sf, result);
741
+ return result;
554
742
  }
555
743
  /** A JavaScript source file Node treats as CommonJS (not an ES module):
556
744
  * ESM namespace/default machinery must not claim it — its export surface
@@ -1462,6 +1650,28 @@ function preflight7(load) {
1462
1650
  // files (a workspace package imported bare AND reached relatively)
1463
1651
  // stay program source — only the island-bound JS steps out.
1464
1652
  !islandJsFile(sf.fileName));
1653
+ // Node stops at the nearest package.json even when it is malformed, and
1654
+ // an explicit CommonJS scope (or .cjs/.cts extension) disables ambiguous-
1655
+ // file syntax detection entirely. TypeScript's bundler checker models
1656
+ // neither loader rule, so restore them before any module-edge analysis:
1657
+ // one malformed-scope diagnostic per package file, and one pointed syntax
1658
+ // diagnostic per CommonJS source file.
1659
+ const invalidPackageConfigs = new Set();
1660
+ for (const sf of userFiles) {
1661
+ const invalidConfig = nearestInvalidPackageJsonPath(sf.fileName);
1662
+ if (invalidConfig !== null) {
1663
+ if (!invalidPackageConfigs.has(invalidConfig)) {
1664
+ invalidPackageConfigs.add(invalidConfig);
1665
+ diags.push(invalidPackageConfigDiag(invalidConfig, { file: sf.fileName, start: 0, end: 0 }));
1666
+ }
1667
+ continue;
1668
+ }
1669
+ if (!isNodeEsmFile7(sf)) {
1670
+ const marker = nodeEsmSyntaxMarker7(sf);
1671
+ if (marker !== null)
1672
+ diags.push(commonJsModuleSyntaxDiag(locOf7(marker)));
1673
+ }
1674
+ }
1465
1675
  const ambientModules = new Set(SUPPORTED_NODE_MODULES);
1466
1676
  // Ambient `declare module "name"` declarations anywhere in the program —
1467
1677
  // exact names and `*` patterns — so the import fence can say "type
@@ -1820,8 +2030,11 @@ function preflight7(load) {
1820
2030
  for (const req of requiresOf7(stmt)) {
1821
2031
  const loc = { file: sf.fileName, start: req.node.getStart(sf), end: req.node.getEnd() };
1822
2032
  if (isNodeEsmFile7(sf)) {
1823
- diags.push(unsupportedDiag("SC1013", loc, "require() in an ES module (Node throws ReferenceError — use import)"));
1824
- continue;
2033
+ const bindingKind = requireCallBindingKind7(program, req.node);
2034
+ if (bindingKind !== "createRequire") {
2035
+ diags.push(unsupportedDiag("SC1013", loc, esmRequireFeature7(bindingKind)));
2036
+ continue;
2037
+ }
1825
2038
  }
1826
2039
  if (load.externalTypes.has(req.spec)) {
1827
2040
  continue;
@@ -1885,40 +2098,45 @@ function preflight7(load) {
1885
2098
  deps.push({ dep });
1886
2099
  }
1887
2100
  }
1888
- if (!ts.isExternalModule(sf)) {
1889
- for (const call of nestedBareRequiresOf7(sf)) {
1890
- const spec = requireSpecOf7(call);
1891
- const loc = { file: sf.fileName, start: call.getStart(sf), end: call.getEnd() };
1892
- if (load.externalTypes.has(spec)) {
2101
+ for (const call of nestedBareRequiresOf7(sf)) {
2102
+ const spec = requireSpecOf7(call);
2103
+ const loc = { file: sf.fileName, start: call.getStart(sf), end: call.getEnd() };
2104
+ if (isNodeEsmFile7(sf)) {
2105
+ const bindingKind = requireCallBindingKind7(program, call);
2106
+ if (bindingKind !== "createRequire") {
2107
+ diags.push(unsupportedDiag("SC1013", loc, esmRequireFeature7(bindingKind)));
1893
2108
  continue;
1894
2109
  }
1895
- if (!isRelativeSpecifier(spec)) {
1896
- // --npm-static: opted-in packages ride the program-module edge
1897
- // (the statement-level require branch above).
1898
- const npmReq = !spec.startsWith("#") ? resolveNpmImport7(sf.fileName, spec) : null;
1899
- if (npmReq !== null && isNpmStaticPackage(npmReq.packageName)) {
1900
- const nDep = npmStaticProgramDep(program, npmReq.packageName, npmReq.typesFile);
1901
- if (nDep !== null)
1902
- deps.push({ dep: nDep });
1903
- continue;
1904
- }
1905
- if (canonicalBuiltinModule(spec) === null && !processModuleAliasRequire7(spec, null)) {
1906
- // Binding-less by construction — same require-site throw
1907
- // channel as the statement-level form above.
1908
- if (probeNodeRequireRefusal(sf.fileName, spec) === null) {
1909
- diags.push(unsupportedDiag("SC1010", loc, unsupportedModuleFeatureOf(spec)));
1910
- }
1911
- }
2110
+ }
2111
+ if (load.externalTypes.has(spec)) {
2112
+ continue;
2113
+ }
2114
+ if (!isRelativeSpecifier(spec)) {
2115
+ // --npm-static: opted-in packages ride the program-module edge
2116
+ // (the statement-level require branch above).
2117
+ const npmReq = !spec.startsWith("#") ? resolveNpmImport7(sf.fileName, spec) : null;
2118
+ if (npmReq !== null && isNpmStaticPackage(npmReq.packageName)) {
2119
+ const nDep = npmStaticProgramDep(program, npmReq.packageName, npmReq.typesFile);
2120
+ if (nDep !== null)
2121
+ deps.push({ dep: nDep });
1912
2122
  continue;
1913
2123
  }
1914
- const dep = resolveImport7(program, sf, spec);
1915
- if (dep && dep.fileName.endsWith(".json")) {
1916
- diags.push(unsupportedDiag("SC1012", loc, "require() of JSON modules"));
1917
- continue;
2124
+ if (canonicalBuiltinModule(spec) === null && !processModuleAliasRequire7(spec, null)) {
2125
+ // Binding-less by construction — same require-site throw
2126
+ // channel as the statement-level form above.
2127
+ if (probeNodeRequireRefusal(sf.fileName, spec) === null) {
2128
+ diags.push(unsupportedDiag("SC1010", loc, unsupportedModuleFeatureOf(spec)));
2129
+ }
1918
2130
  }
1919
- if (dep)
1920
- deps.push({ dep });
2131
+ continue;
2132
+ }
2133
+ const dep = resolveImport7(program, sf, spec);
2134
+ if (dep && dep.fileName.endsWith(".json")) {
2135
+ diags.push(unsupportedDiag("SC1012", loc, "require() of JSON modules"));
2136
+ continue;
1921
2137
  }
2138
+ if (dep)
2139
+ deps.push({ dep });
1922
2140
  }
1923
2141
  }
1924
2142
  }