From af075edf784d9f1ba162a34f0bf150dbcbc0f479 Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Wed, 9 Feb 2022 17:50:42 +0100 Subject: [PATCH] [FIX] XMLTemplateAnalyzer: Analyze core:require of FragmentDefinition The FragmentDefinition node should be skipped, but it may still contain a core:require definition. This is in line with the current runtime which also reads the require and loads the module. --- lib/lbt/analyzer/XMLTemplateAnalyzer.js | 3 ++- test/lib/lbt/analyzer/XMLTemplateAnalyzer.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/lbt/analyzer/XMLTemplateAnalyzer.js b/lib/lbt/analyzer/XMLTemplateAnalyzer.js index ce17f880e..e87dadcfb 100644 --- a/lib/lbt/analyzer/XMLTemplateAnalyzer.js +++ b/lib/lbt/analyzer/XMLTemplateAnalyzer.js @@ -231,9 +231,10 @@ class XMLTemplateAnalyzer { // looks like a UI5 library or package name const moduleName = ModuleName.fromUI5LegacyName( (namespace ? namespace + "." : "") + localName ); + this._analyzeCoreRequire(node); + // ignore FragmentDefinition (also skipped by runtime XMLTemplateProcessor) if ( FRAGMENTDEFINITION_MODULE !== moduleName ) { - this._analyzeCoreRequire(node); this.promises.push(this._analyzeModuleDependency(node, moduleName, this.conditional)); } } diff --git a/test/lib/lbt/analyzer/XMLTemplateAnalyzer.js b/test/lib/lbt/analyzer/XMLTemplateAnalyzer.js index 7019fa03f..1c9877cdc 100644 --- a/test/lib/lbt/analyzer/XMLTemplateAnalyzer.js +++ b/test/lib/lbt/analyzer/XMLTemplateAnalyzer.js @@ -326,6 +326,26 @@ test("integration: Analysis of an xml fragment", async (t) => { "Implicit dependency should be added since a fragment is analyzed"); }); +test("integration: Analysis of an xml fragment with core:require", async (t) => { + const xml = ` + + `; + + const moduleInfo = new ModuleInfo(); + + const analyzer = new XMLTemplateAnalyzer(fakeMockPool); + await analyzer.analyzeFragment(xml, moduleInfo); + t.deepEqual(moduleInfo.dependencies, + [ + "sap/ui/core/Fragment.js", + "sap/m/MessageToast.js" + ], "Dependencies should come from the XML template"); + t.true(moduleInfo.isImplicitDependency("sap/ui/core/Fragment.js"), + "Implicit dependency should be added since an XML Fragment is analyzed"); +}); + test("integration: Analysis of an empty xml view", async (t) => { const xml = "";