( lang: string, userPlugins?: ParserPlugin[], dts = false, )
| 165 | } |
| 166 | |
| 167 | export function resolveParserPlugins( |
| 168 | lang: string, |
| 169 | userPlugins?: ParserPlugin[], |
| 170 | dts = false, |
| 171 | ): ParserPlugin[] { |
| 172 | const plugins: ParserPlugin[] = [] |
| 173 | if ( |
| 174 | !userPlugins || |
| 175 | !userPlugins.some( |
| 176 | p => |
| 177 | p === 'importAssertions' || |
| 178 | p === 'importAttributes' || |
| 179 | (isArray(p) && p[0] === 'importAttributes'), |
| 180 | ) |
| 181 | ) { |
| 182 | plugins.push('importAttributes') |
| 183 | } |
| 184 | if (lang === 'jsx' || lang === 'tsx' || lang === 'mtsx') { |
| 185 | plugins.push('jsx') |
| 186 | } else if (userPlugins) { |
| 187 | // If don't match the case of adding jsx |
| 188 | // should remove the jsx from user options |
| 189 | userPlugins = userPlugins.filter(p => p !== 'jsx') |
| 190 | } |
| 191 | if ( |
| 192 | lang === 'ts' || |
| 193 | lang === 'mts' || |
| 194 | lang === 'tsx' || |
| 195 | lang === 'cts' || |
| 196 | lang === 'mtsx' |
| 197 | ) { |
| 198 | plugins.push(['typescript', { dts }], 'explicitResourceManagement') |
| 199 | if (!userPlugins || !userPlugins.includes('decorators')) { |
| 200 | plugins.push('decorators-legacy') |
| 201 | } |
| 202 | } |
| 203 | if (userPlugins) { |
| 204 | plugins.push(...userPlugins) |
| 205 | } |
| 206 | return plugins |
| 207 | } |
no test coverage detected