This is a strawman for an advanced generator-comprehension syntax for ECMAScript based in the LINQ syntax. The syntax allows for custom semantics for evaluation, as each clause in a query is translated into regular function calls for special symbol-named methods that are evaluated if found on the sequence (see Abstract Operations for more information).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare type DateUnit = "year" | "month" | "day"; | |
declare type DateDelta = "years" | "months" | "weeks" | "days"; | |
declare type TimeUnit = "hour" | "minute" | "second" | "millisecond" | "nanosecond"; | |
declare type TimeDelta = "hours" | "minutes" | "seconds" | "milliseconds" | "nanoseconds"; | |
declare type InstantUnit = "milliseconds" | "nanoseconds"; | |
declare type InstantDelta = "milliseconds" | "nanoseconds"; | |
declare type Components<Unit extends string> = Partial<Record<Unit, number>>; | |
// Represents either a fixed-offset time-zone, the SYSTEM time-zone, or a regional (IANA) time-zone. | |
declare class Zone { | |
static readonly Z: Zone; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const friendship = new WeakMap(); | |
function friend(ref granteeClass) { | |
return function (descriptor) { | |
descriptor.finisher = (granterClass) => { | |
let info = friendship.get(granterClass); | |
if (!info) { | |
const names = descriptor.elements | |
.filter(element => element.name instanceof PrivateName) | |
.reduce((map, element) => map.set(element.name.description, element.name), new Map()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// definition | |
// | |
// marker used to indicate a constructor is a freeesing constructor (see below). | |
const marker = new WeakSet(); | |
export function freeze(descriptor) { | |
// save the previous constructor | |
const previousConstructor = descriptor.constructor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class LinkedList { | |
#head; | |
#size; | |
get first() { return this.#head; } | |
get last() { return this.#head !== undefined ? this.#head.LinkedListNode#previous : undefined; } | |
get size() { return this.#size; } | |
addLast(value) { | |
return this.#insertBefore(this.#head, new LinkedListNode(value), /*replaceHead*/ false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nodeFriend = new FriendKey(); | |
export class LinkedList { | |
#head; | |
#size; | |
get first() { return this.#head; } | |
get last() { return this.#head !== undefined ? nodeFriend.get(this.#head, "#previous") : undefined; } | |
get size() { return this.#size; } |
The following is an interpretation of "protected" state exposed through decorators:
NOTE: this has been adapted from https://github.com/tc39/proposal-unified-class-features/blob/master/friend.js
// protected.js
const protectedMembers = new WeakMap();
The following is a somewhat loose interpretation of a "friend class"-like feature exposed through decorators:
NOTE: this has been adapted from https://github.com/tc39/proposal-unified-class-features/blob/master/friend.js
// friend.js
export class FriendKey {
For the purposes of this investigation, I am breaking down the various statements within ECMAScript into several broad categories:
- Leaf Statements:
- Declaration Statements -
class
,function
,var
,let
,const
,import
,export
- Abrupt Completion Statements -
throw
,return
,break
,continue
- Other -
debugger
- Declaration Statements -
- Branching Statements:
- Control Flow Statements -
if
,switch
,try