Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFull support for CommonJS auto-imports in JS #37027
Merged
+561
−122
Conversation
| Equals, | ||
| ConstEquals | ||
| CommonJS, |
Comment on lines
-173
to
+177
This comment has been minimized.
This comment has been minimized.
andrewbranch
Feb 25, 2020
•
Author
Member
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')
|
Looks pretty good to me, although I wasn't previously familiar with the importFixes code. |
Fix typos Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
f9945f5
into
microsoft:master
8 checks passed
8 checks passed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.


andrewbranch commentedFeb 25, 2020
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: