File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ function toConstant(src) {
3939 return constantinople . toConstant ( src , { pug : runtime , pug_interp : undefined } ) ;
4040}
4141
42+ function isIdentifier ( name ) {
43+ return / ^ [ a - z A - Z _ $ ] [ a - z A - Z 0 - 9 _ $ ] * $ / . test ( name ) ;
44+ }
45+
4246/**
4347 * Initialize `Compiler` with the given `node`.
4448 *
@@ -62,6 +66,23 @@ function Compiler(node, options) {
6266 'The pretty parameter should either be a boolean or whitespace only string'
6367 ) ;
6468 }
69+ if ( this . options . templateName && ! isIdentifier ( this . options . templateName ) ) {
70+ throw new Error (
71+ 'The templateName parameter must be a valid JavaScript identifier if specified.'
72+ ) ;
73+ }
74+ if (
75+ this . doctype &&
76+ ( this . doctype . includes ( '<' ) || this . doctype . includes ( '>' ) )
77+ ) {
78+ throw new Error ( 'Doctype can not contain "<" or ">"' ) ;
79+ }
80+ if ( this . options . globals && ! this . options . globals . every ( isIdentifier ) ) {
81+ throw new Error (
82+ 'The globals option must be an array of valid JavaScript identifiers if specified.'
83+ ) ;
84+ }
85+
6586 this . debug = false !== options . compileDebug ;
6687 this . indents = 0 ;
6788 this . parentIndents = 0 ;
@@ -167,6 +188,7 @@ Compiler.prototype = {
167188 ');' +
168189 '}' ;
169190 }
191+
170192 return (
171193 buildRuntime ( this . runtimeFunctionsUsed ) +
172194 'function ' +
You can’t perform that action at this time.
0 commit comments