Rename AST objects to match type names
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import Exception from "../exception";
|
||||
|
||||
var AST = {
|
||||
ProgramNode: function(statements, blockParams, strip, locInfo) {
|
||||
Program: function(statements, blockParams, strip, locInfo) {
|
||||
this.loc = locInfo;
|
||||
this.type = 'Program';
|
||||
this.body = statements;
|
||||
@@ -10,7 +10,7 @@ var AST = {
|
||||
this.strip = strip;
|
||||
},
|
||||
|
||||
MustacheNode: function(rawParams, open, strip, locInfo) {
|
||||
MustacheStatement: function(rawParams, open, strip, locInfo) {
|
||||
this.loc = locInfo;
|
||||
this.type = 'MustacheStatement';
|
||||
|
||||
@@ -28,7 +28,7 @@ var AST = {
|
||||
this.strip = strip;
|
||||
},
|
||||
|
||||
BlockNode: function(sexpr, program, inverse, strip, locInfo) {
|
||||
BlockStatement: function(sexpr, program, inverse, strip, locInfo) {
|
||||
this.loc = locInfo;
|
||||
|
||||
this.type = 'BlockStatement';
|
||||
@@ -38,7 +38,7 @@ var AST = {
|
||||
this.strip = strip;
|
||||
},
|
||||
|
||||
PartialNode: function(sexpr, strip, locInfo) {
|
||||
PartialStatement: function(sexpr, strip, locInfo) {
|
||||
this.loc = locInfo;
|
||||
this.type = 'PartialStatement';
|
||||
this.sexpr = sexpr;
|
||||
@@ -48,13 +48,13 @@ var AST = {
|
||||
this.strip.inlineStandalone = true;
|
||||
},
|
||||
|
||||
ContentNode: function(string, locInfo) {
|
||||
ContentStatement: function(string, locInfo) {
|
||||
this.loc = locInfo;
|
||||
this.type = 'ContentStatement';
|
||||
this.original = this.value = string;
|
||||
},
|
||||
|
||||
CommentNode: function(comment, strip, locInfo) {
|
||||
CommentStatement: function(comment, strip, locInfo) {
|
||||
this.loc = locInfo;
|
||||
this.type = 'CommentStatement';
|
||||
this.value = comment;
|
||||
@@ -63,7 +63,7 @@ var AST = {
|
||||
strip.inlineStandalone = true;
|
||||
},
|
||||
|
||||
SexprNode: function(rawParams, hash, locInfo) {
|
||||
SubExpression: function(rawParams, hash, locInfo) {
|
||||
this.loc = locInfo;
|
||||
|
||||
this.type = 'SubExpression';
|
||||
@@ -72,7 +72,7 @@ var AST = {
|
||||
this.hash = hash;
|
||||
},
|
||||
|
||||
PathNode: function(data, parts, locInfo) {
|
||||
PathExpression: function(data, parts, locInfo) {
|
||||
this.loc = locInfo;
|
||||
this.type = 'PathExpression';
|
||||
|
||||
@@ -103,27 +103,27 @@ var AST = {
|
||||
this.depth = depth;
|
||||
},
|
||||
|
||||
StringNode: function(string, locInfo) {
|
||||
StringLiteral: function(string, locInfo) {
|
||||
this.loc = locInfo;
|
||||
this.type = 'StringLiteral';
|
||||
this.original =
|
||||
this.value = string;
|
||||
},
|
||||
|
||||
NumberNode: function(number, locInfo) {
|
||||
NumberLiteral: function(number, locInfo) {
|
||||
this.loc = locInfo;
|
||||
this.type = 'NumberLiteral';
|
||||
this.original =
|
||||
this.value = Number(number);
|
||||
},
|
||||
|
||||
BooleanNode: function(bool, locInfo) {
|
||||
BooleanLiteral: function(bool, locInfo) {
|
||||
this.loc = locInfo;
|
||||
this.type = 'BooleanLiteral';
|
||||
this.value = bool === 'true';
|
||||
},
|
||||
|
||||
HashNode: function(pairs, locInfo) {
|
||||
Hash: function(pairs, locInfo) {
|
||||
this.loc = locInfo;
|
||||
this.type = 'Hash';
|
||||
this.pairs = pairs;
|
||||
|
||||
@@ -32,9 +32,9 @@ export function prepareRawBlock(openRawBlock, content, close, locInfo) {
|
||||
throw new Exception(openRawBlock.sexpr.path.original + " doesn't match " + close, errorNode);
|
||||
}
|
||||
|
||||
var program = new this.ProgramNode([content], null, {}, locInfo);
|
||||
var program = new this.Program([content], null, {}, locInfo);
|
||||
|
||||
return new this.BlockNode(openRawBlock.sexpr, program, undefined, undefined, locInfo);
|
||||
return new this.BlockStatement(openRawBlock.sexpr, program, undefined, undefined, locInfo);
|
||||
}
|
||||
|
||||
export function prepareBlock(openBlock, program, inverseAndProgram, close, inverted, locInfo) {
|
||||
@@ -109,9 +109,9 @@ export function prepareBlock(openBlock, program, inverseAndProgram, close, inver
|
||||
}
|
||||
|
||||
if (inverted) {
|
||||
return new this.BlockNode(openBlock.sexpr, inverse, program, strip, locInfo);
|
||||
return new this.BlockStatement(openBlock.sexpr, inverse, program, strip, locInfo);
|
||||
} else {
|
||||
return new this.BlockNode(openBlock.sexpr, program, inverse, strip, locInfo);
|
||||
return new this.BlockStatement(openBlock.sexpr, program, inverse, strip, locInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+32
-38
@@ -22,16 +22,16 @@ describe('ast', function() {
|
||||
equals(node.loc.end.column, 1);
|
||||
}
|
||||
|
||||
describe('MustacheNode', function() {
|
||||
describe('MustacheStatement', function() {
|
||||
function testEscape(open, expected) {
|
||||
var mustache = new handlebarsEnv.AST.MustacheNode([{}], open, false);
|
||||
var mustache = new handlebarsEnv.AST.MustacheStatement([{}], open, false);
|
||||
equals(mustache.escaped, expected);
|
||||
}
|
||||
|
||||
it('should store args', function() {
|
||||
var id = {isSimple: true},
|
||||
hash = {},
|
||||
mustache = new handlebarsEnv.AST.MustacheNode([id, 'param1'], '', false, LOCATION_INFO);
|
||||
mustache = new handlebarsEnv.AST.MustacheStatement([id, 'param1'], '', false, LOCATION_INFO);
|
||||
equals(mustache.type, 'MustacheStatement');
|
||||
equals(mustache.escaped, true);
|
||||
testLocationInfoStorage(mustache);
|
||||
@@ -61,7 +61,7 @@ describe('ast', function() {
|
||||
testEscape(undefined, false);
|
||||
});
|
||||
});
|
||||
describe('BlockNode', function() {
|
||||
describe('BlockStatement', function() {
|
||||
it('should throw on mustache mismatch', function() {
|
||||
shouldThrow(function() {
|
||||
handlebarsEnv.parse("\n {{#foo}}{{/bar}}");
|
||||
@@ -69,9 +69,9 @@ describe('ast', function() {
|
||||
});
|
||||
|
||||
it('stores location info', function(){
|
||||
var sexprNode = new handlebarsEnv.AST.SexprNode([{ original: 'foo'}], null);
|
||||
var mustacheNode = new handlebarsEnv.AST.MustacheNode(sexprNode, null, '{{', {});
|
||||
var block = new handlebarsEnv.AST.BlockNode(mustacheNode,
|
||||
var sexprNode = new handlebarsEnv.AST.SubExpression([{ original: 'foo'}], null);
|
||||
var mustacheNode = new handlebarsEnv.AST.MustacheStatement(sexprNode, null, '{{', {});
|
||||
var block = new handlebarsEnv.AST.BlockStatement(mustacheNode,
|
||||
{body: [], strip: {}}, {body: [], strip: {}},
|
||||
{
|
||||
strip: {},
|
||||
@@ -81,24 +81,24 @@ describe('ast', function() {
|
||||
testLocationInfoStorage(block);
|
||||
});
|
||||
});
|
||||
describe('PathNode', function() {
|
||||
describe('PathExpression', function() {
|
||||
it('should throw on invalid path', function() {
|
||||
shouldThrow(function() {
|
||||
new handlebarsEnv.AST.PathNode(false, [
|
||||
new handlebarsEnv.AST.PathExpression(false, [
|
||||
{part: 'foo'},
|
||||
{part: '..'},
|
||||
{part: 'bar'}
|
||||
], {start: {line: 1, column: 1}});
|
||||
}, Handlebars.Exception, "Invalid path: foo.. - 1:1");
|
||||
shouldThrow(function() {
|
||||
new handlebarsEnv.AST.PathNode(false, [
|
||||
new handlebarsEnv.AST.PathExpression(false, [
|
||||
{part: 'foo'},
|
||||
{part: '.'},
|
||||
{part: 'bar'}
|
||||
], {start: {line: 1, column: 1}});
|
||||
}, Handlebars.Exception, "Invalid path: foo. - 1:1");
|
||||
shouldThrow(function() {
|
||||
new handlebarsEnv.AST.PathNode(false, [
|
||||
new handlebarsEnv.AST.PathExpression(false, [
|
||||
{part: 'foo'},
|
||||
{part: 'this'},
|
||||
{part: 'bar'}
|
||||
@@ -107,69 +107,63 @@ describe('ast', function() {
|
||||
});
|
||||
|
||||
it('stores location info', function(){
|
||||
var idNode = new handlebarsEnv.AST.PathNode(false, [], LOCATION_INFO);
|
||||
var idNode = new handlebarsEnv.AST.PathExpression(false, [], LOCATION_INFO);
|
||||
testLocationInfoStorage(idNode);
|
||||
});
|
||||
});
|
||||
|
||||
describe("HashNode", function(){
|
||||
|
||||
describe('Hash', function(){
|
||||
it('stores location info', function(){
|
||||
var hash = new handlebarsEnv.AST.HashNode([], LOCATION_INFO);
|
||||
var hash = new handlebarsEnv.AST.Hash([], LOCATION_INFO);
|
||||
testLocationInfoStorage(hash);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ContentNode", function(){
|
||||
|
||||
describe('ContentStatement', function(){
|
||||
it('stores location info', function(){
|
||||
var content = new handlebarsEnv.AST.ContentNode("HI", LOCATION_INFO);
|
||||
var content = new handlebarsEnv.AST.ContentStatement("HI", LOCATION_INFO);
|
||||
testLocationInfoStorage(content);
|
||||
});
|
||||
});
|
||||
|
||||
describe("CommentNode", function(){
|
||||
|
||||
describe('CommentStatement', function(){
|
||||
it('stores location info', function(){
|
||||
var comment = new handlebarsEnv.AST.CommentNode("HI", {}, LOCATION_INFO);
|
||||
var comment = new handlebarsEnv.AST.CommentStatement("HI", {}, LOCATION_INFO);
|
||||
testLocationInfoStorage(comment);
|
||||
});
|
||||
});
|
||||
|
||||
describe("NumberNode", function(){
|
||||
|
||||
describe('NumberLiteral', function(){
|
||||
it('stores location info', function(){
|
||||
var integer = new handlebarsEnv.AST.NumberNode("6", LOCATION_INFO);
|
||||
var integer = new handlebarsEnv.AST.NumberLiteral("6", LOCATION_INFO);
|
||||
testLocationInfoStorage(integer);
|
||||
});
|
||||
});
|
||||
|
||||
describe("StringNode", function(){
|
||||
|
||||
describe('StringLiteral', function(){
|
||||
it('stores location info', function(){
|
||||
var string = new handlebarsEnv.AST.StringNode("6", LOCATION_INFO);
|
||||
var string = new handlebarsEnv.AST.StringLiteral("6", LOCATION_INFO);
|
||||
testLocationInfoStorage(string);
|
||||
});
|
||||
});
|
||||
|
||||
describe("BooleanNode", function(){
|
||||
|
||||
describe('BooleanLiteral', function(){
|
||||
it('stores location info', function(){
|
||||
var bool = new handlebarsEnv.AST.BooleanNode("true", LOCATION_INFO);
|
||||
var bool = new handlebarsEnv.AST.BooleanLiteral("true", LOCATION_INFO);
|
||||
testLocationInfoStorage(bool);
|
||||
});
|
||||
});
|
||||
|
||||
describe("PartialNode", function(){
|
||||
describe('PartialStatement', function(){
|
||||
it('stores location info', function(){
|
||||
var pn = new handlebarsEnv.AST.PartialNode('so_partial', {}, LOCATION_INFO);
|
||||
var pn = new handlebarsEnv.AST.PartialStatement('so_partial', {}, LOCATION_INFO);
|
||||
testLocationInfoStorage(pn);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ProgramNode', function(){
|
||||
describe('Program', function(){
|
||||
it('storing location info', function(){
|
||||
var pn = new handlebarsEnv.AST.ProgramNode([], null, {}, LOCATION_INFO);
|
||||
var pn = new handlebarsEnv.AST.Program([], null, {}, LOCATION_INFO);
|
||||
testLocationInfoStorage(pn);
|
||||
});
|
||||
});
|
||||
@@ -193,7 +187,7 @@ describe('ast', function() {
|
||||
testColumns(contentNode, 1, 1, 0, 7);
|
||||
});
|
||||
|
||||
it('gets MustacheNode line numbers', function(){
|
||||
it('gets MustacheStatement line numbers', function(){
|
||||
var mustacheNode = body[1];
|
||||
testColumns(mustacheNode, 1, 1, 7, 21);
|
||||
});
|
||||
@@ -202,9 +196,9 @@ describe('ast', function() {
|
||||
testColumns(body[2], 1, 2, 21, 8);
|
||||
});
|
||||
|
||||
it('gets MustacheNode line numbers correct across newlines', function(){
|
||||
var secondMustacheNode = body[3];
|
||||
testColumns(secondMustacheNode, 2, 2, 8, 22);
|
||||
it('gets MustacheStatement line numbers correct across newlines', function(){
|
||||
var secondMustacheStatement = body[3];
|
||||
testColumns(secondMustacheStatement, 2, 2, 8, 22);
|
||||
});
|
||||
|
||||
it('gets the block helper information correct', function(){
|
||||
|
||||
+2
-2
@@ -41,7 +41,7 @@ describe('compiler', function() {
|
||||
});
|
||||
|
||||
it('can utilize AST instance', function() {
|
||||
equal(Handlebars.compile(new Handlebars.AST.ProgramNode([ new Handlebars.AST.ContentNode("Hello")], null, {}))(), 'Hello');
|
||||
equal(Handlebars.compile(new Handlebars.AST.Program([ new Handlebars.AST.ContentStatement("Hello")], null, {}))(), 'Hello');
|
||||
});
|
||||
|
||||
it("can pass through an empty string", function() {
|
||||
@@ -60,7 +60,7 @@ describe('compiler', function() {
|
||||
});
|
||||
|
||||
it('can utilize AST instance', function() {
|
||||
equal(/return "Hello"/.test(Handlebars.precompile(new Handlebars.AST.ProgramNode([ new Handlebars.AST.ContentNode("Hello")]), null, {})), true);
|
||||
equal(/return "Hello"/.test(Handlebars.precompile(new Handlebars.AST.Program([ new Handlebars.AST.ContentStatement("Hello")]), null, {})), true);
|
||||
});
|
||||
|
||||
it("can pass through an empty string", function() {
|
||||
|
||||
+1
-1
@@ -203,7 +203,7 @@ describe('parser', function() {
|
||||
|
||||
describe('externally compiled AST', function() {
|
||||
it('can pass through an already-compiled AST', function() {
|
||||
equals(ast_for(new Handlebars.AST.ProgramNode([new Handlebars.AST.ContentNode("Hello")], null)), "CONTENT[ \'Hello\' ]\n");
|
||||
equals(ast_for(new Handlebars.AST.Program([new Handlebars.AST.ContentStatement("Hello")], null)), "CONTENT[ \'Hello\' ]\n");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+18
-18
@@ -9,7 +9,7 @@ root
|
||||
;
|
||||
|
||||
program
|
||||
: statement* -> new yy.ProgramNode(yy.prepareProgram($1), null, {}, yy.locInfo(@$))
|
||||
: statement* -> new yy.Program(yy.prepareProgram($1), null, {}, yy.locInfo(@$))
|
||||
;
|
||||
|
||||
statement
|
||||
@@ -18,11 +18,11 @@ statement
|
||||
| rawBlock -> $1
|
||||
| partial -> $1
|
||||
| content -> $1
|
||||
| COMMENT -> new yy.CommentNode(yy.stripComment($1), yy.stripFlags($1, $1), yy.locInfo(@$))
|
||||
| COMMENT -> new yy.CommentStatement(yy.stripComment($1), yy.stripFlags($1, $1), yy.locInfo(@$))
|
||||
;
|
||||
|
||||
content
|
||||
: CONTENT -> new yy.ContentNode($1, yy.locInfo(@$))
|
||||
: CONTENT -> new yy.ContentStatement($1, yy.locInfo(@$))
|
||||
;
|
||||
|
||||
rawBlock
|
||||
@@ -47,7 +47,7 @@ openInverse
|
||||
;
|
||||
|
||||
openInverseChain
|
||||
: OPEN_INVERSE_CHAIN sexpr CLOSE -> new yy.MustacheNode($2, $1, yy.stripFlags($1, $3), yy.locInfo(@$))
|
||||
: OPEN_INVERSE_CHAIN sexpr CLOSE -> new yy.MustacheStatement($2, $1, yy.stripFlags($1, $3), yy.locInfo(@$))
|
||||
;
|
||||
|
||||
inverseAndProgram
|
||||
@@ -57,7 +57,7 @@ inverseAndProgram
|
||||
inverseChain
|
||||
: openInverseChain program inverseChain? {
|
||||
var inverse = yy.prepareBlock($1, $2, $3, $3, false, yy.locInfo(@$)),
|
||||
program = new yy.ProgramNode(yy.prepareProgram([inverse]), null, {}, yy.locInfo(@$));
|
||||
program = new yy.Program(yy.prepareProgram([inverse]), null, {}, yy.locInfo(@$));
|
||||
|
||||
program.inverse = inverse;
|
||||
|
||||
@@ -73,30 +73,30 @@ closeBlock
|
||||
mustache
|
||||
// Parsing out the '&' escape token at AST level saves ~500 bytes after min due to the removal of one parser node.
|
||||
// This also allows for handler unification as all mustache node instances can utilize the same handler
|
||||
: OPEN sexpr CLOSE -> new yy.MustacheNode($2, $1, yy.stripFlags($1, $3), yy.locInfo(@$))
|
||||
| OPEN_UNESCAPED sexpr CLOSE_UNESCAPED -> new yy.MustacheNode($2, $1, yy.stripFlags($1, $3), yy.locInfo(@$))
|
||||
: OPEN sexpr CLOSE -> new yy.MustacheStatement($2, $1, yy.stripFlags($1, $3), yy.locInfo(@$))
|
||||
| OPEN_UNESCAPED sexpr CLOSE_UNESCAPED -> new yy.MustacheStatement($2, $1, yy.stripFlags($1, $3), yy.locInfo(@$))
|
||||
;
|
||||
|
||||
partial
|
||||
: OPEN_PARTIAL sexpr CLOSE -> new yy.PartialNode($2, yy.stripFlags($1, $3), yy.locInfo(@$))
|
||||
: OPEN_PARTIAL sexpr CLOSE -> new yy.PartialStatement($2, yy.stripFlags($1, $3), yy.locInfo(@$))
|
||||
;
|
||||
|
||||
sexpr
|
||||
: helperName param* hash? -> new yy.SexprNode([$1].concat($2), $3, yy.locInfo(@$))
|
||||
| dataName -> new yy.SexprNode([$1], null, yy.locInfo(@$))
|
||||
: helperName param* hash? -> new yy.SubExpression([$1].concat($2), $3, yy.locInfo(@$))
|
||||
| dataName -> new yy.SubExpression([$1], null, yy.locInfo(@$))
|
||||
;
|
||||
|
||||
param
|
||||
: path -> $1
|
||||
| STRING -> new yy.StringNode($1, yy.locInfo(@$))
|
||||
| NUMBER -> new yy.NumberNode($1, yy.locInfo(@$))
|
||||
| BOOLEAN -> new yy.BooleanNode($1, yy.locInfo(@$))
|
||||
| STRING -> new yy.StringLiteral($1, yy.locInfo(@$))
|
||||
| NUMBER -> new yy.NumberLiteral($1, yy.locInfo(@$))
|
||||
| BOOLEAN -> new yy.BooleanLiteral($1, yy.locInfo(@$))
|
||||
| dataName -> $1
|
||||
| OPEN_SEXPR sexpr CLOSE_SEXPR -> $2
|
||||
;
|
||||
|
||||
hash
|
||||
: hashSegment+ -> new yy.HashNode($1, yy.locInfo(@$))
|
||||
: hashSegment+ -> new yy.Hash($1, yy.locInfo(@$))
|
||||
;
|
||||
|
||||
hashSegment
|
||||
@@ -109,16 +109,16 @@ blockParams
|
||||
|
||||
helperName
|
||||
: path -> $1
|
||||
| STRING -> new yy.StringNode($1, yy.locInfo(@$)), yy.locInfo(@$)
|
||||
| NUMBER -> new yy.NumberNode($1, yy.locInfo(@$))
|
||||
| STRING -> new yy.StringLiteral($1, yy.locInfo(@$)), yy.locInfo(@$)
|
||||
| NUMBER -> new yy.NumberLiteral($1, yy.locInfo(@$))
|
||||
;
|
||||
|
||||
dataName
|
||||
: DATA pathSegments -> new yy.PathNode(true, $2, yy.locInfo(@$))
|
||||
: DATA pathSegments -> new yy.PathExpression(true, $2, yy.locInfo(@$))
|
||||
;
|
||||
|
||||
path
|
||||
: pathSegments -> new yy.PathNode(false, $1, yy.locInfo(@$))
|
||||
: pathSegments -> new yy.PathExpression(false, $1, yy.locInfo(@$))
|
||||
;
|
||||
|
||||
pathSegments
|
||||
|
||||
Reference in New Issue
Block a user