Skip to content

ReferenceError: attr is not defined / Javascript Strict needs variables in for loops defined #430

@aheissenberger

Description

@aheissenberger

Description

This only happens when the library is included in a Vitejs React project as the bundler will use strict for the bundled javascript code which does not allow a for (attr in attrMap) { without let.

Code

import { XMLParser, XMLBuilder } from "fast-xml-parser";

const xmlInput = `
<?xml version="1.0" encoding="UTF-8"?>
<TLLDATA>
</TLLDATA>
`
const options = {
    ignoreDeclaration: false,
    ignoreAttributes: false,
    processEntities: false,
    alwaysCreateTextNode: true,
    parseTagValue: false,
    preserveOrder: true,
};

const parser = new XMLParser(options);
const json = parser.parse(xmlInput);

const builder = new XMLBuilder({
    preserveOrder: true,
    ignoreAttributes: false,
    format: false,
});

const output = builder.build(json);
console.log(output)

Output

orderedJs2Xml.js:75 Uncaught ReferenceError: attr is not defined
    at attr_to_str (orderedJs2Xml.js:75:14)
    at arrToStr (orderedJs2Xml.js:43:28)
    at toXml (orderedJs2Xml.js:10:12)
    at Builder.build (json2xml.js:78:12)
    at FileReader.reader.onload (App.jsx:90:30)

Would you like to work on this issue?

  • Yes
  • No

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