Description
When using the for loop, there is an issue with parsing
Input
<script>
function test() {
for (let i = 0; i < 100000; i++) {
console.log(i)
}
}
</script>
Code
const { XMLParser, XMLBuilder } = require('fast-xml-parser')
const fs = require('fs')
const _XMLParser = new XMLParser({ ignoreAttributes: false })
const _builder = new XMLBuilder({
ignoreAttributes: false,
processEntities: false,
format: true,
})
/**
*
- @param {string} filePath
- @returns jsonObj xmlObject
/
const xmlCodeToAST = filePath => {
const fileContent = fs.readFileSync(filePath, 'utf8')
return _XMLParser.parse(fileContent)
}
/*
- @param {Object} xmlObj
- @returns xmlString
*/
const astToXmlCode = xmlObj => {
return _builder.build(xmlObj)
}
const ast = xmlCodeToAST('./test.mpx')
console.log(ast, 'ast')
const xml = astToXmlCode(ast)
console.log(xml, 'xml')
Output
{
script: { '': '', '#text': 'function test() {\n for (let i = 0; i' }
} ast
<script>
<>
function test() {
for (let i = 0; i</script>
xml
expected data
Would you like to work on this issue?
Bookmark this repository for further updates. Visit SoloThought to know about recent features.
Description
When using the for loop, there is an issue with parsing
Input
<script> function test() { for (let i = 0; i < 100000; i++) { console.log(i) } } </script>Code
const { XMLParser, XMLBuilder } = require('fast-xml-parser')
const fs = require('fs')
const _XMLParser = new XMLParser({ ignoreAttributes: false })
const _builder = new XMLBuilder({
ignoreAttributes: false,
processEntities: false,
format: true,
})
/**
*
/
const xmlCodeToAST = filePath => {
const fileContent = fs.readFileSync(filePath, 'utf8')
return _XMLParser.parse(fileContent)
}
/*
*/
const astToXmlCode = xmlObj => {
return _builder.build(xmlObj)
}
const ast = xmlCodeToAST('./test.mpx')
console.log(ast, 'ast')
const xml = astToXmlCode(ast)
console.log(xml, 'xml')
Output
{
<script> <> function test() { for (let i = 0; i</script>script: { '': '', '#text': 'function test() {\n for (let i = 0; i' }
} ast
xml
expected data
Would you like to work on this issue?
Bookmark this repository for further updates. Visit SoloThought to know about recent features.