Skip to content

Commit

Permalink
New WBP fixes
Browse files Browse the repository at this point in the history
commit d4184a6
Author: William C. Johnson <wcjohnson@oigroup.net>
Date:   Sat Sep 30 21:39:47 2017 -0400

    `whiteblockPreferred` updates

commit 5e45d5e
Author: William C. Johnson <wcjohnson@oigroup.net>
Date:   Sat Sep 30 18:13:56 2017 -0400

    Lightscript OBA fixup

commit 1aded08
Author: William C. Johnson <wcjohnson@oigroup.net>
Date:   Sat Sep 30 17:39:12 2017 -0400

    Whiteblock-preferred, step 1
  • Loading branch information
wcjohnson committed Oct 1, 2017
1 parent 0e97a7b commit eea37ea
Show file tree
Hide file tree
Showing 37 changed files with 1,132 additions and 83 deletions.
40 changes: 36 additions & 4 deletions src/parser/statement.js
Expand Up @@ -60,6 +60,11 @@ pp.parseStatement = function (declaration, topLevel) {

const starttype = this.state.type;
const node = this.startNode();
let expr = null;
let objParseError = null;

const isBlock = this.state.nextBraceIsBlock;
if (this.state.nextBraceIsBlock !== undefined) delete this.state.nextBraceIsBlock;

// Most types of statements are recognized by the keyword they
// start with. Many are trivial to parse, some require a bit of
Expand Down Expand Up @@ -94,10 +99,32 @@ pp.parseStatement = function (declaration, topLevel) {
case tt._while: return this.parseWhileStatement(node);
case tt._with: return this.parseWithStatement(node);
case tt.braceL:
// in lightscript, allow line-starting `{` to be parsed as obj or obj pattern
if (this.hasPlugin("lightscript") && this.isLineBreak()) {
if (this.hasPlugin("whiteblockOnly")) {
// whiteblockOnly = what follows must be an ObjectExpression/Pattern
break;
} else if (this.hasPlugin("whiteblockOnly")) {
} else if (this.hasPlugin("whiteblockPreferred") && !isBlock) {
// whiteblockPreferred = try to parse as obj, otherwise rewind and parse as block
const state = this.state.clone();
try {
expr = this.parseExpression();
break;
} catch (err) {
this.state = state;
objParseError = err;
}

try {
return this.parseBlock();
} catch (err) {
if (objParseError && objParseError.pos >= err.pos) {
throw objParseError;
} else {
throw err;
}
}
} else if (this.hasPlugin("lightscript") && this.isLineBreak() && !isBlock) {
// legacy lsc behavior
// allow line-starting `{` to be parsed as obj or obj pattern
break;
} else {
return this.parseBlock();
Expand Down Expand Up @@ -141,7 +168,7 @@ pp.parseStatement = function (declaration, topLevel) {
// next token is a colon and the expression was a simple
// Identifier node, we switch to interpreting it as a label.
const maybeName = this.state.value;
const expr = this.parseExpression();
if (!expr) expr = this.parseExpression();

// rewrite `x = val` and `x: type = val`
if (this.hasPlugin("lightscript") && this.isColonConstAssign(expr)) {
Expand Down Expand Up @@ -238,6 +265,8 @@ pp.parseDoStatement = function (node) {
isWhiteBlock = true;
indentLevel = this.state.indentLevel;
}

this.state.nextBraceIsBlock = true;
node.body = this.parseStatement(false);
this.state.labels.pop();
if (this.hasPlugin("lightscript") && isWhiteBlock && this.state.indentLevel !== indentLevel) {
Expand Down Expand Up @@ -530,6 +559,7 @@ pp.parseWhileStatement = function (node) {
this.next();
node.test = this.parseParenExpression();
this.state.labels.push(loopLabel);
this.state.nextBraceIsBlock = true;
node.body = this.parseStatement(false);
this.state.labels.pop();
return this.finishNode(node, "WhileStatement");
Expand Down Expand Up @@ -673,6 +703,7 @@ pp.parseFor = function (node, init) {
this.expect(tt.parenR);
}

this.state.nextBraceIsBlock = true;
node.body = this.parseStatement(false);
this.state.labels.pop();
return this.finishNode(node, "ForStatement");
Expand All @@ -699,6 +730,7 @@ pp.parseForIn = function (node, init, forAwait) {
this.expect(tt.parenR);
}

this.state.nextBraceIsBlock = true;
node.body = this.parseStatement(false);
this.state.labels.pop();
return this.finishNode(node, type);
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/lightscript.js
Expand Up @@ -96,6 +96,7 @@ pp.parseEnhancedForIn = function (node) {
const iterable = this.parseMaybeAssign(true);

this.expectParenFreeBlockStart(node);
this.state.nextBraceIsBlock = true;
node.body = this.parseStatement(false);

if ((matchingIterationType === "idx") || (matchingIterationType === "elem")) {
Expand Down Expand Up @@ -460,6 +461,7 @@ pp.parseIf = function (node, isExpression, requireColon = null) {
this.state.inFunction = oldInFunction;
this.state.labels = oldLabels;
} else {
this.state.nextBraceIsBlock = true;
node.consequent = this.parseStatement(false);
}

Expand Down Expand Up @@ -510,6 +512,7 @@ pp.parseIfAlternate = function (node, isExpression, ifIsWhiteBlock, ifIndentLeve
}
}

this.state.nextBraceIsBlock = true;
return this.parseStatement(false);
}

Expand Down Expand Up @@ -689,6 +692,7 @@ export default function (instance) {
instance.extend("parseStatement", function (inner) {
return function () {
if (this.match(tt.colon)) {
delete this.state.nextBraceIsBlock;
return this.parseWhiteBlock();
}
return inner.apply(this, arguments);
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/core/uncategorised/214/options.lightscript.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/core/uncategorised/235/options.lightscript.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/core/uncategorised/300/options.lightscript.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/core/uncategorised/301/options.lightscript.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/core/uncategorised/303/options.lightscript.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/core/uncategorised/313/options.lightscript.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/core/uncategorised/314/options.lightscript.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/core/uncategorised/315/options.lightscript.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/core/uncategorised/332/options.lightscript.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/core/uncategorised/336/options.lightscript.json

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,3 +1,3 @@
{
"throws": "Unexpected token, expected , (1:5)"
"throws": "Unexpected token, expected ; (1:23)"
}

0 comments on commit eea37ea

Please sign in to comment.