Files
scriptc/tests/corpus/split-cjs-require-binding/main.cjs
T

56 lines
1.9 KiB
JavaScript

console.log("main: start");
var lib, whole;
lib = require("./lib.cjs");
whole = require("./whole.cjs");
console.log("main: after", lib.n, lib.f(3), whole(4));
exports.fromLib = lib.f;
exports.whole = whole;
console.log("main: exported", exports.fromLib(5), whole(6));
console.log("main: identity", exports.fromLib === lib.f, exports.whole === whole);
const re = require("./reexport.cjs");
console.log("main: reexport", re(7));
let later;
later = require("./lib.cjs");
console.log("main: let", later.n);
const rx = require("./reexport-extra.cjs");
console.log("main: reexport extra", rx(8), rx.extra);
const splitObject = { whole };
console.log("main: shorthand value", splitObject.whole(10));
var libAgain;
libAgain = require("./lib.cjs");
const { n: splitN, f: splitF } = libAgain;
console.log("main: destructured split", splitN, splitF(4));
var chained;
chained = require("./chain-wrap.cjs");
console.log("main: chained", chained(11));
// Any later write, including a destructuring target, keeps ordinary storage.
var shorthand;
shorthand = require("./whole.cjs");
({ shorthand } = { shorthand: "shorthand" });
console.log("main: shorthand write", shorthand);
var renamed;
renamed = require("./whole.cjs");
({ value: renamed } = { value: "renamed" });
console.log("main: renamed write", renamed);
var nested;
nested = require("./whole.cjs");
({ a: { nested } } = { a: { nested: "nested" } });
console.log("main: nested write", nested);
var rest;
rest = require("./whole.cjs");
({ ...rest } = { a: 1, b: 2 });
console.log("main: rest write", rest.a, rest.b);
var array;
array = require("./whole.cjs");
[array] = ["array"];
console.log("main: array write", array);
var arrayRest;
arrayRest = require("./whole.cjs");
[...arrayRest] = [1, 2];
console.log("main: array-rest write", arrayRest[0], arrayRest[1]);
var each;
each = require("./whole.cjs");
for ({ each } of [{ each: "each" }]) {}
console.log("main: for-of write", each);