| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| const { module, allowSyntheticDefaultImports } = context.compilerOptions; | ||
|
|
||
| // Prefer to import as a synthetic `default` if available. | ||
| if (allowSyntheticDefaultImports || module === ModuleKind.System && allowSyntheticDefaultImports !== false) { |
There was a problem hiding this comment.
Add a function to src\core.ts to getAllowSyntheticDefaultImports(compilerOptions) that has this logic, and share it with the checker as well.
Sorry, something went wrong.
| Debug.fail("Either the symbol or the JSX namespace should be a UMD global if we got here"); | ||
| } | ||
|
|
||
| const { module, allowSyntheticDefaultImports } = context.compilerOptions; |
There was a problem hiding this comment.
consider moving compilerOptions to top destructuring declaration.
Sorry, something went wrong.
| } | ||
|
|
||
| // When a synthetic `default` is unavailable, use `import..require` if the module kind supports it. | ||
| if (module === ModuleKind.AMD || module === ModuleKind.CommonJS || module === ModuleKind.UMD) { |
There was a problem hiding this comment.
not sure i agree we need this change.
Sorry, something went wrong.
There was a problem hiding this comment.
The argument here is that if require is available, it is a reliable away to obtain module.exports even when it is callable. I am happy to remove this as requested but believe it is valuable.
Sorry, something went wrong.
There was a problem hiding this comment.
This change is actually what's causing the build failures because of expectations in the four slash tests.
Would you like me to remove the require changes? I'd be happy to open a separate issue for them.
Sorry, something went wrong.
|
For tests, take a look at tests/cases/fourslash/importNameCodeFixNewImportFileDetachedComments.ts |
Sorry, something went wrong.
- use default import under --allowSyntheticDefaultImports - import..require support - make make quick fix info match resulting import - make diagnostics
- extract test for synethetic default imports into getAllowSyntheticDefaultImports in core.ts - use getAllowSyntheticDefaultImports in checker.ts and importFixes.ts - move compilerOptions to top level destructuring
| const allowSyntheticDefaultImports = getAllowSyntheticDefaultImports(compilerOptions); | ||
|
|
||
| // Prefer to import as a synthetic `default` if available. | ||
| if (allowSyntheticDefaultImports) { |
There was a problem hiding this comment.
Wesley Wigham (@weswigham) this is another place for your new change in #19675 to be plugged in. we would like to always show the default import in this case and never fallback to import .. = require
Sorry, something went wrong.
There was a problem hiding this comment.
Roger. Thank you!
Sorry, something went wrong.
|
Aluan Haddad (@aluanhaddad) can you please address the test failures. |
Sorry, something went wrong.
|
I updated it to always uses the synthetic defaults for UMD modules unless --getAllowSyntheticDefaultImports(compilerOptions) returns false in which case it suggests a namespace import. This also resolves the test failures. |
Sorry, something went wrong.
|
thanks Aluan Haddad (@aluanhaddad)! Want to redo the import .. =require support for AMD/CommonJS/UMD? I think we should do that as well. |
Sorry, something went wrong.
|
Mohamed Hegazy (@mhegazy) I will create a PR for that shortly. |
Sorry, something went wrong.
|
thanks! |
Sorry, something went wrong.
| return parent as ImportDeclaration; | ||
| case SyntaxKind.ExternalModuleReference: | ||
| return (parent as ExternalModuleReference).parent; | ||
| case SyntaxKind.ImportEqualsDeclaration: |
There was a problem hiding this comment.
This will never be the parent of a LiteralExpression. Removing in #19667.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
As described in #17860, the import code fix for UMD modules has been updated such that it
Fixes #17860
I'm not sure how to go about writing unit tests for this.