Bug Tracker

Opened 13 years ago

Closed 13 years ago

#7866 closed enhancement (wontfix)

Conditional compilation with #if #else

Reported by: Aziz Owned by:
Priority: undecided Milestone: 1.6
Component: unfiled Version: git
Keywords: Cc:
Blocked by: Blocking:


There are a growing number of special hacks for various browsers inside jQuery. I estimate that most of the hacks are there to circumvent issues in the highly esteemed browser made by Microsoft.

Can we please get a mechanism or a way that allows us to exclude code that's completely unnecessary? Because I'm certain I'm not the only one who doesn't want to support IE in his (hobby) projects. That might not be an option to most developers, but it's reasonable to think that they at least would want to choose to disregard older versions of a browser (like IE6.)

Here's an example of what I'm talking about:

// Make sure leading/trailing whitespace is removed (IE can't handle it)
data = jQuery.trim( data );

The same with an if-directive:

// Make sure leading/trailing whitespace is removed (IE can't handle it)
//#if IE
data = jQuery.trim( data );

Now there only needs to be a tool that can parse these directives and produce a file according to the wishes of a user. The C preprocessor could do this, but we don't have to settle for that program or syntax. This job could easily be done by a JavaScript program (and it could accept "floats" in conditions like: #if IE >= 7.1)

Directives like these would clearly mark all the hacks and thereby improve the documentation. The normal comments already mention it when browsers need special handling, so why not do it in the form of directives to allow for customization? What's the harm?

Change History (1)

comment:1 Changed 13 years ago by snover

Resolution: wontfix
Status: newclosed

We’d all love to drop support for old versions of IE. However, there won’t be changes to the source to allow for preprocessing like that, reasons not the least of which being that it’d be a lot of work on our end for very little practical gain. You’ll maybe be able to reduce the size of the min+gz code by 5kB.

You could always use an AST and blow away trees that are conditionally triggered by a feature tests that you don’t want to allow. Since jQuery uses feature detection, not browser detection, that would be your best bet for removing that code.

Last edited 13 years ago by snover (previous) (diff)
Note: See TracTickets for help on using tickets.