diff --git a/lib/utils/index.js b/lib/utils/index.js index aa411b94c..cd01df744 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -12,6 +12,7 @@ const HTML_ELEMENT_NAMES = new Set(require('./html-elements.json')) const SVG_ELEMENT_NAMES = new Set(require('./svg-elements.json')) const VOID_ELEMENT_NAMES = new Set(require('./void-elements.json')) +const assert = require('assert') // ------------------------------------------------------------------------------ // Exports @@ -63,7 +64,7 @@ module.exports = { * @returns {boolean} `true` if the node is the root element. */ isRootElement (node) { - console.assert(node && node.type === 'VElement') + assert(node && node.type === 'VElement') return ( node.parent.type === 'Program' || @@ -77,7 +78,7 @@ module.exports = { * @returns {ASTNode|null} The previous sibling element. */ prevSibling (node) { - console.assert(node && node.type === 'VElement') + assert(node && node.type === 'VElement') let prevElement = null for (const siblingNode of (node.parent && node.parent.children) || []) { @@ -100,7 +101,7 @@ module.exports = { * @returns {boolean} `true` if the start tag has the directive. */ hasAttribute (node, name, value) { - console.assert(node && node.type === 'VStartTag') + assert(node && node.type === 'VStartTag') return node.attributes.some(a => !a.directive && a.key.name === name && @@ -119,7 +120,7 @@ module.exports = { * @returns {boolean} `true` if the start tag has the directive. */ hasDirective (node, name, argument) { - console.assert(node && node.type === 'VStartTag') + assert(node && node.type === 'VStartTag') return node.attributes.some(a => a.directive && a.key.name === name && @@ -133,7 +134,7 @@ module.exports = { * @returns {boolean} `true` if the attribute has their value. */ hasAttributeValue (node) { - console.assert(node && node.type === 'VAttribute') + assert(node && node.type === 'VAttribute') return ( node.value != null && (node.value.expression != null || node.value.syntaxError != null) @@ -148,7 +149,7 @@ module.exports = { * @returns {ASTNode} The found attribute. */ getAttribute (node, name, value) { - console.assert(node && node.type === 'VStartTag') + assert(node && node.type === 'VStartTag') return node.attributes.find(a => !a.directive && a.key.name === name && @@ -167,7 +168,7 @@ module.exports = { * @returns {ASTNode} The found directive. */ getDirective (node, name, argument) { - console.assert(node && node.type === 'VStartTag') + assert(node && node.type === 'VStartTag') return node.attributes.find(a => a.directive && a.key.name === name && @@ -181,7 +182,7 @@ module.exports = { * @returns {boolean} `true` if the previous sibling element has `if` or `else-if` directive. */ prevElementHasIf (node) { - console.assert(node && node.type === 'VElement') + assert(node && node.type === 'VElement') const prev = this.prevSibling(node) return ( @@ -199,7 +200,7 @@ module.exports = { * @returns {boolean} `true` if the node is a custom component. */ isCustomComponent (node) { - console.assert(node && node.type === 'VStartTag') + assert(node && node.type === 'VStartTag') const name = node.id.name return ( @@ -215,7 +216,7 @@ module.exports = { * @returns {boolean} `true` if the name is a HTML element name. */ isHtmlElementName (name) { - console.assert(typeof name === 'string') + assert(typeof name === 'string') return HTML_ELEMENT_NAMES.has(name.toLowerCase()) }, @@ -226,7 +227,7 @@ module.exports = { * @returns {boolean} `true` if the name is a SVG element name. */ isSvgElementName (name) { - console.assert(typeof name === 'string') + assert(typeof name === 'string') return SVG_ELEMENT_NAMES.has(name.toLowerCase()) }, @@ -237,7 +238,7 @@ module.exports = { * @returns {boolean} `true` if the name is a void element name. */ isVoidElementName (name) { - console.assert(typeof name === 'string') + assert(typeof name === 'string') return VOID_ELEMENT_NAMES.has(name.toLowerCase()) }