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

Added more checks #3428

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/pug-code-gen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ function Compiler(node, options) {
this.mixins = {};
this.dynamicMixins = false;
this.eachCount = 0;
if (options.templateName && !/^[0-9a-zA-Z\-\_]+?$/.test(options.templateName)) {
throw new Error(
'Template name should be a valid function name'
);
}
if (options.doctype) this.setDoctype(options.doctype);
this.runtimeFunctionsUsed = [];
this.inlineRuntimeFunctions = options.inlineRuntimeFunctions || false;
Expand Down Expand Up @@ -311,10 +316,17 @@ Compiler.prototype = {
}

if (debug && node.debug !== false && node.type !== 'Block') {
if (typeof node.line !== 'number') {
throw new Error(
'node.line is not a valid number.'
);
}
Comment on lines 318 to +323

Choose a reason for hiding this comment

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

Suggested change
if (debug && node.debug !== false && node.type !== 'Block') {
if (typeof node.line !== 'number') {
throw new Error(
'node.line is not a valid number.'
);
}
if (debug && node.debug !== false && node.type !== 'Block' && typeof node.line === 'number') {

isnt should better?

Copy link
Author

Choose a reason for hiding this comment

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

It would, but that meant that it’s checking for all three instead of checking for the required two and failing silently. Throwing an error is better as it can alert the user that there may be a pollution.

Choose a reason for hiding this comment

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

Hmmm i understand


if (node.line) {
var js = ';pug_debug_line = ' + node.line;
if (node.filename)
if (node.filename){
js += ';pug_debug_filename = ' + stringify(node.filename);
}
this.buf.push(js + ';');
}
}
Expand Down