Skip to content

Commit

Permalink
fix(compiler-sfc): fix parsing of mts, d.mts, and mtsx files
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 14, 2024
1 parent 4ec387b commit a476692
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/compiler-sfc/src/script/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ export function resolveParserPlugins(
) {
plugins.push('importAttributes')
}
if (lang === 'jsx' || lang === 'tsx') {
if (lang === 'jsx' || lang === 'tsx' || lang === 'mtsx') {
plugins.push('jsx')
} else if (userPlugins) {
// If don't match the case of adding jsx
// should remove the jsx from user options
userPlugins = userPlugins.filter(p => p !== 'jsx')
}
if (lang === 'ts' || lang === 'tsx') {
if (lang === 'ts' || lang === 'mts' || lang === 'tsx' || lang === 'mtsx') {
plugins.push(['typescript', { dts }], 'explicitResourceManagement')
if (!userPlugins || !userPlugins.includes('decorators')) {
plugins.push('decorators-legacy')
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1139,12 +1139,12 @@ function parseFile(
parserPlugins?: SFCScriptCompileOptions['babelParserPlugins'],
): Statement[] {
const ext = extname(filename)
if (ext === '.ts' || ext === '.tsx') {
if (ext === '.ts' || ext === '.mts' || ext === '.tsx' || ext === '.mtsx') {
return babelParse(content, {
plugins: resolveParserPlugins(
ext.slice(1),
parserPlugins,
filename.endsWith('.d.ts'),
/\.d\.m?ts$/.test(filename),
),
sourceType: 'module',
}).program.body
Expand Down

0 comments on commit a476692

Please sign in to comment.