Skip to content

Commit 83d8406

Browse files
committed
[INTERNAL] analyzeLibraryJS: Ignoring SpreadElements in library.js
1 parent cec4be1 commit 83d8406

File tree

2 files changed

+85
-40
lines changed

2 files changed

+85
-40
lines changed

lib/lbt/analyzer/analyzeLibraryJS.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ async function analyze(resource) {
2626
node.arguments.length === 1 &&
2727
node.arguments[0].type === Syntax.ObjectExpression ) {
2828
node.arguments[0].properties.forEach( (prop) => {
29+
if (prop.type === Syntax.SpreadElement) {
30+
// TODO: Support interpreting SpreadElements
31+
return;
32+
}
33+
2934
const key = getPropertyKey(prop);
3035
const value = prop.value;
36+
3137
if ( key === "noLibraryCSS" &&
3238
(value.type === Syntax.Literal && typeof value.value === "boolean") ) {
3339
libInfo.noLibraryCSS = value.value;

test/lib/lbt/analyzer/analyzeLibraryJS.js

Lines changed: 79 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,49 @@ function createMockResource(content, path) {
1313
};
1414
}
1515

16-
test("analyze: library.js with non supported property", async (t) => {
17-
const libraryJS = `sap.ui.define([
18-
'sap/ui/core/Core',
19-
], function(Core) {
20-
21-
"use strict";
22-
23-
sap.ui.getCore().initLibrary({
24-
name : "library.test",
25-
version: "1.0.0",
26-
customProperty1: "UI5",
27-
dependencies : ["sap.ui.core"],
28-
types: [
29-
"library.test.ButtonType",
30-
"library.test.DialogType",
31-
],
32-
interfaces: [
33-
"library.test.IContent",
34-
],
35-
controls: [
36-
"library.test.Button",
37-
"library.test.CheckBox",
38-
"library.test.Dialog",
39-
"library.test.Input",
40-
"library.test.Label",
41-
"library.test.Link",
42-
"library.test.Menu",
43-
"library.test.Text"
44-
],
45-
elements: [
46-
"library.test.MenuItem"
47-
],
48-
extensions: {
49-
customExtension: "UI5"
50-
},
51-
customProperty2: "UI5"
52-
});
53-
54-
return thisLib;
16+
test.afterEach.always((t) => {
17+
mock.stopAll();
18+
sinon.restore();
19+
});
5520

56-
});`;
21+
test.serial("analyze: library.js with non supported property", async (t) => {
22+
const libraryJS = `
23+
sap.ui.define([
24+
'sap/ui/core/Core',
25+
], function(Core) {
26+
"use strict";
27+
sap.ui.getCore().initLibrary({
28+
name : "library.test",
29+
version: "1.0.0",
30+
customProperty1: "UI5",
31+
dependencies : ["sap.ui.core"],
32+
types: [
33+
"library.test.ButtonType",
34+
"library.test.DialogType",
35+
],
36+
interfaces: [
37+
"library.test.IContent",
38+
],
39+
controls: [
40+
"library.test.Button",
41+
"library.test.CheckBox",
42+
"library.test.Dialog",
43+
"library.test.Input",
44+
"library.test.Label",
45+
"library.test.Link",
46+
"library.test.Menu",
47+
"library.test.Text"
48+
],
49+
elements: [
50+
"library.test.MenuItem"
51+
],
52+
extensions: {
53+
customExtension: "UI5"
54+
},
55+
customProperty2: "UI5"
56+
});
57+
return thisLib;
58+
});`;
5759

5860
const librayJSPath = "library/test/library.js";
5961
const logger = require("@ui5/logger");
@@ -76,3 +78,40 @@ test("analyze: library.js with non supported property", async (t) => {
7678
"Unexpected property: 'customProperty2' in sap.ui.getCore().initLibrary call in 'library/test/library.js'",
7779
"The error log message of the first call is correct");
7880
});
81+
82+
83+
test.serial("analyze: library.js with SpreadExpression", async (t) => {
84+
const libraryJS = `
85+
sap.ui.define([
86+
'sap/ui/core/Core',
87+
], function(Core) {
88+
"use strict";
89+
const myExtensions = {myProperty1: "Value1", myProperty2: "Value2"};
90+
sap.ui.getCore().initLibrary({
91+
...myExtensions,
92+
name : "library.test",
93+
version: "1.0.0",
94+
elements: [
95+
"library.test.MenuItem"
96+
],
97+
});
98+
return thisLib;
99+
});`;
100+
101+
const librayJSPath = "library/test/library.js";
102+
const logger = require("@ui5/logger");
103+
const errorLogStub = sinon.stub();
104+
const myLoggerInstance = {
105+
error: errorLogStub
106+
};
107+
sinon.stub(logger, "getLogger").returns(myLoggerInstance);
108+
const analyzeLibraryJSWithStubbedLogger = mock.reRequire("../../../../lib/lbt/analyzer/analyzeLibraryJS");
109+
110+
const mockResource = createMockResource(libraryJS, librayJSPath);
111+
112+
const result = await analyzeLibraryJSWithStubbedLogger(mockResource);
113+
114+
t.is(errorLogStub.callCount, 0, "Error log is not called");
115+
t.is(result.elements[0], "library.test.MenuItem", "The libraryjs is correctly analyzed");
116+
});
117+

0 commit comments

Comments
 (0)