Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat($compile): added new method strictComponentBindingsEnabled #16129

Closed
wants to merge 1 commit into from

Conversation

ZitaNemeckova
Copy link
Contributor

@ZitaNemeckova ZitaNemeckova commented Jul 25, 2017

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Add method strictComponentBindingsEnabled to $compile.

What is the current behavior? (You can also link to an open issue here)
Closes #16126

What is the new behavior (if this is a feature change)?
If enabled, the compiler will enforce that for all bindings of a component that are not set as optional with ?, an attribute needs to be provided on the component's HTML tag. Default value is false.

Does this PR introduce a breaking change?
Nope.

Please check if the PR fulfills these requirements

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

This looks promising 😃 Thx!
We need some tests though.

@fullName Missing required attribute
@description

This error may occur only when `$compileProvider.strictComponentBindingsEnabled` is set to `true`.han all attributes without `?` must be set. If one or more aren't set than first one will throw an error.
Copy link
Member

Choose a reason for hiding this comment

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

There are some typos in this sentence. Can you also limit lines to 100 chars max.

@@ -3526,6 +3570,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
break;

case '&':
if (!hasOwnProperty.call(attrs, attrName) && !optional && strictComponentBindingsEnabled) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Check the booleans first to avoid unnecessary method calls. E.g.:

if (strictComponentBindingsEnabled && !optional && !hasOwnProperty.call(attrs, attrName)) {...

@@ -3526,6 +3570,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
break;

case '&':
if (!hasOwnProperty.call(attrs, attrName) && !optional && strictComponentBindingsEnabled) {
throw $compileMinErr('missingattr',
Copy link
Member

Choose a reason for hiding this comment

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

I would consider encapsulating this into a function or something, to avoid repeating it 4 times.

@ZitaNemeckova
Copy link
Contributor Author

@gkalpak Thanks for review :) issues resolved and some tests added :)

@ZitaNemeckova ZitaNemeckova changed the title WIP: feat($compile): added new method strictComponentBindingsEnabled feat($compile): added new method strictComponentBindingsEnabled Jul 25, 2017
Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

Thx for the updates. Left a couple more comments.

The tests look good. We need some more 😃
E.g. that optional bindings do not throw even if strictComponentBindingsEnabled is true.

'<div prototype-method-name-as-scope-var-a></div>'
)($rootScope);
};
expect(func).toThrowMinErr('$compile', 'missingattr', 'Attribute \'valueOf\' of \'prototypeMethodNameAsScopeVarA\' is non-optional and must be set!');
Copy link
Member

Choose a reason for hiding this comment

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

Please, limit all lines to 100 chars.

});
});

it('should throw an error for undefined non-optional "&" bindings when strictComponentBindingsEnabled is true', function() {
Copy link
Member

Choose a reason for hiding this comment

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

Same description as above 😕

@jeserkin
Copy link

jeserkin commented Jul 26, 2017

Can't wait to try this out 😄

@ZitaNemeckova ZitaNemeckova force-pushed the required_attr branch 2 times, most recently from 6053c8d to a685440 Compare July 26, 2017 11:12
@ZitaNemeckova
Copy link
Contributor Author

@gkalpak Thanks for review :) All issues resolved and more tests added :)

template: '<span></span>'
};
});
directive('optionalBindingsVarA', function() {
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't you use the constructor optional binding of prototypeMethodAsScopeVar<X>?

'missingattr',
'Attribute \'valueOf\' of \'prototypeMethodNameAs' +
'ScopeVarA\' is non-optional and must be set!');
});
Copy link
Member

Choose a reason for hiding this comment

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

Please, also verify that it doesn't fail when the attribute is present.

});
});

it('should handle "=" undefined optional bindings when strictComponentBindingsEnabled is true',
Copy link
Member

Choose a reason for hiding this comment

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

Change these descriptions to "should not throw an error for undefined optional "=" bindings when strictComponentBindingsEnabled is true".

});
});

it('should throw an error for undefined non-optional ">" bindings when ' +
Copy link
Member

Choose a reason for hiding this comment

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

Change > to < (here and below) 😃

@ZitaNemeckova
Copy link
Contributor Author

@gkalpak Again thanks for review :) All issues resolved and some more tests added :D

@jeserkin
Copy link

@ZitaNemeckova you haven't pushed latest changes yet, right?

@ZitaNemeckova
Copy link
Contributor Author

@jeserkin I did. Did I miss something from review?

@jeserkin
Copy link

I see only changes from 2 days ago. I might be looking in the wrong place though.

@Narretz
Copy link
Contributor

Narretz commented Jul 27, 2017

When you amend a commit and force push it, the original commit date is kept. Is that why you think the changes are from 2 days ago?
The code has definitely changed, as is visible from the fact that not all of @gkalpak notes are not shown (because the lines have changed)

@jeserkin
Copy link

@Narretz correct. Have to start using github more often 😄

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

LGTM

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

Successfully merging this pull request may close these issues.

Introduce a way for a component to require an attribute
6 participants