Skip to content

Commit

Permalink
chore: replace typescript/lib/tsserverlibrary imports to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Feb 28, 2024
1 parent 4d827be commit 4643384
Show file tree
Hide file tree
Showing 28 changed files with 76 additions and 76 deletions.
20 changes: 10 additions & 10 deletions packages/component-meta/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vue from '@vue/language-core';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import * as path from 'path-browserify';
import { code as typeHelpersCode } from 'vue-component-type-helpers';
import { code as vue2TypeHelpersCode } from 'vue-component-type-helpers/vue2';
Expand All @@ -21,7 +21,7 @@ export * from './types';
const windowsPathReg = /\\/g;

export function createCheckerByJsonConfigBase(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
rootDir: string,
json: any,
checkerOptions: MetaCheckerOptions = {},
Expand All @@ -38,7 +38,7 @@ export function createCheckerByJsonConfigBase(
}

export function createCheckerBase(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
tsconfig: string,
checkerOptions: MetaCheckerOptions = {},
) {
Expand All @@ -54,7 +54,7 @@ export function createCheckerBase(
}

function createCheckerWorker(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
loadParsedCommandLine: () => vue.ParsedCommandLine,
checkerOptions: MetaCheckerOptions,
rootPath: string,
Expand Down Expand Up @@ -114,7 +114,7 @@ function createCheckerWorker(
}

export function baseCreate(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
configFileName: string | undefined,
host: vue.TypeScriptProjectHost,
vueCompilerOptions: vue.VueCompilerOptions,
Expand Down Expand Up @@ -453,7 +453,7 @@ function createSchemaResolvers(
typeChecker: ts.TypeChecker,
symbolNode: ts.Expression,
{ rawType, schema: options, noDeclarations }: MetaCheckerOptions,
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
context: vue.LanguageContext,
) {
const visited = new Set<ts.Type>();
Expand Down Expand Up @@ -681,7 +681,7 @@ function createSchemaResolvers(
function readVueComponentDefaultProps(
vueSourceFile: vue.VueGeneratedCode,
printer: ts.Printer | undefined,
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
vueCompilerOptions: vue.VueCompilerOptions,
) {
let result: Record<string, { default?: string, required?: boolean; }> = {};
Expand Down Expand Up @@ -760,7 +760,7 @@ function readTsComponentDefaultProps(
tsFileText: string,
exportName: string,
printer: ts.Printer | undefined,
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
) {

const ast = ts.createSourceFile('/tmp.' + lang, tsFileText, ts.ScriptTarget.Latest);
Expand Down Expand Up @@ -839,7 +839,7 @@ function resolvePropsOption(
ast: ts.SourceFile,
props: ts.ObjectLiteralExpression,
printer: ts.Printer | undefined,
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
) {

const result: Record<string, { default?: string, required?: boolean; }> = {};
Expand Down Expand Up @@ -872,7 +872,7 @@ function resolvePropsOption(

function resolveDefaultOptionExpression(
_default: ts.Expression,
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
) {
if (ts.isArrowFunction(_default)) {
if (ts.isBlock(_default.body)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/component-meta/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';

export type ComponentMetaChecker = ReturnType<typeof import('./base')['baseCreate']>;

Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/src/generators/script.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Mapping } from '@volar/language-core';
import * as path from 'path-browserify';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import type { ScriptRanges } from '../parsers/scriptRanges';
import type { ScriptSetupRanges } from '../parsers/scriptSetupRanges';
import type { Code, CodeAndStack, SfcBlock, VueCompilerOptions } from '../types';
Expand All @@ -17,7 +17,7 @@ interface HelperType {
}

export function* generate(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
fileName: string,
script: Sfc['script'],
scriptSetup: Sfc['scriptSetup'],
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/src/generators/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { toString } from '@volar/language-core';
import * as CompilerDOM from '@vue/compiler-dom';
import { camelize, capitalize } from '@vue/shared';
import { minimatch } from 'minimatch';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import { Code, CodeAndStack, Sfc, VueCodeInformation, VueCompilerOptions } from '../types';
import { hyphenateAttr, hyphenateTag } from '../utils/shared';
import { collectVars, eachInterpolationSegment } from '../utils/transform';
Expand Down Expand Up @@ -66,7 +66,7 @@ const transformContext: CompilerDOM.TransformContext = {
type _CodeAndStack = [codeType: 'ts' | 'tsFormat' | 'inlineCss', ...codeAndStack: CodeAndStack];

export function* generate(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
compilerOptions: ts.CompilerOptions,
vueCompilerOptions: VueCompilerOptions,
template: NonNullable<Sfc['template']>,
Expand Down
6 changes: 3 additions & 3 deletions packages/language-core/src/languageModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { forEachEmbeddedCode, type LanguagePlugin } from '@volar/language-core';
import { getDefaultVueLanguagePlugins, createPluginContext } from './plugins';
import { VueGeneratedCode } from './virtualFile/vueFile';
import { VueCompilerOptions, VueLanguagePlugin } from './types';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import { resolveVueCompilerOptions } from './utils/ts';

const fileRegistries: {
Expand Down Expand Up @@ -51,7 +51,7 @@ function getFileRegistryKey(
}

export function createVueLanguage(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
getFileName: (fileId: string) => string,
compilerOptions: ts.CompilerOptions = {},
_vueCompilerOptions: Partial<VueCompilerOptions> = {},
Expand Down Expand Up @@ -165,7 +165,7 @@ export function createVueLanguage(
* @deprecated planed to remove in 2.0, please use createVueLanguage instead of
*/
export function createLanguages(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
getFileName: (fileId: string) => string,
compilerOptions: ts.CompilerOptions = {},
vueCompilerOptions: Partial<VueCompilerOptions> = {},
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/src/parsers/scriptRanges.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { TextRange } from '../types';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import { getNodeText, getStartEnd, parseBindingRanges } from './scriptSetupRanges';

export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> { }

export function parseScriptRanges(ts: typeof import('typescript/lib/tsserverlibrary'), ast: ts.SourceFile, hasScriptSetup: boolean, withNode: boolean) {
export function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, hasScriptSetup: boolean, withNode: boolean) {

let exportDefault: (TextRange & {
expression: TextRange,
Expand Down
12 changes: 6 additions & 6 deletions packages/language-core/src/parsers/scriptSetupRanges.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import type { VueCompilerOptions, TextRange } from '../types';

export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRanges> { }

export function parseScriptSetupRanges(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
ast: ts.SourceFile,
vueCompilerOptions: VueCompilerOptions,
) {
Expand Down Expand Up @@ -245,7 +245,7 @@ export function parseScriptSetupRanges(
}
}

export function parseBindingRanges(ts: typeof import('typescript/lib/tsserverlibrary'), sourceFile: ts.SourceFile) {
export function parseBindingRanges(ts: typeof import('typescript'), sourceFile: ts.SourceFile) {
const bindings: TextRange[] = [];
ts.forEachChild(sourceFile, node => {
if (ts.isVariableStatement(node)) {
Expand Down Expand Up @@ -297,7 +297,7 @@ export function parseBindingRanges(ts: typeof import('typescript/lib/tsserverlib
}
}

export function findBindingVars(ts: typeof import('typescript/lib/tsserverlibrary'), left: ts.BindingName, sourceFile: ts.SourceFile) {
export function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, sourceFile: ts.SourceFile) {
const vars: TextRange[] = [];
worker(left);
return vars;
Expand Down Expand Up @@ -331,7 +331,7 @@ export function findBindingVars(ts: typeof import('typescript/lib/tsserverlibrar
}

export function getStartEnd(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
node: ts.Node,
sourceFile: ts.SourceFile
) {
Expand All @@ -342,7 +342,7 @@ export function getStartEnd(
}

export function getNodeText(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
node: ts.Node,
sourceFile: ts.SourceFile
) {
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/src/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import useHtmlFilePlugin from './plugins/file-html';
import useMdFilePlugin from './plugins/file-md';
import useVueFilePlugin from './plugins/file-vue';
Expand All @@ -13,7 +13,7 @@ import * as CompilerDOM from '@vue/compiler-dom';
import * as CompilerVue2 from './utils/vue2TemplateCompiler';

export function createPluginContext(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
compilerOptions: ts.CompilerOptions,
vueCompilerOptions: VueCompilerOptions,
codegenStack: boolean,
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as CompilerDOM from '@vue/compiler-dom';
import type { SFCParseResult } from '@vue/compiler-sfc';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import type { VueEmbeddedFile } from './virtualFile/embeddedFile';
import type { CodeInformation, Segment } from '@volar/language-core';

Expand Down Expand Up @@ -60,7 +60,7 @@ export interface VueCompilerOptions {

export type VueLanguagePlugin = (ctx: {
modules: {
typescript: typeof import('typescript/lib/tsserverlibrary');
typescript: typeof import('typescript');
'@vue/compiler-dom': typeof import('@vue/compiler-dom');
};
compilerOptions: ts.CompilerOptions;
Expand Down
10 changes: 5 additions & 5 deletions packages/language-core/src/utils/transform.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { isGloballyWhitelisted } from '@vue/shared';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import { VueCompilerOptions } from '../types';
import { getNodeText, getStartEnd } from '../parsers/scriptSetupRanges';

export function* eachInterpolationSegment(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
code: string,
ast: ts.SourceFile,
localVars: Map<string, number>,
Expand Down Expand Up @@ -110,7 +110,7 @@ export function* eachInterpolationSegment(
}

function walkIdentifiers(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
node: ts.Node,
ast: ts.SourceFile,
cb: (varNode: ts.Identifier, isShorthand: boolean) => void,
Expand Down Expand Up @@ -204,7 +204,7 @@ function walkIdentifiers(
}

function walkIdentifiersInTypeReference(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
node: ts.Node,
cb: (varNode: ts.Identifier, isShorthand: boolean) => void,
) {
Expand All @@ -217,7 +217,7 @@ function walkIdentifiersInTypeReference(
}

export function collectVars(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
node: ts.Node,
ast: ts.SourceFile,
result: string[],
Expand Down
8 changes: 4 additions & 4 deletions packages/language-core/src/utils/ts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import * as path from 'path-browserify';
import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from '../types';

Expand All @@ -7,7 +7,7 @@ export type ParsedCommandLine = ts.ParsedCommandLine & {
};

export function createParsedCommandLineByJson(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
parseConfigHost: ts.ParseConfigHost,
rootDir: string,
json: any,
Expand Down Expand Up @@ -54,7 +54,7 @@ export function createParsedCommandLineByJson(
}

export function createParsedCommandLine(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
parseConfigHost: ts.ParseConfigHost,
tsConfigPath: string,
): ParsedCommandLine {
Expand Down Expand Up @@ -131,7 +131,7 @@ function proxyParseConfigHostForExtendConfigPaths(parseConfigHost: ts.ParseConfi
}

function getPartialVueCompilerOptions(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
tsConfigSourceFile: ts.TsConfigSourceFile,
): Partial<VueCompilerOptions> {

Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/src/virtualFile/computedFiles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VirtualCode, buildMappings, buildStacks, resolveCommonLanguageId, toString, track } from '@volar/language-core';
import { computed } from 'computeds';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import type { Sfc, SfcBlock, VueLanguagePlugin } from '../types';
import { VueEmbeddedFile } from './embeddedFile';

Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/src/virtualFile/computedMappings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Mapping, Segment, replaceSourceRange } from '@volar/language-core';
import { computed } from 'computeds';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import { enableAllFeatures } from '../generators/utils';
import { Sfc, VueCodeInformation } from '../types';

Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/src/virtualFile/computedSfc.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type * as CompilerDOM from '@vue/compiler-dom';
import type { SFCBlock, SFCParseResult } from '@vue/compiler-sfc';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import { Sfc, SfcBlock, VueLanguagePlugin } from '../types';
import { parseCssClassNames } from '../utils/parseCssClassNames';
import { parseCssVars } from '../utils/parseCssVars';
import { computed, pauseTracking, resetTracking, computedArray } from 'computeds';

export function computedSfc(
ts: typeof import('typescript/lib/tsserverlibrary'),
ts: typeof import('typescript'),
plugins: ReturnType<VueLanguagePlugin>[],
fileName: string,
snapshot: () => ts.IScriptSnapshot,
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/src/virtualFile/computedVueSfc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SFCParseResult } from '@vue/compiler-sfc';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import { VueLanguagePlugin } from '../types';
import { computed } from 'computeds';

Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/src/virtualFile/vueFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Stack, VirtualCode } from '@volar/language-core';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type * as ts from 'typescript';
import { VueCompilerOptions, VueLanguagePlugin } from '../types';
import { computedFiles } from './computedFiles';
import { computedMappings } from './computedMappings';
Expand Down Expand Up @@ -41,7 +41,7 @@ export class VueGeneratedCode implements VirtualCode {
public initSnapshot: ts.IScriptSnapshot,
public vueCompilerOptions: VueCompilerOptions,
public plugins: ReturnType<VueLanguagePlugin>[],
public ts: typeof import('typescript/lib/tsserverlibrary'),
public ts: typeof import('typescript'),
public codegenStack: boolean,
) {
this._snapshot = signal(initSnapshot);
Expand Down
Loading

0 comments on commit 4643384

Please sign in to comment.