microsoft / microsoft/TypeScript

API: make 'isExternalOrCommonJsModule' public

Open
#42,990 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading isExternalOrCommonJsModule in utilities.ts and the public exports in utilitiesPublic.ts. Check how related public utilities such as isExternalModule are exposed and run the relevant compiler API tests; done means the utility is publicly available without changing existing runtime behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.