Skip to content

Commit 22fa5bb

Browse files
committed
Remove unneeded block type from stack
1 parent 7108452 commit 22fa5bb

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

src/plugins/lightscript.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -369,18 +369,6 @@ pp.parseNamedArrowFromCallExpression = function (node, call) {
369369
return this.finishNode(node, isMember ? "NamedArrowMemberExpression" : "NamedArrowExpression");
370370
};
371371

372-
pp.pushBlockState = function (blockType, indentLevel) {
373-
this.state.blockStack.push({ blockType, indentLevel });
374-
};
375-
376-
pp.matchBlockState = function(blockType, indentLevel) {
377-
return this.state.blockStack.some( (x) => x.blockType === blockType && x.indentLevel === indentLevel );
378-
};
379-
380-
pp.popBlockState = function() {
381-
this.state.blockStack.pop();
382-
};
383-
384372
// c/p parseIfStatement
385373

386374
pp.parseIf = function (node, isExpression) {
@@ -389,7 +377,7 @@ pp.parseIf = function (node, isExpression) {
389377
node.test = this.parseParenExpression();
390378

391379
const isColon = this.match(tt.colon);
392-
if (isColon) this.pushBlockState("if", indentLevel);
380+
if (isColon) this.state.ifWhiteBlockStack.push(indentLevel);
393381

394382
if (isExpression) {
395383
if (this.match(tt.braceL)) {
@@ -405,7 +393,7 @@ pp.parseIf = function (node, isExpression) {
405393

406394
node.alternate = this.parseIfAlternate(node, isExpression, isColon, indentLevel);
407395

408-
if (isColon) this.popBlockState();
396+
if (isColon) this.state.ifWhiteBlockStack.pop();
409397

410398
return this.finishNode(node, isExpression ? "IfExpression" : "IfStatement");
411399
};
@@ -417,11 +405,9 @@ pp.parseIfAlternate = function (node, isExpression, ifIsWhiteBlock, ifIndentLeve
417405
// it matches with a whiteblock `if` higher on the stack, then this alternate
418406
// clause does not match the current `if` -- so unwind the recursive descent.
419407
const alternateIndentLevel = this.state.indentLevel;
420-
if (
421-
(alternateIndentLevel !== ifIndentLevel) &&
422-
(ifIsWhiteBlock || this.matchBlockState("if", alternateIndentLevel))
423-
) {
424-
return null;
408+
if (alternateIndentLevel !== ifIndentLevel) {
409+
if (ifIsWhiteBlock) return null;
410+
if (this.state.ifWhiteBlockStack.some(x => x === alternateIndentLevel)) return null;
425411
}
426412

427413
if (this.match(tt._elif)) {

src/tokenizer/state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class State {
3333
this.leadingComments = [];
3434
this.commentStack = [];
3535

36-
this.blockStack = [];
36+
this.ifWhiteBlockStack = [];
3737

3838
this.pos = this.lineStart = 0;
3939
this.curLine = options.startLine;

0 commit comments

Comments
 (0)