e53f19f8f2
* Always issue cannot find name did-you-mean error This PR issues "cannot find ${name}, did you mean ${name}" errors for identifiers and propery access expressions in JS files *without* `// @ts-check` and without `// @ts-nocheck`. This brings some benefits of Typescript's binder to all Javascript users, even those who haven't opted into Typescript checking. ```js export var inModule = 1 inmodule.toFixed() // errors on exports function f() { var locals = 2 locale.toFixed() // errors on locals } var object = { spaaace: 3 } object.spaaaace // error on read object.spaace = 2 // error on write object.fresh = 12 // OK, no spelling correction to offer ``` To disable the errors, add `// @ts-nocheck` to the file. To get the normal checkJs experience, add `// @ts-check`. == Why This Works == In a word: precision. This change has low recall — it misses lots of correct errors that would be nice to show — but it has high precision: almost all the errors it shows are correct. And they come with a suggested correction. Here are the ingredients: 1. For unchecked JS files, the compiler suppresses all errors except two did-you-mean name resolution errors. 2. Did-you-mean spelling correction is already tuned for high precision/low recall, and doesn't show many bogus errors even in JS. 3. For identifiers, the error is suppressed for suggestions from global files. These are often DOM feature detection, for example. 4. For property accesses, the error is suppressed for suggestions from other files, for the same reason. 5. For property accesses, the error is suppressed for `this` property accesses because the compiler doesn't understand JS constructor functions well enough. In particular, it doesn't understand any inheritance patterns. == Work Remaining == 1. Code cleanup. 2. Fix a couple of failures in existing tests. 3. Suppress errors on property access suggestions from large objects. 4. Combine (3) and (4) above to suppress errors on suggestions from other, global files. 5. A little more testing on random files to make sure that precision is good there too. 6. Have people from the regular Code editor meeting test the code and suggest ideas. * all (most?) tests pass * NOW they all pass * add tonnes of semi-colons * restore this.x check+add a test case * make ts-ignore/no-check codefix work in unchecked js * Issues errors only in the language service * add a few more tests * fix incorrect parentheses * More cleanup in program.ts * Improve readability of isExcludedJSError * make diff in program.ts smaller via closure * Switch unchecked JS did-you-mean to suggestion Instead of selectively letting errors through. * undo more missed changes * disallow ignoring suggestions * Issue different messages for plain JS than others Straw text for the messages, I just changed the modals to avoid name collisions.
58 lines
777 B
Plaintext
58 lines
777 B
Plaintext
=== /a.js ===
|
|
class A {
|
|
>A : A
|
|
|
|
get arguments() {
|
|
>arguments : { bar: {}; }
|
|
|
|
return { bar: {} };
|
|
>{ bar: {} } : { bar: {}; }
|
|
>bar : {}
|
|
>{} : {}
|
|
}
|
|
}
|
|
|
|
class B extends A {
|
|
>B : B
|
|
>A : A
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param {object} [foo={}]
|
|
*/
|
|
constructor(foo = {}) {
|
|
>foo : any
|
|
>{} : {}
|
|
|
|
super();
|
|
>super() : void
|
|
>super : typeof A
|
|
|
|
/**
|
|
* @type object
|
|
*/
|
|
this.foo = foo;
|
|
>this.foo = foo : any
|
|
>this.foo : any
|
|
>this : this
|
|
>foo : any
|
|
>foo : any
|
|
|
|
/**
|
|
* @type object
|
|
*/
|
|
this.bar = super.arguments.foo;
|
|
>this.bar = super.arguments.foo : error
|
|
>this.bar : any
|
|
>this : this
|
|
>bar : any
|
|
>super.arguments.foo : error
|
|
>super.arguments : { bar: {}; }
|
|
>super : A
|
|
>arguments : { bar: {}; }
|
|
>foo : any
|
|
}
|
|
}
|
|
|