Skip to content

Commit 2bdd42d

Browse files
committed
Revert changes adding exprContext to parsing functions
1 parent 70ea722 commit 2bdd42d

File tree

16 files changed

+102
-483
lines changed

16 files changed

+102
-483
lines changed

src/parser/statement.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pp.stmtToDirective = function (stmt) {
5353
// `if (foo) /blah/.exec(foo)`, where looking at the previous token
5454
// does not help.
5555

56-
pp.parseStatement = function (declaration, topLevel, isExprContext) {
56+
pp.parseStatement = function (declaration, topLevel) {
5757
if (this.match(tt.at)) {
5858
this.parseDecorators(true);
5959
}
@@ -66,12 +66,7 @@ pp.parseStatement = function (declaration, topLevel, isExprContext) {
6666
// complexity.
6767

6868
switch (starttype) {
69-
case tt._break:
70-
if (this.hasPlugin("lightscript") && isExprContext) this.unexpected(null, "break is illegal inside LightScript expressions");
71-
case tt._continue:
72-
if (this.hasPlugin("lightscript") && isExprContext) this.unexpected(null, "continue is illegal inside LightScript expressions");
73-
return this.parseBreakContinueStatement(node, starttype.keyword);
74-
69+
case tt._break: case tt._continue: return this.parseBreakContinueStatement(node, starttype.keyword);
7570
case tt._debugger: return this.parseDebuggerStatement(node);
7671
case tt._do: return this.parseDoStatement(node);
7772
case tt._for: return this.parseForStatement(node);
@@ -84,11 +79,7 @@ pp.parseStatement = function (declaration, topLevel, isExprContext) {
8479
return this.parseClass(node, true);
8580

8681
case tt._if: return this.parseIfStatement(node);
87-
88-
case tt._return:
89-
if (this.hasPlugin("lightscript") && isExprContext) this.unexpected(null, "return is illegal inside LightScript expressions");
90-
return this.parseReturnStatement(node);
91-
82+
case tt._return: return this.parseReturnStatement(node);
9283
case tt._switch: return this.parseSwitchStatement(node);
9384
case tt._throw: return this.parseThrowStatement(node);
9485
case tt._try: return this.parseTryStatement(node);
@@ -573,10 +564,10 @@ pp.parseExpressionStatement = function (node, expr) {
573564
// strict"` declarations when `allowStrict` is true (used for
574565
// function bodies).
575566

576-
pp.parseBlock = function (allowDirectives?, isExprContext?) {
567+
pp.parseBlock = function (allowDirectives?) {
577568
const node = this.startNode();
578569
this.expect(tt.braceL);
579-
this.parseBlockBody(node, allowDirectives, false, tt.braceR, isExprContext);
570+
this.parseBlockBody(node, allowDirectives, false, tt.braceR);
580571
return this.finishNode(node, "BlockStatement");
581572
};
582573

@@ -586,7 +577,7 @@ pp.isValidDirective = function (stmt) {
586577
!stmt.expression.extra.parenthesized;
587578
};
588579

589-
pp.parseBlockBody = function (node, allowDirectives, topLevel, end, isExprContext) {
580+
pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {
590581
node.body = [];
591582
node.directives = [];
592583

@@ -606,7 +597,7 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end, isExprContex
606597
octalPosition = this.state.octalPosition;
607598
}
608599

609-
const stmt = this.parseStatement(true, topLevel, isExprContext);
600+
const stmt = this.parseStatement(true, topLevel);
610601

611602
if (allowDirectives && !parsedNonDirective && this.isValidDirective(stmt)) {
612603
const directive = this.stmtToDirective(stmt);

src/plugins/flow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,14 +880,14 @@ export default function (instance) {
880880

881881
// interfaces
882882
instance.extend("parseStatement", function (inner) {
883-
return function (declaration, topLevel, isExprContext) {
883+
return function (declaration, topLevel) {
884884
// strict mode handling of `interface` since it's a reserved word
885885
if (this.state.strict && this.match(tt.name) && this.state.value === "interface") {
886886
const node = this.startNode();
887887
this.next();
888888
return this.flowParseInterface(node);
889889
} else {
890-
return inner.call(this, declaration, topLevel, isExprContext);
890+
return inner.call(this, declaration, topLevel);
891891
}
892892
};
893893
});

src/plugins/lightscript.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,35 +178,35 @@ pp.finishWhiteBlock = function(node, allowEmptyBody) {
178178
return this.finishNode(node, "BlockStatement");
179179
};
180180

181-
pp.parseInlineWhiteBlock = function(node, isExprContext, allowEmptyBody) {
181+
pp.parseInlineWhiteBlock = function(node, allowEmptyBody) {
182182
if (this.state.type.startsExpr) return this.parseMaybeAssign();
183183
// oneline statement case
184-
node.body = this.couldBeginStatement() ? [this.parseStatement(true, false, isExprContext)] : [];
184+
node.body = this.couldBeginStatement() ? [this.parseStatement(true)] : [];
185185
node.directives = [];
186186
return this.finishWhiteBlock(node, allowEmptyBody);
187187
};
188188

189-
pp.parseMultilineWhiteBlock = function(node, indentLevel, isExprContext, allowEmptyBody) {
190-
this.parseBlockBody(node, false, false, indentLevel, isExprContext);
189+
pp.parseMultilineWhiteBlock = function(node, indentLevel, allowEmptyBody) {
190+
this.parseBlockBody(node, false, false, indentLevel);
191191
return this.finishWhiteBlock(node, allowEmptyBody);
192192
};
193193

194-
pp.parseWhiteBlock = function (isExprContext?) {
194+
pp.parseWhiteBlock = function (isExpression?) {
195195
const node = this.startNode(), indentLevel = this.state.indentLevel;
196196

197197
if (!this.eat(tt.colon)) this.unexpected(null, "Whitespace Block must start with a colon or arrow");
198198

199199
// Oneline whiteblock
200200
if (!this.isLineBreak()) {
201-
if (isExprContext) {
202-
return this.parseInlineWhiteBlock(node, true, false);
201+
if (isExpression) {
202+
return this.parseInlineWhiteBlock(node, false);
203203
} else {
204-
return this.parseStatement(false, false, false);
204+
return this.parseStatement(false);
205205
}
206206
}
207207

208208
// TODO: document the fact that directives aren't parsed
209-
return this.parseMultilineWhiteBlock(node, indentLevel, isExprContext, false);
209+
return this.parseMultilineWhiteBlock(node, indentLevel, false);
210210
};
211211

212212
pp.expectCommaOrLineBreak = function () {
@@ -352,10 +352,10 @@ pp.parseArrowFunctionBody = function (node) {
352352
this.addExtra(node.body, "curly", true);
353353
node.body = this.finishNode(node.body, "BlockStatement");
354354
} else {
355-
node.body = this.parseInlineWhiteBlock(node.body, false, true);
355+
node.body = this.parseInlineWhiteBlock(node.body, true);
356356
}
357357
} else {
358-
node.body = this.parseMultilineWhiteBlock(node.body, indentLevel, false, true);
358+
node.body = this.parseMultilineWhiteBlock(node.body, indentLevel, true);
359359
}
360360

361361
if (node.body.type !== "BlockStatement") {
@@ -427,7 +427,7 @@ pp.parseIf = function (node, isExpression) {
427427

428428
if (isExpression) {
429429
if (this.match(tt.braceL)) {
430-
node.consequent = this.parseBlock(false, true);
430+
node.consequent = this.parseBlock(false);
431431
} else if (!isColon) {
432432
node.consequent = this.parseMaybeAssign();
433433
} else {
@@ -476,7 +476,7 @@ pp.parseIfAlternate = function (node, isExpression, ifIsWhiteBlock, ifIndentLeve
476476

477477
if (isExpression) {
478478
if (this.match(tt.braceL)) {
479-
return this.parseBlock(false, true);
479+
return this.parseBlock(false);
480480
} else if (!this.match(tt.colon)) {
481481
return this.parseMaybeAssign();
482482
} else {
@@ -835,9 +835,9 @@ export default function (instance) {
835835
// whitespace following a colon
836836

837837
instance.extend("parseBlock", function (inner) {
838-
return function (allowDirectives, isExprContext) {
838+
return function () {
839839
if (this.match(tt.colon)) {
840-
return this.parseWhiteBlock(isExprContext);
840+
return this.parseWhiteBlock();
841841
}
842842
const block = inner.apply(this, arguments);
843843
this.addExtra(block, "curly", true);

test/fixtures/lightscript/if-expression/illegal-break/actual.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixtures/lightscript/if-expression/illegal-break/options.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixtures/lightscript/if-expression/illegal-continue/actual.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixtures/lightscript/if-expression/illegal-continue/options.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixtures/lightscript/if-expression/illegal-return/actual.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/fixtures/lightscript/if-expression/illegal-return/options.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixtures/lightscript/if-expression/nested-break/actual.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)