Uh oh!
There was an error while loading. Please reload this page.
Full support for CommonJS auto-imports in JS - #37027
Conversation
Uh oh!
There was an error while loading. Please reload this page.
| Equals, | ||
| ConstEquals | ||
| CommonJS, |
There was a problem hiding this comment.
This is the fundamental conceptual change in this file, and everything else is basically just implementation details. This enum used to represent final syntax; now it’s more a representation of where the symbol can be found in the module. Whether or not to use JS is then calculated and stored elsewhere, so that
CommonJScan meanimport foo = require('mod')orconst foo = require('mod')Namespacecan meanimport * as foo from 'mod'orconst foo = require('mod')Defaultcan meanimport foo from 'mod'orconst { default: foo } = require('mod')Namedcan meanimport { foo } from 'mod'orconst { foo } = require('mod')
sandersn
left a comment
There was a problem hiding this comment.
Looks pretty good to me, although I wasn't previously familiar with the importFixes code.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Fix typos Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
In #32684, I added the ability for auto-imports to write a
requirevariable declaration in JS files. However, it didn’t work for named or default exports, and under default project settings, would never be triggered from completions; it was only reachable by code fix. This is particularly problematic for JS, because unless the user has explicitly enabled type checking JS through VS Code settings, a tsconfig or jsconfig file, or// @ts-check, you can’t get code fixes because you don’t get errors.This PR removes those limitations, and also recognizes members of object literals assigned to
module.exportsas importable symbols.How do we choose between
importandrequirefor a JS file?Rules are evaluated in order (highest priority first).
import, add it there.require, add it there.import.require.import.require.How are
requirevariable declarations written for different kinds of exports?const { foo } = require('./foo')maps to named ES exports and CommonJS exported object literal members (module.exports = { foo }).const { default: foo } = require('./foo')maps to default ES exports (hopefully people aren’t actually doing this).const foo = require('./foo')maps to everything else.Fixes#20292
Fixes#30549
Related: