Files
scriptc/tests/corpus/2577-builtin-global-destructuring.js
Chris Tate 4d3ee3fffd Strings destructure through their iterator; stdlib globals destructure as identity tokens
- Array patterns over strings split by code points via the string-iterator machinery: positions, holes, defaults, rest, nesting, and for-of heads
- Destructured stdlib-global members bind their builtin identity tokens with Node-agreeing === identity; aliases register the twin
- Surfaced-global members like Math.max fence eagerly by name — a token would quietly degrade them
- Object patterns over strings bind length; wrapper-method extraction names the detached method

# Conflicts:
#	packages/compiler/test/ts7/baselines/order-parity.json
2026-07-23 23:53:08 -05:00

31 lines
1.2 KiB
JavaScript

'use strict';
// Destructuring a STDLIB GLOBAL in a JavaScript file binds member
// IDENTITY TOKENS (the identifier chokepoint's rule one member deep):
// one global, one member, one interned string, so identity and
// truthiness agree with Node across every spelling, while what a token
// cannot do meets per-site rules lazily at each use. This program pins
// the AGREEING operations — identity across destructures, identity with
// the property spelling, truthiness — under the Node oracle.
const { crypto: wc } = globalThis;
console.log(!!wc);
console.log(wc === globalThis.crypto);
const { subtle } = globalThis.crypto;
const { subtle: again } = globalThis.crypto;
console.log(subtle === again);
console.log(!!subtle);
// A member destructured from the aliased binding IS the same member.
const { subtle: viaAlias } = wc;
console.log(viaAlias === subtle);
const { Console } = console;
console.log(!!Console);
// A globalThis member with a REAL surface destructures as the global
// itself (the stdlibGlobalAliasDecl twin): receiver uses route through
// the same lowerings as the bare spelling.
const { Math: M } = globalThis;
console.log(M.max(1, 2));
console.log(M === globalThis.Math);