Skip to content

Feature request: customize removal of extension on es6 imports to better support TypeScript/deno environments #6003

Closed
@chrisirhc

Description

@chrisirhc

Looks like gentype only supports .bs.js extension but then proceeds to remove the .js in the import statements.
Examples missing extension:
https://github.com/rescript-lang/rescript-compiler/blob/457aeff9948c40fee5fc47df6e431152bd65d869/jscomp/gentype_tests/typescript-react-example/src/JSXV4.gen.tsx#L5

This behavior relies on non-standard import behavior. According to MDN ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#module-name ) ,

The module to import from. The evaluation of the specifier is host-specified. This is often a relative or absolute URL to the .js file containing the module. In Node, extension-less imports often refer to packages in node_modules. Certain bundlers may permit importing files without extensions; check your environment. Only single quoted and double quoted Strings are allowed.

If the .js isn't removed, the TS code and JS code could be compatible with Deno and potentially other bundlers/environments.

Looks like this behavior is also present in the main compiler and on every .bs.js file. Wonder if the community would consider this change interesting/useful to open up to more environments perhaps like Deno or Bun etc.

Related to #4965 #5530

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions