-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(typescript-estree): ensure mjs/mts files are always be parsed as ESM #10011
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
Changes from all commits
4a1e81b
e98727b
0027099
7172c05
b34e53f
d369ec8
fa9d25b
138054e
3bdee13
183d8fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import path from 'node:path'; | ||
|
||
import debug from 'debug'; | ||
import * as ts from 'typescript'; | ||
|
||
|
@@ -46,6 +48,14 @@ export function createParseSettings( | |
? tsestreeOptions.tsconfigRootDir | ||
: process.cwd(); | ||
const passedLoggerFn = typeof tsestreeOptions.loggerFn === 'function'; | ||
const filePath = ensureAbsolutePath( | ||
typeof tsestreeOptions.filePath === 'string' && | ||
tsestreeOptions.filePath !== '<input>' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I checked There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the const PARSE_DEFAULT_OPTIONS: ParseOptions = {
comment: false,
filePath: 'estree.ts', // or 'estree.tsx', if you pass jsx: true
jsDocParsingMode: 'all',
jsx: false,
loc: false,
loggerFn: undefined,
range: false,
tokens: false,
};
declare function parse(
code: string,
options: ParseOptions = PARSE_DEFAULT_OPTIONS,
): TSESTree.Program; But, here's the code I actually found function parse<T extends TSESTreeOptions = TSESTreeOptions>(
code: string,
options?: T, // there's no default value
): AST<T> {
const { ast } = parseWithNodeMapsInternal(code, options, false);
return ast;
} Maybe it's just something missed over time. Should this be fixed in the current PR? I feel like the problem we're dealing with is a little different. |
||
? tsestreeOptions.filePath | ||
: getFileName(tsestreeOptions.jsx), | ||
tsconfigRootDir, | ||
); | ||
const extension = path.extname(filePath).toLowerCase() as ts.Extension; | ||
const jsDocParsingMode = ((): ts.JSDocParsingMode => { | ||
switch (tsestreeOptions.jsDocParsingMode) { | ||
case 'all': | ||
|
@@ -81,13 +91,17 @@ export function createParseSettings( | |
tsestreeOptions.extraFileExtensions.every(ext => typeof ext === 'string') | ||
? tsestreeOptions.extraFileExtensions | ||
: [], | ||
filePath: ensureAbsolutePath( | ||
typeof tsestreeOptions.filePath === 'string' && | ||
tsestreeOptions.filePath !== '<input>' | ||
? tsestreeOptions.filePath | ||
: getFileName(tsestreeOptions.jsx), | ||
tsconfigRootDir, | ||
), | ||
filePath, | ||
setExternalModuleIndicator: | ||
tsestreeOptions.sourceType === 'module' || | ||
(tsestreeOptions.sourceType === undefined && | ||
extension === ts.Extension.Mjs) || | ||
(tsestreeOptions.sourceType === undefined && | ||
extension === ts.Extension.Mts) | ||
? (file): void => { | ||
file.externalModuleIndicator = true; | ||
} | ||
: undefined, | ||
jsDocParsingMode, | ||
jsx: tsestreeOptions.jsx === true, | ||
loc: tsestreeOptions.loc === true, | ||
|
Uh oh!
There was an error while loading. Please reload this page.