Skip to content
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

Closed
wants to merge 35 commits into from
Closed

Conversation

User4martin
Copy link

This branch contains my entire work.

It is ready for review. Please see #288 for an overview what changed.

@User4martin User4martin mentioned this pull request Aug 16, 2017
lib/ejs.js Outdated
case '_' + d + '>':
if (this.mode == Template.modes.LITERAL) {
this._addOutput(line);
var isHandled;
Copy link
Owner

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)
Copy link
Owner

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) {
Copy link
Owner

@mde mde Aug 31, 2017

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
Copy link
Owner

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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Owner

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) {
Copy link
Owner

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 = {
Copy link
Owner

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);
Copy link
Owner

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
Copy link
Owner

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 =
Copy link
Owner

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) {
Copy link
Owner

@mde mde Aug 31, 2017

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.

@User4martin
Copy link
Author

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.
Though

if (cond) {
    var foo;

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 inline file (none function style):
If you want to get rid of it, I can move it to a plugin. Then it will no longer be in the main lib/ejs.js file.
If you want to keep it, I don't think it needs to move, but (if you wish) I can move some of the string constants to the function "includeSource".

@User4martin
Copy link
Author

any updates?

@RyanZim
Copy link
Collaborator

RyanZim commented Oct 23, 2017

@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 linting which are pure noise.

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.

@User4martin
Copy link
Author

User4martin commented Oct 23, 2017

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:
Each of those steps should pass all tests (if not, that I will fix).
Not each of them will have all your other coding style requirements (such as var declared on top of block)

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.
And then later pull requests can still go into a branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants