pug-parser
Advanced tools
Comparing version 5.0.1 to 6.0.0-canary-1
506
index.js
@@ -14,3 +14,3 @@ 'use strict'; | ||
return JSON.parse(JSON.stringify(ast)); | ||
}; | ||
} | ||
@@ -29,6 +29,10 @@ /** | ||
if (!Array.isArray(tokens)) { | ||
throw new Error('Expected tokens to be an Array but got "' + (typeof tokens) + '"'); | ||
throw new Error( | ||
'Expected tokens to be an Array but got "' + typeof tokens + '"' | ||
); | ||
} | ||
if (typeof options !== 'object') { | ||
throw new Error('Expected "options" to be an object but got "' + (typeof options) + '"'); | ||
throw new Error( | ||
'Expected "options" to be an object but got "' + typeof options + '"' | ||
); | ||
} | ||
@@ -40,3 +44,3 @@ this.tokens = new TokenStream(tokens); | ||
this.plugins = options.plugins || []; | ||
}; | ||
} | ||
@@ -48,3 +52,2 @@ /** | ||
Parser.prototype = { | ||
/** | ||
@@ -56,3 +59,3 @@ * Save original constructor | ||
error: function (code, message, token) { | ||
error: function(code, message, token) { | ||
var err = error(code, message, { | ||
@@ -62,3 +65,3 @@ line: token.loc.start.line, | ||
filename: this.filename, | ||
src: this.src | ||
src: this.src, | ||
}); | ||
@@ -75,3 +78,3 @@ throw err; | ||
advance: function(){ | ||
advance: function() { | ||
return this.tokens.advance(); | ||
@@ -99,3 +102,3 @@ }, | ||
lookahead: function(n){ | ||
lookahead: function(n) { | ||
return this.tokens.lookahead(n); | ||
@@ -111,3 +114,3 @@ }, | ||
parse: function(){ | ||
parse: function() { | ||
var block = this.emptyBlock(0); | ||
@@ -142,7 +145,11 @@ | ||
expect: function(type){ | ||
expect: function(type) { | ||
if (this.peek().type === type) { | ||
return this.advance(); | ||
} else { | ||
this.error('INVALID_TOKEN', 'expected "' + type + '", but got "' + this.peek().type + '"', this.peek()); | ||
this.error( | ||
'INVALID_TOKEN', | ||
'expected "' + type + '", but got "' + this.peek().type + '"', | ||
this.peek() | ||
); | ||
} | ||
@@ -158,3 +165,3 @@ }, | ||
accept: function(type){ | ||
accept: function(type) { | ||
if (this.peek().type === type) { | ||
@@ -174,3 +181,3 @@ return this.advance(); | ||
line: line, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -192,7 +199,14 @@ }, | ||
if (plugin[context] && plugin[context][tok.type]) { | ||
if (pluginContext) throw new Error('Multiple plugin handlers found for context ' + JSON.stringify(context) + ', token type ' + JSON.stringify(tok.type)); | ||
if (pluginContext) | ||
throw new Error( | ||
'Multiple plugin handlers found for context ' + | ||
JSON.stringify(context) + | ||
', token type ' + | ||
JSON.stringify(tok.type) | ||
); | ||
pluginContext = plugin[context]; | ||
} | ||
} | ||
if (pluginContext) return pluginContext[tok.type].apply(pluginContext, rest); | ||
if (pluginContext) | ||
return pluginContext[tok.type].apply(pluginContext, rest); | ||
}, | ||
@@ -218,3 +232,3 @@ | ||
parseExpr: function(){ | ||
parseExpr: function() { | ||
switch (this.peek().type) { | ||
@@ -251,2 +265,4 @@ case 'tag': | ||
return this.parseEach(); | ||
case 'eachOf': | ||
return this.parseEachOf(); | ||
case 'code': | ||
@@ -273,3 +289,3 @@ return this.parseCode(); | ||
loc: this.peek().loc, | ||
filename: this.filename | ||
filename: this.filename, | ||
}); | ||
@@ -280,3 +296,7 @@ return this.parseExpr(); | ||
if (pluginResult) return pluginResult; | ||
this.error('INVALID_TOKEN', 'unexpected token "' + this.peek().type + '"', this.peek()); | ||
this.error( | ||
'INVALID_TOKEN', | ||
'unexpected token "' + this.peek().type + '"', | ||
this.peek() | ||
); | ||
} | ||
@@ -294,58 +314,57 @@ }, | ||
parseText: function(options){ | ||
parseText: function(options) { | ||
var tags = []; | ||
var lineno = this.peek().loc.start.line; | ||
var nextTok = this.peek(); | ||
loop: | ||
while (true) { | ||
switch (nextTok.type) { | ||
case 'text': | ||
var tok = this.advance(); | ||
loop: while (true) { | ||
switch (nextTok.type) { | ||
case 'text': | ||
var tok = this.advance(); | ||
tags.push({ | ||
type: 'Text', | ||
val: tok.val, | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename, | ||
}); | ||
break; | ||
case 'interpolated-code': | ||
var tok = this.advance(); | ||
tags.push({ | ||
type: 'Code', | ||
val: tok.val, | ||
buffer: tok.buffer, | ||
mustEscape: tok.mustEscape !== false, | ||
isInline: true, | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename, | ||
}); | ||
break; | ||
case 'newline': | ||
if (!options || !options.block) break loop; | ||
var tok = this.advance(); | ||
var nextType = this.peek().type; | ||
if (nextType === 'text' || nextType === 'interpolated-code') { | ||
tags.push({ | ||
type: 'Text', | ||
val: tok.val, | ||
val: '\n', | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}); | ||
break; | ||
case 'interpolated-code': | ||
var tok = this.advance(); | ||
tags.push({ | ||
type: 'Code', | ||
val: tok.val, | ||
buffer: tok.buffer, | ||
mustEscape: tok.mustEscape !== false, | ||
isInline: true, | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
}); | ||
break; | ||
case 'newline': | ||
if (!options || !options.block) break loop; | ||
var tok = this.advance(); | ||
var nextType = this.peek().type; | ||
if (nextType === 'text' || nextType === 'interpolated-code') { | ||
tags.push({ | ||
type: 'Text', | ||
val: '\n', | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
}); | ||
} | ||
break; | ||
case 'start-pug-interpolation': | ||
this.advance(); | ||
tags.push(this.parseExpr()); | ||
this.expect('end-pug-interpolation'); | ||
break; | ||
default: | ||
var pluginResult = this.runPlugin('textTokens', nextTok, tags); | ||
if (pluginResult) break; | ||
break loop; | ||
} | ||
nextTok = this.peek(); | ||
} | ||
break; | ||
case 'start-pug-interpolation': | ||
this.advance(); | ||
tags.push(this.parseExpr()); | ||
this.expect('end-pug-interpolation'); | ||
break; | ||
default: | ||
var pluginResult = this.runPlugin('textTokens', nextTok, tags); | ||
if (pluginResult) break; | ||
break loop; | ||
} | ||
nextTok = this.peek(); | ||
} | ||
if (tags.length === 1) return tags[0]; | ||
@@ -355,7 +374,6 @@ else return this.initBlock(lineno, tags); | ||
parseTextHtml: function () { | ||
parseTextHtml: function() { | ||
var nodes = []; | ||
var currentNode = null; | ||
loop: | ||
while (true) { | ||
loop: while (true) { | ||
switch (this.peek().type) { | ||
@@ -371,3 +389,3 @@ case 'text-html': | ||
column: text.loc.start.column, | ||
isHtml: true | ||
isHtml: true, | ||
}; | ||
@@ -381,3 +399,3 @@ nodes.push(currentNode); | ||
var block = this.block(); | ||
block.nodes.forEach(function (node) { | ||
block.nodes.forEach(function(node) { | ||
if (node.isHtml) { | ||
@@ -415,7 +433,9 @@ if (!currentNode) { | ||
parseBlockExpansion: function(){ | ||
parseBlockExpansion: function() { | ||
var tok = this.accept(':'); | ||
if (tok) { | ||
var expr = this.parseExpr(); | ||
return expr.type === 'Block' ? expr : this.initBlock(tok.loc.start.line, [expr]); | ||
return expr.type === 'Block' | ||
? expr | ||
: this.initBlock(tok.loc.start.line, [expr]); | ||
} else { | ||
@@ -430,3 +450,3 @@ return this.block(); | ||
parseCase: function(){ | ||
parseCase: function() { | ||
var tok = this.expect('case'); | ||
@@ -438,3 +458,3 @@ var node = { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -459,4 +479,9 @@ | ||
if (pluginResult) break; | ||
this.error('INVALID_TOKEN', 'Unexpected token "' + this.peek().type | ||
+ '", expected "when", "default" or "newline"', this.peek()); | ||
this.error( | ||
'INVALID_TOKEN', | ||
'Unexpected token "' + | ||
this.peek().type + | ||
'", expected "when", "default" or "newline"', | ||
this.peek() | ||
); | ||
} | ||
@@ -475,3 +500,3 @@ } | ||
parseWhen: function(){ | ||
parseWhen: function() { | ||
var tok = this.expect('when'); | ||
@@ -486,3 +511,3 @@ if (this.peek().type !== 'newline') { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -496,3 +521,3 @@ } else { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -506,3 +531,3 @@ } | ||
parseDefault: function(){ | ||
parseDefault: function() { | ||
var tok = this.expect('default'); | ||
@@ -516,3 +541,3 @@ return { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -525,5 +550,8 @@ }, | ||
parseCode: function(noBlock){ | ||
parseCode: function(noBlock) { | ||
var tok = this.expect('code'); | ||
assert(typeof tok.mustEscape === 'boolean', 'Please update to the newest version of pug-lexer.'); | ||
assert( | ||
typeof tok.mustEscape === 'boolean', | ||
'Please update to the newest version of pug-lexer.' | ||
); | ||
var node = { | ||
@@ -537,3 +565,3 @@ type: 'Code', | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -551,3 +579,7 @@ // todo: why is this here? It seems like a hacky workaround | ||
if (tok.buffer) { | ||
this.error('BLOCK_IN_BUFFERED_CODE', 'Buffered code cannot have a block attached to it', this.peek()); | ||
this.error( | ||
'BLOCK_IN_BUFFERED_CODE', | ||
'Buffered code cannot have a block attached to it', | ||
this.peek() | ||
); | ||
} | ||
@@ -559,3 +591,3 @@ node.block = this.block(); | ||
}, | ||
parseConditional: function(){ | ||
parseConditional: function() { | ||
var tok = this.expect('if'); | ||
@@ -569,3 +601,3 @@ var node = { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -584,13 +616,11 @@ | ||
tok = this.expect('else-if'); | ||
currentNode = ( | ||
currentNode.alternate = { | ||
type: 'Conditional', | ||
test: tok.val, | ||
consequent: this.emptyBlock(tok.loc.start.line), | ||
alternate: null, | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
} | ||
); | ||
currentNode = currentNode.alternate = { | ||
type: 'Conditional', | ||
test: tok.val, | ||
consequent: this.emptyBlock(tok.loc.start.line), | ||
alternate: null, | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename, | ||
}; | ||
if ('indent' == this.peek().type) { | ||
@@ -612,3 +642,3 @@ currentNode.consequent = this.block(); | ||
}, | ||
parseWhile: function(){ | ||
parseWhile: function() { | ||
var tok = this.expect('while'); | ||
@@ -620,3 +650,3 @@ var node = { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -638,3 +668,3 @@ | ||
parseBlockCode: function(){ | ||
parseBlockCode: function() { | ||
var tok = this.expect('blockcode'); | ||
@@ -662,3 +692,7 @@ var line = tok.loc.start.line; | ||
} | ||
this.error('INVALID_TOKEN', 'Unexpected token type: ' + tok.type, tok); | ||
this.error( | ||
'INVALID_TOKEN', | ||
'Unexpected token type: ' + tok.type, | ||
tok | ||
); | ||
} | ||
@@ -676,3 +710,3 @@ } | ||
column: column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -684,6 +718,6 @@ }, | ||
parseComment: function(){ | ||
parseComment: function() { | ||
var tok = this.expect('comment'); | ||
var block; | ||
if (block = this.parseTextBlock()) { | ||
if ((block = this.parseTextBlock())) { | ||
return { | ||
@@ -696,3 +730,3 @@ type: 'BlockComment', | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -706,3 +740,3 @@ } else { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -716,3 +750,3 @@ } | ||
parseDoctype: function(){ | ||
parseDoctype: function() { | ||
var tok = this.expect('doctype'); | ||
@@ -724,3 +758,3 @@ return { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -743,3 +777,3 @@ }, | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -752,5 +786,6 @@ }, | ||
parseFilter: function(){ | ||
parseFilter: function() { | ||
var tok = this.expect('filter'); | ||
var block, attrs = []; | ||
var block, | ||
attrs = []; | ||
@@ -769,4 +804,4 @@ if (this.peek().type === 'start-attributes') { | ||
column: textToken.loc.start.column, | ||
filename: this.filename | ||
} | ||
filename: this.filename, | ||
}, | ||
]); | ||
@@ -786,3 +821,3 @@ } else if (this.peek().type === 'filter') { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -795,3 +830,3 @@ }, | ||
parseEach: function(){ | ||
parseEach: function() { | ||
var tok = this.expect('each'); | ||
@@ -806,3 +841,3 @@ var node = { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -816,2 +851,15 @@ if (this.peek().type == 'else') { | ||
parseEachOf: function() { | ||
var tok = this.expect('eachOf'); | ||
var node = { | ||
type: 'EachOf', | ||
obj: tok.code, | ||
val: tok.val, | ||
block: this.block(), | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename, | ||
}; | ||
return node; | ||
}, | ||
/** | ||
@@ -821,3 +869,3 @@ * 'extends' name | ||
parseExtends: function(){ | ||
parseExtends: function() { | ||
var tok = this.expect('extends'); | ||
@@ -832,7 +880,7 @@ var path = this.expect('path'); | ||
column: path.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}, | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -845,6 +893,9 @@ }, | ||
parseBlock: function(){ | ||
parseBlock: function() { | ||
var tok = this.expect('block'); | ||
var node = 'indent' == this.peek().type ? this.block() : this.emptyBlock(tok.loc.start.line); | ||
var node = | ||
'indent' == this.peek().type | ||
? this.block() | ||
: this.emptyBlock(tok.loc.start.line); | ||
node.type = 'NamedBlock'; | ||
@@ -859,6 +910,10 @@ node.name = tok.val.trim(); | ||
parseMixinBlock: function () { | ||
parseMixinBlock: function() { | ||
var tok = this.expect('mixin-block'); | ||
if (!this.inMixin) { | ||
this.error('BLOCK_OUTISDE_MIXIN', 'Anonymous blocks are not allowed unless they are part of a mixin.', tok); | ||
this.error( | ||
'BLOCK_OUTISDE_MIXIN', | ||
'Anonymous blocks are not allowed unless they are part of a mixin.', | ||
tok | ||
); | ||
} | ||
@@ -869,3 +924,3 @@ return { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -880,3 +935,3 @@ }, | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -889,3 +944,3 @@ }, | ||
parseInclude: function(){ | ||
parseInclude: function() { | ||
var tok = this.expect('include'); | ||
@@ -896,7 +951,7 @@ var node = { | ||
type: 'FileReference', | ||
filename: this.filename | ||
filename: this.filename, | ||
}, | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -913,8 +968,18 @@ var filters = []; | ||
if ((/\.jade$/.test(node.file.path) || /\.pug$/.test(node.file.path)) && !filters.length) { | ||
node.block = 'indent' == this.peek().type ? this.block() : this.emptyBlock(tok.loc.start.line); | ||
if ( | ||
(/\.jade$/.test(node.file.path) || /\.pug$/.test(node.file.path)) && | ||
!filters.length | ||
) { | ||
node.block = | ||
'indent' == this.peek().type | ||
? this.block() | ||
: this.emptyBlock(tok.loc.start.line); | ||
if (/\.jade$/.test(node.file.path)) { | ||
console.warn( | ||
this.filename + ', line ' + tok.loc.start.line + | ||
':\nThe .jade extension is deprecated, use .pug for "' + node.file.path +'".' | ||
this.filename + | ||
', line ' + | ||
tok.loc.start.line + | ||
':\nThe .jade extension is deprecated, use .pug for "' + | ||
node.file.path + | ||
'".' | ||
); | ||
@@ -926,3 +991,7 @@ } | ||
if (this.peek().type === 'indent') { | ||
this.error('RAW_INCLUDE_BLOCK', 'Raw inclusion cannot contain a block', this.peek()); | ||
this.error( | ||
'RAW_INCLUDE_BLOCK', | ||
'Raw inclusion cannot contain a block', | ||
this.peek() | ||
); | ||
} | ||
@@ -937,3 +1006,3 @@ } | ||
parseCall: function(){ | ||
parseCall: function() { | ||
var tok = this.expect('call'); | ||
@@ -952,3 +1021,3 @@ var name = tok.val; | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -969,3 +1038,3 @@ | ||
parseMixin: function(){ | ||
parseMixin: function() { | ||
var tok = this.expect('mixin'); | ||
@@ -985,3 +1054,3 @@ var name = tok.val; | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -991,3 +1060,7 @@ this.inMixin--; | ||
} else { | ||
this.error('MIXIN_WITHOUT_BODY', 'Mixin ' + name + ' declared without body', tok); | ||
this.error( | ||
'MIXIN_WITHOUT_BODY', | ||
'Mixin ' + name + ' declared without body', | ||
tok | ||
); | ||
} | ||
@@ -1000,3 +1073,3 @@ }, | ||
parseTextBlock: function(){ | ||
parseTextBlock: function() { | ||
var tok = this.accept('start-pipeless-text'); | ||
@@ -1014,3 +1087,3 @@ if (!tok) return; | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}); | ||
@@ -1024,3 +1097,3 @@ break; | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}); | ||
@@ -1041,3 +1114,3 @@ break; | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}); | ||
@@ -1048,3 +1121,7 @@ break; | ||
if (pluginResult) break; | ||
this.error('INVALID_TOKEN', 'Unexpected token type: ' + tok.type, tok); | ||
this.error( | ||
'INVALID_TOKEN', | ||
'Unexpected token type: ' + tok.type, | ||
tok | ||
); | ||
} | ||
@@ -1060,3 +1137,3 @@ } | ||
block: function(){ | ||
block: function() { | ||
var tok = this.expect('indent'); | ||
@@ -1086,3 +1163,3 @@ var block = this.emptyBlock(tok.loc.start.line); | ||
parseInterpolation: function(){ | ||
parseInterpolation: function() { | ||
var tok = this.advance(); | ||
@@ -1099,3 +1176,3 @@ var tag = { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -1110,3 +1187,3 @@ | ||
parseTag: function(){ | ||
parseTag: function() { | ||
var tok = this.advance(); | ||
@@ -1123,3 +1200,3 @@ var tag = { | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
filename: this.filename, | ||
}; | ||
@@ -1139,46 +1216,59 @@ | ||
// (attrs | class | id)* | ||
out: | ||
while (true) { | ||
switch (this.peek().type) { | ||
case 'id': | ||
case 'class': | ||
var tok = this.advance(); | ||
if (tok.type === 'id') { | ||
if (attributeNames.indexOf('id') !== -1) { | ||
this.error('DUPLICATE_ID', 'Duplicate attribute "id" is not allowed.', tok); | ||
} | ||
attributeNames.push('id'); | ||
out: while (true) { | ||
switch (this.peek().type) { | ||
case 'id': | ||
case 'class': | ||
var tok = this.advance(); | ||
if (tok.type === 'id') { | ||
if (attributeNames.indexOf('id') !== -1) { | ||
this.error( | ||
'DUPLICATE_ID', | ||
'Duplicate attribute "id" is not allowed.', | ||
tok | ||
); | ||
} | ||
tag.attrs.push({ | ||
name: tok.type, | ||
val: "'" + tok.val + "'", | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename, | ||
mustEscape: false | ||
}); | ||
continue; | ||
case 'start-attributes': | ||
if (seenAttrs) { | ||
console.warn(this.filename + ', line ' + this.peek().loc.start.line + ':\nYou should not have pug tags with multiple attributes.'); | ||
} | ||
seenAttrs = true; | ||
tag.attrs = tag.attrs.concat(this.attrs(attributeNames)); | ||
continue; | ||
case '&attributes': | ||
var tok = this.advance(); | ||
tag.attributeBlocks.push({ | ||
type: 'AttributeBlock', | ||
val: tok.val, | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename | ||
}); | ||
break; | ||
default: | ||
var pluginResult = this.runPlugin('tagAttributeTokens', this.peek(), tag, attributeNames); | ||
if (pluginResult) break; | ||
break out; | ||
} | ||
attributeNames.push('id'); | ||
} | ||
tag.attrs.push({ | ||
name: tok.type, | ||
val: "'" + tok.val + "'", | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename, | ||
mustEscape: false, | ||
}); | ||
continue; | ||
case 'start-attributes': | ||
if (seenAttrs) { | ||
console.warn( | ||
this.filename + | ||
', line ' + | ||
this.peek().loc.start.line + | ||
':\nYou should not have pug tags with multiple attributes.' | ||
); | ||
} | ||
seenAttrs = true; | ||
tag.attrs = tag.attrs.concat(this.attrs(attributeNames)); | ||
continue; | ||
case '&attributes': | ||
var tok = this.advance(); | ||
tag.attributeBlocks.push({ | ||
type: 'AttributeBlock', | ||
val: tok.val, | ||
line: tok.loc.start.line, | ||
column: tok.loc.start.column, | ||
filename: this.filename, | ||
}); | ||
break; | ||
default: | ||
var pluginResult = this.runPlugin( | ||
'tagAttributeTokens', | ||
this.peek(), | ||
tag, | ||
attributeNames | ||
); | ||
if (pluginResult) break; | ||
break out; | ||
} | ||
} | ||
@@ -1208,3 +1298,4 @@ // check immediate '.' | ||
var expr = this.parseExpr(); | ||
tag.block = expr.type === 'Block' ? expr : this.initBlock(tag.line, [expr]); | ||
tag.block = | ||
expr.type === 'Block' ? expr : this.initBlock(tag.line, [expr]); | ||
break; | ||
@@ -1225,5 +1316,18 @@ case 'newline': | ||
default: | ||
var pluginResult = this.runPlugin('tagTokens', this.peek(), tag, options); | ||
var pluginResult = this.runPlugin( | ||
'tagTokens', | ||
this.peek(), | ||
tag, | ||
options | ||
); | ||
if (pluginResult) break; | ||
this.error('INVALID_TOKEN', 'Unexpected token `' + this.peek().type + '` expected `text`, `interpolated-code`, `code`, `:`' + (selfClosingAllowed ? ', `slash`' : '') + ', `newline` or `eos`', this.peek()) | ||
this.error( | ||
'INVALID_TOKEN', | ||
'Unexpected token `' + | ||
this.peek().type + | ||
'` expected `text`, `interpolated-code`, `code`, `:`' + | ||
(selfClosingAllowed ? ', `slash`' : '') + | ||
', `newline` or `eos`', | ||
this.peek() | ||
); | ||
} | ||
@@ -1255,3 +1359,7 @@ | ||
if (attributeNames.indexOf(tok.name) !== -1) { | ||
this.error('DUPLICATE_ATTRIBUTE', 'Duplicate attribute "' + tok.name + '" is not allowed.', tok); | ||
this.error( | ||
'DUPLICATE_ATTRIBUTE', | ||
'Duplicate attribute "' + tok.name + '" is not allowed.', | ||
tok | ||
); | ||
} | ||
@@ -1266,3 +1374,3 @@ attributeNames.push(tok.name); | ||
filename: this.filename, | ||
mustEscape: tok.mustEscape !== false | ||
mustEscape: tok.mustEscape !== false, | ||
}); | ||
@@ -1274,3 +1382,3 @@ tok = this.advance(); | ||
return attrs; | ||
} | ||
}; | ||
}, | ||
}; |
'use strict'; | ||
module.exports = [ | ||
'a' | ||
, 'abbr' | ||
, 'acronym' | ||
, 'b' | ||
, 'br' | ||
, 'code' | ||
, 'em' | ||
, 'font' | ||
, 'i' | ||
, 'img' | ||
, 'ins' | ||
, 'kbd' | ||
, 'map' | ||
, 'samp' | ||
, 'small' | ||
, 'span' | ||
, 'strong' | ||
, 'sub' | ||
, 'sup' | ||
]; | ||
'a', | ||
'abbr', | ||
'acronym', | ||
'b', | ||
'br', | ||
'code', | ||
'em', | ||
'font', | ||
'i', | ||
'img', | ||
'ins', | ||
'kbd', | ||
'map', | ||
'samp', | ||
'small', | ||
'span', | ||
'strong', | ||
'sub', | ||
'sup', | ||
]; |
{ | ||
"name": "pug-parser", | ||
"version": "5.0.1", | ||
"version": "6.0.0-canary-1", | ||
"description": "The pug parser (takes an array of tokens and converts it to an abstract syntax tree)", | ||
@@ -9,8 +9,6 @@ "keywords": [ | ||
"dependencies": { | ||
"pug-error": "^1.3.3", | ||
"token-stream": "0.0.1" | ||
"pug-error": "2.0.0-canary-1", | ||
"token-stream": "1.0.0" | ||
}, | ||
"devDependencies": { | ||
"get-repo": "^1.0.0" | ||
}, | ||
"devDependencies": {}, | ||
"files": [ | ||
@@ -25,4 +23,3 @@ "lib/inline-tags.js", | ||
"author": "ForbesLindesay", | ||
"license": "MIT", | ||
"gitHead": "1bdf628a70fda7a0d840c52f3abce54b1c6b0130" | ||
"license": "MIT" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
35830
0
1217
2
+ Addedpug-error@2.0.0-canary-1(transitive)
+ Addedtoken-stream@1.0.0(transitive)
- Removedpug-error@1.3.3(transitive)
- Removedtoken-stream@0.0.1(transitive)
Updatedpug-error@2.0.0-canary-1
Updatedtoken-stream@1.0.0