@scriptc/compiler 0.4.3 → 0.4.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 +73 -29
- package/dist/backend/llvm/bytes-loop-versions.js +6 -0
- package/dist/backend/llvm/bytes-loop-versions.js.map +1 -1
- package/dist/backend/llvm/bytes-loop-versions.test.js +7 -2
- package/dist/backend/llvm/bytes-loop-versions.test.js.map +1 -1
- package/dist/backend/llvm/debug-info.js +2 -5
- package/dist/backend/llvm/debug-info.js.map +1 -1
- package/dist/backend/llvm/dyn.d.ts +4 -0
- package/dist/backend/llvm/dyn.js +21 -9
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emit-function.js +2 -8
- package/dist/backend/llvm/emit-function.js.map +1 -1
- package/dist/backend/llvm/emit-module.js +16 -6
- package/dist/backend/llvm/emit-module.js.map +1 -1
- package/dist/backend/llvm/emitter.d.ts +10 -0
- package/dist/backend/llvm/emitter.js +9 -5
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/emitter.test.js +11 -2
- package/dist/backend/llvm/emitter.test.js.map +1 -1
- package/dist/backend/llvm/expr-async.js +11 -13
- package/dist/backend/llvm/expr-async.js.map +1 -1
- package/dist/backend/llvm/expr-bytes.js +14 -8
- package/dist/backend/llvm/expr-bytes.js.map +1 -1
- package/dist/backend/llvm/expr-containers.js +14 -0
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.js +20 -11
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +16 -4
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/integer-values.d.ts +5 -0
- package/dist/backend/llvm/integer-values.js +27 -3
- package/dist/backend/llvm/integer-values.js.map +1 -1
- package/dist/backend/llvm/lib-dispatch.js +133 -3
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +37 -1
- package/dist/backend/llvm/lib-process.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +21 -0
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/publish.js +3 -3
- package/dist/backend/llvm/publish.js.map +1 -1
- package/dist/backend/llvm/reference-effects.js +3 -0
- package/dist/backend/llvm/reference-effects.js.map +1 -1
- package/dist/backend/llvm/shapes.js +2 -7
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/stack-captures.js +1 -5
- package/dist/backend/llvm/stack-captures.js.map +1 -1
- package/dist/backend/llvm/union-repr.d.ts +4 -3
- package/dist/backend/llvm/union-repr.js +6 -5
- package/dist/backend/llvm/union-repr.js.map +1 -1
- package/dist/backend/llvm/walkers.js +13 -0
- package/dist/backend/llvm/walkers.js.map +1 -1
- package/dist/backend/native-codegen-core.d.ts +5 -3
- package/dist/backend/native-codegen-core.js +13 -6
- package/dist/backend/native-codegen-core.js.map +1 -1
- package/dist/backend/native-codegen.test.js +6 -4
- package/dist/backend/native-codegen.test.js.map +1 -1
- package/dist/backend/target-cpu.d.ts +26 -0
- package/dist/backend/target-cpu.js +98 -0
- package/dist/backend/target-cpu.js.map +1 -0
- package/dist/backend/target-cpu.test.d.ts +1 -0
- package/dist/backend/target-cpu.test.js +38 -0
- package/dist/backend/target-cpu.test.js.map +1 -0
- package/dist/cli/command.js +20 -1
- package/dist/cli/command.js.map +1 -1
- package/dist/cli/usage.d.ts +4 -1
- package/dist/cli/usage.js +7 -0
- package/dist/cli/usage.js.map +1 -1
- package/dist/compile-types.d.ts +7 -0
- package/dist/diagnostics/diagnostic.js +1 -1
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/executable/executable-cache.d.ts +3 -0
- package/dist/executable/executable-cache.js +4 -0
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/executable/executable-cache.test.js +2 -0
- package/dist/executable/executable-cache.test.js.map +1 -1
- package/dist/frontend/decl-projection.js +105 -10
- package/dist/frontend/decl-projection.js.map +1 -1
- package/dist/frontend/lowering/builtins/async-context.d.ts +8 -2
- package/dist/frontend/lowering/builtins/async-context.js +62 -3
- package/dist/frontend/lowering/builtins/async-context.js.map +1 -1
- package/dist/frontend/lowering/builtins/crypto.js +3 -1
- package/dist/frontend/lowering/builtins/crypto.js.map +1 -1
- package/dist/frontend/lowering/builtins/dates.js +4 -1
- package/dist/frontend/lowering/builtins/dates.js.map +1 -1
- package/dist/frontend/lowering/builtins/filesystem-calls.js +3 -3
- package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -1
- package/dist/frontend/lowering/builtins/fs-glob.js +6 -3
- package/dist/frontend/lowering/builtins/fs-glob.js.map +1 -1
- package/dist/frontend/lowering/builtins/fs-paths.d.ts +43 -5
- package/dist/frontend/lowering/builtins/fs-paths.js +245 -93
- package/dist/frontend/lowering/builtins/fs-paths.js.map +1 -1
- package/dist/frontend/lowering/builtins/module-calls.js +6 -3
- package/dist/frontend/lowering/builtins/module-calls.js.map +1 -1
- package/dist/frontend/lowering/builtins/promises.d.ts +1 -1
- package/dist/frontend/lowering/builtins/promises.js +149 -138
- package/dist/frontend/lowering/builtins/promises.js.map +1 -1
- package/dist/frontend/lowering/call-signatures.js +0 -1
- package/dist/frontend/lowering/call-signatures.js.map +1 -1
- package/dist/frontend/lowering/cjs-exports-object.js +1 -1
- package/dist/frontend/lowering/cjs-exports-object.js.map +1 -1
- package/dist/frontend/lowering/cjs-inline-require.d.ts +32 -0
- package/dist/frontend/lowering/cjs-inline-require.js +307 -4
- package/dist/frontend/lowering/cjs-inline-require.js.map +1 -1
- package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +10 -0
- package/dist/frontend/lowering/class-dynamic-dispatch.js +114 -0
- package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
- package/dist/frontend/lowering/class-method-mutations.js +54 -18
- package/dist/frontend/lowering/class-method-mutations.js.map +1 -1
- package/dist/frontend/lowering/class-protocols.d.ts +25 -0
- package/dist/frontend/lowering/class-protocols.js +183 -1
- package/dist/frontend/lowering/class-protocols.js.map +1 -1
- package/dist/frontend/lowering/completion-callbacks.d.ts +4 -0
- package/dist/frontend/lowering/completion-callbacks.js +146 -0
- package/dist/frontend/lowering/completion-callbacks.js.map +1 -0
- package/dist/frontend/lowering/containers/array-callbacks.d.ts +5 -4
- package/dist/frontend/lowering/containers/array-callbacks.js +7 -6
- package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
- package/dist/frontend/lowering/containers/array-construction.js +5 -0
- package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
- package/dist/frontend/lowering/containers/array-methods.js +11 -3
- package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
- package/dist/frontend/lowering/containers/bytes.d.ts +25 -17
- package/dist/frontend/lowering/containers/bytes.js +453 -45
- package/dist/frontend/lowering/containers/bytes.js.map +1 -1
- package/dist/frontend/lowering/date-values.d.ts +11 -0
- package/dist/frontend/lowering/date-values.js +207 -0
- package/dist/frontend/lowering/date-values.js.map +1 -0
- package/dist/frontend/lowering/expressions/array-literals.js +6 -0
- package/dist/frontend/lowering/expressions/array-literals.js.map +1 -1
- package/dist/frontend/lowering/expressions/binary.js +64 -26
- package/dist/frontend/lowering/expressions/binary.js.map +1 -1
- package/dist/frontend/lowering/expressions/element-access.js +79 -0
- package/dist/frontend/lowering/expressions/element-access.js.map +1 -1
- package/dist/frontend/lowering/expressions/identifiers.js +31 -1
- package/dist/frontend/lowering/expressions/identifiers.js.map +1 -1
- package/dist/frontend/lowering/expressions/property-access.js +56 -0
- package/dist/frontend/lowering/expressions/property-access.js.map +1 -1
- package/dist/frontend/lowering/expressions/typeof.js +6 -0
- package/dist/frontend/lowering/expressions/typeof.js.map +1 -1
- package/dist/frontend/lowering/expressions/updates.js +17 -0
- package/dist/frontend/lowering/expressions/updates.js.map +1 -1
- package/dist/frontend/lowering/function-returns.js +15 -0
- package/dist/frontend/lowering/function-returns.js.map +1 -1
- package/dist/frontend/lowering/indexed-unions.d.ts +54 -0
- package/dist/frontend/lowering/indexed-unions.js +401 -0
- package/dist/frontend/lowering/indexed-unions.js.map +1 -0
- package/dist/frontend/lowering/key-order-witness.js +210 -32
- package/dist/frontend/lowering/key-order-witness.js.map +1 -1
- package/dist/frontend/lowering/key-order-witness.test.js +104 -4
- package/dist/frontend/lowering/key-order-witness.test.js.map +1 -1
- package/dist/frontend/lowering/lower-assert.js +15 -3
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +19 -3
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.js +22 -47
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.js +205 -1
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-generators.js +1 -1
- package/dist/frontend/lowering/lower-generators.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.d.ts +1 -1
- package/dist/frontend/lowering/lower-inspect.js +35 -11
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.js +21 -5
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.js +100 -34
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +30 -2
- package/dist/frontend/lowering/lowerer.js +68 -7
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/object-factory-new.d.ts +5 -0
- package/dist/frontend/lowering/object-factory-new.js +20 -6
- package/dist/frontend/lowering/object-factory-new.js.map +1 -1
- package/dist/frontend/lowering/overload-choice.d.ts +33 -0
- package/dist/frontend/lowering/overload-choice.js +190 -0
- package/dist/frontend/lowering/overload-choice.js.map +1 -0
- package/dist/frontend/lowering/surfaces.js +55 -2
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/pipeline.js +1 -1
- package/dist/frontend/pipeline.js.map +1 -1
- package/dist/frontend/program-analysis.d.ts +5 -1
- package/dist/frontend/program-analysis.js +5 -0
- package/dist/frontend/program-analysis.js.map +1 -1
- package/dist/frontend/program.d.ts +13 -5
- package/dist/frontend/program.js +197 -14
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/ts7/semantic-model.d.ts +3 -0
- package/dist/frontend/ts7/semantic-model.js +5 -0
- package/dist/frontend/ts7/semantic-model.js.map +1 -1
- package/dist/frontend/ts7/semantic-model.test.js +6 -1
- package/dist/frontend/ts7/semantic-model.test.js.map +1 -1
- package/dist/frontend/ts7/semantic-types.d.ts +1 -1
- package/dist/frontend/ts7/semantic-types.js +1 -1
- package/dist/frontend/ts7/semantic-types.js.map +1 -1
- package/dist/frontend/type-mapper.js +45 -16
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/ir/builtin-effects.js +8 -0
- package/dist/ir/builtin-effects.js.map +1 -1
- package/dist/ir/builtin-signatures.d.ts +1 -1
- package/dist/ir/builtin-signatures.js +56 -0
- package/dist/ir/builtin-signatures.js.map +1 -1
- package/dist/ir/int32-slots.js +7 -0
- package/dist/ir/int32-slots.js.map +1 -1
- package/dist/ir/int32-slots.test.js +33 -0
- package/dist/ir/int32-slots.test.js.map +1 -1
- package/dist/ir/integer-loops.js +14 -4
- package/dist/ir/integer-loops.js.map +1 -1
- package/dist/ir/ir.d.ts +13 -3
- package/dist/ir/ir.js +19 -5
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/ir.test.js +2 -1
- package/dist/ir/ir.test.js.map +1 -1
- package/dist/ir/js-ic.d.ts +2 -15
- package/dist/ir/js-ic.js +11 -79
- package/dist/ir/js-ic.js.map +1 -1
- package/dist/ir/js-ic.test.js +0 -142
- package/dist/ir/js-ic.test.js.map +1 -1
- package/dist/ir/runtime-features.js +25 -1
- package/dist/ir/runtime-features.js.map +1 -1
- package/dist/ir/validate.js +46 -5
- package/dist/ir/validate.js.map +1 -1
- package/dist/library/ir-policy.js +1 -0
- package/dist/library/ir-policy.js.map +1 -1
- package/dist/native/prepare.d.ts +1 -1
- package/dist/native/prepare.js +11 -1
- package/dist/native/prepare.js.map +1 -1
- package/dist/native/prepare.test.js +18 -2
- package/dist/native/prepare.test.js.map +1 -1
- package/package.json +20 -20
- package/surface-manifest.json +2 -4
|
@@ -130,13 +130,21 @@ declare function requireSpecOf7(node: ts.Node): string | null;
|
|
|
130
130
|
* These lower to NOTHING — the bindings are alias plumbing (tsc models
|
|
131
131
|
* them as import aliases) and the module edge lives in the order walk. */
|
|
132
132
|
declare function isRequireStatement7(stmt: ts.Statement): boolean;
|
|
133
|
-
/**
|
|
134
|
-
*
|
|
135
|
-
|
|
133
|
+
/** A require() occurrence of a top-level statement. `split` marks the
|
|
134
|
+
* assignment of a split require binding (splitRequireBindings7): `node`
|
|
135
|
+
* is its require call and `decl` the binding's declaration. */
|
|
136
|
+
interface RequireOccurrence7 {
|
|
136
137
|
spec: string;
|
|
137
138
|
node: ts.Node;
|
|
138
139
|
decl: ts.VariableDeclaration | null;
|
|
139
|
-
|
|
140
|
+
split?: true;
|
|
141
|
+
}
|
|
142
|
+
/** The require() occurrences of one top-level statement: the declaration
|
|
143
|
+
* forms, the bare side-effect call, and the assignment of a split require
|
|
144
|
+
* binding. Empty for everything else. */
|
|
145
|
+
declare function requiresOf7(stmt: ts.Statement, program: ts.Program): RequireOccurrence7[];
|
|
146
|
+
/** The require call of a split require binding's declaration, or null. */
|
|
147
|
+
declare function splitRequireCallOf7(program: ts.Program, decl: ts.VariableDeclaration): ts.CallExpression | null;
|
|
140
148
|
/** The exact `Object.defineProperty(exports|module.exports, "__esModule",
|
|
141
149
|
* { value: true })` interop stamp (shared by preflight and the no-op lowering);
|
|
142
150
|
* `{ value: !0 }` is the same stamp. */
|
|
@@ -301,7 +309,7 @@ export declare function esmNamedImportLinkCrash(program: ts.Program, entry: ts.S
|
|
|
301
309
|
export { ambientDtsPath, fallbackDtsPath, isNodeTypesPath, overridesDtsPath } from "./dts-paths.js";
|
|
302
310
|
export { builtinDefaultImportModule, canonicalBuiltinModule, npmBuiltinAliasOf, SUPPORTED_BUILTIN_MODULES, } from "./builtin-modules.js";
|
|
303
311
|
export { npmPackageNameOf, workspacePackageOfPath } from "./workspace-registry.js";
|
|
304
|
-
export { requireSpecOf7 as requireSpecOf, isRequireStatement7 as isRequireStatement, requiresOf7 as requiresOf, isNodeEsmFile7 as isNodeEsmFile, resolveImport7 as resolveImport, resolveNpmImport7 as resolveNpmImport, locOf7 as locOf, requireEarlyReference7 as requireEarlyReference, inDeferredPosition7 as inDeferredPosition, };
|
|
312
|
+
export { requireSpecOf7 as requireSpecOf, isRequireStatement7 as isRequireStatement, requiresOf7 as requiresOf, splitRequireCallOf7 as splitRequireCallOf, isNodeEsmFile7 as isNodeEsmFile, resolveImport7 as resolveImport, resolveNpmImport7 as resolveNpmImport, locOf7 as locOf, requireEarlyReference7 as requireEarlyReference, inDeferredPosition7 as inDeferredPosition, };
|
|
305
313
|
/** True for JavaScript source files (.js/.mjs/.cjs) — the files whose
|
|
306
314
|
* types come entirely from inference (checkJs + JSDoc) and whose classes
|
|
307
315
|
* declare fields by constructor assignment. */
|
package/dist/frontend/program.js
CHANGED
|
@@ -1087,6 +1087,11 @@ function suppressedJsStrictness7(d) {
|
|
|
1087
1087
|
if (JS_ANY_OPERATOR_CODES.has(d.code)) {
|
|
1088
1088
|
return ts.flattenDiagnosticMessageText(d, "\n").includes("'any'");
|
|
1089
1089
|
}
|
|
1090
|
+
// The deprecated Buffer(...) call without `new`, which Node's Buffer
|
|
1091
|
+
// function accepts (containers/bytes.ts lowers it).
|
|
1092
|
+
if (d.code === 2348) {
|
|
1093
|
+
return ts.flattenDiagnosticMessageText(d, "\n").includes("'BufferConstructor'");
|
|
1094
|
+
}
|
|
1090
1095
|
return false;
|
|
1091
1096
|
}
|
|
1092
1097
|
/** The specifier of a `require("...")` call: the callee is the bare
|
|
@@ -1126,9 +1131,15 @@ function isRequireStatement7(stmt) {
|
|
|
1126
1131
|
decls.every((d) => d.initializer !== undefined && requireSpecOf7(d.initializer) !== null));
|
|
1127
1132
|
}
|
|
1128
1133
|
/** The require() occurrences of one top-level statement: the declaration
|
|
1129
|
-
* forms
|
|
1130
|
-
|
|
1134
|
+
* forms, the bare side-effect call, and the assignment of a split require
|
|
1135
|
+
* binding. Empty for everything else. */
|
|
1136
|
+
function requiresOf7(stmt, program) {
|
|
1131
1137
|
if (ts.isExpressionStatement(stmt)) {
|
|
1138
|
+
const split = splitRequireOfStatement7(program, stmt);
|
|
1139
|
+
if (split !== null)
|
|
1140
|
+
return [
|
|
1141
|
+
{ spec: requireSpecOf7(split.call), node: split.call, decl: split.decl, split: true },
|
|
1142
|
+
];
|
|
1132
1143
|
const spec = requireSpecOf7(stmt.expression);
|
|
1133
1144
|
return spec !== null ? [{ spec, node: stmt.expression, decl: null }] : [];
|
|
1134
1145
|
}
|
|
@@ -1142,6 +1153,158 @@ function requiresOf7(stmt) {
|
|
|
1142
1153
|
}
|
|
1143
1154
|
return out;
|
|
1144
1155
|
}
|
|
1156
|
+
/** CommonJS require bindings split into a declaration and one later
|
|
1157
|
+
* assignment (`var m; m = require("./x")`): a top-level `var` or `let`
|
|
1158
|
+
* declaration without initializer in a CommonJS file, assigned by exactly one
|
|
1159
|
+
* top-level `m = require("<literal>")` statement of the require global over
|
|
1160
|
+
* a compiled program module, and written nowhere else. The binding holds the
|
|
1161
|
+
* module's exports from the assignment on, as `const m = require("./x")`
|
|
1162
|
+
* does, so preflight treats the assignment as that require: its module edge,
|
|
1163
|
+
* its cycle admission and its early-read fence. The lowering's recognizer
|
|
1164
|
+
* (splitRequireBindingOf in cjs-inline-require.ts) accepts only these
|
|
1165
|
+
* bindings. Keyed by declaration, with the assignment's require call. */
|
|
1166
|
+
function splitRequireBindings7(program, sf) {
|
|
1167
|
+
const memo = program.analysis.splitRequireBindings;
|
|
1168
|
+
const cached = memo.get(sf);
|
|
1169
|
+
if (cached !== undefined)
|
|
1170
|
+
return cached;
|
|
1171
|
+
const out = new Map();
|
|
1172
|
+
memo.set(sf, out);
|
|
1173
|
+
if (sf.isDeclarationFile || !isCjsJsFile7(sf, program) || !sf.text.includes("require"))
|
|
1174
|
+
return out;
|
|
1175
|
+
const checker = program.getTypeChecker();
|
|
1176
|
+
const stmts = sf.statements.nodes;
|
|
1177
|
+
const candidates = new Map();
|
|
1178
|
+
for (const stmt of stmts) {
|
|
1179
|
+
if (!ts.isVariableStatement(stmt))
|
|
1180
|
+
continue;
|
|
1181
|
+
if ((stmt.declarationList.flags & (ts.NodeFlags.Const | ts.NodeFlags.Using)) !== 0)
|
|
1182
|
+
continue;
|
|
1183
|
+
for (const decl of stmt.declarationList.declarations.nodes) {
|
|
1184
|
+
if (!ts.isIdentifier(decl.name) || decl.initializer !== undefined)
|
|
1185
|
+
continue;
|
|
1186
|
+
const symbol = checker.getSymbolAtLocation(decl.name);
|
|
1187
|
+
if (symbol === undefined || symbol.declarations.length !== 1)
|
|
1188
|
+
continue;
|
|
1189
|
+
candidates.set(symbol, { decl, call: null, assigns: 0 });
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
if (candidates.size === 0)
|
|
1193
|
+
return out;
|
|
1194
|
+
// The one top-level `m = ...` statement, whose right side is the require.
|
|
1195
|
+
for (const stmt of stmts) {
|
|
1196
|
+
if (!ts.isExpressionStatement(stmt) || !ts.isBinaryExpression(stmt.expression))
|
|
1197
|
+
continue;
|
|
1198
|
+
const assign = stmt.expression;
|
|
1199
|
+
if (assign.operatorToken.kind !== ts.SyntaxKind.EqualsToken || !ts.isIdentifier(assign.left))
|
|
1200
|
+
continue;
|
|
1201
|
+
const symbol = checker.getSymbolAtLocation(assign.left);
|
|
1202
|
+
const candidate = symbol !== undefined ? candidates.get(symbol) : undefined;
|
|
1203
|
+
if (candidate === undefined)
|
|
1204
|
+
continue;
|
|
1205
|
+
candidate.assigns++;
|
|
1206
|
+
let right = assign.right;
|
|
1207
|
+
while (ts.isParenthesizedExpression(right))
|
|
1208
|
+
right = right.expression;
|
|
1209
|
+
if (ts.isCallExpression(right) && splitRequireTarget7(program, sf, right))
|
|
1210
|
+
candidate.call = right;
|
|
1211
|
+
}
|
|
1212
|
+
const names = new Set();
|
|
1213
|
+
for (const candidate of candidates.values()) {
|
|
1214
|
+
if (candidate.assigns === 1 && candidate.call !== null)
|
|
1215
|
+
names.add(candidate.decl.name.text);
|
|
1216
|
+
}
|
|
1217
|
+
if (names.size === 0)
|
|
1218
|
+
return out;
|
|
1219
|
+
// Exactly one write in the whole file: the assignment itself.
|
|
1220
|
+
const writes = new Map();
|
|
1221
|
+
ts.walkPreorder(sf, (node) => {
|
|
1222
|
+
if (!ts.isIdentifier(node) || !names.has(node.text))
|
|
1223
|
+
return undefined;
|
|
1224
|
+
const parent = node.parent;
|
|
1225
|
+
const symbol = parent !== undefined && ts.isShorthandPropertyAssignment(parent) && parent.name === node
|
|
1226
|
+
? (checker.getShorthandAssignmentValueSymbol(parent) ?? checker.getSymbolAtLocation(node))
|
|
1227
|
+
: checker.getSymbolAtLocation(node);
|
|
1228
|
+
if (symbol === undefined || !candidates.has(symbol) || !isWriteReference7(node))
|
|
1229
|
+
return undefined;
|
|
1230
|
+
writes.set(symbol, (writes.get(symbol) ?? 0) + 1);
|
|
1231
|
+
return undefined;
|
|
1232
|
+
});
|
|
1233
|
+
for (const [symbol, candidate] of candidates) {
|
|
1234
|
+
if (candidate.assigns === 1 && candidate.call !== null && writes.get(symbol) === 1)
|
|
1235
|
+
out.set(candidate.decl, candidate.call);
|
|
1236
|
+
}
|
|
1237
|
+
return out;
|
|
1238
|
+
}
|
|
1239
|
+
/** True when `call` is a require of the CommonJS global over a compiled
|
|
1240
|
+
* program module: not a builtin, a JSON document or a declaration file. */
|
|
1241
|
+
function splitRequireTarget7(program, sf, call) {
|
|
1242
|
+
const spec = requireSpecOf7(call);
|
|
1243
|
+
if (spec === null || canonicalBuiltinModule(spec) !== null)
|
|
1244
|
+
return false;
|
|
1245
|
+
if (requireCallBindingKind7(program, call) !== "ambient")
|
|
1246
|
+
return false;
|
|
1247
|
+
const dep = resolveImport7(program, sf, spec, "require") ?? npmStaticDepSf7(program, sf, spec, "require");
|
|
1248
|
+
return dep !== null && !dep.isDeclarationFile && !dep.fileName.endsWith(".json");
|
|
1249
|
+
}
|
|
1250
|
+
/** The split require binding a top-level statement assigns, or null. */
|
|
1251
|
+
function splitRequireOfStatement7(program, stmt) {
|
|
1252
|
+
if (!ts.isExpressionStatement(stmt) ||
|
|
1253
|
+
!ts.isBinaryExpression(stmt.expression) ||
|
|
1254
|
+
!ts.isSourceFile(stmt.parent))
|
|
1255
|
+
return null;
|
|
1256
|
+
let right = stmt.expression.right;
|
|
1257
|
+
while (ts.isParenthesizedExpression(right))
|
|
1258
|
+
right = right.expression;
|
|
1259
|
+
for (const [decl, call] of splitRequireBindings7(program, stmt.parent))
|
|
1260
|
+
if (call === right)
|
|
1261
|
+
return { decl, call };
|
|
1262
|
+
return null;
|
|
1263
|
+
}
|
|
1264
|
+
/** The top-level statement of a split require binding's assignment, from
|
|
1265
|
+
* its require call (`m = require("./x")` or `m = (require("./x"))`). */
|
|
1266
|
+
function splitRequireStatementOf7(call) {
|
|
1267
|
+
let node = call;
|
|
1268
|
+
while (node.parent !== undefined && ts.isParenthesizedExpression(node.parent))
|
|
1269
|
+
node = node.parent;
|
|
1270
|
+
return node.parent?.parent;
|
|
1271
|
+
}
|
|
1272
|
+
/** The require call of a split require binding's declaration, or null. */
|
|
1273
|
+
function splitRequireCallOf7(program, decl) {
|
|
1274
|
+
return splitRequireBindings7(program, ts.getSourceFileOfNode(decl)).get(decl) ?? null;
|
|
1275
|
+
}
|
|
1276
|
+
/** True when `id` is written: an assignment target (compound and
|
|
1277
|
+
* destructuring included), an update operand, or a for-in/of target. */
|
|
1278
|
+
function isWriteReference7(id) {
|
|
1279
|
+
let n = id;
|
|
1280
|
+
for (;;) {
|
|
1281
|
+
const p = n.parent;
|
|
1282
|
+
if (p === undefined)
|
|
1283
|
+
return false;
|
|
1284
|
+
if (ts.isBinaryExpression(p)) {
|
|
1285
|
+
const k = p.operatorToken.kind;
|
|
1286
|
+
return (p.left === n && k >= ts.SyntaxKind.FirstAssignment && k <= ts.SyntaxKind.LastAssignment);
|
|
1287
|
+
}
|
|
1288
|
+
if (ts.isPostfixUnaryExpression(p) || ts.isPrefixUnaryExpression(p)) {
|
|
1289
|
+
return ((p.operator === ts.SyntaxKind.PlusPlusToken ||
|
|
1290
|
+
p.operator === ts.SyntaxKind.MinusMinusToken) &&
|
|
1291
|
+
p.operand === n);
|
|
1292
|
+
}
|
|
1293
|
+
if (ts.isForOfStatement(p) || ts.isForInStatement(p))
|
|
1294
|
+
return p.initializer === n;
|
|
1295
|
+
if (ts.isParenthesizedExpression(p) ||
|
|
1296
|
+
ts.isArrayLiteralExpression(p) ||
|
|
1297
|
+
ts.isSpreadElement(p) ||
|
|
1298
|
+
ts.isSpreadAssignment(p) ||
|
|
1299
|
+
ts.isShorthandPropertyAssignment(p) ||
|
|
1300
|
+
ts.isObjectLiteralExpression(p) ||
|
|
1301
|
+
(ts.isPropertyAssignment(p) && p.initializer === n)) {
|
|
1302
|
+
n = p;
|
|
1303
|
+
continue;
|
|
1304
|
+
}
|
|
1305
|
+
return false;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1145
1308
|
/** `true`, or `!0`, its minified spelling. */
|
|
1146
1309
|
function isTrueLiteral(expr) {
|
|
1147
1310
|
return (expr.kind === ts.SyntaxKind.TrueKeyword ||
|
|
@@ -1269,7 +1432,7 @@ function purePrefixStmt7(program, s) {
|
|
|
1269
1432
|
return true;
|
|
1270
1433
|
if (ts.isExpressionStatement(s) && ts.isStringLiteral(s.expression))
|
|
1271
1434
|
return true; // directive
|
|
1272
|
-
if (isRequireStatement7(s))
|
|
1435
|
+
if (isRequireStatement7(s) || splitRequireOfStatement7(program, s) !== null)
|
|
1273
1436
|
return true;
|
|
1274
1437
|
if (isCjsJsFile7(ts.getSourceFileOfNode(s), program)) {
|
|
1275
1438
|
if (ts.isExpressionStatement(s) && isEsModuleStamp(s.expression)) {
|
|
@@ -1393,12 +1556,18 @@ function requireEarlyReference7(program, decl) {
|
|
|
1393
1556
|
if (cached !== undefined)
|
|
1394
1557
|
return cached;
|
|
1395
1558
|
let found = null;
|
|
1396
|
-
const stmt = decl.parent?.parent;
|
|
1397
1559
|
const sf = ts.getSourceFileOfNode(decl);
|
|
1398
|
-
|
|
1560
|
+
// A split require binding is bound at its assignment statement.
|
|
1561
|
+
const splitCall = splitRequireCallOf7(program, decl);
|
|
1562
|
+
const stmt = splitCall !== null ? splitRequireStatementOf7(splitCall) : decl.parent?.parent;
|
|
1563
|
+
if (stmt !== undefined &&
|
|
1564
|
+
(ts.isVariableStatement(stmt) || splitCall !== null) &&
|
|
1565
|
+
ts.isSourceFile(stmt.parent)) {
|
|
1399
1566
|
const stmts = sf.statements.nodes;
|
|
1400
1567
|
const k = stmts.indexOf(stmt);
|
|
1401
|
-
const declarations = stmt
|
|
1568
|
+
const declarations = ts.isVariableStatement(stmt)
|
|
1569
|
+
? stmt.declarationList.declarations.nodes
|
|
1570
|
+
: [];
|
|
1402
1571
|
// Earlier declarators run too: `const x = read(), dep = require('./dep')`.
|
|
1403
1572
|
const precedingDecls = declarations.slice(0, declarations.indexOf(decl));
|
|
1404
1573
|
let firstRunnable = program.analysis.requireFirstRunnable.get(sf);
|
|
@@ -1446,6 +1615,12 @@ exactEarlyRead) {
|
|
|
1446
1615
|
}
|
|
1447
1616
|
if (bindings.size === 0)
|
|
1448
1617
|
return null;
|
|
1618
|
+
// A split require binding's assignment writes the binding; it reads nothing.
|
|
1619
|
+
let splitWrite = splitRequireCallOf7(program, decl);
|
|
1620
|
+
while (splitWrite !== null && ts.isParenthesizedExpression(splitWrite.parent))
|
|
1621
|
+
splitWrite = splitWrite.parent;
|
|
1622
|
+
splitWrite =
|
|
1623
|
+
splitWrite !== null && ts.isBinaryExpression(splitWrite.parent) ? splitWrite.parent.left : null;
|
|
1449
1624
|
const stmts = sf.statements.nodes;
|
|
1450
1625
|
const cjs = isCjsJsFile7(sf, program);
|
|
1451
1626
|
const symbolOf = (id) => {
|
|
@@ -1690,7 +1865,7 @@ exactEarlyRead) {
|
|
|
1690
1865
|
if (sym === undefined)
|
|
1691
1866
|
return undefined;
|
|
1692
1867
|
if (bindings.has(sym)) {
|
|
1693
|
-
if (exactEarlyRead?.(n) === true)
|
|
1868
|
+
if (n === splitWrite || exactEarlyRead?.(n) === true)
|
|
1694
1869
|
return undefined;
|
|
1695
1870
|
hit = n;
|
|
1696
1871
|
return "stop";
|
|
@@ -3091,7 +3266,7 @@ function cjsCycleRefusal7(program, comp, lineOf) {
|
|
|
3091
3266
|
}
|
|
3092
3267
|
// Bindings of other members must stay unreachable from top-level code.
|
|
3093
3268
|
for (const st of stmts) {
|
|
3094
|
-
for (const req of requiresOf7(st)) {
|
|
3269
|
+
for (const req of requiresOf7(st, program)) {
|
|
3095
3270
|
if (req.decl === null)
|
|
3096
3271
|
continue;
|
|
3097
3272
|
const dep = resolveImport7(program, m, req.spec, "require");
|
|
@@ -5221,17 +5396,20 @@ function preflight7(load) {
|
|
|
5221
5396
|
const early = req.decl !== null ? requireEarlyReference7(program, req.decl) : null;
|
|
5222
5397
|
if (early === null ||
|
|
5223
5398
|
(bindingKind !== "createRequire" &&
|
|
5399
|
+
req.split === undefined &&
|
|
5224
5400
|
((req.decl.parent?.flags ?? 0) & (ts.NodeFlags.Const | ts.NodeFlags.Let)) !== 0)) {
|
|
5225
5401
|
return false;
|
|
5226
5402
|
}
|
|
5227
5403
|
diags.push(unsupportedDiag("SC1013", loc, bindingKind === "createRequire"
|
|
5228
5404
|
? `createRequire() binding '${early.text}' below code that can reach it (Node throws ReferenceError on any earlier access, which is not modeled — move the require above the code that can run first)`
|
|
5229
|
-
:
|
|
5405
|
+
: req.split !== undefined
|
|
5406
|
+
? `require() binding '${early.text}' assigned below code that can reach it (Node reads undefined before the assignment runs, which is not modeled — move the assignment above the code that can run first)`
|
|
5407
|
+
: `var require() binding '${early.text}' below code that can reach it (Node reads undefined before the require runs, which is not modeled — declare it with const or let, or move the require above the code that can run first)`));
|
|
5230
5408
|
return true;
|
|
5231
5409
|
};
|
|
5232
5410
|
for (let k = 0; k < stmts.length; k++) {
|
|
5233
5411
|
const stmt = stmts[k];
|
|
5234
|
-
for (const req of requiresOf7(stmt)) {
|
|
5412
|
+
for (const req of requiresOf7(stmt, program)) {
|
|
5235
5413
|
const loc = {
|
|
5236
5414
|
file: sf.fileName,
|
|
5237
5415
|
start: ts.tokenStartOfNode(req.node),
|
|
@@ -5260,8 +5438,8 @@ function preflight7(load) {
|
|
|
5260
5438
|
if (jsonDep !== null && jsonDep.fileName.endsWith(".json")) {
|
|
5261
5439
|
if (bindingKind === "createRequire")
|
|
5262
5440
|
continue;
|
|
5263
|
-
if (ts.isVariableStatement(stmt) && requiresOf7(stmt).length > 1) {
|
|
5264
|
-
const others = requiresOf7(stmt).some((r) => {
|
|
5441
|
+
if (ts.isVariableStatement(stmt) && requiresOf7(stmt, program).length > 1) {
|
|
5442
|
+
const others = requiresOf7(stmt, program).some((r) => {
|
|
5265
5443
|
const d = resolveImport7(program, sf, r.spec, "require");
|
|
5266
5444
|
return d === null || !d.fileName.endsWith(".json");
|
|
5267
5445
|
});
|
|
@@ -5423,9 +5601,14 @@ function preflight7(load) {
|
|
|
5423
5601
|
// counts, and targets outside the compiled graph add nothing here:
|
|
5424
5602
|
// their use sites keep their existing lowering fences.
|
|
5425
5603
|
if (jsRequireFile && !isNodeEsmFile7(sf, program)) {
|
|
5604
|
+
// A split require binding's assignment is a statement-level require
|
|
5605
|
+
// edge (requiresOf7 above), parenthesized or not.
|
|
5606
|
+
const splitCalls = new Set(splitRequireBindings7(program, sf).values());
|
|
5426
5607
|
for (const call of inlineRequiresOf7(sf)) {
|
|
5427
5608
|
if (requireCallBindingKind7(program, call) !== "ambient")
|
|
5428
5609
|
continue;
|
|
5610
|
+
if (splitCalls.has(call))
|
|
5611
|
+
continue;
|
|
5429
5612
|
const spec = requireSpecOf7(call);
|
|
5430
5613
|
if (load.externalTypes.has(spec) || canonicalBuiltinModule(spec) !== null)
|
|
5431
5614
|
continue;
|
|
@@ -5798,7 +5981,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
5798
5981
|
const nextSeen = new Set(seenModules);
|
|
5799
5982
|
nextSeen.add(dep);
|
|
5800
5983
|
const module = checker.getSymbolAtLocation(dep);
|
|
5801
|
-
const exported = module?.getExports().get(name);
|
|
5984
|
+
const exported = module?.getExports().get(ts.escapedSymbolName(name));
|
|
5802
5985
|
if (exported !== undefined) {
|
|
5803
5986
|
let resolved = exported;
|
|
5804
5987
|
const seenSymbols = new Set();
|
|
@@ -6076,7 +6259,7 @@ const nodeBuiltinNames = new Set(builtinModules);
|
|
|
6076
6259
|
export { ambientDtsPath, fallbackDtsPath, isNodeTypesPath, overridesDtsPath } from "./dts-paths.js";
|
|
6077
6260
|
export { builtinDefaultImportModule, canonicalBuiltinModule, npmBuiltinAliasOf, SUPPORTED_BUILTIN_MODULES, } from "./builtin-modules.js";
|
|
6078
6261
|
export { npmPackageNameOf, workspacePackageOfPath } from "./workspace-registry.js";
|
|
6079
|
-
export { requireSpecOf7 as requireSpecOf, isRequireStatement7 as isRequireStatement, requiresOf7 as requiresOf, isNodeEsmFile7 as isNodeEsmFile, resolveImport7 as resolveImport, resolveNpmImport7 as resolveNpmImport, locOf7 as locOf, requireEarlyReference7 as requireEarlyReference, inDeferredPosition7 as inDeferredPosition, };
|
|
6262
|
+
export { requireSpecOf7 as requireSpecOf, isRequireStatement7 as isRequireStatement, requiresOf7 as requiresOf, splitRequireCallOf7 as splitRequireCallOf, isNodeEsmFile7 as isNodeEsmFile, resolveImport7 as resolveImport, resolveNpmImport7 as resolveNpmImport, locOf7 as locOf, requireEarlyReference7 as requireEarlyReference, inDeferredPosition7 as inDeferredPosition, };
|
|
6080
6263
|
/** True for JavaScript source files (.js/.mjs/.cjs) — the files whose
|
|
6081
6264
|
* types come entirely from inference (checkJs + JSDoc) and whose classes
|
|
6082
6265
|
* declare fields by constructor assignment. */
|