1

There is a web online, library or something to detect old IE functions that are not compatible with Chrome/Firefox or just ES6?

Like: document.all, event.returnValue, etc

JsHint/Jslint are not detecting them as deprecated or incompatibles

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
spunka
  • 31
  • 5
  • 1
    But `document.all` is compatible with Firefox and Chrome.. It's non-standard but they've implemented it a long time ago to be compatible with IE (same with `.innerHTML` etc.) – slebetman Nov 12 '21 at 08:23
  • Are you looking for https://caniuse.com/? – Christopher Nov 12 '21 at 08:26
  • 1
    @slebetman They still should be considered deprecated as far as modern web development is concerned. Sure, they're included in the standard for compatibility reasons and are widely supported, but they still shouldn't be used. – Bergi Nov 12 '21 at 10:51
  • Open the page in chrome; sometimes if it warns you about deprecated features, apis and may be functions used on the page. – Salman A Nov 12 '21 at 10:55
  • [CanIUse.com](https://caniuse.com) is a good website for checking the compatibility of JS functions. You could also use the [MDN Web Docs](https://developer.mozilla.org/). – TheNightHawk Nov 12 '21 at 11:02
  • @SalmanA The problem is I have a bunch of old javascript files and the owners want to migrate them to Chrome (now are currently failing for some cases), so i wanted to avoid to make a tool to check them all and maybe there was a better way out there, just to copy the script and tell me what were the problems – spunka Nov 12 '21 at 11:25
  • 1
    Just open them in Chrome, press F12 and look at all the warnings/errors. – slebetman Nov 12 '21 at 11:30
  • @spunka You mention using jslint and jshint. Have you tried eslint? Also try TypeScript, it's very good at detecting deprecated properties, it'll even catch `const d = document; d.all.something` – Bergi Nov 12 '21 at 12:56
  • What about using [eslint-plugin-compat](https://github.com/amilajack/eslint-plugin-compat)? You can use `Browserlist` to configure the browsers you want to support. For more information, you can refer to [this answer](https://stackoverflow.com/questions/38257688/is-there-a-tool-for-detecting-browser-compatibility-issues-in-my-javascript-code/68526907#68526907). – Yu Zhou Nov 15 '21 at 09:49

1 Answers1

1

It's not quite fair to say JSLint won't tell you about deprecated properties. Let me explain.

Recall first that JavaScript is a dynamic language. You can assign any property to [almost] any object. You could assign all to window in a browser context if you wanted just by saying window.all = "Muahahaha!!! I'm evil!!!". You could add .all to a string with...

var spam = "a string";
spam.all = "I'm still evil!!!"

Or, worse, some piece of code could have changed the prototype for String (or any other object type) somewhere outside of your file. Try this in a browser console:

String.prototype.all = String.prototype.all || "This is beyond evil.";
// 'This is beyond evil.'
var spam = "spam"
// undefined
spam.all
// 'This is beyond evil.'

So JSLint doesn't, by default, check for properties on objects by names. Especially for objects that could live outside of your file's context (because JSLint lints file-by-file), it simply can't know what's happened to an object's properties and identify what's valid and what isn't.

(That's what TypeScript is for, btw.)

Unless you tell JSLint how!! -- the JSLint property directive ftw

Or you can use the JSLint property directive, which does exactly what you want, if you're willing to do some work.

If you put the property directive at the top of your file, JSLint will show errors for any properties that are used by objects on the page that aren't in that list.

For instance, try this on the official JSLint.com page:

/*property
    log
*/
/*jslint browser, devel */
function mySpam() {
    var spam = document.all;
    console.log(spam);
}

See how I'm using document.all but all isn't in the property directive? It's going to error for me.

1. Unregistered property name 'all'.
    var spam = document.all;

You might be saying, "But it will take me FOREVER to get all the good properties from my 3000 line file I'm linting into that directive!!"

Not so! Here's a tip: Paste your file, even unlinted, into JSLint.com. It will create a property directive for you in its report.

Here's one I made from AngularJS' [sic] route.js in just a few seconds:

/*property
    $$minErr, $evalAsync, $get, angularVersion, caseInsensitiveMatch, create,
    defaultPrevented, eagerInstantiationEnabled, extend, info, isArray,
    isDefined, isObject, isUndefined, length, module, noop, originalPath,
    otherwise, preventDefault, provider, redirectTo, reload, reloadOnSearch,
    reloadOnUrl, routes, run, substr, when
*/

Alphabetical, even.

Now just remove the ones you don't want and presto! You'll catch everything you need.

Is this a little tedious, and will it take a little massaging/training on files that use document properly? Yes, but, again, in a dynamic language, this is close to the best you can hope for with file-by-file linters.

NOTE: If this doesn't solve your issue, however imperfectly, that's when we need to see more of your files and hear more precisely what problem you're trying to solve in practice.

ruffin
  • 16,507
  • 9
  • 88
  • 138
  • Thanks for your time and the complete explanation! (and sorry my late reply) . I will try this option, i haven't got time yet, but it seems promising if i can make it work on a batch of files – spunka Nov 16 '21 at 10:02