-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($compile): added new method strictComponentBindingsEnabled #16129
Conversation
4323a99
to
e34cb82
Compare
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.
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. |
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.
There are some typos in this sentence. Can you also limit lines to 100 chars max.
src/ng/compile.js
Outdated
@@ -3526,6 +3570,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |||
break; | |||
|
|||
case '&': | |||
if (!hasOwnProperty.call(attrs, attrName) && !optional && strictComponentBindingsEnabled) { |
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.
Nit: Check the booleans first to avoid unnecessary method calls. E.g.:
if (strictComponentBindingsEnabled && !optional && !hasOwnProperty.call(attrs, attrName)) {...
src/ng/compile.js
Outdated
@@ -3526,6 +3570,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |||
break; | |||
|
|||
case '&': | |||
if (!hasOwnProperty.call(attrs, attrName) && !optional && strictComponentBindingsEnabled) { | |||
throw $compileMinErr('missingattr', |
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 would consider encapsulating this into a function or something, to avoid repeating it 4 times.
f6d7010
to
905a4ff
Compare
@gkalpak Thanks for review :) issues resolved and some tests added :) |
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.
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.
test/ng/compileSpec.js
Outdated
'<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!'); |
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.
Please, limit all lines to 100 chars.
test/ng/compileSpec.js
Outdated
}); | ||
}); | ||
|
||
it('should throw an error for undefined non-optional "&" bindings when strictComponentBindingsEnabled is true', 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.
Same description as above 😕
905a4ff
to
9ce340a
Compare
Can't wait to try this out 😄 |
6053c8d
to
a685440
Compare
@gkalpak Thanks for review :) All issues resolved and more tests added :) |
test/ng/compileSpec.js
Outdated
template: '<span></span>' | ||
}; | ||
}); | ||
directive('optionalBindingsVarA', 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.
Couldn't you use the constructor
optional binding of prototypeMethodAsScopeVar<X>
?
'missingattr', | ||
'Attribute \'valueOf\' of \'prototypeMethodNameAs' + | ||
'ScopeVarA\' is non-optional and must be set!'); | ||
}); |
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.
Please, also verify that it doesn't fail when the attribute is present.
test/ng/compileSpec.js
Outdated
}); | ||
}); | ||
|
||
it('should handle "=" undefined optional bindings when strictComponentBindingsEnabled is true', |
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.
Change these descriptions to "should not throw an error for undefined optional "=" bindings when strictComponentBindingsEnabled is true"
.
test/ng/compileSpec.js
Outdated
}); | ||
}); | ||
|
||
it('should throw an error for undefined non-optional ">" bindings when ' + |
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.
Change >
to <
(here and below) 😃
a685440
to
6a33834
Compare
@gkalpak Again thanks for review :) All issues resolved and some more tests added :D |
@ZitaNemeckova you haven't pushed latest changes yet, right? |
@jeserkin I did. Did I miss something from review? |
I see only changes from 2 days ago. I might be looking in the wrong place though. |
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? |
@Narretz correct. Have to start using github more often 😄 |
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.
LGTM
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