Skip to content

Commit

Permalink
Merge 2.3 fixes
Browse files Browse the repository at this point in the history
commit 15799aa
Author: William C. Johnson <wcjohnson@oigroup.net>
Date:   Mon Sep 25 16:01:25 2017 -0400

    @oigroup/babylon-lightscript@2.3.1

commit e816aa7
Author: William C. Johnson <wcjohnson@oigroup.net>
Date:   Mon Sep 25 15:54:40 2017 -0400

    @oigroup/babylon-lightscript@2.3.0

commit 2376b75
Author: William C. Johnson <wcjohnson@oigroup.net>
Date:   Mon Sep 25 15:41:14 2017 -0400

    2.3.0

    - Syntactic placeholders
    - Pipe calls `|>`, `<|`
    - Track block nesting level in parser state
    - Fix bang call subscript unwinding crossing block boundaries
    - Fix premature “comprehensions are illegal” error disallowing patterns with “for” or “case” keys
    - Don’t lint when testing

    commit 64f066f
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Mon Sep 25 15:36:41 2017 -0400

        Fix for bang call subscripting issue across block boundaries

    commit bda54e5
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Mon Sep 25 14:38:44 2017 -0400

        Comprehension fixes

    commit 476419a
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Sat Sep 23 15:53:55 2017 -0400

        Run lint and flow at `preversion`, not `test`

    commit 266f948
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Mon Sep 18 23:16:07 2017 -0400

        @oigroup/babylon-lightscript@2.3.0-alpha.3

    commit 2342c39
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Tue Sep 5 16:51:01 2017 -0400

        @oigroup/babylon-lightscript@2.3.0-alpha.2

    commit 21a26a8
    Merge: e61679c 7c5e20e
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Tue Sep 5 15:24:38 2017 -0400

        Merge branch 'prerelease/2.3.0' of https://github.com/wcjohnson/babylon-lightscript into prerelease/2.3.0

    commit e61679c
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Tue Sep 5 15:24:20 2017 -0400

        Unit test for unfortunate flow typecast in if test clause

    commit 7c5e20e
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Sun Aug 6 12:58:46 2017 -0400

        Misc cleanup

        - Remove errant copypasta from tildeCall.js
        - Clean up spacing/comments

    commit ffb7ddb
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Wed Jul 19 21:43:42 2017 -0400

        @oigroup/babylon-lightscript@2.3.0-alpha.1

    commit fb570ee
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Wed Jul 19 21:28:23 2017 -0400

        Pipe call improvements

        - Support arrows as pipe call operands
        - Support leftward-pointing pipe calls

    commit f248451
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Mon Jul 17 16:09:12 2017 -0400

        @oigroup/babylon-lightscript@2.3.0-alpha.0

    commit 00a76ef
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Mon Jul 17 15:52:31 2017 -0400

        Fix for left-associativity and subscripts of pipeCalls

    commit 6d4d300
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Mon Jul 17 00:43:08 2017 -0400

        `pipeCall` tests

    commit 4e579c7
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Mon Jul 17 00:28:40 2017 -0400

        @oigroup/babylon-lightscript@2.3.0-2

    commit 17f5a44
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Sun Jul 16 23:19:22 2017 -0400

        @oigroup/babylon-lightscript@2.3.0-1

    commit 0bcd865
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Sun Jul 16 23:07:36 2017 -0400

        @oigroup/babylon-lightscript@2.3.0-0

    commit 6975053
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Sun Jul 16 23:03:53 2017 -0400

        Parsing for pipe operator

        commit b10a5e48d1552ff389de314762e863197bc0da7e
        Author: William C. Johnson <wcjohnson@oigroup.net>
        Date:   Sun Jul 16 22:55:34 2017 -0400

            Fix associativity

        commit 0fac7c226b9cd9cda94a5956a45a067a145e2976
        Author: William C. Johnson <wcjohnson@oigroup.net>
        Date:   Sun Jul 16 22:22:34 2017 -0400

            Parse pipe operator as subscript

        commit b21acb2f12941d9d7d4279320de4c55c7ee3b50f
        Author: William C. Johnson <wcjohnson@oigroup.net>
        Date:   Sun Jul 16 21:17:17 2017 -0400

            Basic pipeCall parsing

    commit 70ee2c8
    Author: William C. Johnson <wcjohnson@oigroup.net>
    Date:   Sun Jul 16 20:46:52 2017 -0400

        Syntactic placeholders

        commit d5d4e74
        Author: William C. Johnson <wcjohnson@oigroup.net>
        Date:   Sun Jul 16 20:41:48 2017 -0400

            Allow placeholder to be changed via config

        commit 32e43a0
        Author: William C. Johnson <wcjohnson@oigroup.net>
        Date:   Sun Jul 16 20:24:59 2017 -0400

            Spread placeholder tests

        commit 73b9d32
        Author: William C. Johnson <wcjohnson@oigroup.net>
        Date:   Sun Jul 16 15:31:50 2017 -0400

            Initial implementation of syntactic placeholders

commit 833e5b9
Author: William C. Johnson <wcjohnson@oigroup.net>
Date:   Sun Aug 6 12:58:46 2017 -0400

    Misc cleanup

    - Remove errant copypasta from tildeCall.js
    - Clean up spacing/comments
  • Loading branch information
