Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements covering a few ongoing issues #89

Merged
merged 8 commits into from Jan 6, 2020
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -71,6 +71,11 @@ assert(record1.a === 1);
assert(record1["a"] === 1);
assert(record1 !== record2);
assert(record2 === #{ a: 1, c: 3, b: 5 });
assert(record1?.a === 1);
assert(1 === record1?.a);
assert(record1?.d === undefined);
assert(record1?.d ?? 5 === 5);
assert(3 === record1?.d ?? 3);
```
rricard marked this conversation as resolved.
Show resolved Hide resolved

#### `Tuple`
Expand Down Expand Up @@ -151,6 +156,14 @@ At runtime, attempting to create a `Record` with a key that is not a `string` or

At runtime, it is a `TypeError` to add a value to a `Record` or `Tuple` of any type except the following: `Record`, `Tuple`, `string`, `number`, `symbol`, `boolean`, `bigint`, `undefined`, or `null`.

However whenever the engine can figure out at parse time that something is wrong, it should fail at that moment:
rricard marked this conversation as resolved.
Show resolved Hide resolved

```js
const r1 = #{ obj: {} }; // fails at parse time because an object declaration in a record is obviously going to be an error
const r2 = #{ obj: true ? {} : #{} }; // will fail at runtime as it's not obvious from the parser's perspective that we should fail
const r3 = #{ method() {} }; // fails at parse time
```

# Equality

Instances of `Record` and `Tuple` are deeply immutable, so their equality works like that of other JS primitive value types like `boolean` and `string` instances:
Expand Down Expand Up @@ -326,6 +339,12 @@ JSON.stringify(#{ a: #[1, 2, 3] }); // '{"a":[1,2,3]}'
JSON.stringify(#[true, #{ a: #[1, 2, 3] }]); // '[true,{"a":[1,2,3]}]'
```

## JSON.parseImmutable
rricard marked this conversation as resolved.
Show resolved Hide resolved

We propose to add `JSON.parseImmutable` so we can extract a Record/Tuple type out of a JSON string instead of an Object/Array.

The signature of `JSON.parseImmutable` is identical to `JSON.parse` with the only change being in the return type that is now a Record or a Tuple.

## `Record` prototype

The `Record` prototype is an empty object.
Expand Down