Skip to content

Commit a476692

Browse files
committedJun 14, 2024
fix(compiler-sfc): fix parsing of mts, d.mts, and mtsx files
1 parent 4ec387b commit a476692

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed
 

‎packages/compiler-sfc/src/script/context.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ export function resolveParserPlugins(
175175
) {
176176
plugins.push('importAttributes')
177177
}
178-
if (lang === 'jsx' || lang === 'tsx') {
178+
if (lang === 'jsx' || lang === 'tsx' || lang === 'mtsx') {
179179
plugins.push('jsx')
180180
} else if (userPlugins) {
181181
// If don't match the case of adding jsx
182182
// should remove the jsx from user options
183183
userPlugins = userPlugins.filter(p => p !== 'jsx')
184184
}
185-
if (lang === 'ts' || lang === 'tsx') {
185+
if (lang === 'ts' || lang === 'mts' || lang === 'tsx' || lang === 'mtsx') {
186186
plugins.push(['typescript', { dts }], 'explicitResourceManagement')
187187
if (!userPlugins || !userPlugins.includes('decorators')) {
188188
plugins.push('decorators-legacy')

‎packages/compiler-sfc/src/script/resolveType.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1139,12 +1139,12 @@ function parseFile(
11391139
parserPlugins?: SFCScriptCompileOptions['babelParserPlugins'],
11401140
): Statement[] {
11411141
const ext = extname(filename)
1142-
if (ext === '.ts' || ext === '.tsx') {
1142+
if (ext === '.ts' || ext === '.mts' || ext === '.tsx' || ext === '.mtsx') {
11431143
return babelParse(content, {
11441144
plugins: resolveParserPlugins(
11451145
ext.slice(1),
11461146
parserPlugins,
1147-
filename.endsWith('.d.ts'),
1147+
/\.d\.m?ts$/.test(filename),
11481148
),
11491149
sourceType: 'module',
11501150
}).program.body

0 commit comments

Comments
 (0)
Please sign in to comment.