Files
parcoursup/node_modules/@riotjs/compiler/src/utils/has-html-outside-root-node.js
lalBi94 7bc56c09b5 $
2023-03-05 13:23:23 +01:00

30 lines
903 B
JavaScript

import {isObject} from '@riotjs/util/checks'
/**
* Find whether there is html code outside of the root node
* @param {RiotParser.Node} root - node generated by the riot compiler
* @param {string} code - riot tag source code
* @param {Function} parse - riot parser function
* @returns {boolean} true if extra markup is detected
*/
export default function hasHTMLOutsideRootNode(root, code, parse) {
const additionalCode = root ? [
// head
code.substr(0, root.start),
// tail
code.substr(root.end, code.length)
].join('').trim() : ''
if (additionalCode) {
// if there are parsing errors we assume that there are no html
// tags outside of the root node
try {
const { template, javascript, css } = parse(additionalCode).output
return [template, javascript, css].some(isObject)
} catch (error) {
return false
}
}
return false
}