Skip to content

When using the for loop, there is an issue with parsing #757

@coderi521

Description

@coderi521
  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool?
  • Have you checked the docs for helpful APIs and examples?

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?

  • Yes
  • No

Bookmark this repository for further updates. Visit SoloThought to know about recent features.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions