Initial support for module: node12#44501
Closed
weswigham wants to merge 8 commits intomicrosoft:mainfrom
Closed
Conversation
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the basic framework for (compiler options and defaults) and core emit behavior for a new
module: node12andmodule: nodenextcompiler option. Both should be almost identical, for now.The core of this PR is allowing
.jsand.tsfiles to be interpreted as either esm or cjs format files, within the same compilation.import = requirestatements down to a helper-likecreateRequirecall, rather than error'ing and eliding them. (This gives easy access to syncrequirestatements as-needed for, eg, conditional top-level access to cjs dependencies)importcall expressions as-is, this way they can be used to pull in async (esm) dependencies within cjs-targeted files, and is otherwise normal cjs output..tsor.jsfile is determined by the enclosingpackage.jsonand itstypefield (if it is present and set tomodule,.tsand.jsfiles are esm format, otherwise they are cjs format).As far as checking goes, both options imply
esModuleInteropfor now (this only really affects default import checking and cjs module emit and may be subject to change when more checker behaviors are added later if they pickup the work this flag does). Additionally,module: node12implies amoduleResolution: node12andtarget: es2020, andmodule: nodenextimplies amoduleResolution: nodenextandtarget: esnext. The newmoduleResolutionmodes currently just redirect to the oldnoderesolution mode until they're actually implemented in another PR.Also included is a driveby fix for js declaration emit where
export {default} from "fs";in js was mistakenly serialized toexport {"fs" as default} from "fs";in a declaration file when"fs"is just a shorthand module declaration.