Skip to content

Commit 112207c

Browse files
committed
[INTERNAL] Enable stricter parsing of analyseLibraryJS
1 parent 26064a9 commit 112207c

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/lbt/analyzer/analyzeLibraryJS.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22
const {parseJS, Syntax, VisitorKeys} = require("../utils/parseUtils");
33
const {getPropertyKey, isMethodCall, isIdentifier, getStringArray} = require("../utils/ASTUtils");
4+
const log = require("@ui5/logger").getLogger("lbt:analyzer:LibraryJS");
45

56
const CALL__SAP_UI_GETCORE = ["sap", "ui", "getCore"];
67

@@ -39,7 +40,7 @@ async function analyze(resource) {
3940
} else if ( key === "elements" && value.type == Syntax.ArrayExpression ) {
4041
libInfo.elements = getStringArray(value, true);
4142
} else {
42-
// TODO: Maybe log an error/warning when unexpected properties are defined?
43+
log.error(`Unexpected property: '${key}' in sap.ui.getCore().initLibrary call`);
4344
}
4445
});
4546

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const test = require("ava");
2+
const sinon = require("sinon");
3+
const mock = require("mock-require");
4+
5+
function createMockResource(libraryJS) {
6+
return {
7+
async getBuffer() {
8+
return libraryJS;
9+
}
10+
};
11+
}
12+
13+
test("analyze: library.js with non supported property", (t) => {
14+
const libraryjs = `sap.ui.define([
15+
'sap/ui/core/Core',
16+
], function(Core) {
17+
18+
"use strict";
19+
20+
sap.ui.getCore().initLibrary({
21+
name : "library.test",
22+
customProperty: "UI5"
23+
});
24+
25+
return thisLib;
26+
27+
});`;
28+
29+
const logger = require("@ui5/logger");
30+
const errorLogStub = sinon.stub();
31+
const myLoggerInstance = {
32+
error: errorLogStub
33+
};
34+
sinon.stub(logger, "getLogger").returns(myLoggerInstance);
35+
const analyzeLibraryJSWithStubbedLogger = mock.reRequire("../../../../lib/lbt/analyzer/analyzeLibraryJS");
36+
37+
const mockResource = createMockResource(libraryjs);
38+
39+
analyzeLibraryJSWithStubbedLogger(mockResource);
40+
41+
t.is(errorLogStub.callCount, 1, "Error log is called once");
42+
});

0 commit comments

Comments
 (0)