Skip to content
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

Merged
merged 6 commits into from Jan 11, 2019
Merged

Property check for getDefaultActionAlias on node #20249

merged 6 commits into from Jan 11, 2019

Conversation

alabiaga
Copy link
Contributor

@alabiaga alabiaga commented Jan 10, 2019

Check that function 'getDefaultActionAlias' exists on node as the node can be document whereas the method will not exist.

b/122615607

@alabiaga
Copy link
Contributor Author

cc\ @zhangsu

@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, reverted. thanks

@@ -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')

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());
});

Copy link
Contributor Author

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

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.

return whitelist.some(w => {
return (w.tagOrTarget === '*'
|| w.tagOrTarget.toLowerCase() === lcTagOrTarget) &&
(w.method.toLowerCase() === lcMethod);

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;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@alabiaga alabiaga merged commit eb331c4 into ampproject:master Jan 11, 2019
@alabiaga alabiaga deleted the b122615607 branch January 11, 2019 22:14
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
* check for method on node

* !! to coerce string to bool to guard against empty string default alias

* choumx comment

* choumx comment

* comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants