Skip to content

Commit

Permalink
removed noop functions from parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Gaggl committed May 1, 2021
1 parent 0fe25e7 commit dc50416
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/filter/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports.length_is = (value, arg) => {
if (isNaN(len)) {
return '';
}
if (value instanceof Array || typeof (value) === 'string' || value instanceof String) {
if (Array.isArray(value) || typeof (value) === 'string' || value instanceof String) {
return value.length === len;
}
return '';
Expand Down
29 changes: 4 additions & 25 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ const Parser = exports.Parser = function(tokens, environment, origin) {
Parser.prototype.addEnvironmentExtensions = function() {
if (this.environment.extensions.filters) {
let filterExt = this.environment.extensions.filters;
if (!(filterExt instanceof Array)) {
if (!Array.isArray(filterExt)) {
filterExt = [filterExt];
}
filterExt.forEach(extension => this.addFilters(extension));
}
if (this.environment.extensions.tags) {
let tagExt = this.environment.extensions.tags;
if (!(tagExt instanceof Array)) {
if (!Array.isArray(tagExt)) {
tagExt = [tagExt];
}
tagExt.forEach(extension => this.addTags(extension));
Expand All @@ -63,14 +63,7 @@ Parser.prototype.parse = function(parseUntil) {
if (!token.contents) {
this.emptyVariable(token);
}
let filterExpression;
try {
filterExpression = this.compileFilter(token.contents);
} catch (e if e instanceof TemplateSyntaxError) {
this.compileFilterError(token, e);
throw e;
}
let node = this.createVariableNode(filterExpression);
let node = this.createVariableNode(this.compileFilter(token.contents));
this.extendNodeList(nodeList, node, token);
} else if (token.tokenType === constants.TOKEN_BLOCK) {
let command;
Expand All @@ -83,20 +76,11 @@ Parser.prototype.parse = function(parseUntil) {
this.prependToken(token);
return nodeList;
}
this.enterCommand(command, token);

This comment has been minimized.

Copy link
@oberhamsi

oberhamsi May 6, 2021

Contributor

in debug mode the parser implements those seemingly noop functions, see here https://github.com/orfon/reinhardt/blob/b9ea31abfc073ad59b9081beb55d8d210fb4ff06/lib/debug.js

so removing the try/catch and the enter/exitCommand makes the debug mode less functional

This comment has been minimized.

Copy link
@grob

grob May 6, 2021

Contributor

yep, oversaw this, it's fixed in 25d4b09

let compileFunc = this.tags[command];
if (!compileFunc || !(typeof (compileFunc) == 'function')) {
this.invalidBlockTag(token, command);
}
let compiledResult;
try {
compiledResult = compileFunc(this, token);
} catch (e if e instanceof TemplateSyntaxError) {
this.compileFunctionError(token, e);
throw e;
}
this.extendNodeList(nodeList, compiledResult, token);
this.exitCommand();
this.extendNodeList(nodeList, compileFunc(this, token), token);
}
}
if (parseUntil.length > 0) {
Expand Down Expand Up @@ -177,8 +161,3 @@ Parser.prototype.createNodeList = function() {
Parser.prototype.error = function(token, msg) {
return new TemplateSyntaxError(msg);
};

Parser.prototype.enterCommand = () => {};
Parser.prototype.exitCommand = () => {};
Parser.prototype.compileFunctionError = () => {};
Parser.prototype.compileFilterError = () => {};
2 changes: 1 addition & 1 deletion lib/tag/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ForNode.prototype.render = function(context) {
let values = this.sequence.resolve(context, true) || [];
if (typeof (values) === 'string') {
values = values.split('');
} else if (!(values instanceof Array)) {
} else if (!Array.isArray(values)) {
values = [values];
}
// FIXME if values is object put the property values into an array
Expand Down

0 comments on commit dc50416

Please sign in to comment.