File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ function toConstant(src) {
39
39
return constantinople . toConstant ( src , { pug : runtime , pug_interp : undefined } ) ;
40
40
}
41
41
42
+ function isIdentifier ( name ) {
43
+ return / ^ [ a - z A - Z _ $ ] [ a - z A - Z 0 - 9 _ $ ] * $ / . test ( name ) ;
44
+ }
45
+
42
46
/**
43
47
* Initialize `Compiler` with the given `node`.
44
48
*
@@ -62,6 +66,23 @@ function Compiler(node, options) {
62
66
'The pretty parameter should either be a boolean or whitespace only string'
63
67
) ;
64
68
}
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
+
65
86
this . debug = false !== options . compileDebug ;
66
87
this . indents = 0 ;
67
88
this . parentIndents = 0 ;
@@ -167,6 +188,7 @@ Compiler.prototype = {
167
188
');' +
168
189
'}' ;
169
190
}
191
+
170
192
return (
171
193
buildRuntime ( this . runtimeFunctionsUsed ) +
172
194
'function ' +
You can’t perform that action at this time.
0 commit comments