New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Property check for getDefaultActionAlias on node #20249
Conversation
cc\ @zhangsu |
src/service/action-impl.js
Outdated
@@ -914,7 +915,7 @@ function tokenizeMethodArguments(toks, assertToken, assertAction) { | |||
let args = null; | |||
// Object literal. Format: {...} | |||
if (peek.type == TokenType.OBJECT) { | |||
// Don't parse object literals. Tokenize as a single expression | |||
// Don't parse object literalands. Tokenize as a single expression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, reverted. thanks
src/service/action-impl.js
Outdated
@@ -748,9 +748,10 @@ function isActionWhitelisted_(invocation, whitelist) { | |||
const {method, node, tagOrTarget} = invocation; | |||
const tagOrTargetCalled = tagOrTarget.toLowerCase(); | |||
let methodCalled = method.toLowerCase(); | |||
const defaultActionAlias = node.getDefaultActionAlias(); | |||
const defaultActionAlias = (typeof node.getDefaultActionAlias == 'function') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be cleaner:
const {method, node, tagOrTarget} = invocation;
// Use alias if default action was invoked.
if (method === DEFAULT_ACTION && typeof node.getDefaultActionAlias === 'function') {
method = node.getDefaultActionAlias();
}
const lcMethod = method.toLowerCase();
const lcTagOrTarget = tagOrTarget.toLowerCase();
return whitelist.some(w => {
return (lcMethod === w.method.toLowerCase()
&& lcTagOrTarget === w.tagOrTarget.toLowerCase());
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. Thanks.
if (calledByDefaultActionAndHasDefaultAlias) { | ||
methodCalled = defaultActionAlias.toLowerCase(); | ||
let {method, node, tagOrTarget} = invocation; | ||
if (method === DEFAULT_ACTION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Add a comment above this conditional.
// Use alias if default action is invoked.
src/service/action-impl.js
Outdated
return whitelist.some(w => { | ||
return (w.tagOrTarget === '*' | ||
|| w.tagOrTarget.toLowerCase() === lcTagOrTarget) && | ||
(w.method.toLowerCase() === lcMethod); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot about *
target. In this case I'd deconstruct it for readability:
return whitelist.some(w => {
if (w.tagOrTarget.toLowerCase() === lcTagOrTarget || (w.tagOrTarget === '*')) {
if (w.method.toLowerCase() === lcMethod) {
return true;
}
}
return false;
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* check for method on node * !! to coerce string to bool to guard against empty string default alias * choumx comment * choumx comment * comment
Check that function 'getDefaultActionAlias' exists on node as the node can be document whereas the method will not exist.
b/122615607