Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple usage documentation refers to nonexistent export #6

Open
scott-ln opened this issue Mar 10, 2020 · 2 comments
Open

Simple usage documentation refers to nonexistent export #6

scott-ln opened this issue Mar 10, 2020 · 2 comments

Comments

@scott-ln
Copy link

The simple usage documentation specifies the following:

import { DOMImplementationImpl, DOMParserImpl, XMLSerializerImpl } from 'xmldom-ts'
import { install, xsltProcess, xmlParse } from 'xslt-ts'

This results in the error:

file:///C:/Users/scott/code/xslt/test.mjs:2
import { install, xsltProcess, xmlParse } from 'xslt-ts'
         ^^^^^^^
SyntaxError: The requested module 'xslt-ts' does not provide an export named 'install'

This is a brand new project where I've done nothing but install xslt-ts and xmldom-ts and try to run the example code on a string of XML.

@PachiSystems
Copy link

xmlParse, also.

@RovoMe
Copy link

RovoMe commented Nov 18, 2024

Seeing that the last commit on this project was more than 3 years ago and even xmldom-ts, which is maintained by the same guy, and is used as dependency on this project received the last update 2 years ago, I think this project is more or less dead or at least unmaintained further.

xmlParase i.e. can be found within test/utils.ts which though is not exported. So an import of

import { xmlParse } from 'xslt-ts/test/utils';

should do the trick here. The import of the install(...) function worked on my end actually.

However, depending on which library you've installed alongside xslt-ts you will see different issues down the road. I.e. with xmldom-ts you will see different, mostly compile-time, errors than when you use xmldom and the @types/xmldom typescript types. @xmldom/xmldom is the actual successor of the xmldom project and is the one that seems to be maintained now. It seems to be incompatible with xslt-ts though.

This whole dependency chain looks extremely messy IMO. Granted, I'm not a regular JS/TS developer but I'm really wondering whether serious XML/XSLT processing is actually done in that stack. I.e. if I replace the DOMParser to use the one from @xmldom/xmldom and I try to generate a Document via the parseFromString(doc, mimeType) method, the Document object returned here misses roughly 190+ properties like URL, anchors and so forth.

xmldom-ts

Given dependency imports of

  • xmldom-ts: 0.3.1
  • xpath-ts: 1.3.13
  • xslt-ts: 1.1.8
  • he: 1.2.0
  • @types/he: 1.2.3

for a code excerpt that looks like this:

import { DOMParserImpl, XMLSerializerImpl, DOMImplementationImpl } from 'xmldom-ts';
import { install, xsltProcess, getParser } from 'xslt-ts';
import { XSLTProcessorImpl } from 'xslt-ts/types/xslt-processor';
import { xmlParse } from 'xslt-ts/test/utils';

install(new DOMParserImpl(), new XMLSerializerImpl(), new DOMImplementationImpl());

...
const parser = getParser();
const xsltDoc = parser.parseFromString(xsltString, 'text/xml');
// or
const xsltDoc = xmlParse(xsltString);

const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
// or
const xmlDoc = xmlParse(xmlString);

const outXmlString = xsltProcess(xmlDoc, xsltDoc);
console.log(`Out XML: {outXmlString}`);


const processor = new XSLTprocessorImpl();
processor.importStylesheet(xsltDoc);

This will compile but when executed will produce the following errors:

node_modules/xslt-ts/src/install.ts:1:11 - error TS2304: Cannot find name 'DOMImplementation'.

1 let _dom: DOMImplementation;
            ~~~~~~~~~~~~~~~~~

node_modules/xslt-ts/src/install.ts:2:14 - error TS2304: Cannot find name 'DOMParser'.

2 let _parser: DOMParser;
               ~~~~~~~~~

node_modules/xslt-ts/src/install.ts:3:18 - error TS2304: Cannot find name 'XMLSerializer'.

3 let _serializer: XMLSerializer;
                   ~~~~~~~~~~~~~

node_modules/xslt-ts/src/install.ts:29:33 - error TS2304: Cannot find name 'DOMParser'.

