Skip to content

Commit

Permalink
fix: patch for volar with pnp mode
Browse files Browse the repository at this point in the history
fix #385
  • Loading branch information
qmhc committed Sep 30, 2024
1 parent d5cd854 commit 1e2824f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ function transformAlias(
return importer
}

function isVLSNode(node: ts.Node) {
if (ts.isVariableStatement(node)) {
return node.declarationList.declarations.some(
d => ts.isIdentifier(d.name) && `${d.name.escapedText}`.startsWith('__VLS_')
)
}

if (ts.isTypeAliasDeclaration(node)) {
return `${node.name.escapedText}`.startsWith('__VLS_')
}

if (ts.isFunctionDeclaration(node)) {
return !!node.name && `${node.name.escapedText}`.startsWith('__VLS_')
}

return false
}

export function transformCode(options: {
filePath: string,
content: string,
Expand Down Expand Up @@ -229,6 +247,19 @@ export function transformCode(options: {

return false
}

if (
ts.isModuleDeclaration(node) &&
node.body &&
ts.isModuleBlock(node.body) &&
ts.isIdentifier(node.name) &&
node.name.escapedText === 'global' &&
node.body.statements.some(isVLSNode)
) {
s.remove(node.pos, node.end + 1)

return false
}
})

let prependImports = ''
Expand Down

0 comments on commit 1e2824f

Please # to comment.