└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # REPL Goal for JS 2 | 3 | For all examples, a single input passed to the REPL will be represented by lines prefixed by `> ` and output from the REPL will be represented by lines prefixed by `< `. 4 | 5 | * [V8 Issue](https://bugs.chromium.org/p/v8/issues/detail?id=6903) 6 | * [Related Node PR](https://github.com/nodejs/node/pull/17285) 7 | 8 | ## Grammar Intentions 9 | 10 | These are a list of intended usages with grammar examples, production mechanics will be done at a later time. 11 | 12 | * Top Level Await 13 | 14 | ```js 15 | > Date.now() - await {then(f) {setTimeout(() => f(Date.now), 1000;)}} 16 | < 1000 17 | ``` 18 | 19 | * Reused environment record that removes conflicting bindings between evluations 20 | 21 | ```js 22 | > let x = 1; let y = 'a'; x 23 | < 1 24 | > let x = 2; x 25 | < 2 26 | > x 27 | < 2 28 | > y 29 | < 'a' 30 | ``` 31 | 32 | * `this` is the global 33 | 34 | ```js 35 | > typeof this 36 | < "object" 37 | > let x = 1; this.x 38 | < undefined 39 | ``` 40 | 41 | * Sloppy by default 42 | 43 | ```js 44 | > with ({x: 1}) x 45 | < 1 46 | > let x = 2; x 47 | < 2 48 | > eval('let x =3; x') 49 | < 3 50 | > x 51 | < 3 52 | ``` 53 | 54 | * Top level static import 55 | 56 | ```js 57 | > import {x} from './y'; 58 | < undefined 59 | ``` 60 | 61 | * Object literal at start 62 | 63 | ```js 64 | > {x: 1} 65 | < {"x": 1} 66 | ``` 67 | 68 | * Strict mode DirectivePrologue 69 | 70 | ```js 71 | > "use strict"; with ({}) {} 72 | < SyntaxError: Strict mode code may not include a with statement 73 | ``` 74 | 75 | * REPL Environment Record is not Global Environment Record 76 | 77 | ```js 78 | > geval = eval; geval('let x = 1; x') 79 | < 1 80 | > let x = 2; x 81 | < 2 82 | > geval('x') 83 | < 1 84 | ``` 85 | 86 | ### Productions 87 | 88 | ``` 89 | REPL Input : 90 | [lookahead = {] ObjectLiteral[+Await] 91 | [lookahead != {] Script[+Await, +Import] 92 | 93 | ScriptBody: 94 | ScriptItemList[?Await, ?Import] 95 | 96 | ScriptItemList: 97 | ScriptItem[?Await, ?Import] 98 | ScriptItemList ScriptItem[?Await, ?Import] 99 | 100 | ScriptItem: 101 | if (+import) ImportDeclaration 102 | StatementListItem[~Yield, ?Await, ?Import, ~Return] 103 | ``` 104 | 105 | ## Semantic Intentions 106 | 107 | These are a list of intended spec changes by adding various things with new semantics. 108 | 109 | 1. Allow the repeated running of lines from scrollback history. 110 | 111 | Allow repeated running of the same input even if the input would collide with existing bindings on the REPL Environment Record. 112 | 113 | 2. Abililty to remove bindings that have permanently been stuck in the Temporal Dead Zone. 114 | 115 | Allow cleaning up of bindings that have become stuck in a TDZ. 116 | 117 | 3. Separation from the global scope. 118 | 119 | Allow a separation from the Global Environment in order to preserve logical consistency of how bindings work and giving a level of isolation to prevent leaving accidental bindings on the global when using tools such as a debugger. 120 | 121 | ### REPL Lexical Environment 122 | 123 | A Lexical Environment with an outer environment reference to a Global Lexical Environment. A REPL environment's Environment Record may be shared amongst multiple REPL Input Records. 124 | 125 | ### REPL Input Record 126 | 127 | A REPL Input Record encapsulates information about a repl input being evaluated. Each REPL Input Record contains the fields. 128 | 129 | #### REPL Input Record Fields 130 | 131 | Field Name | Value Type | Meaning 132 | ---- | ---- | ---- 133 | [[Realm]] Realm Record | undefined | The realm within which this REPL Input Record was created. undefined if not yet assigned. 134 | [[Environment]] Lexical Environment | a REPL Lexical Environment | The Lexical Environment containing the top level bindings for this REPL Input Record. This field is set when the REPL Input Record is instantiated. 135 | [[ECMAScriptCode]] | a Parse Node | The result of parsing the source text of this module using REPL as the goal symbol. 136 | [[HostDefined]] | Any, default value is undefined. | Field reserved for use by host environments that need to associate additional information with a REPL Input Record. 137 | 138 | ### REPL Environment Record 139 | 140 | A REPL Environment Record is a declarative Environment Record that is used to represent the top-level scope of a REPL. It may be reused amongst multiple REPL Input Records. 141 | 142 | ### ParseREPLInput ( sourceText, realm, REPLEnvironment, hostDefined ) 143 | 144 | Parses the sourceText and initializes all the lexical bindings declared in `sourceText` on a REPL Environment, removing them before hand if needed to avoid errors from bindings already being defined. All lexical bindings declared in `sourceText` may be deleted. 145 | 146 | Returns a REPL Input Record. 147 | 148 | ### REPL Input . Evaluate 149 | 150 | Evaluates a REPL Input Record. 151 | 152 | Returns a Promise to the Completion Value. 153 | --------------------------------------------------------------------------------