Skip to content

Commit

Permalink
Update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Sep 1, 2020
1 parent 65404fe commit 4906f56
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
3 changes: 2 additions & 1 deletion lib/lbt/analyzer/SmartTemplateAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class TemplateComponentAnalyzer {
log.verbose("No manifest found for '%s', skipping analysis", resource.name);
}
} catch (err) {
log.error("an error occurred while analyzing template app %s (ignored)", resource.name, err.stack);
log.error("an error occurred while analyzing template app %s (ignored):", resource.name);
log.error(err.stack);
}

return info;
Expand Down
13 changes: 9 additions & 4 deletions lib/lbt/analyzer/XMLTemplateAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,21 @@ class XMLTemplateAnalyzer {
// represent an expression binding which needs to be evaluated before analysis
// e.g. "{= '{Handler: \'' + ${myActions > handlerModule} + '\'}'}"
if ((coreRequire.startsWith("{=") || coreRequire.startsWith("{:=")) && this.templateTag) {
log.verbose(`Ignoring core:require: Attribute of Node ${node.$ns.local} contains an expression binding and is within a 'template' Node`);
log.verbose(coreRequire);
log.verbose(
`Ignoring core:require: '%s' on Node %s:%s contains ` +
`an expression binding and is within a 'template' Node`,
coreRequire, node.$ns.uri, node.$ns.local
);
return;
}

try {
requireContext = JSTokenizer.parseJS(coreRequire);
} catch (e) {
log.error("Ignoring core:require: Attribute can't be parsed on Node %s", node.$ns.local);
log.error(coreRequire);
log.error(
"Ignoring core:require: '%s' can't be parsed on Node %s:%s",
coreRequire, node.$ns.uri, node.$ns.local
);
}
if ( requireContext ) {
Object.keys(requireContext).forEach((key) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ function rewriteDefine(targetBundleFormat, code, moduleName, avoidLazyParsing) {
try {
ast = esprima.parseScript(code.toString(), {loc: true});
} catch (e) {
log.error("error while parsing %s:%s", moduleName, e);
log.error("error while parsing %s: %s", moduleName, e.message);
return;
}

Expand Down
17 changes: 12 additions & 5 deletions lib/lbt/resources/ResourcePool.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@ async function determineDependencyInfo(resource, rawInfo, pool) {
const code = await resource.buffer();
info.size = code.length;
const promises = [];
let ast;
try {
const ast = esprima.parseScript(code.toString(), {comment: true});
jsAnalyzer.analyze(ast, resource.name, info);
new XMLCompositeAnalyzer(pool).analyze(ast, resource.name, info);
} catch (error) {
log.error("failed to parse or analyze %s:", resource.name, error.stack);
ast = esprima.parseScript(code.toString(), {comment: true});
} catch (err) {
log.error("failed to parse %s: %s", resource.name, err.message);
}
if (ast) {
try {
jsAnalyzer.analyze(ast, resource.name, info);
new XMLCompositeAnalyzer(pool).analyze(ast, resource.name, info);
} catch (error) {
log.error("failed to analyze %s: %s", resource.name, error.stack);
}
}
if ( rawInfo ) {
info.rawModule = true;
Expand Down
30 changes: 22 additions & 8 deletions test/lib/lbt/analyzer/XMLTemplateAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test.serial("integration: Analysis of an xml view with core:require from databin
</HBox>
<HBox>
<Button
core:require="{= '{Handler: \\'' + \${myActions > handlerModule} + '\\'}'}"
core:require="{= '{Handler: \\'' + \${myActions>handlerModule} + '\\'}'}"
id="myID"
text="{myAction>text}"
press="myMethod"
Expand All @@ -107,9 +107,13 @@ test.serial("integration: Analysis of an xml view with core:require from databin
t.true(moduleInfo.isImplicitDependency("sap/ui/core/mvc/XMLView.js"),
"Implicit dependency should be added since an XMLView is analyzed");

t.is(errorLogStub.callCount, 2, "should be called 2 times");
t.is(errorLogStub.getCall(0).args[0], "Ignoring core:require: Attribute can't be parsed on Node ", "first argument");
t.is(errorLogStub.getCall(0).args[1], "Button", "second argument");
t.is(errorLogStub.callCount, 1, "should be called 1 time");
t.deepEqual(errorLogStub.getCall(0).args, [
"Ignoring core:require: '%s' can't be parsed on Node %s:%s",
"{= '{Handler: \\'' + ${myActions>handlerModule} + '\\'}'}",
"sap.m",
"Button"
], "should be called with expected args");
});

test.serial("integration: Analysis of an xml view with core:require from databinding in template", async (t) => {
Expand Down Expand Up @@ -153,8 +157,13 @@ test.serial("integration: Analysis of an xml view with core:require from databin
t.true(moduleInfo.isImplicitDependency("sap/ui/core/mvc/XMLView.js"),
"Implicit dependency should be added since an XMLView is analyzed");

t.is(verboseLogStub.callCount, 2, "should be called 2 times");
t.is(verboseLogStub.getCall(0).args[0], "Ignoring core:require: Attribute of Node Button contains an expression binding and is within a 'template' Node", "first argument");
t.is(verboseLogStub.callCount, 1, "should be called 1 time");
t.deepEqual(verboseLogStub.getCall(0).args, [
"Ignoring core:require: '%s' on Node %s:%s contains an expression binding and is within a 'template' Node",
"{= '{Handler: \\'' + ${myActions > handlerModule} + '\\'}'}",
"sap.m",
"Button"
], "should be called with expected args");
});

test.serial("integration: Analysis of an xml view with core:require from expression binding in template", async (t) => {
Expand Down Expand Up @@ -194,8 +203,13 @@ test.serial("integration: Analysis of an xml view with core:require from express
t.true(moduleInfo.isImplicitDependency("sap/ui/core/mvc/XMLView.js"),
"Implicit dependency should be added since an XMLView is analyzed");

t.is(verboseLogStub.callCount, 2, "should be called 2 times");
t.is(verboseLogStub.getCall(0).args[0], "Ignoring core:require: Attribute of Node Button contains an expression binding and is within a 'template' Node", "first argument");
t.is(verboseLogStub.callCount, 1, "should be called 1 time");
t.deepEqual(verboseLogStub.getCall(0).args, [
"Ignoring core:require: '%s' on Node %s:%s contains an expression binding and is within a 'template' Node",
"{= 'foo': true}",
"sap.m",
"Button"
], "should be called with expected args");
});

test("integration: Analysis of an xml view with core:require", async (t) => {
Expand Down

0 comments on commit 4906f56

Please sign in to comment.