@scriptc/compiler 0.0.3 → 0.0.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 +145 -9
- package/dist/backend/cc.d.ts +23 -0
- package/dist/backend/cc.js +89 -0
- package/dist/backend/cc.js.map +1 -1
- package/dist/backend/emission/emit-async.js +2 -2
- package/dist/backend/emission/emit-async.js.map +1 -1
- package/dist/backend/emission/emit-exprs.js +37 -2
- package/dist/backend/emission/emit-exprs.js.map +1 -1
- package/dist/backend/emission/emit-shapes.js +3 -2
- package/dist/backend/emission/emit-shapes.js.map +1 -1
- package/dist/backend/emission/emit-walkers.js +7 -8
- package/dist/backend/emission/emit-walkers.js.map +1 -1
- package/dist/backend/emission/emitter.d.ts +1 -0
- package/dist/backend/emission/emitter.js +123 -3
- package/dist/backend/emission/emitter.js.map +1 -1
- package/dist/backend/llvm/emitter.js +198 -15
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/shapes.js +1 -0
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/diagnostics/diagnostic.d.ts +25 -0
- package/dist/diagnostics/diagnostic.js +88 -2
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/frontend/lib-exports.d.ts +16 -0
- package/dist/frontend/lib-exports.js +35 -0
- package/dist/frontend/lib-exports.js.map +1 -0
- package/dist/frontend/lowering/lib-boundary.js +76 -6
- package/dist/frontend/lowering/lib-boundary.js.map +1 -1
- package/dist/frontend/lowering/lower-builtins.d.ts +37 -4
- package/dist/frontend/lowering/lower-builtins.js +240 -6
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +124 -34
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.d.ts +34 -2
- package/dist/frontend/lowering/lower-classes.js +257 -34
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.js +25 -3
- package/dist/frontend/lowering/lower-containers.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.d.ts +10 -0
- package/dist/frontend/lowering/lower-exprs.js +411 -10
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.d.ts +16 -1
- package/dist/frontend/lowering/lower-inspect.js +132 -5
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-island.js +25 -4
- package/dist/frontend/lowering/lower-island.js.map +1 -1
- package/dist/frontend/lowering/lower-mixins.js +4 -2
- package/dist/frontend/lowering/lower-mixins.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.d.ts +6 -5
- package/dist/frontend/lowering/lower-modules.js +56 -18
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.js +163 -0
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +72 -2
- package/dist/frontend/lowering/lowerer.js +339 -19
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/surfaces.d.ts +9 -2
- package/dist/frontend/lowering/surfaces.js +44 -7
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/npm-static-rewrite.d.ts +3 -0
- package/dist/frontend/npm-static-rewrite.js +677 -0
- package/dist/frontend/npm-static-rewrite.js.map +1 -0
- package/dist/frontend/npm-static.d.ts +8 -1
- package/dist/frontend/npm-static.js +159 -18
- package/dist/frontend/npm-static.js.map +1 -1
- package/dist/frontend/npm.js +2 -2
- package/dist/frontend/npm.js.map +1 -1
- package/dist/frontend/program.d.ts +6 -0
- package/dist/frontend/program.js +110 -22
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/resolve.js +120 -5
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/shared.d.ts +8 -2
- package/dist/frontend/shared.js +22 -6
- package/dist/frontend/shared.js.map +1 -1
- package/dist/frontend/ts7/checker.js +1 -1
- package/dist/frontend/ts7/checker.js.map +1 -1
- package/dist/frontend/types.d.ts +25 -1
- package/dist/frontend/types.js +121 -7
- package/dist/frontend/types.js.map +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.js +256 -17
- package/dist/index.js.map +1 -1
- package/dist/ir/nodes.d.ts +86 -1
- package/dist/ir/nodes.js +183 -0
- package/dist/ir/nodes.js.map +1 -1
- package/dist/ir/validate.js +89 -6
- package/dist/ir/validate.js.map +1 -1
- package/dist/library/profile.d.ts +52 -0
- package/dist/library/profile.js +232 -0
- package/dist/library/profile.js.map +1 -0
- package/package.json +2 -2
- package/surface-manifest.json +67 -2
|
@@ -1276,6 +1276,62 @@ export function lowerBindingPattern(L, pattern, srcRef, srcType, isLet, out) {
|
|
|
1276
1276
|
}
|
|
1277
1277
|
return;
|
|
1278
1278
|
}
|
|
1279
|
+
// A CLASS-INSTANCE source (`const { previous, next } = path` —
|
|
1280
|
+
// the path-walker idiom): the desugar IS JS's — one member read
|
|
1281
|
+
// per element, left to right, at the element's pattern position:
|
|
1282
|
+
// declared fields read their slots and accessor properties call
|
|
1283
|
+
// their getters through the same fieldGetExpr dispatch as dotted
|
|
1284
|
+
// reads (base-chain accessors and setter-only rejections resolve
|
|
1285
|
+
// identically). Rest elements, methods, and names no class on the
|
|
1286
|
+
// chain declares keep named fences (a detached method would lose its
|
|
1287
|
+
// receiver silently; JS binds the prototype function).
|
|
1288
|
+
if (srcType.kind === "object") {
|
|
1289
|
+
const info = L.classes.get(srcType.className);
|
|
1290
|
+
if (!info)
|
|
1291
|
+
L.flushDeferredClass(srcType.className);
|
|
1292
|
+
if (info) {
|
|
1293
|
+
for (const el of pattern.elements) {
|
|
1294
|
+
if (el.name === undefined)
|
|
1295
|
+
continue;
|
|
1296
|
+
const loc = locOf(el);
|
|
1297
|
+
if (el.dotDotDotToken) {
|
|
1298
|
+
L.unsupported("SC1031", el, "rest elements over class-instance sources (the remaining-properties object has no lowering yet)");
|
|
1299
|
+
}
|
|
1300
|
+
const prop = el.propertyName ?? el.name;
|
|
1301
|
+
const propName = ts.isIdentifier(prop) || ts.isComputedPropertyName(prop) || ts.isStringLiteralLike(prop) || ts.isNumericLiteral(prop)
|
|
1302
|
+
? patternKeyNameOf(L, prop)
|
|
1303
|
+
: null;
|
|
1304
|
+
if (propName === null) {
|
|
1305
|
+
L.unsupported("SC1031", el, "destructuring with computed keys that do not fold to one property name");
|
|
1306
|
+
}
|
|
1307
|
+
const fieldType = info.fields.get(propName);
|
|
1308
|
+
const getF = fieldType === undefined ? L.findMethodOn(info, `get:${propName}`) : null;
|
|
1309
|
+
const setF = fieldType === undefined ? L.findMethodOn(info, `set:${propName}`) : null;
|
|
1310
|
+
let value;
|
|
1311
|
+
if (fieldType !== undefined) {
|
|
1312
|
+
value = L.fieldGetExpr({ container: "class", obj: srcRef(), className: srcType.className, field: propName, fieldType }, loc, el);
|
|
1313
|
+
}
|
|
1314
|
+
else if (getF || setF) {
|
|
1315
|
+
value = L.fieldGetExpr({
|
|
1316
|
+
container: "accessor",
|
|
1317
|
+
obj: srcRef(),
|
|
1318
|
+
className: srcType.className,
|
|
1319
|
+
field: propName,
|
|
1320
|
+
fieldType: getF ? getF.sig.ret : setF.sig.params[0].type,
|
|
1321
|
+
}, loc, el);
|
|
1322
|
+
}
|
|
1323
|
+
else {
|
|
1324
|
+
L.unsupported("SC1031", el, L.findMethodOn(info, propName)
|
|
1325
|
+
? `destructuring the method '${propName}' (a detached method loses its receiver — call it through the instance)`
|
|
1326
|
+
: `destructuring the property '${propName}' the class '${info.def.jsName ?? info.def.name}' does not declare`);
|
|
1327
|
+
}
|
|
1328
|
+
if (el.initializer)
|
|
1329
|
+
value = applyBindingDefault(L, el, value);
|
|
1330
|
+
L.bindPatternTarget(el.name, value, isLet, out);
|
|
1331
|
+
}
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1279
1335
|
if (srcType.kind !== "record") {
|
|
1280
1336
|
L.unsupported("SC1031", pattern, srcType.kind === "object"
|
|
1281
1337
|
? "object destructuring of class instances (read the fields directly — accessors make the desugar observable)"
|
|
@@ -2698,6 +2754,40 @@ function lowerDeleteStatement(L, expr) {
|
|
|
2698
2754
|
}
|
|
2699
2755
|
L.unsupported("SC1090", expr, `'delete' on '${L.fmt(obj.type)}' receivers (process.env keys and pure Record<string, T> keys delete)`);
|
|
2700
2756
|
}
|
|
2757
|
+
/** The exact `Object.defineProperty(exports|module.exports, "__esModule",
|
|
2758
|
+
* { value: true })` interop stamp (see the no-op lowering above). */
|
|
2759
|
+
function isEsModuleStamp(expr) {
|
|
2760
|
+
if (!ts.isCallExpression(expr) || expr.questionDotToken !== undefined)
|
|
2761
|
+
return false;
|
|
2762
|
+
const callee = expr.expression;
|
|
2763
|
+
if (!ts.isPropertyAccessExpression(callee) ||
|
|
2764
|
+
!ts.isIdentifier(callee.expression) ||
|
|
2765
|
+
callee.expression.text !== "Object" ||
|
|
2766
|
+
!ts.isIdentifier(callee.name) ||
|
|
2767
|
+
callee.name.text !== "defineProperty") {
|
|
2768
|
+
return false;
|
|
2769
|
+
}
|
|
2770
|
+
if (expr.arguments.length !== 3)
|
|
2771
|
+
return false;
|
|
2772
|
+
const [recv, nameArg, desc] = expr.arguments;
|
|
2773
|
+
const isExports = (ts.isIdentifier(recv) && recv.text === "exports") ||
|
|
2774
|
+
(ts.isPropertyAccessExpression(recv) &&
|
|
2775
|
+
ts.isIdentifier(recv.expression) &&
|
|
2776
|
+
recv.expression.text === "module" &&
|
|
2777
|
+
ts.isIdentifier(recv.name) &&
|
|
2778
|
+
recv.name.text === "exports");
|
|
2779
|
+
if (!isExports)
|
|
2780
|
+
return false;
|
|
2781
|
+
if (!ts.isStringLiteral(nameArg) || nameArg.text !== "__esModule")
|
|
2782
|
+
return false;
|
|
2783
|
+
if (!ts.isObjectLiteralExpression(desc) || desc.properties.length !== 1)
|
|
2784
|
+
return false;
|
|
2785
|
+
const p = desc.properties[0];
|
|
2786
|
+
return (ts.isPropertyAssignment(p) &&
|
|
2787
|
+
ts.isIdentifier(p.name) &&
|
|
2788
|
+
p.name.text === "value" &&
|
|
2789
|
+
p.initializer.kind === ts.SyntaxKind.TrueKeyword);
|
|
2790
|
+
}
|
|
2701
2791
|
/** A top-level CommonJS export statement (see cjsExportAssignmentOf):
|
|
2702
2792
|
* `exports.f = <expr>` and each expression-valued property of
|
|
2703
2793
|
* `module.exports = { ... }` assign their pre-registered export globals
|
|
@@ -2739,6 +2829,56 @@ function lowerCjsExportStatement(L, cjs) {
|
|
|
2739
2829
|
if (L.cjsMemberExportClassSymbol(cjs.expr) !== null) {
|
|
2740
2830
|
return { kind: "block", body: [], loc };
|
|
2741
2831
|
}
|
|
2832
|
+
// The tsc VOID-INIT PREAMBLE (`exports.leaf = void 0;` with the real
|
|
2833
|
+
// `exports.leaf = leaf;` further down — every tsc-emitted dist file
|
|
2834
|
+
// opens its exports this way): the export global takes its value at
|
|
2835
|
+
// the REAL assignment, and pushing undefined through a typed slot
|
|
2836
|
+
// here would trap at module load. Node's only observable difference
|
|
2837
|
+
// is a transient undefined between the two statements — reads in
|
|
2838
|
+
// that window are the declaring module's own top-level code, which
|
|
2839
|
+
// the real assignment's position already orders. Preambles with no
|
|
2840
|
+
// later real assignment keep the ordinary path (the export IS
|
|
2841
|
+
// undefined then).
|
|
2842
|
+
if (ts.isIdentifier(cjs.name)) {
|
|
2843
|
+
const isExportsMember = (e) => ts.isPropertyAccessExpression(e) &&
|
|
2844
|
+
ts.isIdentifier(e.name) &&
|
|
2845
|
+
((ts.isIdentifier(e.expression) && e.expression.text === "exports") ||
|
|
2846
|
+
(ts.isPropertyAccessExpression(e.expression) &&
|
|
2847
|
+
ts.isIdentifier(e.expression.expression) &&
|
|
2848
|
+
e.expression.expression.text === "module" &&
|
|
2849
|
+
ts.isIdentifier(e.expression.name) &&
|
|
2850
|
+
e.expression.name.text === "exports"));
|
|
2851
|
+
const isVoid = (e) => {
|
|
2852
|
+
while (ts.isParenthesizedExpression(e))
|
|
2853
|
+
e = e.expression;
|
|
2854
|
+
return e.kind === ts.SyntaxKind.VoidExpression || (ts.isIdentifier(e) && e.text === "undefined");
|
|
2855
|
+
};
|
|
2856
|
+
// chains: `exports.a = exports.b = void 0;` collects every name
|
|
2857
|
+
const names = [cjs.name.text];
|
|
2858
|
+
let tail = cjs.value;
|
|
2859
|
+
while (ts.isBinaryExpression(tail) &&
|
|
2860
|
+
tail.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
2861
|
+
isExportsMember(tail.left)) {
|
|
2862
|
+
names.push(tail.left.name.text);
|
|
2863
|
+
tail = tail.right;
|
|
2864
|
+
}
|
|
2865
|
+
if (isVoid(tail)) {
|
|
2866
|
+
const sfHere = cjs.expr.getSourceFile();
|
|
2867
|
+
const myPos = cjs.expr.getStart(sfHere);
|
|
2868
|
+
const laterRealOf = (name) => sfHere.statements.some((s) => {
|
|
2869
|
+
const other = cjsExportAssignmentOf(s);
|
|
2870
|
+
if (other?.kind !== "member" || !ts.isIdentifier(other.name))
|
|
2871
|
+
return false;
|
|
2872
|
+
if (other.name.text !== name)
|
|
2873
|
+
return false;
|
|
2874
|
+
if (other.expr.getStart(sfHere) <= myPos)
|
|
2875
|
+
return false;
|
|
2876
|
+
return !isVoid(other.value);
|
|
2877
|
+
});
|
|
2878
|
+
if (names.every(laterRealOf))
|
|
2879
|
+
return { kind: "block", body: [], loc };
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2742
2882
|
return assignExport(cjs.name, cjs.value);
|
|
2743
2883
|
}
|
|
2744
2884
|
let tableObj = cjs.obj;
|
|
@@ -2799,6 +2939,20 @@ function lowerCjsExportStatement(L, cjs) {
|
|
|
2799
2939
|
// fence at the write site.
|
|
2800
2940
|
if (ts.isGetAccessorDeclaration(prop) || ts.isSetAccessorDeclaration(prop))
|
|
2801
2941
|
continue;
|
|
2942
|
+
// `...require('spec')` SPREAD entries are star-re-export plumbing
|
|
2943
|
+
// (the bundler-emitted CJS canonical table — npm-static-rewrite.ts):
|
|
2944
|
+
// importers of the spread names resolve statically through the
|
|
2945
|
+
// TARGET module's own export machinery (the checker chases the
|
|
2946
|
+
// spread; explicit member entries carry the values), and the module
|
|
2947
|
+
// LOAD itself rides the ordinary import edge preflight collected —
|
|
2948
|
+
// so no runtime copy exists to emit and the entry lowers to nothing.
|
|
2949
|
+
if (ts.isSpreadAssignment(prop)) {
|
|
2950
|
+
let inner = prop.expression;
|
|
2951
|
+
while (ts.isParenthesizedExpression(inner))
|
|
2952
|
+
inner = inner.expression;
|
|
2953
|
+
if (requireSpecOf(inner) !== null)
|
|
2954
|
+
continue;
|
|
2955
|
+
}
|
|
2802
2956
|
L.unsupported("SC1090", prop, "module.exports table entries beyond plain 'name: value' properties (methods, accessors, spreads, computed names)");
|
|
2803
2957
|
}
|
|
2804
2958
|
return { kind: "block", body, loc };
|
|
@@ -2946,6 +3100,15 @@ export function lowerExprStatement(L, expr) {
|
|
|
2946
3100
|
const cjs = cjsExportAssignmentOf(stmtNode);
|
|
2947
3101
|
if (cjs)
|
|
2948
3102
|
return lowerCjsExportStatement(L, cjs);
|
|
3103
|
+
// The tsc CJS interop stamp — `Object.defineProperty(exports,
|
|
3104
|
+
// "__esModule", { value: true });` at a module's top — lowers to
|
|
3105
|
+
// NOTHING: the compiled module system has no reflective exports
|
|
3106
|
+
// object to mark, and the marker's one job (import interop) is
|
|
3107
|
+
// already modeled statically by the checker and the CJS lexer link
|
|
3108
|
+
// check. Every tsc-emitted dist file opens with it, and the generic
|
|
3109
|
+
// defineProperty fence would throw at module load.
|
|
3110
|
+
if (isEsModuleStamp(expr))
|
|
3111
|
+
return { kind: "block", body: [], loc: locOf(expr) };
|
|
2949
3112
|
}
|
|
2950
3113
|
// Statement-position `delete` — the two honest receivers: process.env
|
|
2951
3114
|
// keys (unsetenv(3) — later reads and spawned children observe the
|