Skip to content
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

API: make 'isExternalOrCommonJsModule' public #42990

Open
5 tasks done
ajafff opened this issue Feb 26, 2021 · 2 comments
Open
5 tasks done

API: make 'isExternalOrCommonJsModule' public #42990

ajafff opened this issue Feb 26, 2021 · 2 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@ajafff
Copy link
Contributor

ajafff commented Feb 26, 2021

Suggestion

πŸ” Search Terms

isExternalOrCommonJsModule, commonJsModuleIndicator

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Make the existing utility function ts.isExternalOrCommonJsModule public by moving it from utilities.ts to utilitiesPublic.ts

πŸ“ƒ Motivating Example

TypeScript treats commonJS modules similar to external modules. But currently there's no way for an API user to know whether TypeScript considers a file as commonJS module. SourceFile#commonJsModuleIndicator is not exposed in the public API and there's no ts.isCommonJsModule as pendant to ts.isExternalModule.

πŸ’» Use Cases

My current use case is to determine whether a file (or top-level declaration inside of it) contributes to the global scope. Currently I can only handle external modules, which doesn't match what TypeScript does internally.

@RyanCavanaugh
Copy link
Member

@sheetalkamat any concerns with doing this?

@sheetalkamat
Copy link
Member

Dont see any issue with exposing this method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants