Skip to content

Commit 94145ab

Browse files
committed
add the halt compiler node
1 parent 7d47ac9 commit 94145ab

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

docs/AST.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
- [Statement](#statement)
4444
- [Eval](#eval)
4545
- [Exit](#exit)
46+
- [Halt](#halt)
4647
- [Clone](#clone)
4748
- [Declare](#declare)
4849
- [Global](#global)
@@ -597,6 +598,16 @@ Defines goto statement
597598

598599
- `label` **[String](#string)**
599600

601+
# Halt
602+
603+
**Extends Statement**
604+
605+
Halts the compiler execution
606+
607+
**Properties**
608+
609+
- `after` **[String](#string)** String after the halt statement
610+
600611
# Identifier
601612

602613
**Extends Node**

src/ast.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var Position = require('./ast/position');
4949
* - [Statement](#statement)
5050
* - [Eval](#eval)
5151
* - [Exit](#exit)
52+
* - [Halt](#halt)
5253
* - [Clone](#clone)
5354
* - [Declare](#declare)
5455
* - [Global](#global)
@@ -207,6 +208,7 @@ AST.prototype.prepare = function(kind, parser) {
207208
require('./ast/function'),
208209
require('./ast/global'),
209210
require('./ast/goto'),
211+
require('./ast/halt'),
210212
require('./ast/identifier'),
211213
require('./ast/if'),
212214
require('./ast/include'),

src/ast/halt.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*!
2+
* Copyright (C) 2017 Glayzzle (BSD3 License)
3+
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
4+
* @url http://glayzzle.com
5+
*/
6+
"use strict";
7+
8+
var Statement = require('./statement');
9+
var KIND = 'halt';
10+
11+
/**
12+
* Halts the compiler execution
13+
* @constructor Halt
14+
* @extends {Statement}
15+
* @property {String} after - String after the halt statement
16+
* @see http://php.net/manual/en/function.halt-compiler.php
17+
*/
18+
var Halt = Statement.extends(function Halt(after, location) {
19+
Statement.apply(this, [KIND, location]);
20+
this.after = after;
21+
});
22+
23+
module.exports = Halt;

test/statementTests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('Test statements', function() {
1616
ast.children[2].kind.should.be.exactly('goto');
1717
ast.children[2].label.should.be.exactly('start');
1818
});
19+
1920
it('test global', function() {
2021
var ast = parser.parseEval([
2122
'function foo() {',
@@ -32,6 +33,20 @@ describe('Test statements', function() {
3233
expr.items[1].name.should.be.exactly('b');
3334
});
3435

36+
it('test halt statement', function() {
37+
var ast = parser.parseEval([
38+
'$a = 1;',
39+
'__halt_compiler();',
40+
'$b = 1;'
41+
].join('\n'), {
42+
parser: { debug: false }
43+
});
44+
ast.children.length.should.be.exactly(2);
45+
ast.children[0].kind.should.be.exactly('assign');
46+
ast.children[1].kind.should.be.exactly('halt');
47+
ast.children[1].after.should.be.exactly('\n$b = 1;');
48+
});
49+
3550
it('test static', function() {
3651
var ast = parser.parseEval([
3752
'function foo() {',

0 commit comments

Comments
 (0)