Skip to content

Commit

Permalink
Eliminate nested block level tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Oct 6, 2017
1 parent 87afe91 commit cc81f86
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/parser/statement.js
Expand Up @@ -663,7 +663,6 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {

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

let isEnd;
if (this.hasPlugin("lightscript") && typeof end === "number") {
Expand Down Expand Up @@ -701,7 +700,6 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {
node.body.push(stmt);
}

this.state.nestedBlockLevel--;
if (this.hasPlugin("lightscript")) {
this.state.inWhiteBlock = oldInWhiteBlock;
this.state.whiteBlockIndentLevel = oldWhiteBlockIndentLevel;
Expand Down
14 changes: 8 additions & 6 deletions src/plugins/bangCall.js
Expand Up @@ -40,13 +40,15 @@ export default function(parser) {
this.unexpected(null, "Whitespace required between `!` and first argument.");
}

// Read args
let first = true;
// Collect state
const oldBangUnwindLevel = this.state.bangUnwindLevel;
const oldBangBlockLevel = this.state.bangBlockLevel;
this.state.bangBlockLevel = this.state.nestedBlockLevel;
this.state.bangUnwindLevel = bangIndentLevel + 1;

const oldBangWhiteBlockLevel = this.state.bangWhiteBlockLevel;
this.state.bangWhiteBlockLevel = this.state.whiteBlockIndentLevel;

// Read args
let first = true;
while (true) {
// First argument on a different line from the `!` establishes indent level
if (this.state.curLine !== bangLine && argIndentLevel === null) {
Expand Down Expand Up @@ -83,7 +85,7 @@ export default function(parser) {
}

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

node = this.finishNode(node, nodeType);

Expand All @@ -97,7 +99,7 @@ export default function(parser) {
// Subscripts to a bang call must appear at the arg indent level
pp.shouldUnwindBangSubscript = function() {
return this.isLineBreak() &&
(this.state.bangBlockLevel == this.state.nestedBlockLevel) &&
(this.state.bangWhiteBlockLevel === this.state.whiteBlockIndentLevel) &&
(this.state.indentLevel <= this.state.bangUnwindLevel);
};
}
4 changes: 0 additions & 4 deletions src/plugins/lightscript.js
Expand Up @@ -140,9 +140,7 @@ pp.parseObjectComprehension = function(node) {
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 @@ -167,9 +165,7 @@ pp.parseWhiteBlock = function (isExpression?) {
return this.parseInlineWhiteBlock(node);
}

this.state.nestedBlockLevel++;
const stmt = this.parseStatement(false);
this.state.nestedBlockLevel--;
return stmt;
}

Expand Down
1 change: 0 additions & 1 deletion src/tokenizer/state.js
Expand Up @@ -40,7 +40,6 @@ export default class State {

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

this.type = tt.eof;
Expand Down

0 comments on commit cc81f86

Please sign in to comment.