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

cts, mts, cjs, mjs, etc extension support #67

Closed
wants to merge 9 commits into from

Conversation

weswigham
Copy link
Owner

This is my first followup to
microsoft#44501 which officially adds support for loading .mjs, .cjs, .mts, .cts, .d.mts, and .d.cts files. In non-node moduleResolution modes, these are largely the same as .js, .ts, and .d.ts - the only difference being the output path mappings - a .mts or .mjs input always makes a .mjs and .d.mts output, while a .cjs or .cts input always makes a .cjs and .d.cts output. In nodeish module resolution modes, c-prefixed files imply a commonjs emit format, while m-prefixed files imply an esm format. As we've discussed in design meetings, to avoid comitting to a direction, we also forbid ambiguous generic arrow functions and angle bracket type cast syntax in .cts and .mts files, so we can reserve the right to make these files parse as jsx in the future.

The watch/build mode baseline tests currently don't show any changes with edits, due to the bug fixed in microsoft#44935 - that'll need to get pulled in, and, once it is, the baseline updated.

Copy link
Collaborator

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial comments -- mostly questions about the new Extension[][] structure for supported extensions.

src/compiler/diagnosticMessages.json Outdated Show resolved Hide resolved
src/compiler/emitter.ts Show resolved Hide resolved
src/compiler/emitter.ts Outdated Show resolved Hide resolved
src/compiler/utilities.ts Outdated Show resolved Hide resolved
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: readonly FileExtensionInfo[]): readonly string[];
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: readonly FileExtensionInfo[]): readonly string[] {
const supportedTSExtensionsForExtractExtension: readonly Extension[] = [Extension.Dts, Extension.Dcts, Extension.Dmts, Extension.Cts, Extension.Mts, Extension.Ts, Extension.Tsx, Extension.Cts, Extension.Mts];
export const supportedJSExtensions: readonly Extension[][] = [[Extension.Js, Extension.Jsx], [Extension.Mjs], [Extension.Cjs]];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find where the non-flat version is used.

src/compiler/commandLineParser.ts Outdated Show resolved Hide resolved
src/compiler/commandLineParser.ts Show resolved Hide resolved
src/compiler/commandLineParser.ts Show resolved Hide resolved
src/compiler/commandLineParser.ts Outdated Show resolved Hide resolved
src/compiler/utilities.ts Outdated Show resolved Hide resolved
@DanielRosenwasser
Copy link

@typescript-bot pack this

@DanielRosenwasser
Copy link

D'oh.

@orta
Copy link

orta commented Sep 7, 2021

Might be worth making this a separate draft PR to TypeScript so we can get pack this working?

@weswigham
Copy link
Owner Author

microsoft#45774 should track this on the TS repo and be a place where you can run bot commands (versus usefully review code)

@@ -6742,58 +6750,63 @@ namespace ts {
}

/**
* List of supported extensions in order of file resolution precedence.
* Groups of supported extensions in order of file resolution precedence. (eg, TS > TSX > DTS and seperately, CTS > DCTS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Groups of supported extensions in order of file resolution precedence. (eg, TS > TSX > DTS and seperately, CTS > DCTS)
* Groups of supported extensions in order of file resolution precedence. (eg, TS > TSX > DTS and separately, CTS > DCTS)

@weswigham
Copy link
Owner Author

Merged in microsoft#45884

@weswigham weswigham closed this Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants