Skip to content

Commit d804784

Browse files
test: heredoc and nowdoc
1 parent 6e63a00 commit d804784

File tree

10 files changed

+1043
-36
lines changed

10 files changed

+1043
-36
lines changed

src/ast.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,15 @@ AST.prototype.resolvePrecedence = function(result, parser) {
323323
result = buffer;
324324
}
325325
}
326-
} else if (
327-
result.kind === "silent" &&
328-
!result.expr.parenthesizedExpression
329-
) {
330-
if (result.expr.kind === 'assign') return result;
326+
} else if (result.kind === "silent" && !result.expr.parenthesizedExpression) {
327+
if (result.expr.kind === "assign") return result;
331328
// overall least precedence
332329
if (result.expr.right) {
333330
buffer = result.expr;
334331
result.expr = buffer.left;
335332
buffer.left = result;
336333
this.swapLocations(buffer, buffer.left, buffer.right, parser);
337-
result = buffer;
334+
result = buffer;
338335
}
339336
}
340337
return result;

src/parser/scalar.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ module.exports = {
9696
value = value.substring(0, value.length - 1);
9797
}
9898
this.expect(this.tok.T_ENCAPSED_AND_WHITESPACE) && this.next();
99+
this.expect(this.tok.T_END_HEREDOC) && this.next();
99100
const raw = this.lexer._input.substring(
100101
start,
101-
this.lexer.yylloc.last_offset
102+
this.lexer.yylloc.first_offset
102103
);
103-
this.expect(this.tok.T_END_HEREDOC) && this.next();
104104
node = node(
105105
value,
106106
raw,
@@ -266,6 +266,7 @@ module.exports = {
266266
* Reads an encapsed string
267267
*/
268268
read_encapsed_string: function(expect, isBinary = false) {
269+
const labelStart = this.lexer.yylloc.first_offset;
269270
let node = this.node("encapsed");
270271
this.next();
271272
const start = this.lexer.yylloc.prev_offset - (isBinary ? 1 : 0);
@@ -284,13 +285,12 @@ module.exports = {
284285
while (this.token !== expect && this.token !== this.EOF) {
285286
value.push(this.read_encapsed_string_item(true));
286287
}
287-
288288
this.expect(expect) && this.next();
289-
node = node(
290-
value,
291-
this.lexer._input.substring(start - 1, this.lexer.yylloc.first_offset),
292-
type
289+
const raw = this.lexer._input.substring(
290+
type === "heredoc" ? labelStart : start - 1,
291+
this.lexer.yylloc.first_offset
293292
);
293+
node = node(value, raw, type);
294294

295295
if (expect === this.tok.T_END_HEREDOC) {
296296
node.label = this.lexer.heredoc_label;

test/snapshot/__snapshots__/acid.test.js.snap

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7437,7 +7437,7 @@ BAZ",
74377437
},
74387438
},
74397439
"parenthesizedExpression": true,
7440-
"raw": "
7440+
"raw": "<<<BAZ
74417441
Hello world
74427442
BAZ
74437443
",
@@ -7565,15 +7565,6 @@ BAR",
75657565
"raw": "<<<'BAR'
75667566
$foo + $bar
75677567
BAR
7568-
));
7569-
eval(<<<FOO
7570-
return 'This is madness!';
7571-
FOO
7572-
);
7573-
7574-
}
7575-
__halt_compiler();
7576-
THE END ...
75777568
",
75787569
"value": " $foo + $bar",
75797570
},
@@ -7671,7 +7662,7 @@ FOO",
76717662
"offset": 3127,
76727663
},
76737664
},
7674-
"raw": "
7665+
"raw": "<<<FOO
76757666
return 'This is madness!';
76767667
FOO
76777668
",

0 commit comments

Comments
 (0)