Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vue-code-gan): add .js when import vue file for esm support
- Loading branch information
1 parent
0066107
commit d507974
Showing
4 changed files
with
170 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
import { getStartEnd } from './scriptSetupRanges'; | ||
import type { TextRange } from '../types'; | ||
|
||
export interface ScriptImportRanges extends ReturnType<typeof parseScriptImportRanges> { } | ||
|
||
export function parseScriptImportRanges(ts: typeof import('typescript/lib/tsserverlibrary'), ast: ts.SourceFile, end: number) { | ||
|
||
const calls: { | ||
code: TextRange, | ||
// import BaseText from './vue.js' | ||
// ^^^^^^^^^^ | ||
moduleSpecifier: TextRange | ||
}[] = []; | ||
|
||
ast.forEachChild(node => { | ||
visitNode(node); | ||
}); | ||
|
||
return calls; | ||
|
||
function visitNode(node: ts.Node) { | ||
if (ts.isImportDeclaration(node)) { | ||
const code = getStartEnd(node, ast) | ||
if (code.start <= end) { | ||
calls.push({ | ||
code: code, | ||
moduleSpecifier: getStartEnd(node.moduleSpecifier, ast) | ||
}) | ||
node.moduleSpecifier | ||
} | ||
} | ||
node.forEachChild(child => visitNode(child)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters