Skip to content

Commit

Permalink
refactor: avoid constref node
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Nov 2, 2018
1 parent e9a186f commit bdb8236
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 46 deletions.
2 changes: 0 additions & 2 deletions src/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const Position = require("./ast/position");
* - [Array](#array)
* - [Variable](#variable)
* - [Variadic](#variadic)
* - [ConstRef](#constref)
* - [Yield](#yield)
* - [YieldFrom](#yieldfrom)
* - [Lookup](#lookup)
Expand Down Expand Up @@ -358,7 +357,6 @@ AST.prototype.prepare = function(kind, docs, parser) {
require("./ast/commentblock"),
require("./ast/commentline"),
require("./ast/constant"),
require("./ast/constref"),
require("./ast/continue"),
require("./ast/declaration"),
require("./ast/declare"),
Expand Down
24 changes: 0 additions & 24 deletions src/ast/constref.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/parser/scalar.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ module.exports = {
this.expect("]") && this.next();
name = node(name, offset);
} else {
name = this.node("constref")(varName);
name = varName;
}
} else {
name = this.read_expr();
Expand Down Expand Up @@ -244,7 +244,7 @@ module.exports = {
if (this.token === this.tok.T_OBJECT_OPERATOR) {
node = this.node("propertylookup");
this.next().expect(this.tok.T_STRING);
const what = this.node("constref");
const what = this.node("identifier");
name = this.text();
this.next();
result = node(result, what(name));
Expand Down
335 changes: 335 additions & 0 deletions test/snapshot/__snapshots__/encapsed.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`encapsed offsetlookup (simple syntax) 1`] = `
Program {
"children": Array [
Echo {
"expressions": Array [
Encapsed {
"kind": "encapsed",
"raw": "\\"string $array[0] string\\"",
"type": "string",
"value": Array [
String {
"isDoubleQuote": false,
"kind": "string",
"raw": "string ",
"unicode": false,
"value": "string ",
},
OffsetLookup {
"kind": "offsetlookup",
"offset": Number {
"kind": "number",
"value": "0",
},
"what": Variable {
"byref": false,
"curly": false,
"kind": "variable",
"name": "array",
},
},
String {
"isDoubleQuote": false,
"kind": "string",
"raw": " string",
"unicode": false,
"value": " string",
},
],
},
],
"kind": "echo",
"shortForm": false,
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`encapsed offsetlookup (simple syntax) 2`] = `
Program {
"children": Array [
Echo {
"expressions": Array [
Encapsed {
"kind": "encapsed",
"raw": "\\"string $array[koolaid1] string\\"",
"type": "string",
"value": Array [
String {
"isDoubleQuote": false,
"kind": "string",
"raw": "string ",
"unicode": false,
"value": "string ",
},
OffsetLookup {
"kind": "offsetlookup",
"offset": Identifier {
"kind": "identifier",
"name": "koolaid1",
},
"what": Variable {
"byref": false,
"curly": false,
"kind": "variable",
"name": "array",
},
},
String {
"isDoubleQuote": false,
"kind": "string",
"raw": " string",
"unicode": false,
"value": " string",
},
],
},
],
"kind": "echo",
"shortForm": false,
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`encapsed propertylookup (simple syntax) 1`] = `
Program {
"children": Array [
Echo {
"expressions": Array [
Encapsed {
"kind": "encapsed",
"raw": "\\"string $obj->property string\\"",
"type": "string",
"value": Array [
String {
"isDoubleQuote": false,
"kind": "string",
"raw": "string ",
"unicode": false,
"value": "string ",
},
PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "property",
},
"what": Variable {
"byref": false,
"curly": false,
"kind": "variable",
"name": "obj",
},
},
String {
"isDoubleQuote": false,
"kind": "string",
"raw": " string",
"unicode": false,
"value": " string",
},
],
},
],
"kind": "echo",
"shortForm": false,
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`encapsed two variable (simple syntax) 1`] = `
Program {
"children": Array [
Echo {
"expressions": Array [
Encapsed {
"kind": "encapsed",
"raw": "\\"string $var->$var string\\"",
"type": "string",
"value": Array [
String {
"isDoubleQuote": false,
"kind": "string",
"raw": "string ",
"unicode": false,
"value": "string ",
},
Variable {
"byref": false,
"curly": false,
"kind": "variable",
"name": "var",
},
String {
"isDoubleQuote": false,
"kind": "string",
"raw": "->",
"unicode": false,
"value": "->",
},
Variable {
"byref": false,
"curly": false,
"kind": "variable",
"name": "var",
},
String {
"isDoubleQuote": false,
"kind": "string",
"raw": " string",
"unicode": false,
"value": " string",
},
],
},
],
"kind": "echo",
"shortForm": false,
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`encapsed variable (simple syntax) 1`] = `
Program {
"children": Array [
Echo {
"expressions": Array [
Encapsed {
"kind": "encapsed",
"raw": "\\"string \${var} string\\"",
"type": "string",
"value": Array [
String {
"isDoubleQuote": false,
"kind": "string",
"raw": "string ",
"unicode": false,
"value": "string ",
},
Variable {
"byref": false,
"curly": true,
"kind": "variable",
"name": Identifier {
"kind": "identifier",
"name": "var",
},
},
String {
"isDoubleQuote": false,
"kind": "string",
"raw": " string",
"unicode": false,
"value": " string",
},
],
},
],
"kind": "echo",
"shortForm": false,
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`encapsed variable (simple syntax) 2`] = `
Program {
"children": Array [
Echo {
"expressions": Array [
Encapsed {
"kind": "encapsed",
"raw": "\\"string \${var} string\\"",
"type": "string",
"value": Array [
String {
"isDoubleQuote": false,
"kind": "string",
"raw": "string ",
"unicode": false,
"value": "string ",
},
Variable {
"byref": false,
"curly": true,
"kind": "variable",
"name": Identifier {
"kind": "identifier",
"name": "var",
},
},
String {
"isDoubleQuote": false,
"kind": "string",
"raw": " string",
"unicode": false,
"value": " string",
},
],
},
],
"kind": "echo",
"shortForm": false,
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`encapsed variable curly (simple syntax) 1`] = `
Program {
"children": Array [
Echo {
"arguments": Array [
Encapsed {
"kind": "encapsed",
"raw": "\\"string \${var} string\\"",
"type": "string",
"value": Array [
String {
"isDoubleQuote": false,
"kind": "string",
"raw": "string ",
"unicode": false,
"value": "string ",
},
Variable {
"byref": false,
"curly": true,
"kind": "variable",
"name": "var",
},
String {
"isDoubleQuote": false,
"kind": "string",
"raw": " string",
"unicode": false,
"value": " string",
},
],
},
],
"kind": "echo",
"shortForm": false,
},
],
"errors": Array [],
"kind": "program",
}
`;
Loading

0 comments on commit bdb8236

Please sign in to comment.