diff --git a/js/test_cases/walk_up/README.md b/js/test_cases/walk_up/README.md index f30e7cc..7099d95 100644 --- a/js/test_cases/walk_up/README.md +++ b/js/test_cases/walk_up/README.md @@ -31,3 +31,36 @@ After walk "foo": ``` This appears to be using dynamic scoping instead of lexical scoping. For example, in lexical scoping a read of "b1" would fail after that final walk because you're inside the "foo" context which does not have any "b1" in or above it, however, since this is using dynamic scoping its using the invocations to build a scope tree rather than their original position. + +Itermediate scopes appear to not be added. For example: +```js +{ + "globals": { + "item": "pencil", + "things": {"color": "purple"} + }, + "people": [ + {"name": "Dave"}, + {"name": "Emily", "item": "pen"} + ] +} +``` + +If we walk into people and then into globals.things in one step, globals will not be added to the dynamic scope: +``` +(attempts to read from the context in-order starting with the first line) + +Starting access context: +{"globals":{"item":"pencil","things":{"color":"purple"}},"people":[{"name":"Dave"},{"name":"Emily","item":"pen"}]} + +After walk "people": +[{"name":"Dave"},{"name":"Emily","item":"pen"}] +{"globals":{"item":"pencil","things":{"color":"purple"}},"people":[{"name":"Dave"},{"name":"Emily","item":"pen"}]} + +After walk globals.things +{"color":"purple"} +[{"name":"Dave"},{"name":"Emily","item":"pen"}] +{"globals":{"item":"pencil","things":{"color":"purple"}},"people":[{"name":"Dave"},{"name":"Emily","item":"pen"}]} +``` + +So if we were on the "Dave" iteration in people and I attempted to read "item" it would not find a value despite "item" being a key in the lexical context above `globals.things`. diff --git a/js/test_cases/walk_up/input1.json b/js/test_cases/walk_up/input1.json index 1d96d10..e1d0c8f 100644 --- a/js/test_cases/walk_up/input1.json +++ b/js/test_cases/walk_up/input1.json @@ -7,5 +7,13 @@ {"name": "Alice", "job": "Chief Swinger"}, {"name": "Bob", "job": "Chief Swayer"}, {"name": "Chris", "job": "Barista", "company": "GenericCoffee", "email": "thecoffeeguy@generic.coffee"} - ] + ], + "deep_globals": { + "item": "pencil", + "things": {"color": "purple"} + }, + "deep_people": [ + {"name": "Dave"}, + {"name": "Emily", "item": "pen"} + ] } diff --git a/js/test_cases/walk_up/main.dust b/js/test_cases/walk_up/main.dust index 94a2d2f..b143107 100644 --- a/js/test_cases/walk_up/main.dust +++ b/js/test_cases/walk_up/main.dust @@ -3,3 +3,10 @@ Directory for {company}:{~n} {name}: {job} at {company} (email: {globals.email}){~n} Testing walking after entering a parent context {#globals}job: {job}, email: {email}, company: {company}{/globals}{~n} {/people} + +Doing a deep walk to see if intermediate steps are added to the dynamic context.{~n} +{#deep_people} +{#deep_globals.things} +{name} has a {color} {item}{~n} +{/deep_globals.things} +{/deep_people}