wcjohnson committed Sep 27, 2017
1 parent eaa42cd commit 5aa3ee5
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oigroup/babylon-lightscript",
"version": "2.3.0-alpha.3",
"version": "2.3.1",
"description": "A LightScript parser, based on babylon (a JavaScript parser)",
"author": "Alex Rattray <rattray.alex@gmail.com>",
"homepage": "http://lightscript.org/",
Expand Down
3 changes: 2 additions & 1 deletion src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {
node.computed = true;
this.expect(tt.bracketR);
} else {
this.unexpected();
node.property = this.parseIdentifierOrPlaceholder(true);
node.computed = false;
}

node.optional = true;
Expand Down
4 changes: 4 additions & 0 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {
let oldStrict;
let octalPosition;

this.state.nestedBlockLevel++;

let isEnd;
if (this.hasPlugin("lightscript") && typeof end === "number") {
isEnd = () => this.state.indentLevel <= end || this.match(tt.eof);
Expand Down Expand Up @@ -642,6 +644,8 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {
node.body.push(stmt);
}

this.state.nestedBlockLevel--;

if (oldStrict === false) {
this.setStrict(false);
}
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/bangCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export default function(parser) {
// Read args
let first = true;
const oldBangUnwindLevel = this.state.bangUnwindLevel;
const oldBangBlockLevel = this.state.bangBlockLevel;
this.state.bangBlockLevel = this.state.nestedBlockLevel;
this.state.bangUnwindLevel = bangIndentLevel + 1;

while (true) {
Expand Down Expand Up @@ -81,6 +83,7 @@ export default function(parser) {
}

this.state.bangUnwindLevel = oldBangUnwindLevel;
this.state.bangBlockLevel = oldBangBlockLevel;

node = this.finishNode(node, nodeType);

Expand All @@ -93,6 +96,8 @@ export default function(parser) {

// Subscripts to a bang call must appear at the arg indent level
pp.shouldUnwindBangSubscript = function() {
return this.isLineBreak() && (this.state.indentLevel <= this.state.bangUnwindLevel);
return this.isLineBreak() &&
(this.state.bangBlockLevel == this.state.nestedBlockLevel) &&
(this.state.indentLevel <= this.state.bangUnwindLevel);
};
}
20 changes: 15 additions & 5 deletions src/plugins/lightscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ pp.rethrowObjParseError = function(objParseResult, blockParseError) {
pp.parseInlineWhiteBlock = function(node) {
if (this.state.type.startsExpr) return this.parseMaybeAssign();
// oneline statement case
this.state.nestedBlockLevel++;
node.body = [this.parseStatement(true)];
this.state.nestedBlockLevel--;
node.directives = [];
this.addExtra(node, "curly", false);
return this.finishNode(node, "BlockStatement");
Expand All @@ -198,15 +200,20 @@ pp.parseMultilineWhiteBlock = function(node, indentLevel) {
if (this.match(tt.braceL) && this.hasPlugin("objectBlockAmbiguity_preferObject")) {
objParseResult = this.tryParseObjectWhiteBlock(node, indentLevel);
if (objParseResult[0]) return objParseResult[0];
}

try {
try {
this.parseBlockBody(node, false, false, indentLevel);
if (!node.body.length) {
this.unexpected(node.start, "Expected an Indent or Statement");
}
} catch (err) {
this.rethrowObjParseError(objParseResult, err);
}
} else {
this.parseBlockBody(node, false, false, indentLevel);
if (!node.body.length) {
this.unexpected(node.start, "Expected an Indent or Statement");
}
} catch (err) {
this.rethrowObjParseError(objParseResult, err);
}

this.addExtra(node, "curly", false);
Expand All @@ -230,7 +237,10 @@ pp.parseWhiteBlock = function (isExpression?) {
if (objParseResult[0]) return objParseResult[0];
}
try {
return this.parseStatement(false);
this.state.nestedBlockLevel++;
const stmt = this.parseStatement(false);
this.state.nestedBlockLevel--;
return stmt;
} catch (err) {
this.rethrowObjParseError(objParseResult, err);
}
Expand Down
1 change: 1 addition & 0 deletions src/tokenizer/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class State {

// for lightscript
this.indentLevel = 0;
this.nestedBlockLevel = 0;
this.inMatchCaseTest = false;

this.type = tt.eof;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a! ->
b
~c()
195 changes: 195 additions & 0 deletions test/fixtures/bang-call/subscripts/ambiguous-arrow-body/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
{
"type": "File",
"start": 0,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 6
}
},
"program": {
"type": "Program",
"start": 0,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 6
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 6
}
},
"expression": {
"type": "CallExpression",
"start": 0,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 6
}
},
"callee": {
"type": "Identifier",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
},
"identifierName": "a"
},
"name": "a"
},
"arguments": [
{
"type": "ArrowFunctionExpression",
"start": 3,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 3,
"column": 6
}
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"skinny": true,
"body": {
"type": "BlockStatement",
"start": 3,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 3,
"column": 6
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 8,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 3,
"column": 6
}
},
"expression": {
"type": "CallExpression",
"start": 8,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 3,
"column": 6
}
},
"callee": {
"type": "Identifier",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 4
},
"identifierName": "c"
},
"name": "c"
},
"arguments": [
{
"type": "Identifier",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "b"
},
"name": "b"
}
],
"tilde": true
}
}
],
"directives": [],
"extra": {
"curly": false
}
}
}
],
"extra": {
"bang": true
}
}
}
],
"directives": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"alternatives": {
"default": {
"throws": "Indentation required. (3:2)"
},
"noEnforcedSubscriptIndentation": {
"allPlugins": true,
"excludePlugins": ["enforceSubscriptIndentation"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a
~b()
Loading

0 comments on commit 5aa3ee5

Please sign in to comment.