rome / tools

Unified developer tools for JavaScript, TypeScript, and the web
https://docs.rome.tools/
MIT License
23.76k stars 663 forks source link

🐛 Illegal use of an export declaration outside of a module for .cts files #3918

Closed IanVS closed 1 year ago

IanVS commented 1 year ago

Environment information

vscode extension

What happened?

I installed the vscode extension into a simple project exploring typescript module resolution.

I got an error from rome on a file:

// example.cts

export function helper() {
    console.log("hello world!");
}

As far as I know, this is valid TypeScript code. In fact, it's taken from the TypeScript docs. The .cts extension indicates that the compilation target should be cjs. But rome throws an error:

Illegal use of an export declaration outside of a module

Expected result

Rome should not error for valid TypeScript code.

Code of Conduct

ematipico commented 1 year ago

I suppose that the TypeScript compiler relaxes its parsing rules because it knows that eventually the code will be compiled into a CJS script. Maybe our parser should do the same assumptions.

MichaReiser commented 1 year ago

I suppose that the TypeScript compiler relaxes its parsing rules because it knows that eventually the code will be compiled into a CJS script. Maybe our parser should do the same assumptions.

It may just be an incorrect mapping in our SourceType implementation.