-
Notifications
You must be signed in to change notification settings - Fork 847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin opts filter #295
Plugin opts filter #295
Conversation
lib/ejs.js
Outdated
case '_' + d + '>': | ||
if (this.mode == Template.modes.LITERAL) { | ||
this._addOutput(line); | ||
var isHandled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge deal here, but I generally prefer to hoist all the declarations to the very top, to reflect what the runtime actually does.
lib/ejs.js
Outdated
case Template.modes.COMMENT: | ||
// Do nothing | ||
if (isHandled && this.mode != Template.modes.LITERAL) { | ||
if (this.isInTag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor quibble: isInTag
implies a Boolean value. I can see you're leaning on the truthy/falsy in JS here, and letting this property do double-duty by holding an actual value -- but ideally if the property name looks Boolean (e.g., isSomething
, hasSomething
, etc.) it should actually be a Bool.
lib/ejs.js
Outdated
// In string mode, just add the output | ||
else { | ||
this._addOutput(line); | ||
if (! isHandled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style issue: space between !
"not" operator and variable name is not needed. Should be simply !isHandled
.
lib/ejs.js
Outdated
includeOpts.filename)); | ||
return; // TODO: debug info | ||
} | ||
// END HACH include |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling: "HACK," not "HACH."
lib/ejs.js
Outdated
self.scanLine(line); | ||
}); | ||
if (this.isInTag) | ||
if (this.isInTag) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my experience, omitted brackets are a major source of confusion during refactoring.
lib/ejs.js
Outdated
@@ -701,8 +702,9 @@ Template.prototype = { | |||
isHandled = false; | |||
} | |||
if (isHandled && this.mode != Template.modes.LITERAL) { | |||
if (this.isInTag) | |||
if (this.isInTag) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/ejs.js
Outdated
this.regexLiteral = this.createRegex(_REGEX_STRING_LITERAL, 'g'); | ||
this.regexLiteralReplace = _REGEX_STRING_LITERAL_REPL; | ||
|
||
this.modeMap = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I have wanted to organized the modes like this for a long time!
lib/ejs.js
Outdated
@@ -478,7 +503,18 @@ function Template(text, opts) { | |||
|
|||
this.opts = options; | |||
|
|||
this.regex = this.createRegex(); | |||
this.regexOpen = this.createRegex(_REGEX_STRING_OPEN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this stuff internal.
lib/ejs.js
Outdated
switch (this.mode) { | ||
case Template.modes.EVAL: | ||
case Template.modes.RAW: | ||
// HACK: backward-compat `include` preprocessor directives |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's worth a major version bump just to jettison this silly preprocessor stuff.
lib/ejs.js
Outdated
includeOpts = utils.shallowCopy({}, self.opts); | ||
includeObj = includeSource(include[1], includeOpts); | ||
if (self.opts.compileDebug) { | ||
includeSrc = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth moving all this inline stuff to a utility function.
lib/ejs.js
Outdated
this.isAfterTag = false; | ||
} | ||
|
||
switch (this.mode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we're actively using fall-through, might be worth considering doing some sort of dispatch via properties / named methods on an object, e.g.:
this.processors = {};
this.processors[Template.modes.EVAL] = function (line) {
this.source += ' ; ' + line + '\n';
};
// Etc....
var processor = this.processors[this.mode];
if (typeof processor == function) {
processor.call(this, line);
}
Something like that. If the function doesn't exist, throw some sort of reasonable error.
If I am not mistaken most of your reviews were on individual commits. Most of the code you commented on is not present in the final commit. I did look for variables that where declared not on top of their block, and moved (most) of them up.
still is not the same as on top of the function. But jslint would complain if used outside the block, so it should be safe. About the old |
any updates? |
@User4martin Sorry for being so slow to respond here. To be honest, I do not have the time to review this huge diff. This basically amounts to a nearly total rewrite of EJS. I cannot review all that code and be confident that there aren't regressions. I can't review commit-by-commit, because we have commits like I'd prefer if this were split into several PRs, with clearly defined commits for each particular change, with no noise commits to fix typos, linting, comments, etc. Sorry if this comes across as blunt; I realize you invested quite a bit of time into this PR; but the last time I checked, EJS was in the top 100 packages on npm. At that rank, we cannot afford to have regressions, even for edge cases. And I do not have an unlimited amount of time to review code here; especially since I don't make any money doing this. All the same, my apologies for letting this sit so long without a proper response. |
I understand the time issue. This is why I waited a while before asking. There are "smaller" changesets available. A breakdown into 4 or 5 sets. I made a branch for each of them and then based the next branch on this. I though initially that small steps would be easier, but somewhere along the way was mislead to think you like one big pull request instead. However: Fixing all the variables for example makes limited sense, if the next changeset will remove the variable entirely. I created pull request #311. This is the first complete change. See issue #288 for an overview of all the change-sets (well on top of 288 there are then the addition of the new plugins.) If #311 is within review-able limits, then we can take it from there. (I may need some time to do any changes, if required) If you want I can already create pull request for all the other changes (But they need to be done in order, as they base on each other) I suggest, if you review it, you create a new branch, so coding style issues can be ignored, and addressed when all pull request are in this branch. Of course, if it can be merged to the main branch, it is a complete change in itself. |
… / throw error on unmatched/unopened closing tags
9c80970
to
05df465
Compare
This branch contains my entire work.
It is ready for review. Please see #288 for an overview what changed.