29 export function install(parser: DOMParser, serializer: XMLSerializer, dom: DOMImplementation) {
                                   ~~~~~~~~~

node_modules/xslt-ts/src/install.ts:29:56 - error TS2304: Cannot find name 'XMLSerializer'.

29 export function install(parser: DOMParser, serializer: XMLSerializer, dom: DOMImplementation) {
                                                          ~~~~~~~~~~~~~

node_modules/xslt-ts/src/install.ts:29:76 - error TS2304: Cannot find name 'DOMImplementation'.

29 export function install(parser: DOMParser, serializer: XMLSerializer, dom: DOMImplementation) {
                                                                              ~~~~~~~~~~~~~~~~~


Found 6 errors in the same file, starting at: node_modules/xslt-ts/src/install.ts:1

xmldom

On removing xmldom-ts and replacing it with

  • xmldom: 0.6.0
  • @types/xmldom: 0.1.34

and modifying th code to look like

...
import { DOMParser, XMLSerializer, DOMImplementation } from 'xmldom';
import { install, xsltProcess, getParser } from 'xslt-ts';
...

install(new DOMParser(), new XMLSerializer(), new DOMImplementation());

function runXSLT(): void {
  ...
  try {
    const parser = getParser();
    const xsltDoc = parser.parseFromString(xsltString, 'text/xml');
    console.log(xsltDoc);
    const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
    console.log(xmlDoc);

    const outXmlString = xsltProcess(xmlDoc, xsltDoc);
    console.log(outXmlString);
  } catch (err) {
    console.error(err);
  }
}

runXSLT();

the TS files compiles and at least runs the XSLT processor. Note however, that the import and usage of xmlParse(...) did not work in this case on my end as it complaint about a missing parser implementation then.

When trying to add

import { ..., XSLTProcessor } from 'xslt-ts';
...
const processor = new XSLTProcessor();
processor.importStylesheet(xsltDoc);
const output = processor.transformToDocument(xmlDoc);
...

back in compilation fails however due to

node_modules/xslt-ts/src/xslt.ts:66:31 - error TS2345: Argument of type 'XPathResultImpl' is not assignable to parameter of type 'XPathResult'.
  Types of property 'ANY_TYPE' are incompatible.
    Type 'number' is not assignable to type '0'.

66           nodes = gatherNodes(input.eval(select));
                                 ~~~~~~~~~~~~~~~~~~

node_modules/xslt-ts/src/xslt.ts:148:29 - error TS2345: Argument of type 'XPathResultImpl' is not assignable to parameter of type 'XPathResult'.
  Types of property 'ANY_TYPE' are incompatible.
    Type 'number' is not assignable to type '0'.

148         if (isResultNodeSet(value)) {
                                ~~~~~

node_modules/xslt-ts/src/xslt.ts:149:37 - error TS2345: Argument of type 'XPathResultImpl' is not assignable to parameter of type 'XPathResult'.
  Types of property 'ANY_TYPE' are incompatible.
    Type 'number' is not assignable to type '0'.

149           const nodes = gatherNodes(value);
                                        ~~~~~

node_modules/xslt-ts/src/xslt.ts:330:27 - error TS2345: Argument of type 'XPathResultImpl' is not assignable to parameter of type 'XPathResult'.
  Types of property 'ANY_TYPE' are incompatible.
    Type 'number' is not assignable to type '0'.

330     value = convertResult(input.eval(select));
                              ~~~~~~~~~~~~~~~~~~

node_modules/xslt-ts/src/xslt.ts:364:29 - error TS2345: Argument of type 'XPathResultImpl' is not assignable to parameter of type 'XPathResult'.
  Types of property 'ANY_TYPE' are incompatible.
    Type 'number' is not assignable to type '0'.

364   const nodes = gatherNodes(input.eval(select));
                                ~~~~~~~~~~~~~~~~~~

node_modules/xslt-ts/src/xslt.ts:582:32 - error TS2345: Argument of type 'XPathResultImpl' is not assignable to parameter of type 'XPathResult'.
  Types of property 'ANY_TYPE' are incompatible.
    Type 'number' is not assignable to type '0'.

582     const result = gatherNodes(cloned.eval(match));
                                   ~~~~~~~~~~~~~~~~~~


Found 6 errors in the same file, starting at: node_modules/xslt-ts/src/xslt.ts:66

While I'm not an expert on this matter, the issue seems to be within xpath-result-impl and assigning the constants to readonly fields which my lib.dom.ts privided in newer VSCode environments ship with defines. If I just change the typescript dependency version from 3.5.1 to 5.3.2 i.e. I get the same errors on the xslt-ts project when attempting to build it locally via npm run build. I'm therefore pretty sure that typescript changed that interface along the way which is now imcompatible to older versions as used by the rather unmaintained xslt-ts and xpath-ts projects. This is probably what is mentioned in Typescript 5.0 changelog in regards to converting numbers to numeric literal types. When I replace typescript 5.x with the latest 4 release, 4.9.5 to be more particular, then also the xpath/xslt processing seems to work.

This and xmldom-ts as well as xpath-ts could really need an update to coop with more recent typescript versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants