Skip to content

Commit 9257613

Browse files
committed
STASH add tests
1 parent fc8012c commit 9257613

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

rollup/jsPolyfills/originals.js

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// Originals of the jsPolyfills from Sucrase and Rollup we use (which we have adapted in various ways), preserved here for testing, to prove that
2+
// the modified versions do the same thing the originals do.
3+
4+
// From Sucrase
5+
export async function _asyncNullishCoalesce(lhs, rhsFn) {
6+
if (lhs != null) {
7+
return lhs;
8+
} else {
9+
return await rhsFn();
10+
}
11+
}
12+
13+
// From Sucrase
14+
export async function _asyncOptionalChain(ops) {
15+
let lastAccessLHS = undefined;
16+
let value = ops[0];
17+
let i = 1;
18+
while (i < ops.length) {
19+
const op = ops[i];
20+
const fn = ops[i + 1];
21+
i += 2;
22+
if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) {
23+
return undefined;
24+
}
25+
if (op === 'access' || op === 'optionalAccess') {
26+
lastAccessLHS = value;
27+
value = await fn(value);
28+
} else if (op === 'call' || op === 'optionalCall') {
29+
value = await fn((...args) => value.call(lastAccessLHS, ...args));
30+
lastAccessLHS = undefined;
31+
}
32+
}
33+
return value;
34+
}
35+
36+
// From Sucrase
37+
export async function _asyncOptionalChainDelete(ops) {
38+
const result = await _asyncOptionalChain(ops);
39+
// by checking for loose equality to `null`, we catch both `null` and `undefined`
40+
return result == null ? true : result;
41+
}
42+
43+
// From Sucrase
44+
export function createNamedExportFrom(obj, localName, importedName) {
45+
Object.defineProperty(exports, localName, { enumerable: true, get: () => obj[importedName] });
46+
}
47+
48+
// From Sucrase
49+
export function _createStarExport(obj) {
50+
Object.keys(obj)
51+
.filter(key => key !== 'default' && key !== '__esModule')
52+
.forEach(key => {
53+
// eslint-disable-next-line no-prototype-builtins
54+
if (exports.hasOwnProperty(key)) {
55+
return;
56+
}
57+
Object.defineProperty(exports, key, { enumerable: true, get: () => obj[key] });
58+
});
59+
}
60+
61+
// From Rollup
62+
export function _interopDefault(e) {
63+
return e && e.__esModule ? e['default'] : e;
64+
}
65+
66+
// From Rollup
67+
export function _interopNamespace(e) {
68+
if (e && e.__esModule) return e;
69+
var n = Object.create(null);
70+
if (e) {
71+
// eslint-disable-next-line guard-for-in
72+
for (var k in e) {
73+
n[k] = e[k];
74+
}
75+
}
76+
n['default'] = e;
77+
return n;
78+
}
79+
80+
// From Sucrase
81+
export function _interopRequireDefault(obj) {
82+
return obj && obj.__esModule ? obj : { default: obj };
83+
}
84+
85+
// From Sucrase
86+
export function _interopRequireWildcard(obj) {
87+
if (obj && obj.__esModule) {
88+
return obj;
89+
} else {
90+
var newObj = {};
91+
if (obj != null) {
92+
for (var key in obj) {
93+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
94+
newObj[key] = obj[key];
95+
}
96+
}
97+
}
98+
newObj.default = obj;
99+
return newObj;
100+
}
101+
}
102+
103+
// From Sucrase
104+
export function _nullishCoalesce(lhs, rhsFn) {
105+
if (lhs != null) {
106+
return lhs;
107+
} else {
108+
return rhsFn();
109+
}
110+
}
111+
112+
// From Sucrase
113+
export function _optionalChain(ops) {
114+
let lastAccessLHS = undefined;
115+
let value = ops[0];
116+
let i = 1;
117+
while (i < ops.length) {
118+
const op = ops[i];
119+
const fn = ops[i + 1];
120+
i += 2;
121+
if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) {
122+
return undefined;
123+
}
124+
if (op === 'access' || op === 'optionalAccess') {
125+
lastAccessLHS = value;
126+
value = fn(value);
127+
} else if (op === 'call' || op === 'optionalCall') {
128+
value = fn((...args) => value.call(lastAccessLHS, ...args));
129+
lastAccessLHS = undefined;
130+
}
131+
}
132+
return value;
133+
}
134+
135+
// From Sucrase
136+
export function _optionalChainDelete(ops) {
137+
const result = _optionalChain(ops);
138+
// by checking for loose equality to `null`, we catch both `null` and `undefined`
139+
return result == null ? true : result;
140+
}

0 commit comments

Comments
 (0)