@volar/vue-typescript
Advanced tools
Comparing version 0.37.7 to 0.37.8
import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
import { LanguageServiceHost } from './types'; | ||
import { EmbeddedFile } from './sourceFile'; | ||
import { EmbeddedFile, VueLanguagePlugin } from './sourceFile'; | ||
export declare type LanguageServiceContext = ReturnType<typeof createLanguageServiceContext>; | ||
export declare function createLanguageServiceContext(ts: typeof import('typescript/lib/tsserverlibrary'), host: LanguageServiceHost): { | ||
export declare function createLanguageServiceContext(ts: typeof import('typescript/lib/tsserverlibrary'), host: LanguageServiceHost, extraPlugins?: VueLanguagePlugin[], exts?: string[]): { | ||
typescriptLanguageServiceHost: ts.LanguageServiceHost; | ||
@@ -7,0 +7,0 @@ typescriptLanguageService: ts.LanguageService; |
@@ -8,3 +8,3 @@ "use strict"; | ||
const documentRegistry_1 = require("./documentRegistry"); | ||
function createLanguageServiceContext(ts, host) { | ||
function createLanguageServiceContext(ts, host, extraPlugins = [], exts = ['.vue', '.md', '.html']) { | ||
var _a; | ||
@@ -28,3 +28,3 @@ let lastProjectVersion; | ||
const vueFileName = fileName.substring(0, fileName.lastIndexOf('.')); | ||
if (vueFileName.endsWith('.vue') || vueFileName.endsWith('.md') || vueFileName.endsWith('.html')) { | ||
if (exts.some(ext => vueFileName.endsWith(ext))) { | ||
const vueFile = documentRegistry.get(vueFileName); | ||
@@ -37,3 +37,3 @@ if (!vueFile) { | ||
if (scriptSnapshot) { | ||
documentRegistry.set(vueFileName, (0, sourceFile_1.createSourceFile)(vueFileName, scriptSnapshot.getText(0, scriptSnapshot.getLength()), compilerOptions, vueCompilerOptions, ts)); | ||
documentRegistry.set(vueFileName, (0, sourceFile_1.createSourceFile)(vueFileName, scriptSnapshot.getText(0, scriptSnapshot.getLength()), compilerOptions, vueCompilerOptions, ts, extraPlugins)); | ||
} | ||
@@ -73,6 +73,5 @@ } | ||
getScriptKind(fileName) { | ||
if (exts.some(ext => fileName.endsWith(ext))) | ||
return ts.ScriptKind.TSX; // can't use External, Unknown | ||
switch (path.extname(fileName)) { | ||
case '.vue': return ts.ScriptKind.TSX; // can't use External, Unknown | ||
case '.md': return ts.ScriptKind.TSX; // can't use External, Unknown | ||
case '.html': return ts.ScriptKind.TSX; // can't use External, Unknown | ||
case '.js': return ts.ScriptKind.JS; | ||
@@ -109,4 +108,4 @@ case '.jsx': return ts.ScriptKind.JSX; | ||
const fileNames = host.getScriptFileNames(); | ||
const vueFileNames = new Set(fileNames.filter(file => file.endsWith('.vue') || file.endsWith('.md') || file.endsWith('.html'))); | ||
const tsFileNames = new Set(fileNames.filter(file => !file.endsWith('.vue') && !file.endsWith('.md') && !file.endsWith('.html'))); | ||
const vueFileNames = new Set(fileNames.filter(file => exts.some(ext => file.endsWith(ext)))); | ||
const tsFileNames = new Set(fileNames.filter(file => !exts.some(ext => file.endsWith(ext)))); | ||
const fileNamesToRemove = []; | ||
@@ -176,3 +175,3 @@ const fileNamesToCreate = []; | ||
if (!sourceFile) { | ||
documentRegistry.set(fileName, (0, sourceFile_1.createSourceFile)(fileName, scriptText, compilerOptions, vueCompilerOptions, ts)); | ||
documentRegistry.set(fileName, (0, sourceFile_1.createSourceFile)(fileName, scriptText, compilerOptions, vueCompilerOptions, ts, extraPlugins)); | ||
tsFileUpdated = true; | ||
@@ -219,3 +218,3 @@ } | ||
} | ||
else if (!fileName.endsWith('.vue') && !fileName.endsWith('.md') && !fileName.endsWith('.html')) { | ||
else if (!exts.some(ext => fileName.endsWith(ext))) { | ||
tsFileNames.push(fileName); // .ts | ||
@@ -222,0 +221,0 @@ } |
import { VueLanguagePlugin } from '../sourceFile'; | ||
export default function (): VueLanguagePlugin; | ||
export default function (ts: typeof import('typescript/lib/tsserverlibrary')): VueLanguagePlugin; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const code_gen_1 = require("@volar/code-gen"); | ||
function default_1() { | ||
function default_1(ts) { | ||
return { | ||
@@ -11,3 +11,5 @@ getEmbeddedFilesCount(fileName, sfc) { | ||
if (sfc.script) { | ||
const createVueArg = sfc.script.content.match(/createApp\s*\(([\s\S]*?)\)/); | ||
const ast = ts.createSourceFile(fileName, sfc.script.content, ts.ScriptTarget.Latest); | ||
let createAppArgRange; | ||
ast.forEachChild(child => walkNode(child)); | ||
const codeGen = new code_gen_1.CodeGen(); | ||
@@ -28,11 +30,17 @@ codeGen.addCode2(sfc.script.content, 0, { | ||
codeGen.addText(`const __VLS_scope = `); | ||
if (createVueArg && createVueArg.index !== undefined) { | ||
codeGen.addCode2(createVueArg[1], createVueArg.index + createVueArg[0].indexOf(createVueArg[1]), { | ||
vueTag: 'script', | ||
capabilities: { | ||
references: true, | ||
definitions: true, | ||
rename: true, | ||
}, | ||
}); | ||
if (createAppArgRange) { | ||
const createAppArgText = sfc.script.content.slice(createAppArgRange[0], createAppArgRange[1]); | ||
if (createAppArgText.trim()) { | ||
codeGen.addCode2(createAppArgText, createAppArgRange[0], { | ||
vueTag: 'script', | ||
capabilities: { | ||
references: true, | ||
definitions: true, | ||
rename: true, | ||
}, | ||
}); | ||
} | ||
else { | ||
codeGen.addText('{}'); | ||
} | ||
} | ||
@@ -43,3 +51,4 @@ else { | ||
codeGen.addText(';\n'); | ||
codeGen.addText('declare const __VLS_export: new () => typeof __VLS_scope;\n'); | ||
codeGen.addText(`const __VLS_ctx = (await import('vue')).defineComponent({});\n`); | ||
codeGen.addText(`declare const __VLS_export: new () => typeof __VLS_scope & import('./__VLS_types').PickNotAny<InstanceType<typeof __VLS_ctx>, {}>;\n`); | ||
codeGen.addText('export default __VLS_export;\n'); | ||
@@ -61,2 +70,13 @@ const file = { | ||
return file; | ||
function walkNode(node) { | ||
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'createApp') { | ||
if (node.arguments.length) { | ||
const arg0 = node.arguments[0]; | ||
createAppArgRange = [arg0.getStart(ast), arg0.getEnd()]; | ||
} | ||
} | ||
else { | ||
node.forEachChild(child => walkNode(child)); | ||
} | ||
} | ||
} | ||
@@ -63,0 +83,0 @@ }, |
@@ -43,3 +43,3 @@ "use strict"; | ||
writeImportTypes(); | ||
tsxCodeGen.addText(`declare var __VLS_ctx: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''} InstanceType<typeof __VLS_component> & {\n`); | ||
tsxCodeGen.addText(`declare var __VLS_ctx: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''} __VLS_types.PickNotAny<InstanceType<typeof __VLS_component>, {}> & {\n`); | ||
/* CSS Module */ | ||
@@ -46,0 +46,0 @@ for (const cssModule of cssModuleClasses.value) { |
@@ -79,3 +79,3 @@ import { EmbeddedFileMappingData, TeleportMappingData, TextRange } from '@volar/vue-code-gen'; | ||
} | ||
export declare function createSourceFile(fileName: string, _content: string, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, ts: typeof import('typescript/lib/tsserverlibrary')): { | ||
export declare function createSourceFile(fileName: string, _content: string, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, ts: typeof import('typescript/lib/tsserverlibrary'), extraPlugins?: VueLanguagePlugin[]): { | ||
fileName: string; | ||
@@ -82,0 +82,0 @@ text: string; |
@@ -30,3 +30,3 @@ "use strict"; | ||
; | ||
function createSourceFile(fileName, _content, compilerOptions, vueCompilerOptions, ts) { | ||
function createSourceFile(fileName, _content, compilerOptions, vueCompilerOptions, ts, extraPlugins = []) { | ||
var _a; | ||
@@ -122,3 +122,3 @@ // refs | ||
const scriptLang = (0, reactivity_1.computed)(() => { | ||
return !sfc.script && !sfc.scriptSetup ? 'ts' | ||
return !sfc.script && !sfc.scriptSetup ? 'js' | ||
: sfc.scriptSetup && sfc.scriptSetup.lang !== 'js' ? sfc.scriptSetup.lang | ||
@@ -133,6 +133,7 @@ : sfc.script && sfc.script.lang !== 'js' ? sfc.script.lang | ||
const plugins = [ | ||
...extraPlugins, | ||
(0, file_vue_1.default)(), | ||
(0, file_md_1.default)(), | ||
(0, file_html_1.default)(), | ||
(0, petite_vue_script_1.default)(), | ||
(0, petite_vue_script_1.default)(ts), | ||
(0, vue_template_html_1.default)(), | ||
@@ -139,0 +140,0 @@ (0, vue_template_pug_1.default)(), |
{ | ||
"name": "@volar/vue-typescript", | ||
"version": "0.37.7", | ||
"version": "0.37.8", | ||
"main": "out/index.js", | ||
@@ -16,9 +16,9 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@volar/pug-language-service": "0.37.7", | ||
"@volar/pug-language-service": "0.37.8", | ||
"typescript": "latest" | ||
}, | ||
"dependencies": { | ||
"@volar/code-gen": "0.37.7", | ||
"@volar/source-map": "0.37.7", | ||
"@volar/vue-code-gen": "0.37.7", | ||
"@volar/code-gen": "0.37.8", | ||
"@volar/source-map": "0.37.8", | ||
"@volar/vue-code-gen": "0.37.8", | ||
"@vue/compiler-sfc": "^3.2.37", | ||
@@ -30,3 +30,3 @@ "@vue/reactivity": "^3.2.37" | ||
}, | ||
"gitHead": "cbc98157a9cfd85e7709d63461556394660d88e3" | ||
"gitHead": "22fce979edb8cb2473ee46c2059b95611cf97e64" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
112909
52
2422
+ Added@volar/code-gen@0.37.8(transitive)
+ Added@volar/source-map@0.37.8(transitive)
+ Added@volar/vue-code-gen@0.37.8(transitive)
- Removed@volar/code-gen@0.37.7(transitive)
- Removed@volar/source-map@0.37.7(transitive)
- Removed@volar/vue-code-gen@0.37.7(transitive)
Updated@volar/code-gen@0.37.8
Updated@volar/source-map@0.37.8
Updated@volar/vue-code-gen@0.37.8