Skip to content

Commit c9c6c81

Browse files
committed
glayzzle#127 - fix lexer initial state on eval
1 parent da39c64 commit c9c6c81

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

dist/php-parser.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! php-parser - BSD3 License - 2018-03-05 */
1+
/*! php-parser - BSD3 License - 2018-03-06 */
22

33
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
44
/*!
@@ -3198,11 +3198,12 @@ lexer.prototype.setInput = function (input) {
31983198
last_column: 0
31993199
};
32003200
this.tokens = [];
3201-
this.conditionStack = [];
32023201
this.done = this.offset >= this.size;
32033202
if (!this.all_tokens && this.mode_eval) {
3203+
this.conditionStack = ['INITIAL'];
32043204
this.begin("ST_IN_SCRIPTING");
32053205
} else {
3206+
this.conditionStack = [];
32063207
this.begin("INITIAL");
32073208
}
32083209
return this;

dist/php-parser.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/php-parser.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,12 @@ lexer.prototype.setInput = function(input) {
143143
last_column: 0
144144
};
145145
this.tokens = [];
146-
this.conditionStack = [];
147146
this.done = this.offset >= this.size;
148147
if (!this.all_tokens && this.mode_eval) {
148+
this.conditionStack = ['INITIAL'];
149149
this.begin("ST_IN_SCRIPTING");
150150
} else {
151+
this.conditionStack = [];
151152
this.begin("INITIAL");
152153
}
153154
return this;

test/astTests.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
var parser = require("./main");
22

33
describe("Test AST structure", function() {
4+
5+
it('fix #127 - echo statements', function() {
6+
var ast = parser.parseEval('echo "hello"; ?> world');
7+
ast.children.length.should.be.exactly(2);
8+
ast.children[0].kind.should.be.exactly("echo");
9+
ast.children[1].kind.should.be.exactly("inline");
10+
});
11+
12+
it('fix #127 - inline', function() {
13+
var ast = parser.parseEval('?>?>?>');
14+
ast.children.length.should.be.exactly(1);
15+
ast.children[0].kind.should.be.exactly("inline");
16+
ast.children[0].value.should.be.exactly("?>?>");
17+
});
18+
19+
420
it("test program", function() {
521
var ast = parser.parseEval("");
622
ast.kind.should.be.exactly("program");

0 commit comments

Comments
 (0)