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

[Fix #17612][V4] Throw explicit error when a nonexistent method is invoked #17616

Merged
merged 1 commit into from
Oct 2, 2015
Merged

[Fix #17612][V4] Throw explicit error when a nonexistent method is invoked #17616

merged 1 commit into from
Oct 2, 2015

Conversation

Johann-S
Copy link
Member

Hi

it's a fix for #17612

@@ -169,7 +169,7 @@
"prefer-const": 0,
"prefer-reflect": 0,
"prefer-spread": 2,
"prefer-template": 2,
"prefer-template": 0, // not replace content in string
Copy link
Member Author

Choose a reason for hiding this comment

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

I changed this line because template string not working with QUnit test, so all my test cases failed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Leave this at 2. I'll figure out how to exempt the tests from this particular ESLint rule.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we can use this in js files : /*eslint prefer-template: 0*/ so it would be ok
What do you think about this ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good

@Johann-S
Copy link
Member Author

Travis dislike my commit 😢

@cvrebert
Copy link
Collaborator

GitHub isn't showing it for some reason, but looks like the forced rebuild succeeded: https://travis-ci.org/twbs/bootstrap/jobs/80598464

@Johann-S
Copy link
Member Author

Oh that's it thank you

@cvrebert
Copy link
Collaborator

@Johann-S What failure did you encounter when you used template strings?

@Johann-S
Copy link
Member Author

When I ran my test case the template wasn't working.

In my JS src I wrote :
throw new Error('No method named "${config}"')

And in my test case I check
assert.strictEqual(err.message, 'No method named "noMethod"')

But err.message was equal to : No method named "${config}"
so the ${config} wasn't replaced by the value

for exemple :
bootstrap plugin test suite - google chrome

@cvrebert
Copy link
Collaborator

In my JS src I wrote :
throw new Error('No method named "${config}"')

Template strings are enclosed in backticks, not single quotes.
So it should be:
throw new Error(No method named "${config}")

@Johann-S
Copy link
Member Author

Thank you very much ! I wasn't aware of that.

I made a few changes : removed /*eslint prefer-template: 0*/ and using backsticks

build passed : https://travis-ci.org/twbs/bootstrap/builds/80774970

@cvrebert cvrebert added this to the v4.0.0-alpha.2 milestone Sep 17, 2015
@@ -390,10 +390,12 @@ const Carousel = (($) => {

if (typeof config === 'number') {
data.to(config)

} else if (action) {
} else if (typeof action === 'string') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why'd you change the condition here?

Copy link
Member Author

Choose a reason for hiding this comment

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

because action is always a string.

But if you prefer I can restore the old condition

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess it's okay.

@cvrebert
Copy link
Collaborator

Thanks for all the revising. I'll be happy to merge this once the undefined change is made.

@Johann-S
Copy link
Member Author

Thank you for your review and feedbacks you helped me a lot ! 👍

let method = data[config]
if (method === undefined) {
throw new Error(`No method named "${config}"`)
}
data[config](relatedTarget)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use method here instead of data[config]

@Johann-S
Copy link
Member Author

The problem is when I replace data[config] by method a lot of use cases failed.

For exemple if I change this in Tooltip file I have 43 tests failed with the same error message :
TypeError: Cannot read property 'constructor' of undefined

Because the this isn't a Tooltip object when I call a method with method() so this why I let
data[config]() because data is a Tooltip object.

Any thoughts about this @cvrebert ?
Maybe it's better to do this :

if (data[config] === undefined) {
    throw new Error(`No method named "${config}"`)
}
data[config]()

@cvrebert
Copy link
Collaborator

cvrebert commented Oct 1, 2015

Ah, right, JS doesn't hold onto this...
There wasn't much difference in the microbenchmark I tried (http://jsperf.com/call-vs-reget), so..

Maybe it's better to do this :

@Johann-S Yeah, do that.

@Johann-S
Copy link
Member Author

Johann-S commented Oct 2, 2015

Done !
I removed all let method because it's not relevant for just a condition and a method call.

cvrebert added a commit that referenced this pull request Oct 2, 2015
Fix #17612: Throw explicit error when a nonexistent method is invoked
@cvrebert cvrebert merged commit 10f6e97 into twbs:v4-dev Oct 2, 2015
@cvrebert
Copy link
Collaborator

cvrebert commented Oct 2, 2015

Thank you for your patience!

@Johann-S
Copy link
Member Author

Johann-S commented Oct 2, 2015

You're welcome and thank you for your help and feedbacks 👍

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.

2 participants