Skip to content

Commit

Permalink
Disallow subscripting from crossing whiteblock boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Oct 6, 2017
1 parent d447c02 commit 87afe91
Show file tree
Hide file tree
Showing 5 changed files with 392 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/parser/expression.js
Expand Up @@ -386,7 +386,9 @@ pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {
this.state.noPipeSubscripts = false;

for (;;) {
if (this.hasPlugin("bangCall") && this.shouldUnwindBangSubscript()) {
if (this.hasPlugin("lightscript") && this.crossesWhiteBlockBoundary()) {
return base;
} else if (this.hasPlugin("bangCall") && this.shouldUnwindBangSubscript()) {
return base;
} else if (!noCalls && this.eat(tt.doubleColon)) {
const node = this.startNodeAt(startPos, startLoc);
Expand Down
8 changes: 8 additions & 0 deletions src/parser/statement.js
Expand Up @@ -661,10 +661,14 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {
let oldStrict;
let octalPosition;

const oldInWhiteBlock = this.state.inWhiteBlock;
const oldWhiteBlockIndentLevel = this.state.whiteBlockIndentLevel;
this.state.nestedBlockLevel++;

let isEnd;
if (this.hasPlugin("lightscript") && typeof end === "number") {
this.state.inWhiteBlock = true;
this.state.whiteBlockIndentLevel = end;
isEnd = () => this.state.indentLevel <= end || this.match(tt.eof);
} else {
isEnd = () => this.eat(end);
Expand Down Expand Up @@ -698,6 +702,10 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {
}

this.state.nestedBlockLevel--;
if (this.hasPlugin("lightscript")) {
this.state.inWhiteBlock = oldInWhiteBlock;
this.state.whiteBlockIndentLevel = oldWhiteBlockIndentLevel;
}

if (oldStrict === false) {
this.setStrict(false);
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/lightscript.js
Expand Up @@ -177,6 +177,10 @@ pp.parseWhiteBlock = function (isExpression?) {
return this.parseMultilineWhiteBlock(node, indentLevel);
};

pp.crossesWhiteBlockBoundary = function() {
return (this.state.inWhiteBlock && this.state.indentLevel <= this.state.whiteBlockIndentLevel);
};

pp.expectCommaOrLineBreak = function (loc = null) {
// TODO: consider error message like "Missing comma or newline."
if (!(this.eat(tt.comma) || this.isLineBreak())) this.unexpected(loc, tt.comma);
Expand Down
@@ -0,0 +1,5 @@
a()
.then! b ->
c
.catch! d ->
e

0 comments on commit 87afe91

Please sign in to comment.