diff --git a/xml-namespace-loader.spec.ts b/xml-namespace-loader.spec.ts index d155ded1..80ab872f 100644 --- a/xml-namespace-loader.spec.ts +++ b/xml-namespace-loader.spec.ts @@ -20,13 +20,15 @@ interface TestSetup { expectedRegs: { name: string, path: string }[], ignore?: RegExp, assureNoDeps?: boolean, - expectError?: boolean + expectError?: boolean, + expectWarnings?: number } function getContext( done: DoneFn, - { resolveMap, expectedDeps, expectedRegs, assureNoDeps, ignore, expectError }: TestSetup) { + { resolveMap, expectedDeps, expectedRegs, assureNoDeps, ignore, expectError, expectWarnings }: TestSetup) { const actualDeps: string[] = []; + const actualWarnings: Error[] =[] let callbackCalled = false; const loaderContext = { @@ -50,6 +52,10 @@ function getContext( expect(source).not.toContain("global.registerModule"); } + if(expectWarnings){ + expect(actualWarnings.length).toEqual(expectWarnings); + } + if (error && !expectError) { done.fail(error) } else if (!error && expectError) { @@ -69,6 +75,9 @@ function getContext( addDependency: (dep: string) => { actualDeps.push(dep); }, + emitWarning: (err: Error) => { + actualWarnings.push(err); + }, query: { ignore } } @@ -277,4 +286,30 @@ describe("XmlNamespaceLoader", () => { xmlNsLoader.call(loaderContext, testXml); }) + + + it("with '&&', '||', '<=' and '>=' in binding expression, emits warnings, but does not fail", (done) => { + const resolveMap = { + "nativescript-ui-chart": "node_module/nativescript-ui-chart/ui-chart.js", + } + + const expectedDeps = []; + + const expectedRegs = [ + { name: "nativescript-ui-chart", path: "nativescript-ui-chart" }, + { name: "nativescript-ui-chart/RadCartesianChart", path: "nativescript-ui-chart" }, + ]; + + const testXml = ` + + + + + + `; + + const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs, expectWarnings: 1 }); + + xmlNsLoader.call(loaderContext, testXml); + }) }); diff --git a/xml-namespace-loader.ts b/xml-namespace-loader.ts index be9d8d4a..5c211537 100644 --- a/xml-namespace-loader.ts +++ b/xml-namespace-loader.ts @@ -103,8 +103,17 @@ const loader: loader.Loader = function (source: string, map) { saxParser.onopentag = (node: QualifiedTag) => { handleOpenTag(node.uri, node.local); }; saxParser.onerror = (err) => { + // Do only warning about invalid character "&"" for back-compatibility + // as it is common to use it in a binding expression + if (err && + err.message.indexOf("Invalid character") >= 0 && + err.message.indexOf("Char: &") >= 0) { + this.emitWarning(err) + } else { + callbackWrapper(err); + } + saxParser.error = null; - callbackWrapper(err); }; saxParser.write(source).close();