-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add moduleDetection compiler flag to allow for changing how modules are parsed #47495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
f073cb6
53a409b
60f709b
9ad5610
6215541
9bd8c47
ccb851a
f9eb659
dcc86cc
e5c3dc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6211,12 +6211,13 @@ namespace ts { | |
* Unfortunately, there's no `NodeFlag` space to do the same for JSX. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should there be? (there might not be any NodeFlags left in any case) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This bails on the first JSX tag you find in a JSX tag, which is usually almost instantly, so.... probably not? Still, I think |
||
*/ | ||
function walkTreeForJSXTags(node: Node): Node | undefined { | ||
sandersn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!(node.transformFlags & TransformFlags.ContainsJsx)) return undefined; | ||
return isJsxOpeningLikeElement(node) || isJsxFragment(node) ? node : forEachChild(node, walkTreeForJSXTags); | ||
} | ||
|
||
function isFileModuleFromUsingJSXTag(file: SourceFile): Node | undefined { | ||
// Excludes declaration files - they still require an explicit `export {}` or the like | ||
// for back compat purposes. (not that declaration files should contian JSX tags!) | ||
// for back compat purposes. (not that declaration files should contain JSX tags!) | ||
return !file.isDeclarationFile ? walkTreeForJSXTags(file) : undefined; | ||
} | ||
|
||
|
@@ -6235,10 +6236,10 @@ namespace ts { | |
switch (getEmitModuleDetectionKind(options)) { | ||
case ModuleDetectionKind.Force: | ||
// All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule | ||
return (file: SourceFile) => void (file.externalModuleIndicator = !file.isDeclarationFile || isFileProbablyExternalModule(file)); | ||
return (file: SourceFile) => { file.externalModuleIndicator = !file.isDeclarationFile || isFileProbablyExternalModule(file); }; | ||
case ModuleDetectionKind.Legacy: | ||
// Files are modules if they have imports, exports, or import.meta | ||
return (file: SourceFile) => void (file.externalModuleIndicator = isFileProbablyExternalModule(file)); | ||
return (file: SourceFile) => { file.externalModuleIndicator = isFileProbablyExternalModule(file); }; | ||
case ModuleDetectionKind.Auto: | ||
// If module is nodenext or node12, all esm format files are modules | ||
// If jsx is react-jsx or react-jsxdev then jsx tags force module-ness | ||
|
Uh oh!
There was an error while loading. Please reload this page.