jsdom / webidl2js

Auto-generate JS class structures for Web IDL specifications
MIT License
79 stars 30 forks source link

Avoid useless `if`‑`else` check during fallback type conversion #232

Closed ExE-Boss closed 3 years ago

ExE-Boss commented 3 years ago

This makes it so that for fallback types (e.g. boolean and number), if it’s the last fallback type among overloads or in a union, then the conversion will no longer be duplicated in the if‑and‑else branches:

-} else if (typeof curArg === \\"boolean\\") {
-   {
-       let curArg = arguments[0];
-       curArg = conversions[\\"boolean\\"](curArg, {
-           context: \\"Failed to execute 'overloadsObjectOrBoolean' on 'NoUselessIfElse': parameter 1\\"
-       });
-       args.push(curArg);
-   }
 } else {
    {
        let curArg = arguments[0];
        curArg = conversions[\\"boolean\\"](curArg, {
            context: \\"Failed to execute 'overloadsObjectOrBoolean' on 'NoUselessIfElse': parameter 1\\"
        });
        args.push(curArg);
    }
 }

Depends on:

TimothyGu commented 3 years ago

I'd rather not do this, since it makes the code harder to maintain by diverging from the overload resolution algorithm in the spec.