Skip to content

Commit

Permalink
Revert safe traversal policy
Browse files Browse the repository at this point in the history
- `safeCall` no longer enabled by default
- Remove `?.(` syntax
- Update changelog accordingly
  • Loading branch information
wcjohnson committed Oct 3, 2017
1 parent e2f3e68 commit 787f2d7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
26 changes: 6 additions & 20 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,7 @@ Implicit parentheses around sequence expressions introduce additional ambiguitie

### Changes:

#### 1. Safe calls (`{safeCall: true}`) are now enabled by default.

The JavaScript proposal for optional chaining is now Stage 1 and it includes safe calls. Therefore we are enabling them by default.

Passing `{safeCall: false}` will disable safe calls for stricter backward compatibility with `lightscript@0.5.x`.

Assuming they are not removed from the JS optional chaining proposal, safe calls will be considered a core JS feature, and thus the `safeCall` flag will be removed completely in 4.0.

#### 2. The proposed JS syntax for safe calls is now legal

Both of these syntaxes will safe-call `a` with argument `b`.
```js
a?(b)
a?.(b)
```
The `?.()` syntax is endorsed by the official JS proposal, but the nicer `?()` syntax will continue to be supported as well.
#### 3. The semantics of safe chaining now match the JS proposal
#### 1. The semantics of safe chaining now match the JS proposal

The JavaScript optional chaining proposal specifies details on how safe chains should be evaluated. We've adopted the algorithm specified in the proposal. This results in a number of bug fixes as well as improved short-circuiting semantics.

Expand All @@ -89,9 +71,13 @@ a == null ? void 0 : (_a = a[b++]) == null ? void 0 : _a.c;
This is a **breaking change** to language semantics! Most user code should not be affected, as it should not rely on this kind of side effect ordering -- but please do note the possible impact here.
#### 2. Syntax and other changes
The JS optional chaining proposal is still in rapid flux despite its position at Stage 1 in the standards process. There is considerable uncertainty on the final syntax. For that reason, we are delaying introducing any syntax changes at this time. Also, for the time being, `{safeCall: true}` is still required to enable safe calls.
### Rationale:
Here we are converging with the direction that JavaScript proper is headed in, as well as picking up some bug fixes along the way.
We're trying to converge with the JS safe traversal proposal when possible, as well as fix bugs in the previous LSC implementation.
## Bang calls
Expand Down
2 changes: 1 addition & 1 deletion src/config.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export getParserOpts(pluginOpts, initialParserOpts) ->

if not pluginOpts?.disableJsx: plugins.push("jsx")
if not pluginOpts?.disableFlow: plugins.push("flow")
if pluginOpts?.safeCall != false: plugins.push("safeCallExpression")
if pluginOpts?.safeCall: plugins.push("safeCallExpression")
if pluginOpts?.existential: plugins.push("existentialExpression")
if pluginOpts?.bangCall != false: plugins.push("bangCall")
if not pluginOpts?.noEnforcedSubscriptIndentation: plugins.push("enforceSubscriptIndentation")
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/safe-call-expression/disabled/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use @oigroup/lightscript with safeCall: false'
a?(b)
3 changes: 3 additions & 0 deletions test/fixtures/safe-call-expression/disabled/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected : (2:5)"
}

0 comments on commit 787f2d7

Please sign in to comment.