q9
This commit is contained in:
12
node_modules/@vue/language-core/lib/codegen/common.d.ts
generated
vendored
Normal file
12
node_modules/@vue/language-core/lib/codegen/common.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import type * as ts from 'typescript';
|
||||
import type { Code, SfcBlock, VueCodeInformation } from '../types';
|
||||
export declare const newLine = "\n";
|
||||
export declare const endOfLine = ";\n";
|
||||
export declare const combineLastMapping: VueCodeInformation;
|
||||
export declare const variableNameRegex: RegExp;
|
||||
export declare function conditionWrapWith(condition: boolean, startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
|
||||
export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
|
||||
export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, results?: string[]): string[];
|
||||
export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: [id: ts.Identifier, isRest: boolean][], isRest?: boolean): [id: ts.Identifier, isRest: boolean][];
|
||||
export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
|
||||
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
||||
79
node_modules/@vue/language-core/lib/codegen/common.js
generated
vendored
Normal file
79
node_modules/@vue/language-core/lib/codegen/common.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.variableNameRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
|
||||
exports.conditionWrapWith = conditionWrapWith;
|
||||
exports.wrapWith = wrapWith;
|
||||
exports.collectVars = collectVars;
|
||||
exports.collectIdentifiers = collectIdentifiers;
|
||||
exports.createTsAst = createTsAst;
|
||||
exports.generateSfcBlockSection = generateSfcBlockSection;
|
||||
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
||||
exports.newLine = '\n';
|
||||
exports.endOfLine = `;${exports.newLine}`;
|
||||
exports.combineLastMapping = { __combineLastMapping: true };
|
||||
exports.variableNameRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
||||
function* conditionWrapWith(condition, startOffset, endOffset, features, ...wrapCodes) {
|
||||
if (condition) {
|
||||
yield* wrapWith(startOffset, endOffset, features, ...wrapCodes);
|
||||
}
|
||||
else {
|
||||
for (const wrapCode of wrapCodes) {
|
||||
yield wrapCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
function* wrapWith(startOffset, endOffset, features, ...wrapCodes) {
|
||||
yield ['', 'template', startOffset, features];
|
||||
let offset = 1;
|
||||
for (const wrapCode of wrapCodes) {
|
||||
if (typeof wrapCode !== 'string') {
|
||||
offset++;
|
||||
}
|
||||
yield wrapCode;
|
||||
}
|
||||
yield ['', 'template', endOffset, { __combineOffsetMapping: offset }];
|
||||
}
|
||||
function collectVars(ts, node, ast, results = []) {
|
||||
const identifiers = collectIdentifiers(ts, node, []);
|
||||
for (const [id] of identifiers) {
|
||||
results.push((0, scriptSetupRanges_1.getNodeText)(ts, id, ast));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
function collectIdentifiers(ts, node, results = [], isRest = false) {
|
||||
if (ts.isIdentifier(node)) {
|
||||
results.push([node, isRest]);
|
||||
}
|
||||
else if (ts.isObjectBindingPattern(node)) {
|
||||
for (const el of node.elements) {
|
||||
collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
|
||||
}
|
||||
}
|
||||
else if (ts.isArrayBindingPattern(node)) {
|
||||
for (const el of node.elements) {
|
||||
if (ts.isBindingElement(el)) {
|
||||
collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ts.forEachChild(node, node => collectIdentifiers(ts, node, results, false));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
function createTsAst(ts, astHolder, text) {
|
||||
if (astHolder.__volar_ast_text !== text) {
|
||||
astHolder.__volar_ast_text = text;
|
||||
astHolder.__volar_ast = ts.createSourceFile('/a.ts', text, 99);
|
||||
}
|
||||
return astHolder.__volar_ast;
|
||||
}
|
||||
function generateSfcBlockSection(block, start, end, features) {
|
||||
return [
|
||||
block.content.substring(start, end),
|
||||
block.name,
|
||||
start,
|
||||
features,
|
||||
];
|
||||
}
|
||||
//# sourceMappingURL=common.js.map
|
||||
1
node_modules/@vue/language-core/lib/codegen/globalTypes.d.ts
generated
vendored
Normal file
1
node_modules/@vue/language-core/lib/codegen/globalTypes.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare function generateGlobalTypes(lib: string, target: number, strictTemplates: boolean): string;
|
||||
142
node_modules/@vue/language-core/lib/codegen/globalTypes.js
generated
vendored
Normal file
142
node_modules/@vue/language-core/lib/codegen/globalTypes.js
generated
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateGlobalTypes = generateGlobalTypes;
|
||||
const shared_1 = require("../utils/shared");
|
||||
function generateGlobalTypes(lib, target, strictTemplates) {
|
||||
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${strictTemplates ? '' : ' & Record<string, unknown>'}`;
|
||||
let text = ``;
|
||||
if (target < 3.5) {
|
||||
text += `
|
||||
; declare module '${lib}' {
|
||||
export interface GlobalComponents { }
|
||||
export interface GlobalDirectives { }
|
||||
}`;
|
||||
}
|
||||
text += `
|
||||
; declare global {
|
||||
const __VLS_intrinsicElements: __VLS_IntrinsicElements;
|
||||
const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
|
||||
const __VLS_unref: typeof import('${lib}').unref;
|
||||
|
||||
const __VLS_nativeElements = {
|
||||
...{} as SVGElementTagNameMap,
|
||||
...{} as HTMLElementTagNameMap,
|
||||
};
|
||||
|
||||
type __VLS_IntrinsicElements = ${(target >= 3.3
|
||||
? `import('${lib}/jsx-runtime').JSX.IntrinsicElements;`
|
||||
: `globalThis.JSX.IntrinsicElements;`)}
|
||||
type __VLS_Element = ${(target >= 3.3
|
||||
? `import('${lib}/jsx-runtime').JSX.Element;`
|
||||
: `globalThis.JSX.Element;`)}
|
||||
type __VLS_GlobalComponents = ${(target >= 3.5
|
||||
? `import('${lib}').GlobalComponents;`
|
||||
: `import('${lib}').GlobalComponents & Pick<typeof import('${lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`)}
|
||||
type __VLS_GlobalDirectives = import('${lib}').GlobalDirectives;
|
||||
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
|
||||
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
||||
type __VLS_unknownDirective = (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
|
||||
type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
|
||||
N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
|
||||
N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
|
||||
N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N3] } :
|
||||
N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
|
||||
N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
|
||||
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
|
||||
${strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
|
||||
type __VLS_FunctionalComponentProps<T, K> =
|
||||
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
|
||||
: T extends (props: infer P, ...args: any) => any ? P :
|
||||
{};
|
||||
type __VLS_IsFunction<T, K> = K extends keyof T
|
||||
? __VLS_IsAny<T[K]> extends false
|
||||
? unknown extends T[K]
|
||||
? false
|
||||
: true
|
||||
: false
|
||||
: false;
|
||||
// fix https://github.com/vuejs/language-tools/issues/926
|
||||
type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
|
||||
type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
|
||||
? U extends T
|
||||
? never
|
||||
: __VLS_OverloadUnionInner<T, Pick<T, keyof T> & U & ((...args: A) => R)> | ((...args: A) => R)
|
||||
: never;
|
||||
type __VLS_OverloadUnion<T> = Exclude<
|
||||
__VLS_OverloadUnionInner<(() => never) & T>,
|
||||
T extends () => never ? never : () => never
|
||||
>;
|
||||
type __VLS_ConstructorOverloads<T> = __VLS_OverloadUnion<T> extends infer F
|
||||
? F extends (event: infer E, ...args: infer A) => any
|
||||
? { [K in E & string]: (...args: A) => void; }
|
||||
: never
|
||||
: never;
|
||||
type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
|
||||
__VLS_UnionToIntersection<
|
||||
__VLS_ConstructorOverloads<T> & {
|
||||
[K in keyof T]: T[K] extends any[] ? { (...args: T[K]): void } : never
|
||||
}
|
||||
>
|
||||
>;
|
||||
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
||||
type __VLS_PickFunctionalComponentCtx<T, K> = NonNullable<__VLS_PickNotAny<
|
||||
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
||||
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
||||
>>;
|
||||
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
|
||||
|
||||
function __VLS_getVForSourceType(source: number): [number, number, number][];
|
||||
function __VLS_getVForSourceType(source: string): [string, number, number][];
|
||||
function __VLS_getVForSourceType<T extends any[]>(source: T): [
|
||||
item: T[number],
|
||||
key: number,
|
||||
index: number,
|
||||
][];
|
||||
function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
||||
item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
|
||||
key: number,
|
||||
index: undefined,
|
||||
][];
|
||||
// #3845
|
||||
function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
||||
item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
|
||||
key: number,
|
||||
index: undefined,
|
||||
][];
|
||||
function __VLS_getVForSourceType<T>(source: T): [
|
||||
item: T[keyof T],
|
||||
key: keyof T,
|
||||
index: number,
|
||||
][];
|
||||
// @ts-ignore
|
||||
function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
|
||||
// @ts-ignore
|
||||
function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
|
||||
function __VLS_asFunctionalDirective<T>(dir: T): T extends import('${lib}').ObjectDirective
|
||||
? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
|
||||
: T extends (...args: any) => any
|
||||
? T
|
||||
: __VLS_unknownDirective;
|
||||
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
|
||||
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
||||
function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
|
||||
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
|
||||
T extends new (...args: any) => any
|
||||
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
|
||||
attrs?: any,
|
||||
slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : any,
|
||||
emit?: K extends { $emit: infer Emit } ? Emit : any
|
||||
} & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
|
||||
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
|
||||
: T extends (...args: any) => any ? T
|
||||
: (_: {}${strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictTemplates ? '' : ' & Record<string, unknown>'} } };
|
||||
function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
|
||||
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
|
||||
function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
|
||||
function __VLS_tryAsConstant<const T>(t: T): T;
|
||||
}
|
||||
`;
|
||||
return text;
|
||||
}
|
||||
;
|
||||
//# sourceMappingURL=globalTypes.js.map
|
||||
11
node_modules/@vue/language-core/lib/codegen/inlayHints.d.ts
generated
vendored
Normal file
11
node_modules/@vue/language-core/lib/codegen/inlayHints.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import type * as CompilerDOM from '@vue/compiler-dom';
|
||||
export interface InlayHintInfo {
|
||||
blockName: string;
|
||||
offset: number;
|
||||
setting: string;
|
||||
label: string;
|
||||
tooltip?: string;
|
||||
paddingRight?: boolean;
|
||||
paddingLeft?: boolean;
|
||||
}
|
||||
export declare function createVBindShorthandInlayHintInfo(loc: CompilerDOM.SourceLocation, variableName: string): InlayHintInfo;
|
||||
17
node_modules/@vue/language-core/lib/codegen/inlayHints.js
generated
vendored
Normal file
17
node_modules/@vue/language-core/lib/codegen/inlayHints.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createVBindShorthandInlayHintInfo = createVBindShorthandInlayHintInfo;
|
||||
function createVBindShorthandInlayHintInfo(loc, variableName) {
|
||||
return {
|
||||
blockName: 'template',
|
||||
offset: loc.end.offset,
|
||||
setting: 'vue.inlayHints.vBindShorthand',
|
||||
label: `="${variableName}"`,
|
||||
tooltip: [
|
||||
`This is a shorthand for \`${loc.source}="${variableName}"\`.`,
|
||||
'To hide this hint, set `vue.inlayHints.vBindShorthand` to `false` in IDE settings.',
|
||||
'[More info](https://github.com/vuejs/core/pull/9451)',
|
||||
].join('\n\n'),
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=inlayHints.js.map
|
||||
13
node_modules/@vue/language-core/lib/codegen/localTypes.d.ts
generated
vendored
Normal file
13
node_modules/@vue/language-core/lib/codegen/localTypes.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import type * as ts from 'typescript';
|
||||
import { VueCompilerOptions } from '../types';
|
||||
export declare function getLocalTypesGenerator(compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): {
|
||||
generate: (names: string[]) => Generator<string, void, unknown>;
|
||||
getUsedNames(): Set<string>;
|
||||
readonly PrettifyLocal: string;
|
||||
readonly OmitKeepDiscriminatedUnion: string;
|
||||
readonly WithDefaults: string;
|
||||
readonly WithTemplateSlots: string;
|
||||
readonly PropsChildren: string;
|
||||
readonly TypePropsToOption: string;
|
||||
readonly OmitIndexSignature: string;
|
||||
};
|
||||
109
node_modules/@vue/language-core/lib/codegen/localTypes.js
generated
vendored
Normal file
109
node_modules/@vue/language-core/lib/codegen/localTypes.js
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getLocalTypesGenerator = getLocalTypesGenerator;
|
||||
const shared_1 = require("../utils/shared");
|
||||
const common_1 = require("./common");
|
||||
function getLocalTypesGenerator(compilerOptions, vueCompilerOptions) {
|
||||
const used = new Set();
|
||||
const OmitKeepDiscriminatedUnion = defineHelper(`__VLS_OmitKeepDiscriminatedUnion`, () => `
|
||||
type __VLS_OmitKeepDiscriminatedUnion<T, K extends keyof any> = T extends any
|
||||
? Pick<T, Exclude<keyof T, K>>
|
||||
: never;
|
||||
`.trimStart());
|
||||
const WithDefaults = defineHelper(`__VLS_WithDefaults`, () => `
|
||||
type __VLS_WithDefaults<P, D> = {
|
||||
[K in keyof Pick<P, keyof P>]: K extends keyof D
|
||||
? ${PrettifyLocal.name}<P[K] & { default: D[K]}>
|
||||
: P[K]
|
||||
};
|
||||
`.trimStart());
|
||||
const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {}${common_1.endOfLine}`);
|
||||
const WithTemplateSlots = defineHelper(`__VLS_WithTemplateSlots`, () => `
|
||||
type __VLS_WithTemplateSlots<T, S> = T & {
|
||||
new(): {
|
||||
${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;
|
||||
${vueCompilerOptions.jsxSlots ? `$props: ${PropsChildren.name}<S>;` : ''}
|
||||
}
|
||||
};
|
||||
`.trimStart());
|
||||
const PropsChildren = defineHelper(`__VLS_PropsChildren`, () => `
|
||||
type __VLS_PropsChildren<S> = {
|
||||
[K in keyof (
|
||||
boolean extends (
|
||||
// @ts-ignore
|
||||
JSX.ElementChildrenAttribute extends never
|
||||
? true
|
||||
: false
|
||||
)
|
||||
? never
|
||||
// @ts-ignore
|
||||
: JSX.ElementChildrenAttribute
|
||||
)]?: S;
|
||||
};
|
||||
`.trimStart());
|
||||
const TypePropsToOption = defineHelper(`__VLS_TypePropsToOption`, () => compilerOptions.exactOptionalPropertyTypes ?
|
||||
`
|
||||
type __VLS_TypePropsToOption<T> = {
|
||||
[K in keyof T]-?: {} extends Pick<T, K>
|
||||
? { type: import('${vueCompilerOptions.lib}').PropType<T[K]> }
|
||||
: { type: import('${vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
||||
};
|
||||
`.trimStart() :
|
||||
`
|
||||
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
||||
type __VLS_TypePropsToOption<T> = {
|
||||
[K in keyof T]-?: {} extends Pick<T, K>
|
||||
? { type: import('${vueCompilerOptions.lib}').PropType<__VLS_NonUndefinedable<T[K]>> }
|
||||
: { type: import('${vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
||||
};
|
||||
`.trimStart());
|
||||
const OmitIndexSignature = defineHelper(`__VLS_OmitIndexSignature`, () => `type __VLS_OmitIndexSignature<T> = { [K in keyof T as {} extends Record<K, unknown> ? never : K]: T[K]; }${common_1.endOfLine}`);
|
||||
const helpers = {
|
||||
[PrettifyLocal.name]: PrettifyLocal,
|
||||
[OmitKeepDiscriminatedUnion.name]: OmitKeepDiscriminatedUnion,
|
||||
[WithDefaults.name]: WithDefaults,
|
||||
[WithTemplateSlots.name]: WithTemplateSlots,
|
||||
[PropsChildren.name]: PropsChildren,
|
||||
[TypePropsToOption.name]: TypePropsToOption,
|
||||
[OmitIndexSignature.name]: OmitIndexSignature,
|
||||
};
|
||||
used.clear();
|
||||
return {
|
||||
generate,
|
||||
getUsedNames() {
|
||||
return used;
|
||||
},
|
||||
get PrettifyLocal() { return PrettifyLocal.name; },
|
||||
get OmitKeepDiscriminatedUnion() { return OmitKeepDiscriminatedUnion.name; },
|
||||
get WithDefaults() { return WithDefaults.name; },
|
||||
get WithTemplateSlots() { return WithTemplateSlots.name; },
|
||||
get PropsChildren() { return PropsChildren.name; },
|
||||
get TypePropsToOption() { return TypePropsToOption.name; },
|
||||
get OmitIndexSignature() { return OmitIndexSignature.name; },
|
||||
};
|
||||
function* generate(names) {
|
||||
const generated = new Set();
|
||||
while (names.length) {
|
||||
used.clear();
|
||||
for (const name of names) {
|
||||
if (generated.has(name)) {
|
||||
continue;
|
||||
}
|
||||
const helper = helpers[name];
|
||||
yield helper.generate();
|
||||
generated.add(name);
|
||||
}
|
||||
names = [...used].filter(name => !generated.has(name));
|
||||
}
|
||||
}
|
||||
function defineHelper(name, generate) {
|
||||
return {
|
||||
get name() {
|
||||
used.add(name);
|
||||
return name;
|
||||
},
|
||||
generate,
|
||||
};
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=localTypes.js.map
|
||||
8
node_modules/@vue/language-core/lib/codegen/script/component.d.ts
generated
vendored
Normal file
8
node_modules/@vue/language-core/lib/codegen/script/component.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
||||
import type { Code, Sfc } from '../../types';
|
||||
import type { ScriptCodegenContext } from './context';
|
||||
import { ScriptCodegenOptions } from './index';
|
||||
export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
||||
export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
||||
export declare function generateEmitsOption(options: ScriptCodegenOptions, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
||||
export declare function generatePropsOption(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, hasEmitsOption: boolean, inheritAttrs: boolean): Generator<Code>;
|
||||
179
node_modules/@vue/language-core/lib/codegen/script/component.js
generated
vendored
Normal file
179
node_modules/@vue/language-core/lib/codegen/script/component.js
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateComponent = generateComponent;
|
||||
exports.generateComponentSetupReturns = generateComponentSetupReturns;
|
||||
exports.generateEmitsOption = generateEmitsOption;
|
||||
exports.generatePropsOption = generatePropsOption;
|
||||
const common_1 = require("../common");
|
||||
const index_1 = require("./index");
|
||||
function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
||||
if (options.sfc.script && options.scriptRanges?.exportDefault && options.scriptRanges.exportDefault.expression.start !== options.scriptRanges.exportDefault.args.start) {
|
||||
// use defineComponent() from user space code if it exist
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.exportDefault.expression.start, options.scriptRanges.exportDefault.args.start, index_1.codeFeatures.all);
|
||||
yield `{${common_1.newLine}`;
|
||||
}
|
||||
else {
|
||||
yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
|
||||
}
|
||||
yield `setup() {${common_1.newLine}`;
|
||||
yield `return {${common_1.newLine}`;
|
||||
if (ctx.bypassDefineComponent) {
|
||||
yield* generateComponentSetupReturns(scriptSetupRanges);
|
||||
}
|
||||
if (scriptSetupRanges.expose.define) {
|
||||
yield `...__VLS_exposed,${common_1.newLine}`;
|
||||
}
|
||||
yield `}${common_1.endOfLine}`;
|
||||
yield `},${common_1.newLine}`;
|
||||
if (!ctx.bypassDefineComponent) {
|
||||
const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
|
||||
for (const code of emitOptionCodes) {
|
||||
yield code;
|
||||
}
|
||||
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length, true);
|
||||
}
|
||||
if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
|
||||
const { args } = options.scriptRanges.exportDefault;
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
|
||||
}
|
||||
if (options.vueCompilerOptions.target >= 3.5 && scriptSetupRanges.templateRefs.length) {
|
||||
yield `__typeRefs: {} as __VLS_TemplateResult['refs'],${common_1.newLine}`;
|
||||
}
|
||||
if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.singleRootElType) {
|
||||
yield `__typeEl: {} as __VLS_TemplateResult['rootEl'],${common_1.newLine}`;
|
||||
}
|
||||
yield `})`;
|
||||
}
|
||||
function* generateComponentSetupReturns(scriptSetupRanges) {
|
||||
// fill $props
|
||||
if (scriptSetupRanges.props.define) {
|
||||
// NOTE: defineProps is inaccurate for $props
|
||||
yield `$props: __VLS_makeOptional(${scriptSetupRanges.props.name ?? `__VLS_props`}),${common_1.newLine}`;
|
||||
yield `...${scriptSetupRanges.props.name ?? `__VLS_props`},${common_1.newLine}`;
|
||||
}
|
||||
// fill $emit
|
||||
if (scriptSetupRanges.emits.define) {
|
||||
yield `$emit: ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
|
||||
}
|
||||
}
|
||||
function* generateEmitsOption(options, scriptSetupRanges) {
|
||||
const codes = [];
|
||||
if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
|
||||
codes.push({
|
||||
optionExp: `{} as __VLS_NormalizeEmits<typeof __VLS_modelEmit>`,
|
||||
typeOptionType: `__VLS_ModelEmit`,
|
||||
});
|
||||
}
|
||||
if (scriptSetupRanges.emits.define) {
|
||||
const { typeArg, hasUnionTypeArg } = scriptSetupRanges.emits.define;
|
||||
codes.push({
|
||||
optionExp: `{} as __VLS_NormalizeEmits<typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}>`,
|
||||
typeOptionType: typeArg && !hasUnionTypeArg
|
||||
? `__VLS_Emit`
|
||||
: undefined,
|
||||
});
|
||||
}
|
||||
if (options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionType)) {
|
||||
if (codes.length === 1) {
|
||||
yield `__typeEmits: {} as `;
|
||||
yield codes[0].typeOptionType;
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
else if (codes.length >= 2) {
|
||||
yield `__typeEmits: {} as `;
|
||||
yield codes[0].typeOptionType;
|
||||
for (let i = 1; i < codes.length; i++) {
|
||||
yield ` & `;
|
||||
yield codes[i].typeOptionType;
|
||||
}
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
}
|
||||
else if (codes.every(code => code.optionExp)) {
|
||||
if (codes.length === 1) {
|
||||
yield `emits: `;
|
||||
yield codes[0].optionExp;
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
else if (codes.length >= 2) {
|
||||
yield `emits: {${common_1.newLine}`;
|
||||
for (const code of codes) {
|
||||
yield `...`;
|
||||
yield code.optionExp;
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
yield `},${common_1.newLine}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption, inheritAttrs) {
|
||||
const codes = [];
|
||||
if (ctx.generatedPropsType) {
|
||||
codes.push({
|
||||
optionExp: [
|
||||
`{} as `,
|
||||
scriptSetupRanges.props.withDefaults?.arg ? `${ctx.localTypes.WithDefaults}<` : '',
|
||||
`${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`,
|
||||
scriptSetupRanges.props.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
|
||||
].join(''),
|
||||
typeOptionExp: `{} as __VLS_PublicProps`,
|
||||
});
|
||||
}
|
||||
if (scriptSetupRanges.props.define?.arg) {
|
||||
const { arg } = scriptSetupRanges.props.define;
|
||||
codes.push({
|
||||
optionExp: (0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation),
|
||||
typeOptionExp: undefined,
|
||||
});
|
||||
}
|
||||
if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
|
||||
let attrsType = `__VLS_TemplateResult['attrs']`;
|
||||
if (hasEmitsOption) {
|
||||
attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
|
||||
}
|
||||
const propsType = `__VLS_PickNotAny<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
|
||||
const optionType = `${ctx.localTypes.TypePropsToOption}<${propsType}>`;
|
||||
codes.unshift({
|
||||
optionExp: codes.length
|
||||
? `{} as ${optionType}`
|
||||
// workaround for https://github.com/vuejs/core/pull/7419
|
||||
: `{} as keyof ${propsType} extends never ? never: ${optionType}`,
|
||||
typeOptionExp: `{} as ${attrsType}`,
|
||||
});
|
||||
}
|
||||
const useTypeOption = options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionExp);
|
||||
const useOption = !useTypeOption || scriptSetupRanges.props.withDefaults;
|
||||
if (useTypeOption) {
|
||||
if (codes.length === 1) {
|
||||
yield `__typeProps: `;
|
||||
yield codes[0].typeOptionExp;
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
else if (codes.length >= 2) {
|
||||
yield `__typeProps: {${common_1.newLine}`;
|
||||
for (const { typeOptionExp } of codes) {
|
||||
yield `...`;
|
||||
yield typeOptionExp;
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
yield `},${common_1.newLine}`;
|
||||
}
|
||||
}
|
||||
if (useOption) {
|
||||
if (codes.length === 1) {
|
||||
yield `props: `;
|
||||
yield codes[0].optionExp;
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
else if (codes.length >= 2) {
|
||||
yield `props: {${common_1.newLine}`;
|
||||
for (const { optionExp } of codes) {
|
||||
yield `...`;
|
||||
yield optionExp;
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
yield `},${common_1.newLine}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=component.js.map
|
||||
5
node_modules/@vue/language-core/lib/codegen/script/componentSelf.d.ts
generated
vendored
Normal file
5
node_modules/@vue/language-core/lib/codegen/script/componentSelf.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from '../template/context';
|
||||
import type { ScriptCodegenContext } from './context';
|
||||
import { type ScriptCodegenOptions } from './index';
|
||||
export declare function generateComponentSelf(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, templateCodegenCtx: TemplateCodegenContext): Generator<Code>;
|
||||
64
node_modules/@vue/language-core/lib/codegen/script/componentSelf.js
generated
vendored
Normal file
64
node_modules/@vue/language-core/lib/codegen/script/componentSelf.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateComponentSelf = generateComponentSelf;
|
||||
const path = require("path-browserify");
|
||||
const common_1 = require("../common");
|
||||
const component_1 = require("./component");
|
||||
const index_1 = require("./index");
|
||||
const template_1 = require("./template");
|
||||
function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
||||
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
||||
yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
|
||||
yield `setup() {${common_1.newLine}`;
|
||||
yield `return {${common_1.newLine}`;
|
||||
if (ctx.bypassDefineComponent) {
|
||||
yield* (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges);
|
||||
}
|
||||
// bindings
|
||||
const templateUsageVars = (0, template_1.getTemplateUsageVars)(options, ctx);
|
||||
for (const [content, bindings] of [
|
||||
[options.sfc.scriptSetup.content, options.scriptSetupRanges.bindings],
|
||||
options.sfc.script && options.scriptRanges
|
||||
? [options.sfc.script.content, options.scriptRanges.bindings]
|
||||
: ['', []],
|
||||
]) {
|
||||
for (const expose of bindings) {
|
||||
const varName = content.substring(expose.start, expose.end);
|
||||
if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
|
||||
continue;
|
||||
}
|
||||
const templateOffset = options.getGeneratedLength();
|
||||
yield `${varName}: ${varName} as typeof `;
|
||||
const scriptOffset = options.getGeneratedLength();
|
||||
yield `${varName},${common_1.newLine}`;
|
||||
options.linkedCodeMappings.push({
|
||||
sourceOffsets: [scriptOffset],
|
||||
generatedOffsets: [templateOffset],
|
||||
lengths: [varName.length],
|
||||
data: undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
yield `}${common_1.endOfLine}`; // return {
|
||||
yield `},${common_1.newLine}`; // setup() {
|
||||
if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
|
||||
const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
|
||||
for (const code of emitOptionCodes) {
|
||||
yield code;
|
||||
}
|
||||
yield* (0, component_1.generatePropsOption)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges, !!emitOptionCodes.length, false);
|
||||
}
|
||||
if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
|
||||
const { args } = options.scriptRanges.exportDefault;
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
|
||||
}
|
||||
yield `})${common_1.endOfLine}`; // defineComponent {
|
||||
}
|
||||
else if (options.sfc.script) {
|
||||
yield `let __VLS_self!: typeof import('./${path.basename(options.fileName)}').default${common_1.endOfLine}`;
|
||||
}
|
||||
else {
|
||||
yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${common_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=componentSelf.js.map
|
||||
28
node_modules/@vue/language-core/lib/codegen/script/context.d.ts
generated
vendored
Normal file
28
node_modules/@vue/language-core/lib/codegen/script/context.d.ts
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { InlayHintInfo } from '../inlayHints';
|
||||
import type { ScriptCodegenOptions } from './index';
|
||||
export interface HelperType {
|
||||
name: string;
|
||||
used?: boolean;
|
||||
generated?: boolean;
|
||||
code: string;
|
||||
}
|
||||
export type ScriptCodegenContext = ReturnType<typeof createScriptCodegenContext>;
|
||||
export declare function createScriptCodegenContext(options: ScriptCodegenOptions): {
|
||||
generatedTemplate: boolean;
|
||||
generatedPropsType: boolean;
|
||||
scriptSetupGeneratedOffset: number | undefined;
|
||||
bypassDefineComponent: boolean;
|
||||
bindingNames: Set<string>;
|
||||
localTypes: {
|
||||
generate: (names: string[]) => Generator<string, void, unknown>;
|
||||
getUsedNames(): Set<string>;
|
||||
readonly PrettifyLocal: string;
|
||||
readonly OmitKeepDiscriminatedUnion: string;
|
||||
readonly WithDefaults: string;
|
||||
readonly WithTemplateSlots: string;
|
||||
readonly PropsChildren: string;
|
||||
readonly TypePropsToOption: string;
|
||||
readonly OmitIndexSignature: string;
|
||||
};
|
||||
inlayHints: InlayHintInfo[];
|
||||
};
|
||||
21
node_modules/@vue/language-core/lib/codegen/script/context.js
generated
vendored
Normal file
21
node_modules/@vue/language-core/lib/codegen/script/context.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createScriptCodegenContext = createScriptCodegenContext;
|
||||
const localTypes_1 = require("../localTypes");
|
||||
function createScriptCodegenContext(options) {
|
||||
const localTypes = (0, localTypes_1.getLocalTypesGenerator)(options.compilerOptions, options.vueCompilerOptions);
|
||||
const inlayHints = [];
|
||||
return {
|
||||
generatedTemplate: false,
|
||||
generatedPropsType: false,
|
||||
scriptSetupGeneratedOffset: undefined,
|
||||
bypassDefineComponent: options.lang === 'js' || options.lang === 'jsx',
|
||||
bindingNames: new Set([
|
||||
...options.scriptRanges?.bindings.map(range => options.sfc.script.content.substring(range.start, range.end)) ?? [],
|
||||
...options.scriptSetupRanges?.bindings.map(range => options.sfc.scriptSetup.content.substring(range.start, range.end)) ?? [],
|
||||
]),
|
||||
localTypes,
|
||||
inlayHints,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=context.js.map
|
||||
33
node_modules/@vue/language-core/lib/codegen/script/index.d.ts
generated
vendored
Normal file
33
node_modules/@vue/language-core/lib/codegen/script/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { Mapping } from '@volar/language-core';
|
||||
import type * as ts from 'typescript';
|
||||
import type { ScriptRanges } from '../../parsers/scriptRanges';
|
||||
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
||||
import type { Code, Sfc, VueCodeInformation, VueCompilerOptions } from '../../types';
|
||||
import type { TemplateCodegenContext } from '../template/context';
|
||||
import { ScriptCodegenContext } from './context';
|
||||
export declare const codeFeatures: {
|
||||
all: VueCodeInformation;
|
||||
none: VueCodeInformation;
|
||||
verification: VueCodeInformation;
|
||||
navigation: VueCodeInformation;
|
||||
navigationWithoutRename: VueCodeInformation;
|
||||
};
|
||||
export interface ScriptCodegenOptions {
|
||||
fileName: string;
|
||||
ts: typeof ts;
|
||||
compilerOptions: ts.CompilerOptions;
|
||||
vueCompilerOptions: VueCompilerOptions;
|
||||
sfc: Sfc;
|
||||
lang: string;
|
||||
scriptRanges: ScriptRanges | undefined;
|
||||
scriptSetupRanges: ScriptSetupRanges | undefined;
|
||||
templateCodegen: TemplateCodegenContext & {
|
||||
codes: Code[];
|
||||
} | undefined;
|
||||
edited: boolean;
|
||||
appendGlobalTypes: boolean;
|
||||
getGeneratedLength: () => number;
|
||||
linkedCodeMappings: Mapping[];
|
||||
}
|
||||
export declare function generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext>;
|
||||
export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string): Generator<Code>;
|
||||
171
node_modules/@vue/language-core/lib/codegen/script/index.js
generated
vendored
Normal file
171
node_modules/@vue/language-core/lib/codegen/script/index.js
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.codeFeatures = void 0;
|
||||
exports.generateScript = generateScript;
|
||||
exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
|
||||
const path = require("path-browserify");
|
||||
const common_1 = require("../common");
|
||||
const globalTypes_1 = require("../globalTypes");
|
||||
const componentSelf_1 = require("./componentSelf");
|
||||
const context_1 = require("./context");
|
||||
const scriptSetup_1 = require("./scriptSetup");
|
||||
const src_1 = require("./src");
|
||||
const styleModulesType_1 = require("./styleModulesType");
|
||||
const template_1 = require("./template");
|
||||
exports.codeFeatures = {
|
||||
all: {
|
||||
verification: true,
|
||||
completion: true,
|
||||
semantic: true,
|
||||
navigation: true,
|
||||
},
|
||||
none: {},
|
||||
verification: {
|
||||
verification: true,
|
||||
},
|
||||
navigation: {
|
||||
navigation: true,
|
||||
},
|
||||
navigationWithoutRename: {
|
||||
navigation: {
|
||||
shouldRename() {
|
||||
return false;
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
function* generateScript(options) {
|
||||
const ctx = (0, context_1.createScriptCodegenContext)(options);
|
||||
if (options.vueCompilerOptions.__setupedGlobalTypes) {
|
||||
const globalTypes = options.vueCompilerOptions.__setupedGlobalTypes;
|
||||
if (typeof globalTypes === 'object') {
|
||||
let relativePath = path.relative(path.dirname(options.fileName), globalTypes.absolutePath);
|
||||
if (relativePath !== globalTypes.absolutePath && !relativePath.startsWith('./') && !relativePath.startsWith('../')) {
|
||||
relativePath = './' + relativePath;
|
||||
}
|
||||
yield `/// <reference types="${relativePath}" />${common_1.newLine}`;
|
||||
}
|
||||
else {
|
||||
yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${common_1.newLine}`;
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield `/* placeholder */`;
|
||||
}
|
||||
if (options.sfc.script?.src) {
|
||||
yield* (0, src_1.generateSrc)(options.sfc.script, options.sfc.script.src);
|
||||
}
|
||||
if (options.sfc.script && options.scriptRanges) {
|
||||
const { exportDefault, classBlockEnd } = options.scriptRanges;
|
||||
const isExportRawObject = exportDefault
|
||||
&& options.sfc.script.content[exportDefault.expression.start] === '{';
|
||||
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
||||
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
||||
yield* generateDefineProp(options, options.sfc.scriptSetup);
|
||||
if (exportDefault) {
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
|
||||
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
|
||||
}
|
||||
else {
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
|
||||
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/both.vue');
|
||||
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
||||
}
|
||||
}
|
||||
else if (exportDefault && isExportRawObject && options.vueCompilerOptions.optionsWrapper.length) {
|
||||
ctx.inlayHints.push({
|
||||
blockName: options.sfc.script.name,
|
||||
offset: exportDefault.expression.start,
|
||||
setting: 'vue.inlayHints.optionsWrapper',
|
||||
label: options.vueCompilerOptions.optionsWrapper.length
|
||||
? options.vueCompilerOptions.optionsWrapper[0]
|
||||
: '[Missing optionsWrapper[0]]',
|
||||
tooltip: [
|
||||
'This is virtual code that is automatically wrapped for type support, it does not affect your runtime behavior, you can customize it via `vueCompilerOptions.optionsWrapper` option in tsconfig / jsconfig.',
|
||||
'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
|
||||
].join('\n\n'),
|
||||
}, {
|
||||
blockName: options.sfc.script.name,
|
||||
offset: exportDefault.expression.end,
|
||||
setting: 'vue.inlayHints.optionsWrapper',
|
||||
label: options.vueCompilerOptions.optionsWrapper.length >= 2
|
||||
? options.vueCompilerOptions.optionsWrapper[1]
|
||||
: '[Missing optionsWrapper[1]]',
|
||||
});
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
|
||||
yield options.vueCompilerOptions.optionsWrapper[0];
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.start, exportDefault.expression.end, exports.codeFeatures.all);
|
||||
yield options.vueCompilerOptions.optionsWrapper[1];
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
|
||||
}
|
||||
else if (classBlockEnd !== undefined) {
|
||||
if (options.vueCompilerOptions.skipTemplateCodegen) {
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
|
||||
}
|
||||
else {
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, exports.codeFeatures.all);
|
||||
yield `__VLS_template = () => {${common_1.newLine}`;
|
||||
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
||||
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
||||
yield `}${common_1.endOfLine}`;
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, exports.codeFeatures.all);
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
|
||||
}
|
||||
}
|
||||
else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
||||
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
||||
yield* generateDefineProp(options, options.sfc.scriptSetup);
|
||||
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
||||
}
|
||||
if (options.sfc.script) {
|
||||
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
|
||||
}
|
||||
if (options.sfc.scriptSetup) {
|
||||
yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
|
||||
}
|
||||
if (!ctx.generatedTemplate) {
|
||||
yield `function __VLS_template() {${common_1.newLine}`;
|
||||
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
||||
yield `}${common_1.endOfLine}`;
|
||||
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
||||
}
|
||||
// #4788
|
||||
yield* (0, styleModulesType_1.generateStyleModulesType)(options, ctx);
|
||||
if (options.edited) {
|
||||
yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${common_1.endOfLine}`;
|
||||
}
|
||||
yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
|
||||
if (options.appendGlobalTypes) {
|
||||
yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions.lib, options.vueCompilerOptions.target, options.vueCompilerOptions.strictTemplates);
|
||||
}
|
||||
if (options.sfc.scriptSetup) {
|
||||
yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, exports.codeFeatures.verification];
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
function* generateScriptSectionPartiallyEnding(source, end, mark) {
|
||||
yield `;`;
|
||||
yield ['', source, end, exports.codeFeatures.verification];
|
||||
yield `/* PartiallyEnd: ${mark} */${common_1.newLine}`;
|
||||
}
|
||||
function* generateDefineProp(options, scriptSetup) {
|
||||
const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
|
||||
const definePropProposalB = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
|
||||
if (definePropProposalA || definePropProposalB) {
|
||||
yield `type __VLS_PropOptions<T> = Exclude<import('${options.vueCompilerOptions.lib}').Prop<T>, import('${options.vueCompilerOptions.lib}').PropType<T>>${common_1.endOfLine}`;
|
||||
if (definePropProposalA) {
|
||||
yield `declare function defineProp<T>(name: string, options: ({ required: true } | { default: T }) & __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
|
||||
yield `declare function defineProp<T>(name?: string, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${common_1.endOfLine}`;
|
||||
}
|
||||
if (definePropProposalB) {
|
||||
yield `declare function defineProp<T>(value: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
|
||||
yield `declare function defineProp<T>(value: T | (() => T) | undefined, required: true, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
|
||||
yield `declare function defineProp<T>(value?: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${common_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
6
node_modules/@vue/language-core/lib/codegen/script/scriptSetup.d.ts
generated
vendored
Normal file
6
node_modules/@vue/language-core/lib/codegen/script/scriptSetup.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
||||
import type { Code, Sfc } from '../../types';
|
||||
import type { ScriptCodegenContext } from './context';
|
||||
import { ScriptCodegenOptions } from './index';
|
||||
export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
||||
export declare function generateScriptSetup(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
||||
438
node_modules/@vue/language-core/lib/codegen/script/scriptSetup.js
generated
vendored
Normal file
438
node_modules/@vue/language-core/lib/codegen/script/scriptSetup.js
generated
vendored
Normal file
@@ -0,0 +1,438 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateScriptSetupImports = generateScriptSetupImports;
|
||||
exports.generateScriptSetup = generateScriptSetup;
|
||||
const common_1 = require("../common");
|
||||
const component_1 = require("./component");
|
||||
const componentSelf_1 = require("./componentSelf");
|
||||
const index_1 = require("./index");
|
||||
const template_1 = require("./template");
|
||||
function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
|
||||
yield [
|
||||
scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)),
|
||||
'scriptSetup',
|
||||
0,
|
||||
index_1.codeFeatures.all,
|
||||
];
|
||||
yield common_1.newLine;
|
||||
}
|
||||
function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
||||
const definePropMirrors = new Map();
|
||||
if (scriptSetup.generic) {
|
||||
if (!options.scriptRanges?.exportDefault) {
|
||||
if (options.sfc.scriptSetup) {
|
||||
// #4569
|
||||
yield [
|
||||
'',
|
||||
'scriptSetup',
|
||||
options.sfc.scriptSetup.content.length,
|
||||
index_1.codeFeatures.verification,
|
||||
];
|
||||
}
|
||||
yield `export default `;
|
||||
}
|
||||
yield `(<`;
|
||||
yield [
|
||||
scriptSetup.generic,
|
||||
scriptSetup.name,
|
||||
scriptSetup.genericOffset,
|
||||
index_1.codeFeatures.all,
|
||||
];
|
||||
if (!scriptSetup.generic.endsWith(`,`)) {
|
||||
yield `,`;
|
||||
}
|
||||
yield `>(${common_1.newLine}`
|
||||
+ ` __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'],${common_1.newLine}`
|
||||
+ ` __VLS_ctx?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>,${common_1.newLine}` // use __VLS_Prettify for less dts code
|
||||
+ ` __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],${common_1.newLine}`
|
||||
+ ` __VLS_setup = (async () => {${common_1.newLine}`;
|
||||
yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, undefined, definePropMirrors);
|
||||
const emitTypes = [];
|
||||
if (scriptSetupRanges.emits.define) {
|
||||
emitTypes.push(`typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}`);
|
||||
}
|
||||
if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
|
||||
emitTypes.push(`typeof __VLS_modelEmit`);
|
||||
}
|
||||
yield ` return {} as {${common_1.newLine}`
|
||||
+ ` props: ${ctx.localTypes.PrettifyLocal}<typeof __VLS_functionalComponentProps & __VLS_TemplateResult['attrs'] & __VLS_PublicProps> & __VLS_BuiltInPublicProps,${common_1.newLine}`
|
||||
+ ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,${common_1.newLine}`
|
||||
+ ` attrs: any,${common_1.newLine}`
|
||||
+ ` slots: __VLS_TemplateResult['slots'],${common_1.newLine}`
|
||||
+ ` emit: ${emitTypes.length ? emitTypes.join(' & ') : `{}`},${common_1.newLine}`
|
||||
+ ` }${common_1.endOfLine}`;
|
||||
yield ` })(),${common_1.newLine}`; // __VLS_setup = (async () => {
|
||||
yield `) => ({} as import('${options.vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`;
|
||||
}
|
||||
else if (!options.sfc.script) {
|
||||
// no script block, generate script setup code at root
|
||||
yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, 'export default', definePropMirrors);
|
||||
}
|
||||
else {
|
||||
if (!options.scriptRanges?.exportDefault) {
|
||||
yield `export default `;
|
||||
}
|
||||
yield `await (async () => {${common_1.newLine}`;
|
||||
yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, 'return', definePropMirrors);
|
||||
yield `})()`;
|
||||
}
|
||||
if (ctx.scriptSetupGeneratedOffset !== undefined) {
|
||||
for (const defineProp of scriptSetupRanges.defineProp) {
|
||||
if (!defineProp.localName) {
|
||||
continue;
|
||||
}
|
||||
const [_, localName] = getPropAndLocalName(scriptSetup, defineProp);
|
||||
const propMirror = definePropMirrors.get(localName);
|
||||
if (propMirror !== undefined) {
|
||||
options.linkedCodeMappings.push({
|
||||
sourceOffsets: [defineProp.localName.start + ctx.scriptSetupGeneratedOffset],
|
||||
generatedOffsets: [propMirror],
|
||||
lengths: [defineProp.localName.end - defineProp.localName.start],
|
||||
data: undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, syntax, definePropMirrors) {
|
||||
if (options.vueCompilerOptions.target >= 3.3) {
|
||||
yield `const { `;
|
||||
for (const macro of Object.keys(options.vueCompilerOptions.macros)) {
|
||||
if (!ctx.bindingNames.has(macro) && macro !== 'templateRef') {
|
||||
yield macro + `, `;
|
||||
}
|
||||
}
|
||||
yield `} = await import('${options.vueCompilerOptions.lib}')${common_1.endOfLine}`;
|
||||
}
|
||||
ctx.scriptSetupGeneratedOffset = options.getGeneratedLength() - scriptSetupRanges.importSectionEndOffset;
|
||||
let setupCodeModifies = [];
|
||||
if (scriptSetupRanges.props.define) {
|
||||
setupCodeModifies.push(...generateDefineWithType(scriptSetup, scriptSetupRanges.props.name, scriptSetupRanges.props.define, scriptSetupRanges.props.withDefaults ?? scriptSetupRanges.props.define, '__VLS_props', '__VLS_Props'));
|
||||
}
|
||||
if (scriptSetupRanges.slots.define) {
|
||||
if (scriptSetupRanges.slots.isObjectBindingPattern) {
|
||||
setupCodeModifies.push([
|
||||
[`__VLS_slots;\nconst __VLS_slots = `],
|
||||
scriptSetupRanges.slots.define.start,
|
||||
scriptSetupRanges.slots.define.start,
|
||||
]);
|
||||
}
|
||||
else if (!scriptSetupRanges.slots.name) {
|
||||
setupCodeModifies.push([[`const __VLS_slots = `], scriptSetupRanges.slots.define.start, scriptSetupRanges.slots.define.start]);
|
||||
}
|
||||
}
|
||||
if (scriptSetupRanges.emits.define) {
|
||||
setupCodeModifies.push(...generateDefineWithType(scriptSetup, scriptSetupRanges.emits.name, scriptSetupRanges.emits.define, scriptSetupRanges.emits.define, '__VLS_emit', '__VLS_Emit'));
|
||||
}
|
||||
if (scriptSetupRanges.expose.define) {
|
||||
if (scriptSetupRanges.expose.define?.typeArg) {
|
||||
setupCodeModifies.push([
|
||||
[
|
||||
`let __VLS_exposed!: `,
|
||||
(0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.expose.define.typeArg.start, scriptSetupRanges.expose.define.typeArg.end, index_1.codeFeatures.navigation),
|
||||
`${common_1.endOfLine}`,
|
||||
],
|
||||
scriptSetupRanges.expose.define.start,
|
||||
scriptSetupRanges.expose.define.start,
|
||||
]);
|
||||
}
|
||||
else if (scriptSetupRanges.expose.define?.arg) {
|
||||
setupCodeModifies.push([
|
||||
[
|
||||
`const __VLS_exposed = `,
|
||||
(0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.expose.define.arg.start, scriptSetupRanges.expose.define.arg.end, index_1.codeFeatures.navigation),
|
||||
`${common_1.endOfLine}`,
|
||||
],
|
||||
scriptSetupRanges.expose.define.start,
|
||||
scriptSetupRanges.expose.define.start,
|
||||
]);
|
||||
}
|
||||
else {
|
||||
setupCodeModifies.push([
|
||||
[`const __VLS_exposed = {}${common_1.endOfLine}`],
|
||||
scriptSetupRanges.expose.define.start,
|
||||
scriptSetupRanges.expose.define.start,
|
||||
]);
|
||||
}
|
||||
}
|
||||
if (scriptSetupRanges.cssModules.length) {
|
||||
for (const { define } of scriptSetupRanges.cssModules) {
|
||||
setupCodeModifies.push([
|
||||
[`(`],
|
||||
define.start,
|
||||
define.start
|
||||
], [
|
||||
define.arg ? [
|
||||
` as Omit<__VLS_StyleModules, '$style'>[`,
|
||||
(0, common_1.generateSfcBlockSection)(scriptSetup, define.arg.start, define.arg.end, index_1.codeFeatures.all),
|
||||
`])`
|
||||
] : [
|
||||
` as __VLS_StyleModules[`,
|
||||
['', scriptSetup.name, define.exp.start, index_1.codeFeatures.verification],
|
||||
`'$style'`,
|
||||
['', scriptSetup.name, define.exp.end, index_1.codeFeatures.verification],
|
||||
`])`
|
||||
],
|
||||
define.end,
|
||||
define.end
|
||||
]);
|
||||
}
|
||||
}
|
||||
const isTs = options.lang !== 'js' && options.lang !== 'jsx';
|
||||
for (const { define } of scriptSetupRanges.templateRefs) {
|
||||
if (!define.arg) {
|
||||
continue;
|
||||
}
|
||||
if (isTs) {
|
||||
setupCodeModifies.push([
|
||||
[
|
||||
`<__VLS_TemplateResult['refs'][`,
|
||||
(0, common_1.generateSfcBlockSection)(scriptSetup, define.arg.start, define.arg.end, index_1.codeFeatures.navigation),
|
||||
`], keyof __VLS_TemplateResult['refs']>`
|
||||
],
|
||||
define.exp.end,
|
||||
define.exp.end
|
||||
]);
|
||||
}
|
||||
else {
|
||||
setupCodeModifies.push([
|
||||
[`(`],
|
||||
define.start,
|
||||
define.start
|
||||
], [
|
||||
[
|
||||
` as __VLS_UseTemplateRef<__VLS_TemplateResult['refs'][`,
|
||||
(0, common_1.generateSfcBlockSection)(scriptSetup, define.arg.start, define.arg.end, index_1.codeFeatures.navigation),
|
||||
`]>)`
|
||||
],
|
||||
define.end,
|
||||
define.end
|
||||
]);
|
||||
}
|
||||
}
|
||||
setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
|
||||
let nextStart = scriptSetupRanges.importSectionEndOffset;
|
||||
for (const [codes, start, end] of setupCodeModifies) {
|
||||
yield (0, common_1.generateSfcBlockSection)(scriptSetup, nextStart, start, index_1.codeFeatures.all);
|
||||
for (const code of codes) {
|
||||
yield code;
|
||||
}
|
||||
nextStart = end;
|
||||
}
|
||||
yield (0, common_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, index_1.codeFeatures.all);
|
||||
yield* (0, index_1.generateScriptSectionPartiallyEnding)(scriptSetup.name, scriptSetup.content.length, '#3632/scriptSetup.vue');
|
||||
if (scriptSetupRanges.props.define?.typeArg && scriptSetupRanges.props.withDefaults?.arg) {
|
||||
// fix https://github.com/vuejs/language-tools/issues/1187
|
||||
yield `const __VLS_withDefaultsArg = (function <T>(t: T) { return t })(`;
|
||||
yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.withDefaults.arg.start, scriptSetupRanges.props.withDefaults.arg.end, index_1.codeFeatures.navigation);
|
||||
yield `)${common_1.endOfLine}`;
|
||||
}
|
||||
yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors);
|
||||
yield* generateModelEmit(scriptSetup, scriptSetupRanges);
|
||||
yield `function __VLS_template() {${common_1.newLine}`;
|
||||
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
||||
yield `}${common_1.endOfLine}`;
|
||||
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
||||
yield `type __VLS_TemplateResult = ReturnType<typeof __VLS_template>${common_1.endOfLine}`;
|
||||
if (syntax) {
|
||||
if (!options.vueCompilerOptions.skipTemplateCodegen && (options.templateCodegen?.hasSlot || scriptSetupRanges?.slots.define)) {
|
||||
yield `const __VLS_component = `;
|
||||
yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
|
||||
yield common_1.endOfLine;
|
||||
yield `${syntax} `;
|
||||
yield `{} as ${ctx.localTypes.WithTemplateSlots}<typeof __VLS_component, __VLS_TemplateResult['slots']>${common_1.endOfLine}`;
|
||||
}
|
||||
else {
|
||||
yield `${syntax} `;
|
||||
yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
|
||||
yield common_1.endOfLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
function* generateDefineWithType(scriptSetup, name, define, expression, defaultName, typeName) {
|
||||
const { statement, typeArg } = define;
|
||||
if (typeArg) {
|
||||
yield [[
|
||||
`type ${typeName} = `,
|
||||
(0, common_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, index_1.codeFeatures.all),
|
||||
common_1.endOfLine,
|
||||
], statement.start, statement.start];
|
||||
yield [[typeName], typeArg.start, typeArg.end];
|
||||
}
|
||||
if (!name) {
|
||||
if (statement.start === expression.start && statement.end === expression.end) {
|
||||
yield [[`const ${defaultName} = `], expression.start, expression.start];
|
||||
}
|
||||
else if (typeArg) {
|
||||
yield [[
|
||||
`const ${defaultName} = `,
|
||||
(0, common_1.generateSfcBlockSection)(scriptSetup, expression.start, typeArg.start, index_1.codeFeatures.all)
|
||||
], statement.start, typeArg.start];
|
||||
yield [[
|
||||
(0, common_1.generateSfcBlockSection)(scriptSetup, typeArg.end, expression.end, index_1.codeFeatures.all),
|
||||
common_1.endOfLine,
|
||||
(0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, expression.start, index_1.codeFeatures.all),
|
||||
defaultName
|
||||
], typeArg.end, expression.end];
|
||||
}
|
||||
else {
|
||||
yield [[
|
||||
`const ${defaultName} = `,
|
||||
(0, common_1.generateSfcBlockSection)(scriptSetup, expression.start, expression.end, index_1.codeFeatures.all),
|
||||
common_1.endOfLine,
|
||||
(0, common_1.generateSfcBlockSection)(scriptSetup, statement.start, expression.start, index_1.codeFeatures.all),
|
||||
defaultName
|
||||
], statement.start, expression.end];
|
||||
}
|
||||
}
|
||||
}
|
||||
function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors) {
|
||||
yield `const __VLS_fnComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
|
||||
if (scriptSetupRanges.props.define?.arg) {
|
||||
yield `props: `;
|
||||
yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end, index_1.codeFeatures.navigation);
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
yield* (0, component_1.generateEmitsOption)(options, scriptSetupRanges);
|
||||
yield `})${common_1.endOfLine}`;
|
||||
yield `type __VLS_BuiltInPublicProps = ${options.vueCompilerOptions.target >= 3.4
|
||||
? `import('${options.vueCompilerOptions.lib}').PublicProps;`
|
||||
: options.vueCompilerOptions.target >= 3.0
|
||||
? `import('${options.vueCompilerOptions.lib}').VNodeProps
|
||||
& import('${options.vueCompilerOptions.lib}').AllowedComponentProps
|
||||
& import('${options.vueCompilerOptions.lib}').ComponentCustomProps;`
|
||||
: `globalThis.JSX.IntrinsicAttributes;`}`;
|
||||
yield common_1.endOfLine;
|
||||
yield `let __VLS_functionalComponentProps!: `;
|
||||
yield `${ctx.localTypes.OmitKeepDiscriminatedUnion}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
|
||||
yield common_1.endOfLine;
|
||||
if (scriptSetupRanges.defineProp.length) {
|
||||
yield `const __VLS_defaults = {${common_1.newLine}`;
|
||||
for (const defineProp of scriptSetupRanges.defineProp) {
|
||||
if (defineProp.defaultValue) {
|
||||
const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
|
||||
if (defineProp.name || defineProp.isModel) {
|
||||
yield propName;
|
||||
}
|
||||
else if (defineProp.localName) {
|
||||
yield localName;
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
yield `: `;
|
||||
yield getRangeName(scriptSetup, defineProp.defaultValue);
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
}
|
||||
yield `}${common_1.endOfLine}`;
|
||||
}
|
||||
yield `type __VLS_PublicProps = `;
|
||||
if (scriptSetupRanges.slots.define && options.vueCompilerOptions.jsxSlots) {
|
||||
if (ctx.generatedPropsType) {
|
||||
yield ` & `;
|
||||
}
|
||||
ctx.generatedPropsType = true;
|
||||
yield `${ctx.localTypes.PropsChildren}<typeof __VLS_slots>`;
|
||||
}
|
||||
if (scriptSetupRanges.defineProp.length) {
|
||||
if (ctx.generatedPropsType) {
|
||||
yield ` & `;
|
||||
}
|
||||
ctx.generatedPropsType = true;
|
||||
yield `{${common_1.newLine}`;
|
||||
for (const defineProp of scriptSetupRanges.defineProp) {
|
||||
const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
|
||||
if (defineProp.isModel && !defineProp.name) {
|
||||
yield propName;
|
||||
}
|
||||
else if (defineProp.name) {
|
||||
// renaming support
|
||||
yield (0, common_1.generateSfcBlockSection)(scriptSetup, defineProp.name.start, defineProp.name.end, index_1.codeFeatures.navigation);
|
||||
}
|
||||
else if (defineProp.localName) {
|
||||
definePropMirrors.set(localName, options.getGeneratedLength());
|
||||
yield localName;
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
yield defineProp.required
|
||||
? `: `
|
||||
: `?: `;
|
||||
yield* generateDefinePropType(scriptSetup, propName, localName, defineProp);
|
||||
yield `,${common_1.newLine}`;
|
||||
if (defineProp.modifierType) {
|
||||
let propModifierName = 'modelModifiers';
|
||||
if (defineProp.name) {
|
||||
propModifierName = `${getRangeName(scriptSetup, defineProp.name, true)}Modifiers`;
|
||||
}
|
||||
const modifierType = getRangeName(scriptSetup, defineProp.modifierType);
|
||||
definePropMirrors.set(propModifierName, options.getGeneratedLength());
|
||||
yield `${propModifierName}?: Record<${modifierType}, true>,${common_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
yield `}`;
|
||||
}
|
||||
if (scriptSetupRanges.props.define?.typeArg) {
|
||||
if (ctx.generatedPropsType) {
|
||||
yield ` & `;
|
||||
}
|
||||
ctx.generatedPropsType = true;
|
||||
yield `__VLS_Props`;
|
||||
}
|
||||
if (!ctx.generatedPropsType) {
|
||||
yield `{}`;
|
||||
}
|
||||
yield common_1.endOfLine;
|
||||
}
|
||||
function* generateModelEmit(scriptSetup, scriptSetupRanges) {
|
||||
const defineModels = scriptSetupRanges.defineProp.filter(p => p.isModel);
|
||||
if (defineModels.length) {
|
||||
yield `type __VLS_ModelEmit = {${common_1.newLine}`;
|
||||
for (const defineModel of defineModels) {
|
||||
const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
|
||||
yield `'update:${propName}': [value:`;
|
||||
yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
|
||||
yield `]${common_1.endOfLine}`;
|
||||
}
|
||||
yield `}${common_1.endOfLine}`;
|
||||
yield `const __VLS_modelEmit = defineEmits<__VLS_ModelEmit>()${common_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
function* generateDefinePropType(scriptSetup, propName, localName, defineProp) {
|
||||
if (defineProp.type) {
|
||||
// Infer from defineProp<T>
|
||||
yield getRangeName(scriptSetup, defineProp.type);
|
||||
}
|
||||
else if (defineProp.runtimeType && localName) {
|
||||
// Infer from actual prop declaration code
|
||||
yield `typeof ${localName}['value']`;
|
||||
}
|
||||
else if (defineProp.defaultValue && propName) {
|
||||
// Infer from defineProp({default: T})
|
||||
yield `typeof __VLS_defaults['${propName}']`;
|
||||
}
|
||||
else {
|
||||
yield `any`;
|
||||
}
|
||||
}
|
||||
function getPropAndLocalName(scriptSetup, defineProp) {
|
||||
const localName = defineProp.localName
|
||||
? getRangeName(scriptSetup, defineProp.localName)
|
||||
: undefined;
|
||||
let propName = defineProp.name
|
||||
? getRangeName(scriptSetup, defineProp.name)
|
||||
: defineProp.isModel
|
||||
? 'modelValue'
|
||||
: localName;
|
||||
if (defineProp.name) {
|
||||
propName = propName.replace(/['"]+/g, '');
|
||||
}
|
||||
return [propName, localName];
|
||||
}
|
||||
function getRangeName(scriptSetup, range, unwrap = false) {
|
||||
const offset = unwrap ? 1 : 0;
|
||||
return scriptSetup.content.substring(range.start + offset, range.end - offset);
|
||||
}
|
||||
//# sourceMappingURL=scriptSetup.js.map
|
||||
2
node_modules/@vue/language-core/lib/codegen/script/src.d.ts
generated
vendored
Normal file
2
node_modules/@vue/language-core/lib/codegen/script/src.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { Code, Sfc } from '../../types';
|
||||
export declare function generateSrc(script: NonNullable<Sfc['script']>, src: string): Generator<Code>;
|
||||
51
node_modules/@vue/language-core/lib/codegen/script/src.js
generated
vendored
Normal file
51
node_modules/@vue/language-core/lib/codegen/script/src.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateSrc = generateSrc;
|
||||
const common_1 = require("../common");
|
||||
const index_1 = require("./index");
|
||||
function* generateSrc(script, src) {
|
||||
if (src.endsWith('.d.ts')) {
|
||||
src = src.substring(0, src.length - '.d.ts'.length);
|
||||
}
|
||||
else if (src.endsWith('.ts')) {
|
||||
src = src.substring(0, src.length - '.ts'.length);
|
||||
}
|
||||
else if (src.endsWith('.tsx')) {
|
||||
src = src.substring(0, src.length - '.tsx'.length) + '.jsx';
|
||||
}
|
||||
if (!src.endsWith('.js') && !src.endsWith('.jsx')) {
|
||||
src = src + '.js';
|
||||
}
|
||||
yield `export * from `;
|
||||
yield [
|
||||
`'${src}'`,
|
||||
'script',
|
||||
script.srcOffset - 1,
|
||||
{
|
||||
...index_1.codeFeatures.all,
|
||||
navigation: src === script.src
|
||||
? true
|
||||
: {
|
||||
shouldRename: () => false,
|
||||
resolveRenameEditText(newName) {
|
||||
if (newName.endsWith('.jsx') || newName.endsWith('.js')) {
|
||||
newName = newName.split('.').slice(0, -1).join('.');
|
||||
}
|
||||
if (script?.src?.endsWith('.d.ts')) {
|
||||
newName = newName + '.d.ts';
|
||||
}
|
||||
else if (script?.src?.endsWith('.ts')) {
|
||||
newName = newName + '.ts';
|
||||
}
|
||||
else if (script?.src?.endsWith('.tsx')) {
|
||||
newName = newName + '.tsx';
|
||||
}
|
||||
return newName;
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
yield common_1.endOfLine;
|
||||
yield `export { default } from '${src}'${common_1.endOfLine}`;
|
||||
}
|
||||
//# sourceMappingURL=src.js.map
|
||||
4
node_modules/@vue/language-core/lib/codegen/script/styleModulesType.d.ts
generated
vendored
Normal file
4
node_modules/@vue/language-core/lib/codegen/script/styleModulesType.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { Code } from '../../types';
|
||||
import type { ScriptCodegenContext } from './context';
|
||||
import { ScriptCodegenOptions } from './index';
|
||||
export declare function generateStyleModulesType(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
|
||||
34
node_modules/@vue/language-core/lib/codegen/script/styleModulesType.js
generated
vendored
Normal file
34
node_modules/@vue/language-core/lib/codegen/script/styleModulesType.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateStyleModulesType = generateStyleModulesType;
|
||||
const index_1 = require("./index");
|
||||
const template_1 = require("./template");
|
||||
const common_1 = require("../common");
|
||||
function* generateStyleModulesType(options, ctx) {
|
||||
const styles = options.sfc.styles.map((style, i) => [style, i]).filter(([style]) => style.module);
|
||||
if (!styles.length && !options.scriptSetupRanges?.cssModules.length) {
|
||||
return;
|
||||
}
|
||||
yield `type __VLS_StyleModules = {${common_1.newLine}`;
|
||||
for (const [style, i] of styles) {
|
||||
const { name, offset } = style.module;
|
||||
if (offset) {
|
||||
yield [
|
||||
name,
|
||||
'main',
|
||||
offset + 1,
|
||||
index_1.codeFeatures.all
|
||||
];
|
||||
}
|
||||
else {
|
||||
yield name;
|
||||
}
|
||||
yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
|
||||
for (const className of style.classNames) {
|
||||
yield* (0, template_1.generateCssClassProperty)(i, className.text, className.offset, 'string', false);
|
||||
}
|
||||
yield `>${common_1.endOfLine}`;
|
||||
}
|
||||
yield `}${common_1.endOfLine}`;
|
||||
}
|
||||
//# sourceMappingURL=styleModulesType.js.map
|
||||
8
node_modules/@vue/language-core/lib/codegen/script/template.d.ts
generated
vendored
Normal file
8
node_modules/@vue/language-core/lib/codegen/script/template.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { Code } from '../../types';
|
||||
import { TemplateCodegenContext } from '../template/context';
|
||||
import type { ScriptCodegenContext } from './context';
|
||||
import { type ScriptCodegenOptions } from './index';
|
||||
export declare function generateTemplateDirectives(options: ScriptCodegenOptions): Generator<Code>;
|
||||
export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code, TemplateCodegenContext>;
|
||||
export declare function generateCssClassProperty(styleIndex: number, classNameWithDot: string, offset: number, propertyType: string, optional: boolean): Generator<Code>;
|
||||
export declare function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Set<string>;
|
||||
229
node_modules/@vue/language-core/lib/codegen/script/template.js
generated
vendored
Normal file
229
node_modules/@vue/language-core/lib/codegen/script/template.js
generated
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateTemplateDirectives = generateTemplateDirectives;
|
||||
exports.generateTemplate = generateTemplate;
|
||||
exports.generateCssClassProperty = generateCssClassProperty;
|
||||
exports.getTemplateUsageVars = getTemplateUsageVars;
|
||||
const path = require("path-browserify");
|
||||
const shared_1 = require("../../utils/shared");
|
||||
const common_1 = require("../common");
|
||||
const context_1 = require("../template/context");
|
||||
const interpolation_1 = require("../template/interpolation");
|
||||
const styleScopedClasses_1 = require("../template/styleScopedClasses");
|
||||
const index_1 = require("./index");
|
||||
function* generateTemplateCtx(options) {
|
||||
const exps = [];
|
||||
exps.push(`{} as InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>`);
|
||||
if (options.vueCompilerOptions.petiteVueExtensions.some(ext => options.fileName.endsWith(ext))) {
|
||||
exps.push(`globalThis`);
|
||||
}
|
||||
if (options.sfc.styles.some(style => style.module)) {
|
||||
exps.push(`{} as __VLS_StyleModules`);
|
||||
}
|
||||
yield `const __VLS_ctx = `;
|
||||
if (exps.length === 1) {
|
||||
yield exps[0];
|
||||
yield `${common_1.endOfLine}`;
|
||||
}
|
||||
else {
|
||||
yield `{${common_1.newLine}`;
|
||||
for (const exp of exps) {
|
||||
yield `...`;
|
||||
yield exp;
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
yield `}${common_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
function* generateTemplateComponents(options) {
|
||||
const exps = [];
|
||||
if (options.sfc.script && options.scriptRanges?.exportDefault?.componentsOption) {
|
||||
const { componentsOption } = options.scriptRanges.exportDefault;
|
||||
exps.push([
|
||||
options.sfc.script.content.substring(componentsOption.start, componentsOption.end),
|
||||
'script',
|
||||
componentsOption.start,
|
||||
index_1.codeFeatures.navigation,
|
||||
]);
|
||||
}
|
||||
let nameType;
|
||||
if (options.sfc.script && options.scriptRanges?.exportDefault?.nameOption) {
|
||||
const { nameOption } = options.scriptRanges.exportDefault;
|
||||
nameType = options.sfc.script.content.substring(nameOption.start, nameOption.end);
|
||||
}
|
||||
else if (options.sfc.scriptSetup) {
|
||||
const baseName = path.basename(options.fileName);
|
||||
nameType = `'${options.scriptSetupRanges?.options.name ?? baseName.substring(0, baseName.lastIndexOf('.'))}'`;
|
||||
}
|
||||
if (nameType) {
|
||||
exps.push(`{} as {
|
||||
[K in ${nameType}]: typeof __VLS_self
|
||||
& (new () => {
|
||||
${(0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target)}: typeof ${options.scriptSetupRanges?.slots?.name ?? '__VLS_slots'}
|
||||
})
|
||||
}`);
|
||||
}
|
||||
exps.push(`{} as NonNullable<typeof __VLS_self extends { components: infer C } ? C : {}>`);
|
||||
exps.push(`__VLS_ctx`);
|
||||
yield `const __VLS_localComponents = {${common_1.newLine}`;
|
||||
for (const type of exps) {
|
||||
yield `...`;
|
||||
yield type;
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
yield `}${common_1.endOfLine}`;
|
||||
yield `let __VLS_components!: typeof __VLS_localComponents & __VLS_GlobalComponents${common_1.endOfLine}`;
|
||||
}
|
||||
function* generateTemplateDirectives(options) {
|
||||
const exps = [];
|
||||
if (options.sfc.script && options.scriptRanges?.exportDefault?.directivesOption) {
|
||||
const { directivesOption } = options.scriptRanges.exportDefault;
|
||||
exps.push([
|
||||
options.sfc.script.content.substring(directivesOption.start, directivesOption.end),
|
||||
'script',
|
||||
directivesOption.start,
|
||||
index_1.codeFeatures.navigation,
|
||||
]);
|
||||
}
|
||||
exps.push(`{} as NonNullable<typeof __VLS_self extends { directives: infer D } ? D : {}>`);
|
||||
exps.push(`__VLS_ctx`);
|
||||
yield `const __VLS_localDirectives = {${common_1.newLine}`;
|
||||
for (const type of exps) {
|
||||
yield `...`;
|
||||
yield type;
|
||||
yield `,${common_1.newLine}`;
|
||||
}
|
||||
yield `}${common_1.endOfLine}`;
|
||||
yield `let __VLS_directives!: typeof __VLS_localDirectives & __VLS_GlobalDirectives${common_1.endOfLine}`;
|
||||
}
|
||||
function* generateTemplate(options, ctx) {
|
||||
ctx.generatedTemplate = true;
|
||||
const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)({
|
||||
scriptSetupBindingNames: new Set(),
|
||||
edited: options.edited,
|
||||
});
|
||||
yield* generateTemplateCtx(options);
|
||||
yield* generateTemplateComponents(options);
|
||||
yield* generateTemplateDirectives(options);
|
||||
yield* generateTemplateBody(options, templateCodegenCtx);
|
||||
return templateCodegenCtx;
|
||||
}
|
||||
function* generateTemplateBody(options, templateCodegenCtx) {
|
||||
const firstClasses = new Set();
|
||||
yield `let __VLS_styleScopedClasses!: {}`;
|
||||
for (let i = 0; i < options.sfc.styles.length; i++) {
|
||||
const style = options.sfc.styles[i];
|
||||
const option = options.vueCompilerOptions.experimentalResolveStyleCssClasses;
|
||||
if (option === 'always' || (option === 'scoped' && style.scoped)) {
|
||||
for (const className of style.classNames) {
|
||||
if (firstClasses.has(className.text)) {
|
||||
templateCodegenCtx.scopedClasses.push({
|
||||
source: 'style_' + i,
|
||||
className: className.text.slice(1),
|
||||
offset: className.offset + 1
|
||||
});
|
||||
continue;
|
||||
}
|
||||
firstClasses.add(className.text);
|
||||
yield* generateCssClassProperty(i, className.text, className.offset, 'boolean', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
yield common_1.endOfLine;
|
||||
yield* (0, styleScopedClasses_1.generateStyleScopedClasses)(templateCodegenCtx, true);
|
||||
yield* generateCssVars(options, templateCodegenCtx);
|
||||
if (options.templateCodegen) {
|
||||
for (const code of options.templateCodegen.codes) {
|
||||
yield code;
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield `// no template${common_1.newLine}`;
|
||||
if (!options.scriptSetupRanges?.slots.define) {
|
||||
yield `const __VLS_slots = {}${common_1.endOfLine}`;
|
||||
}
|
||||
yield `const __VLS_inheritedAttrs = {}${common_1.endOfLine}`;
|
||||
yield `const $refs = {}${common_1.endOfLine}`;
|
||||
yield `const $el = {} as any${common_1.endOfLine}`;
|
||||
}
|
||||
yield `return {${common_1.newLine}`;
|
||||
yield ` attrs: {} as Partial<typeof __VLS_inheritedAttrs>,${common_1.newLine}`;
|
||||
yield ` slots: ${options.scriptSetupRanges?.slots.name ?? '__VLS_slots'},${common_1.newLine}`;
|
||||
yield ` refs: $refs,${common_1.newLine}`;
|
||||
yield ` rootEl: $el,${common_1.newLine}`;
|
||||
yield `}${common_1.endOfLine}`;
|
||||
}
|
||||
function* generateCssClassProperty(styleIndex, classNameWithDot, offset, propertyType, optional) {
|
||||
yield `${common_1.newLine} & { `;
|
||||
yield [
|
||||
'',
|
||||
'style_' + styleIndex,
|
||||
offset,
|
||||
index_1.codeFeatures.navigation,
|
||||
];
|
||||
yield `'`;
|
||||
yield [
|
||||
classNameWithDot.substring(1),
|
||||
'style_' + styleIndex,
|
||||
offset + 1,
|
||||
index_1.codeFeatures.navigation,
|
||||
];
|
||||
yield `'`;
|
||||
yield [
|
||||
'',
|
||||
'style_' + styleIndex,
|
||||
offset + classNameWithDot.length,
|
||||
index_1.codeFeatures.navigationWithoutRename,
|
||||
];
|
||||
yield `${optional ? '?' : ''}: ${propertyType}`;
|
||||
yield ` }`;
|
||||
}
|
||||
function* generateCssVars(options, ctx) {
|
||||
if (!options.sfc.styles.length) {
|
||||
return;
|
||||
}
|
||||
yield `// CSS variable injection ${common_1.newLine}`;
|
||||
for (const style of options.sfc.styles) {
|
||||
for (const cssBind of style.cssVars) {
|
||||
for (const [segment, offset, onlyError] of (0, interpolation_1.forEachInterpolationSegment)(options.ts, undefined, undefined, ctx, cssBind.text, cssBind.offset, options.ts.createSourceFile('/a.txt', cssBind.text, 99))) {
|
||||
if (offset === undefined) {
|
||||
yield segment;
|
||||
}
|
||||
else {
|
||||
yield [
|
||||
segment,
|
||||
style.name,
|
||||
cssBind.offset + offset,
|
||||
onlyError
|
||||
? index_1.codeFeatures.navigation
|
||||
: index_1.codeFeatures.all,
|
||||
];
|
||||
}
|
||||
}
|
||||
yield common_1.endOfLine;
|
||||
}
|
||||
}
|
||||
yield `// CSS variable injection end ${common_1.newLine}`;
|
||||
}
|
||||
function getTemplateUsageVars(options, ctx) {
|
||||
const usageVars = new Set();
|
||||
const components = new Set(options.sfc.template?.ast?.components);
|
||||
if (options.templateCodegen) {
|
||||
// fix import components unused report
|
||||
for (const varName of ctx.bindingNames) {
|
||||
if (components.has(varName) || components.has((0, shared_1.hyphenateTag)(varName))) {
|
||||
usageVars.add(varName);
|
||||
}
|
||||
}
|
||||
for (const component of components) {
|
||||
if (component.indexOf('.') >= 0) {
|
||||
usageVars.add(component.split('.')[0]);
|
||||
}
|
||||
}
|
||||
for (const [varName] of options.templateCodegen.accessExternalVariables) {
|
||||
usageVars.add(varName);
|
||||
}
|
||||
}
|
||||
return usageVars;
|
||||
}
|
||||
//# sourceMappingURL=template.js.map
|
||||
2
node_modules/@vue/language-core/lib/codegen/template/camelized.d.ts
generated
vendored
Normal file
2
node_modules/@vue/language-core/lib/codegen/template/camelized.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { Code, VueCodeInformation } from '../../types';
|
||||
export declare function generateCamelized(code: string, offset: number, info: VueCodeInformation): Generator<Code>;
|
||||
31
node_modules/@vue/language-core/lib/codegen/template/camelized.js
generated
vendored
Normal file
31
node_modules/@vue/language-core/lib/codegen/template/camelized.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateCamelized = generateCamelized;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const common_1 = require("../common");
|
||||
function* generateCamelized(code, offset, info) {
|
||||
const parts = code.split('-');
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const part = parts[i];
|
||||
if (part !== '') {
|
||||
if (i === 0) {
|
||||
yield [
|
||||
part,
|
||||
'template',
|
||||
offset,
|
||||
info,
|
||||
];
|
||||
}
|
||||
else {
|
||||
yield [
|
||||
(0, shared_1.capitalize)(part),
|
||||
'template',
|
||||
offset,
|
||||
common_1.combineLastMapping,
|
||||
];
|
||||
}
|
||||
}
|
||||
offset += part.length + 1;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=camelized.js.map
|
||||
56
node_modules/@vue/language-core/lib/codegen/template/context.d.ts
generated
vendored
Normal file
56
node_modules/@vue/language-core/lib/codegen/template/context.d.ts
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
import type * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code, VueCodeInformation } from '../../types';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
import { InlayHintInfo } from '../inlayHints';
|
||||
export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;
|
||||
export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames' | 'edited'>): {
|
||||
slots: {
|
||||
name: string;
|
||||
loc?: number;
|
||||
tagRange: [number, number];
|
||||
varName: string;
|
||||
nodeLoc: any;
|
||||
}[];
|
||||
dynamicSlots: {
|
||||
expVar: string;
|
||||
varName: string;
|
||||
}[];
|
||||
codeFeatures: {
|
||||
all: VueCodeInformation;
|
||||
verification: VueCodeInformation;
|
||||
completion: VueCodeInformation;
|
||||
additionalCompletion: VueCodeInformation;
|
||||
navigation: VueCodeInformation;
|
||||
navigationWithoutRename: VueCodeInformation;
|
||||
navigationAndCompletion: VueCodeInformation;
|
||||
navigationAndAdditionalCompletion: VueCodeInformation;
|
||||
withoutHighlight: VueCodeInformation;
|
||||
withoutHighlightAndCompletion: VueCodeInformation;
|
||||
withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
|
||||
};
|
||||
accessExternalVariables: Map<string, Set<number>>;
|
||||
hasSlotElements: Set<CompilerDOM.ElementNode>;
|
||||
blockConditions: string[];
|
||||
usedComponentCtxVars: Set<string>;
|
||||
scopedClasses: {
|
||||
source: string;
|
||||
className: string;
|
||||
offset: number;
|
||||
}[];
|
||||
emptyClassOffsets: number[];
|
||||
inlayHints: InlayHintInfo[];
|
||||
hasSlot: boolean;
|
||||
inheritedAttrVars: Set<unknown>;
|
||||
templateRefs: Map<string, [varName: string, offset: number]>;
|
||||
singleRootElType: string | undefined;
|
||||
singleRootNode: CompilerDOM.ElementNode | undefined;
|
||||
accessExternalVariable(name: string, offset?: number): void;
|
||||
hasLocalVariable: (name: string) => boolean;
|
||||
addLocalVariable: (name: string) => void;
|
||||
removeLocalVariable: (name: string) => void;
|
||||
getInternalVariable: () => string;
|
||||
ignoreError: () => Generator<Code>;
|
||||
expectError: (prevNode: CompilerDOM.CommentNode) => Generator<Code>;
|
||||
resetDirectiveComments: (endStr: string) => Generator<Code>;
|
||||
generateAutoImportCompletion: () => Generator<Code>;
|
||||
};
|
||||
208
node_modules/@vue/language-core/lib/codegen/template/context.js
generated
vendored
Normal file
208
node_modules/@vue/language-core/lib/codegen/template/context.js
generated
vendored
Normal file
@@ -0,0 +1,208 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createTemplateCodegenContext = createTemplateCodegenContext;
|
||||
const common_1 = require("../common");
|
||||
const _codeFeatures = {
|
||||
all: {
|
||||
verification: true,
|
||||
completion: true,
|
||||
semantic: true,
|
||||
navigation: true,
|
||||
},
|
||||
verification: {
|
||||
verification: true,
|
||||
},
|
||||
completion: {
|
||||
completion: true,
|
||||
},
|
||||
additionalCompletion: {
|
||||
completion: { isAdditional: true },
|
||||
},
|
||||
navigation: {
|
||||
navigation: true,
|
||||
},
|
||||
navigationWithoutRename: {
|
||||
navigation: {
|
||||
shouldRename() {
|
||||
return false;
|
||||
},
|
||||
},
|
||||
},
|
||||
navigationAndCompletion: {
|
||||
navigation: true,
|
||||
completion: true,
|
||||
},
|
||||
navigationAndAdditionalCompletion: {
|
||||
navigation: true,
|
||||
completion: { isAdditional: true },
|
||||
},
|
||||
withoutHighlight: {
|
||||
semantic: { shouldHighlight: () => false },
|
||||
verification: true,
|
||||
navigation: true,
|
||||
completion: true,
|
||||
},
|
||||
withoutHighlightAndCompletion: {
|
||||
semantic: { shouldHighlight: () => false },
|
||||
verification: true,
|
||||
navigation: true,
|
||||
},
|
||||
withoutHighlightAndCompletionAndNavigation: {
|
||||
semantic: { shouldHighlight: () => false },
|
||||
verification: true,
|
||||
},
|
||||
};
|
||||
function createTemplateCodegenContext(options) {
|
||||
let ignoredError = false;
|
||||
let expectErrorToken;
|
||||
let variableId = 0;
|
||||
const codeFeatures = new Proxy(_codeFeatures, {
|
||||
get(target, key) {
|
||||
const data = target[key];
|
||||
if (data.verification) {
|
||||
if (ignoredError) {
|
||||
return {
|
||||
...data,
|
||||
verification: false,
|
||||
};
|
||||
}
|
||||
if (expectErrorToken) {
|
||||
const token = expectErrorToken;
|
||||
if (typeof data.verification !== 'object' || !data.verification.shouldReport) {
|
||||
return {
|
||||
...data,
|
||||
verification: {
|
||||
shouldReport: () => {
|
||||
token.errors++;
|
||||
return false;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
},
|
||||
});
|
||||
const localVars = new Map();
|
||||
const accessExternalVariables = new Map();
|
||||
const slots = [];
|
||||
const dynamicSlots = [];
|
||||
const hasSlotElements = new Set();
|
||||
;
|
||||
const blockConditions = [];
|
||||
const usedComponentCtxVars = new Set();
|
||||
const scopedClasses = [];
|
||||
const emptyClassOffsets = [];
|
||||
const inlayHints = [];
|
||||
const templateRefs = new Map();
|
||||
return {
|
||||
slots,
|
||||
dynamicSlots,
|
||||
codeFeatures,
|
||||
accessExternalVariables,
|
||||
hasSlotElements,
|
||||
blockConditions,
|
||||
usedComponentCtxVars,
|
||||
scopedClasses,
|
||||
emptyClassOffsets,
|
||||
inlayHints,
|
||||
hasSlot: false,
|
||||
inheritedAttrVars: new Set(),
|
||||
templateRefs,
|
||||
singleRootElType: undefined,
|
||||
singleRootNode: undefined,
|
||||
accessExternalVariable(name, offset) {
|
||||
let arr = accessExternalVariables.get(name);
|
||||
if (!arr) {
|
||||
accessExternalVariables.set(name, arr = new Set());
|
||||
}
|
||||
if (offset !== undefined) {
|
||||
arr.add(offset);
|
||||
}
|
||||
},
|
||||
hasLocalVariable: (name) => {
|
||||
return !!localVars.get(name);
|
||||
},
|
||||
addLocalVariable: (name) => {
|
||||
localVars.set(name, (localVars.get(name) ?? 0) + 1);
|
||||
},
|
||||
removeLocalVariable: (name) => {
|
||||
localVars.set(name, localVars.get(name) - 1);
|
||||
},
|
||||
getInternalVariable: () => {
|
||||
return `__VLS_${variableId++}`;
|
||||
},
|
||||
ignoreError: function* () {
|
||||
if (!ignoredError) {
|
||||
ignoredError = true;
|
||||
yield `// @vue-ignore start${common_1.newLine}`;
|
||||
}
|
||||
},
|
||||
expectError: function* (prevNode) {
|
||||
if (!expectErrorToken) {
|
||||
expectErrorToken = {
|
||||
errors: 0,
|
||||
node: prevNode,
|
||||
};
|
||||
yield `// @vue-expect-error start${common_1.newLine}`;
|
||||
}
|
||||
},
|
||||
resetDirectiveComments: function* (endStr) {
|
||||
if (expectErrorToken) {
|
||||
const token = expectErrorToken;
|
||||
yield* (0, common_1.wrapWith)(expectErrorToken.node.loc.start.offset, expectErrorToken.node.loc.end.offset, {
|
||||
verification: {
|
||||
shouldReport: () => token.errors === 0,
|
||||
},
|
||||
}, `// @ts-expect-error __VLS_TS_EXPECT_ERROR`);
|
||||
yield `${common_1.newLine}${common_1.endOfLine}`;
|
||||
expectErrorToken = undefined;
|
||||
yield `// @vue-expect-error ${endStr}${common_1.newLine}`;
|
||||
}
|
||||
if (ignoredError) {
|
||||
ignoredError = false;
|
||||
yield `// @vue-ignore ${endStr}${common_1.newLine}`;
|
||||
}
|
||||
},
|
||||
generateAutoImportCompletion: function* () {
|
||||
if (!options.edited) {
|
||||
return;
|
||||
}
|
||||
const all = [...accessExternalVariables.entries()];
|
||||
if (!all.some(([_, offsets]) => offsets.size)) {
|
||||
return;
|
||||
}
|
||||
yield `// @ts-ignore${common_1.newLine}`; // #2304
|
||||
yield `[`;
|
||||
for (const [varName, offsets] of all) {
|
||||
for (const offset of offsets) {
|
||||
if (options.scriptSetupBindingNames.has(varName)) {
|
||||
// #3409
|
||||
yield [
|
||||
varName,
|
||||
'template',
|
||||
offset,
|
||||
{
|
||||
...codeFeatures.additionalCompletion,
|
||||
...codeFeatures.withoutHighlightAndCompletionAndNavigation,
|
||||
},
|
||||
];
|
||||
}
|
||||
else {
|
||||
yield [
|
||||
varName,
|
||||
'template',
|
||||
offset,
|
||||
codeFeatures.additionalCompletion,
|
||||
];
|
||||
}
|
||||
yield `,`;
|
||||
}
|
||||
offsets.clear();
|
||||
}
|
||||
yield `]${common_1.endOfLine}`;
|
||||
}
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=context.js.map
|
||||
8
node_modules/@vue/language-core/lib/codegen/template/element.d.ts
generated
vendored
Normal file
8
node_modules/@vue/language-core/lib/codegen/template/element.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentComponent: CompilerDOM.ElementNode | undefined): Generator<Code>;
|
||||
export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined, isVForChild: boolean): Generator<Code>;
|
||||
export declare function getCanonicalComponentName(tagText: string): string;
|
||||
export declare function getPossibleOriginalComponentNames(tagText: string, deduplicate: boolean): string[];
|
||||
544
node_modules/@vue/language-core/lib/codegen/template/element.js
generated
vendored
Normal file
544
node_modules/@vue/language-core/lib/codegen/template/element.js
generated
vendored
Normal file
@@ -0,0 +1,544 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateComponent = generateComponent;
|
||||
exports.generateElement = generateElement;
|
||||
exports.getCanonicalComponentName = getCanonicalComponentName;
|
||||
exports.getPossibleOriginalComponentNames = getPossibleOriginalComponentNames;
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const shared_1 = require("@vue/shared");
|
||||
const shared_2 = require("../../utils/shared");
|
||||
const common_1 = require("../common");
|
||||
const camelized_1 = require("./camelized");
|
||||
const elementChildren_1 = require("./elementChildren");
|
||||
const elementDirectives_1 = require("./elementDirectives");
|
||||
const elementEvents_1 = require("./elementEvents");
|
||||
const elementProps_1 = require("./elementProps");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const propertyAccess_1 = require("./propertyAccess");
|
||||
const templateChild_1 = require("./templateChild");
|
||||
const objectProperty_1 = require("./objectProperty");
|
||||
const inlayHints_1 = require("../inlayHints");
|
||||
const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
|
||||
const colonReg = /:/g;
|
||||
function* generateComponent(options, ctx, node, currentComponent) {
|
||||
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
||||
const endTagOffset = !node.isSelfClosing && options.template.lang === 'html' ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag) : undefined;
|
||||
const tagOffsets = endTagOffset !== undefined && endTagOffset > startTagOffset
|
||||
? [startTagOffset, endTagOffset]
|
||||
: [startTagOffset];
|
||||
const propsFailedExps = [];
|
||||
const possibleOriginalNames = getPossibleOriginalComponentNames(node.tag, true);
|
||||
const matchImportName = possibleOriginalNames.find(name => options.scriptSetupImportComponentNames.has(name));
|
||||
const var_originalComponent = matchImportName ?? ctx.getInternalVariable();
|
||||
const var_functionalComponent = ctx.getInternalVariable();
|
||||
const var_componentInstance = ctx.getInternalVariable();
|
||||
const var_componentEmit = ctx.getInternalVariable();
|
||||
const var_componentEvents = ctx.getInternalVariable();
|
||||
const var_defineComponentCtx = ctx.getInternalVariable();
|
||||
const isComponentTag = node.tag.toLowerCase() === 'component';
|
||||
let props = node.props;
|
||||
let dynamicTagInfo;
|
||||
if (isComponentTag) {
|
||||
for (const prop of node.props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.name === 'bind'
|
||||
&& prop.arg?.loc.source === 'is'
|
||||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
if (prop.arg.loc.end.offset === prop.exp.loc.end.offset) {
|
||||
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.exp.loc, 'is'));
|
||||
}
|
||||
dynamicTagInfo = {
|
||||
tag: prop.exp.content,
|
||||
offsets: [prop.exp.loc.start.offset, undefined],
|
||||
astHolder: prop.exp.loc,
|
||||
};
|
||||
props = props.filter(p => p !== prop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.tag.includes('.')) {
|
||||
// namespace tag
|
||||
dynamicTagInfo = {
|
||||
tag: node.tag,
|
||||
offsets: [startTagOffset, endTagOffset],
|
||||
astHolder: node.loc,
|
||||
};
|
||||
}
|
||||
if (matchImportName) {
|
||||
// hover, renaming / find references support
|
||||
yield `// @ts-ignore${common_1.newLine}`; // #2304
|
||||
yield `[`;
|
||||
for (const tagOffset of tagOffsets) {
|
||||
if (var_originalComponent === node.tag) {
|
||||
yield [
|
||||
var_originalComponent,
|
||||
'template',
|
||||
tagOffset,
|
||||
ctx.codeFeatures.withoutHighlightAndCompletion,
|
||||
];
|
||||
}
|
||||
else {
|
||||
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag), tagOffset, {
|
||||
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
||||
navigation: {
|
||||
resolveRenameNewName: camelizeComponentName,
|
||||
resolveRenameEditText: getTagRenameApply(node.tag),
|
||||
},
|
||||
});
|
||||
}
|
||||
yield `,`;
|
||||
}
|
||||
yield `]${common_1.endOfLine}`;
|
||||
}
|
||||
else if (dynamicTagInfo) {
|
||||
yield `const ${var_originalComponent} = (`;
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, dynamicTagInfo.tag, dynamicTagInfo.astHolder, dynamicTagInfo.offsets[0], ctx.codeFeatures.all, '(', ')');
|
||||
if (dynamicTagInfo.offsets[1] !== undefined) {
|
||||
yield `,`;
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, dynamicTagInfo.tag, dynamicTagInfo.astHolder, dynamicTagInfo.offsets[1], {
|
||||
...ctx.codeFeatures.all,
|
||||
completion: false,
|
||||
}, '(', ')');
|
||||
}
|
||||
yield `)${common_1.endOfLine}`;
|
||||
}
|
||||
else if (!isComponentTag) {
|
||||
yield `const ${var_originalComponent} = __VLS_resolvedLocalAndGlobalComponents.`;
|
||||
yield* generateCanonicalComponentName(node.tag, startTagOffset, {
|
||||
// with hover support
|
||||
...ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation,
|
||||
...ctx.codeFeatures.verification,
|
||||
});
|
||||
yield `${common_1.endOfLine}`;
|
||||
const camelizedTag = (0, shared_1.camelize)(node.tag);
|
||||
if (common_1.variableNameRegex.test(camelizedTag)) {
|
||||
// renaming / find references support
|
||||
yield `/** @type { [`;
|
||||
for (const tagOffset of tagOffsets) {
|
||||
for (const shouldCapitalize of (node.tag[0] === node.tag[0].toUpperCase() ? [false] : [true, false])) {
|
||||
const expectName = shouldCapitalize ? (0, shared_1.capitalize)(camelizedTag) : camelizedTag;
|
||||
yield `typeof __VLS_components.`;
|
||||
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, tagOffset, {
|
||||
navigation: {
|
||||
resolveRenameNewName: node.tag !== expectName ? camelizeComponentName : undefined,
|
||||
resolveRenameEditText: getTagRenameApply(node.tag),
|
||||
},
|
||||
});
|
||||
yield `, `;
|
||||
}
|
||||
}
|
||||
yield `] } */${common_1.newLine}`;
|
||||
// auto import support
|
||||
if (options.edited) {
|
||||
yield `// @ts-ignore${common_1.newLine}`; // #2304
|
||||
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag), startTagOffset, {
|
||||
completion: {
|
||||
isAdditional: true,
|
||||
onlyImport: true,
|
||||
},
|
||||
});
|
||||
yield `${common_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield `const ${var_originalComponent} = {} as any${common_1.endOfLine}`;
|
||||
}
|
||||
yield `// @ts-ignore${common_1.newLine}`;
|
||||
yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({`;
|
||||
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, false);
|
||||
yield `}))${common_1.endOfLine}`;
|
||||
yield `const ${var_componentInstance} = ${var_functionalComponent}(`;
|
||||
yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, true, propsFailedExps), `}`);
|
||||
yield `, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}))${common_1.endOfLine}`;
|
||||
currentComponent = node;
|
||||
for (const failedExp of propsFailedExps) {
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.node.loc.source, failedExp.node.loc, failedExp.node.loc.start.offset, ctx.codeFeatures.all, failedExp.prefix, failedExp.suffix);
|
||||
yield common_1.endOfLine;
|
||||
}
|
||||
const [refName, offset] = yield* generateVScope(options, ctx, node, props);
|
||||
const isRootNode = node === ctx.singleRootNode;
|
||||
if (refName || isRootNode) {
|
||||
const varName = ctx.getInternalVariable();
|
||||
ctx.usedComponentCtxVars.add(var_defineComponentCtx);
|
||||
yield `var ${varName} = {} as (Parameters<NonNullable<typeof ${var_defineComponentCtx}['expose']>>[0] | null)`;
|
||||
if (node.codegenNode?.type === CompilerDOM.NodeTypes.VNODE_CALL
|
||||
&& node.codegenNode.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION
|
||||
&& node.codegenNode.props.properties.some(({ key }) => key.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && key.content === 'ref_for')) {
|
||||
yield `[]`;
|
||||
}
|
||||
yield `${common_1.endOfLine}`;
|
||||
if (refName) {
|
||||
ctx.templateRefs.set(refName, [varName, offset]);
|
||||
}
|
||||
if (isRootNode) {
|
||||
ctx.singleRootElType = `NonNullable<typeof ${varName}>['$el']`;
|
||||
}
|
||||
}
|
||||
const usedComponentEventsVar = yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance, var_componentEmit, var_componentEvents);
|
||||
if (usedComponentEventsVar) {
|
||||
ctx.usedComponentCtxVars.add(var_defineComponentCtx);
|
||||
yield `let ${var_componentEmit}!: typeof ${var_defineComponentCtx}.emit${common_1.endOfLine}`;
|
||||
yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${var_componentEmit}>${common_1.endOfLine}`;
|
||||
}
|
||||
if (options.vueCompilerOptions.fallthroughAttributes
|
||||
&& (node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs')
|
||||
|| node === ctx.singleRootNode)) {
|
||||
const varAttrs = ctx.getInternalVariable();
|
||||
ctx.inheritedAttrVars.add(varAttrs);
|
||||
yield `var ${varAttrs}!: Parameters<typeof ${var_functionalComponent}>[0];\n`;
|
||||
}
|
||||
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
||||
if (slotDir) {
|
||||
yield* generateComponentSlot(options, ctx, node, slotDir, currentComponent, var_defineComponentCtx);
|
||||
}
|
||||
else {
|
||||
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, var_defineComponentCtx);
|
||||
}
|
||||
if (ctx.usedComponentCtxVars.has(var_defineComponentCtx)) {
|
||||
yield `var ${var_defineComponentCtx}!: __VLS_PickFunctionalComponentCtx<typeof ${var_originalComponent}, typeof ${var_componentInstance}>${common_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
function* generateElement(options, ctx, node, currentComponent, componentCtxVar, isVForChild) {
|
||||
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
||||
const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
|
||||
? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
|
||||
: undefined;
|
||||
const propsFailedExps = [];
|
||||
yield `__VLS_elementAsFunction(__VLS_intrinsicElements`;
|
||||
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
||||
if (endTagOffset !== undefined) {
|
||||
yield `, __VLS_intrinsicElements`;
|
||||
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
||||
}
|
||||
yield `)(`;
|
||||
yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, true, propsFailedExps), `}`);
|
||||
yield `)${common_1.endOfLine}`;
|
||||
for (const failedExp of propsFailedExps) {
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.node.loc.source, failedExp.node.loc, failedExp.node.loc.start.offset, ctx.codeFeatures.all, failedExp.prefix, failedExp.suffix);
|
||||
yield common_1.endOfLine;
|
||||
}
|
||||
const [refName, offset] = yield* generateVScope(options, ctx, node, node.props);
|
||||
if (refName) {
|
||||
let refValue = `__VLS_nativeElements['${node.tag}']`;
|
||||
if (isVForChild) {
|
||||
refValue = `[${refValue}]`;
|
||||
}
|
||||
ctx.templateRefs.set(refName, [refValue, offset]);
|
||||
}
|
||||
if (ctx.singleRootNode === node) {
|
||||
ctx.singleRootElType = `typeof __VLS_nativeElements['${node.tag}']`;
|
||||
}
|
||||
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
||||
if (slotDir && componentCtxVar) {
|
||||
yield* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar);
|
||||
}
|
||||
else {
|
||||
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
|
||||
}
|
||||
if (options.vueCompilerOptions.fallthroughAttributes
|
||||
&& (node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs')
|
||||
|| node === ctx.singleRootNode)) {
|
||||
ctx.inheritedAttrVars.add(`__VLS_intrinsicElements.${node.tag}`);
|
||||
}
|
||||
}
|
||||
function* generateVScope(options, ctx, node, props) {
|
||||
const vScope = props.find(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && (prop.name === 'scope' || prop.name === 'data'));
|
||||
let inScope = false;
|
||||
let originalConditionsNum = ctx.blockConditions.length;
|
||||
if (vScope?.type === CompilerDOM.NodeTypes.DIRECTIVE && vScope.exp) {
|
||||
const scopeVar = ctx.getInternalVariable();
|
||||
const condition = `__VLS_withScope(__VLS_ctx, ${scopeVar})`;
|
||||
yield `const ${scopeVar} = `;
|
||||
yield [
|
||||
vScope.exp.loc.source,
|
||||
'template',
|
||||
vScope.exp.loc.start.offset,
|
||||
ctx.codeFeatures.all,
|
||||
];
|
||||
yield common_1.endOfLine;
|
||||
yield `if (${condition}) {${common_1.newLine}`;
|
||||
ctx.blockConditions.push(condition);
|
||||
inScope = true;
|
||||
}
|
||||
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
||||
const [refName, offset] = yield* generateReferencesForElements(options, ctx, node); // <el ref="foo" />
|
||||
yield* generateReferencesForScopedCssClasses(options, ctx, node);
|
||||
if (inScope) {
|
||||
yield `}${common_1.newLine}`;
|
||||
ctx.blockConditions.length = originalConditionsNum;
|
||||
}
|
||||
return [refName, offset];
|
||||
}
|
||||
function getCanonicalComponentName(tagText) {
|
||||
return common_1.variableNameRegex.test(tagText)
|
||||
? tagText
|
||||
: (0, shared_1.capitalize)((0, shared_1.camelize)(tagText.replace(colonReg, '-')));
|
||||
}
|
||||
function getPossibleOriginalComponentNames(tagText, deduplicate) {
|
||||
const name1 = (0, shared_1.capitalize)((0, shared_1.camelize)(tagText));
|
||||
const name2 = (0, shared_1.camelize)(tagText);
|
||||
const name3 = tagText;
|
||||
const names = [name1];
|
||||
if (!deduplicate || name2 !== name1) {
|
||||
names.push(name2);
|
||||
}
|
||||
if (!deduplicate || name3 !== name2) {
|
||||
names.push(name3);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
function* generateCanonicalComponentName(tagText, offset, features) {
|
||||
if (common_1.variableNameRegex.test(tagText)) {
|
||||
yield [tagText, 'template', offset, features];
|
||||
}
|
||||
else {
|
||||
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tagText.replace(colonReg, '-')), offset, features);
|
||||
}
|
||||
}
|
||||
function* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar) {
|
||||
yield `{${common_1.newLine}`;
|
||||
ctx.usedComponentCtxVars.add(componentCtxVar);
|
||||
if (currentComponent) {
|
||||
ctx.hasSlotElements.add(currentComponent);
|
||||
}
|
||||
const slotBlockVars = [];
|
||||
yield `const {`;
|
||||
if (slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
||||
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc, false, true);
|
||||
yield ': __VLS_thisSlot';
|
||||
}
|
||||
else {
|
||||
yield `default: `;
|
||||
yield* (0, common_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
|
||||
? '#'.length
|
||||
: slotDir.loc.source.startsWith('v-slot:')
|
||||
? 'v-slot:'.length
|
||||
: 0), ctx.codeFeatures.withoutHighlightAndCompletion, `__VLS_thisSlot`);
|
||||
}
|
||||
yield `} = __VLS_nonNullable(${componentCtxVar}.slots)${common_1.endOfLine}`;
|
||||
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
const slotAst = (0, common_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
|
||||
(0, common_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
|
||||
if (!slotDir.exp.content.includes(':')) {
|
||||
yield `const [`;
|
||||
yield [
|
||||
slotDir.exp.content,
|
||||
'template',
|
||||
slotDir.exp.loc.start.offset,
|
||||
ctx.codeFeatures.all,
|
||||
];
|
||||
yield `] = __VLS_getSlotParams(__VLS_thisSlot)${common_1.endOfLine}`;
|
||||
}
|
||||
else {
|
||||
yield `const `;
|
||||
yield [
|
||||
slotDir.exp.content,
|
||||
'template',
|
||||
slotDir.exp.loc.start.offset,
|
||||
ctx.codeFeatures.all,
|
||||
];
|
||||
yield ` = __VLS_getSlotParam(__VLS_thisSlot)${common_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
for (const varName of slotBlockVars) {
|
||||
ctx.addLocalVariable(varName);
|
||||
}
|
||||
yield* ctx.resetDirectiveComments('end of slot children start');
|
||||
let prev;
|
||||
for (const childNode of node.children) {
|
||||
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
||||
prev = childNode;
|
||||
}
|
||||
for (const varName of slotBlockVars) {
|
||||
ctx.removeLocalVariable(varName);
|
||||
}
|
||||
let isStatic = true;
|
||||
if (slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
isStatic = slotDir.arg.isStatic;
|
||||
}
|
||||
if (isStatic && slotDir && !slotDir.arg) {
|
||||
yield `__VLS_nonNullable(${componentCtxVar}.slots)['`;
|
||||
yield [
|
||||
'',
|
||||
'template',
|
||||
slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
|
||||
? '#'.length : slotDir.loc.source.startsWith('v-slot:')
|
||||
? 'v-slot:'.length
|
||||
: 0),
|
||||
ctx.codeFeatures.completion,
|
||||
];
|
||||
yield `'/* empty slot name completion */]${common_1.newLine}`;
|
||||
}
|
||||
yield* ctx.generateAutoImportCompletion();
|
||||
yield `}${common_1.newLine}`;
|
||||
}
|
||||
function* generateReferencesForElements(options, ctx, node) {
|
||||
for (const prop of node.props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
||||
&& prop.name === 'ref'
|
||||
&& prop.value) {
|
||||
const [content, startOffset] = normalizeAttributeValue(prop.value);
|
||||
yield `// @ts-ignore navigation for \`const ${content} = ref()\`${common_1.newLine}`;
|
||||
yield `__VLS_ctx`;
|
||||
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, startOffset, ctx.codeFeatures.navigation, prop.value.loc);
|
||||
yield common_1.endOfLine;
|
||||
if (common_1.variableNameRegex.test(content)) {
|
||||
ctx.accessExternalVariable(content, startOffset);
|
||||
}
|
||||
return [content, startOffset];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
function* generateReferencesForScopedCssClasses(options, ctx, node) {
|
||||
for (const prop of node.props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
||||
&& prop.name === 'class'
|
||||
&& prop.value) {
|
||||
if (options.template.lang === 'pug') {
|
||||
const getClassOffset = Reflect.get(prop.value.loc.start, 'getClassOffset');
|
||||
const content = prop.value.loc.source.slice(1, -1);
|
||||
let startOffset = 1;
|
||||
for (const className of content.split(' ')) {
|
||||
if (className) {
|
||||
ctx.scopedClasses.push({
|
||||
source: 'template',
|
||||
className,
|
||||
offset: getClassOffset(startOffset),
|
||||
});
|
||||
}
|
||||
startOffset += className.length + 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
let isWrapped = false;
|
||||
const [content, startOffset] = normalizeAttributeValue(prop.value);
|
||||
if (content) {
|
||||
const classes = collectClasses(content, startOffset + (isWrapped ? 1 : 0));
|
||||
ctx.scopedClasses.push(...classes);
|
||||
}
|
||||
else {
|
||||
ctx.emptyClassOffsets.push(startOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& prop.arg.content === 'class') {
|
||||
const content = '`${' + prop.exp.content + '}`';
|
||||
const startOffset = prop.exp.loc.start.offset - 3;
|
||||
const { ts } = options;
|
||||
const ast = ts.createSourceFile('', content, 99);
|
||||
const literals = [];
|
||||
ts.forEachChild(ast, node => {
|
||||
if (!ts.isExpressionStatement(node) ||
|
||||
!isTemplateExpression(node.expression)) {
|
||||
return;
|
||||
}
|
||||
const expression = node.expression.templateSpans[0].expression;
|
||||
if (ts.isStringLiteralLike(expression)) {
|
||||
literals.push(expression);
|
||||
}
|
||||
if (ts.isArrayLiteralExpression(expression)) {
|
||||
walkArrayLiteral(expression);
|
||||
}
|
||||
if (ts.isObjectLiteralExpression(expression)) {
|
||||
walkObjectLiteral(expression);
|
||||
}
|
||||
});
|
||||
for (const literal of literals) {
|
||||
const classes = collectClasses(literal.text, literal.end - literal.text.length - 1 + startOffset);
|
||||
ctx.scopedClasses.push(...classes);
|
||||
}
|
||||
function walkArrayLiteral(node) {
|
||||
const { elements } = node;
|
||||
for (const element of elements) {
|
||||
if (ts.isStringLiteralLike(element)) {
|
||||
literals.push(element);
|
||||
}
|
||||
else if (ts.isObjectLiteralExpression(element)) {
|
||||
walkObjectLiteral(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
function walkObjectLiteral(node) {
|
||||
const { properties } = node;
|
||||
for (const property of properties) {
|
||||
if (ts.isPropertyAssignment(property)) {
|
||||
const { name } = property;
|
||||
if (ts.isIdentifier(name)) {
|
||||
walkIdentifier(name);
|
||||
}
|
||||
else if (ts.isStringLiteral(name)) {
|
||||
literals.push(name);
|
||||
}
|
||||
else if (ts.isComputedPropertyName(name)) {
|
||||
const { expression } = name;
|
||||
if (ts.isStringLiteralLike(expression)) {
|
||||
literals.push(expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ts.isShorthandPropertyAssignment(property)) {
|
||||
walkIdentifier(property.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
function walkIdentifier(node) {
|
||||
const text = (0, scriptSetupRanges_1.getNodeText)(ts, node, ast);
|
||||
ctx.scopedClasses.push({
|
||||
source: 'template',
|
||||
className: text,
|
||||
offset: node.end - text.length + startOffset
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function camelizeComponentName(newName) {
|
||||
return (0, shared_1.camelize)('-' + newName);
|
||||
}
|
||||
function getTagRenameApply(oldName) {
|
||||
return oldName === (0, shared_2.hyphenateTag)(oldName) ? shared_2.hyphenateTag : undefined;
|
||||
}
|
||||
function normalizeAttributeValue(node) {
|
||||
let offset = node.loc.start.offset;
|
||||
let content = node.loc.source;
|
||||
if ((content.startsWith(`'`) && content.endsWith(`'`))
|
||||
|| (content.startsWith(`"`) && content.endsWith(`"`))) {
|
||||
offset++;
|
||||
content = content.slice(1, -1);
|
||||
}
|
||||
return [content, offset];
|
||||
}
|
||||
function collectClasses(content, startOffset = 0) {
|
||||
const classes = [];
|
||||
let currentClassName = '';
|
||||
let offset = 0;
|
||||
for (const char of (content + ' ')) {
|
||||
if (char.trim() === '') {
|
||||
if (currentClassName !== '') {
|
||||
classes.push({
|
||||
source: 'template',
|
||||
className: currentClassName,
|
||||
offset: offset + startOffset
|
||||
});
|
||||
offset += currentClassName.length;
|
||||
currentClassName = '';
|
||||
}
|
||||
offset += char.length;
|
||||
}
|
||||
else {
|
||||
currentClassName += char;
|
||||
}
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
// isTemplateExpression is missing in tsc
|
||||
function isTemplateExpression(node) {
|
||||
return node.kind === 228;
|
||||
}
|
||||
//# sourceMappingURL=element.js.map
|
||||
5
node_modules/@vue/language-core/lib/codegen/template/elementChildren.d.ts
generated
vendored
Normal file
5
node_modules/@vue/language-core/lib/codegen/template/elementChildren.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
||||
27
node_modules/@vue/language-core/lib/codegen/template/elementChildren.js
generated
vendored
Normal file
27
node_modules/@vue/language-core/lib/codegen/template/elementChildren.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateElementChildren = generateElementChildren;
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const common_1 = require("../common");
|
||||
const templateChild_1 = require("./templateChild");
|
||||
function* generateElementChildren(options, ctx, node, currentComponent, componentCtxVar) {
|
||||
yield* ctx.resetDirectiveComments('end of element children start');
|
||||
let prev;
|
||||
for (const childNode of node.children) {
|
||||
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
||||
prev = childNode;
|
||||
}
|
||||
yield* ctx.generateAutoImportCompletion();
|
||||
// fix https://github.com/vuejs/language-tools/issues/932
|
||||
if (componentCtxVar
|
||||
&& !ctx.hasSlotElements.has(node)
|
||||
&& node.children.length
|
||||
&& node.tagType !== CompilerDOM.ElementTypes.ELEMENT
|
||||
&& node.tagType !== CompilerDOM.ElementTypes.TEMPLATE) {
|
||||
ctx.usedComponentCtxVars.add(componentCtxVar);
|
||||
yield `__VLS_nonNullable(${componentCtxVar}.slots).`;
|
||||
yield* (0, common_1.wrapWith)(node.children[0].loc.start.offset, node.children[node.children.length - 1].loc.end.offset, ctx.codeFeatures.navigation, `default`);
|
||||
yield common_1.endOfLine;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=elementChildren.js.map
|
||||
5
node_modules/@vue/language-core/lib/codegen/template/elementDirectives.d.ts
generated
vendored
Normal file
5
node_modules/@vue/language-core/lib/codegen/template/elementDirectives.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateElementDirectives(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
||||
81
node_modules/@vue/language-core/lib/codegen/template/elementDirectives.js
generated
vendored
Normal file
81
node_modules/@vue/language-core/lib/codegen/template/elementDirectives.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateElementDirectives = generateElementDirectives;
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const shared_1 = require("@vue/shared");
|
||||
const shared_2 = require("../../utils/shared");
|
||||
const common_1 = require("../common");
|
||||
const camelized_1 = require("./camelized");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const objectProperty_1 = require("./objectProperty");
|
||||
const stringLiteralKey_1 = require("./stringLiteralKey");
|
||||
function* generateElementDirectives(options, ctx, node) {
|
||||
for (const prop of node.props) {
|
||||
if (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE
|
||||
|| prop.name === 'slot'
|
||||
|| prop.name === 'on'
|
||||
|| prop.name === 'model'
|
||||
|| prop.name === 'bind'
|
||||
|| prop.name === 'scope'
|
||||
|| prop.name === 'data') {
|
||||
continue;
|
||||
}
|
||||
ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
|
||||
yield* (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, `__VLS_asFunctionalDirective(`, ...generateIdentifier(ctx, prop), `)(null!, { ...__VLS_directiveBindingRestFields, `, ...generateArg(options, ctx, prop), ...generateModifiers(options, ctx, prop), ...generateValue(options, ctx, prop), `}, null!, null!)`);
|
||||
yield common_1.endOfLine;
|
||||
}
|
||||
}
|
||||
function* generateIdentifier(ctx, prop) {
|
||||
const rawName = 'v-' + prop.name;
|
||||
yield* (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + rawName.length, ctx.codeFeatures.verification, `__VLS_directives.`, ...(0, camelized_1.generateCamelized)(rawName, prop.loc.start.offset, {
|
||||
...ctx.codeFeatures.all,
|
||||
verification: false,
|
||||
completion: {
|
||||
// fix https://github.com/vuejs/language-tools/issues/1905
|
||||
isAdditional: true,
|
||||
},
|
||||
navigation: {
|
||||
resolveRenameNewName: shared_1.camelize,
|
||||
resolveRenameEditText: getPropRenameApply(prop.name),
|
||||
},
|
||||
}));
|
||||
}
|
||||
function* generateArg(options, ctx, prop) {
|
||||
const { arg } = prop;
|
||||
if (arg?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
return;
|
||||
}
|
||||
const startOffset = arg.loc.start.offset + arg.loc.source.indexOf(arg.content);
|
||||
yield* (0, common_1.wrapWith)(startOffset, startOffset + arg.content.length, ctx.codeFeatures.verification, 'arg');
|
||||
yield ': ';
|
||||
if (arg.isStatic) {
|
||||
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, ctx.codeFeatures.withoutHighlight);
|
||||
}
|
||||
else {
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, arg.content, arg.loc, startOffset, ctx.codeFeatures.all, '(', ')');
|
||||
}
|
||||
yield ', ';
|
||||
}
|
||||
function* generateModifiers(options, ctx, prop) {
|
||||
if (options.vueCompilerOptions.target < 3.5) {
|
||||
return;
|
||||
}
|
||||
yield 'modifiers: { ';
|
||||
for (const mod of prop.modifiers) {
|
||||
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, ctx.codeFeatures.withoutHighlight);
|
||||
yield ': true, ';
|
||||
}
|
||||
yield '}, ';
|
||||
}
|
||||
function* generateValue(options, ctx, prop) {
|
||||
if (prop.exp?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
return;
|
||||
}
|
||||
yield* (0, common_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, 'value');
|
||||
yield ': ';
|
||||
yield* (0, common_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, ...(0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')'));
|
||||
}
|
||||
function getPropRenameApply(oldName) {
|
||||
return oldName === (0, shared_2.hyphenateAttr)(oldName) ? shared_2.hyphenateAttr : undefined;
|
||||
}
|
||||
//# sourceMappingURL=elementDirectives.js.map
|
||||
9
node_modules/@vue/language-core/lib/codegen/template/elementEvents.d.ts
generated
vendored
Normal file
9
node_modules/@vue/language-core/lib/codegen/template/elementEvents.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type * as ts from 'typescript';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentVar: string, componentInstanceVar: string, emitVar: string, eventsVar: string): Generator<Code>;
|
||||
export declare function generateEventArg(ctx: TemplateCodegenContext, arg: CompilerDOM.SimpleExpressionNode, enableHover: boolean): Generator<Code>;
|
||||
export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
||||
export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
|
||||
170
node_modules/@vue/language-core/lib/codegen/template/elementEvents.js
generated
vendored
Normal file
170
node_modules/@vue/language-core/lib/codegen/template/elementEvents.js
generated
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateElementEvents = generateElementEvents;
|
||||
exports.generateEventArg = generateEventArg;
|
||||
exports.generateEventExpression = generateEventExpression;
|
||||
exports.isCompoundExpression = isCompoundExpression;
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const shared_1 = require("@vue/shared");
|
||||
const shared_2 = require("../../utils/shared");
|
||||
const common_1 = require("../common");
|
||||
const camelized_1 = require("./camelized");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
function* generateElementEvents(options, ctx, node, componentVar, componentInstanceVar, emitVar, eventsVar) {
|
||||
let usedComponentEventsVar = false;
|
||||
let propsVar;
|
||||
for (const prop of node.props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.name === 'on'
|
||||
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& !prop.arg.loc.source.startsWith('[')
|
||||
&& !prop.arg.loc.source.endsWith(']')) {
|
||||
usedComponentEventsVar = true;
|
||||
if (!propsVar) {
|
||||
propsVar = ctx.getInternalVariable();
|
||||
yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${componentInstanceVar}>${common_1.endOfLine}`;
|
||||
}
|
||||
const originalPropName = (0, shared_1.camelize)('on-' + prop.arg.loc.source);
|
||||
const originalPropNameObjectKey = common_1.variableNameRegex.test(originalPropName)
|
||||
? originalPropName
|
||||
: `'${originalPropName}'`;
|
||||
yield `const ${ctx.getInternalVariable()}: `;
|
||||
if (!options.vueCompilerOptions.strictTemplates) {
|
||||
yield `Record<string, unknown> & `;
|
||||
}
|
||||
yield `(${common_1.newLine}`;
|
||||
yield `__VLS_IsFunction<typeof ${propsVar}, '${originalPropName}'> extends true${common_1.newLine}`;
|
||||
yield `? typeof ${propsVar}${common_1.newLine}`;
|
||||
yield `: __VLS_IsFunction<typeof ${eventsVar}, '${prop.arg.loc.source}'> extends true${common_1.newLine}`;
|
||||
yield `? {${common_1.newLine}`;
|
||||
yield `/**__VLS_emit,${emitVar},${prop.arg.loc.source}*/${common_1.newLine}`;
|
||||
yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${prop.arg.loc.source}']${common_1.newLine}`;
|
||||
yield `}${common_1.newLine}`;
|
||||
if (prop.arg.loc.source !== (0, shared_1.camelize)(prop.arg.loc.source)) {
|
||||
yield `: __VLS_IsFunction<typeof ${eventsVar}, '${(0, shared_1.camelize)(prop.arg.loc.source)}'> extends true${common_1.newLine}`;
|
||||
yield `? {${common_1.newLine}`;
|
||||
yield `/**__VLS_emit,${emitVar},${(0, shared_1.camelize)(prop.arg.loc.source)}*/${common_1.newLine}`;
|
||||
yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${(0, shared_1.camelize)(prop.arg.loc.source)}']${common_1.newLine}`;
|
||||
yield `}${common_1.newLine}`;
|
||||
}
|
||||
yield `: typeof ${propsVar}${common_1.newLine}`;
|
||||
yield `) = {${common_1.newLine}`;
|
||||
yield* generateEventArg(ctx, prop.arg, true);
|
||||
yield `: `;
|
||||
yield* generateEventExpression(options, ctx, prop);
|
||||
yield `}${common_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
return usedComponentEventsVar;
|
||||
}
|
||||
const eventArgFeatures = {
|
||||
navigation: {
|
||||
// @click-outside -> onClickOutside
|
||||
resolveRenameNewName(newName) {
|
||||
return (0, shared_1.camelize)('on-' + newName);
|
||||
},
|
||||
// onClickOutside -> @click-outside
|
||||
resolveRenameEditText(newName) {
|
||||
const hName = (0, shared_2.hyphenateAttr)(newName);
|
||||
if ((0, shared_2.hyphenateAttr)(newName).startsWith('on-')) {
|
||||
return (0, shared_1.camelize)(hName.slice('on-'.length));
|
||||
}
|
||||
return newName;
|
||||
},
|
||||
},
|
||||
};
|
||||
function* generateEventArg(ctx, arg, enableHover) {
|
||||
const features = enableHover
|
||||
? {
|
||||
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
||||
...eventArgFeatures,
|
||||
}
|
||||
: eventArgFeatures;
|
||||
if (common_1.variableNameRegex.test((0, shared_1.camelize)(arg.loc.source))) {
|
||||
yield ['', 'template', arg.loc.start.offset, features];
|
||||
yield `on`;
|
||||
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(arg.loc.source), arg.loc.start.offset, common_1.combineLastMapping);
|
||||
}
|
||||
else {
|
||||
yield* (0, common_1.wrapWith)(arg.loc.start.offset, arg.loc.end.offset, features, `'`, ['', 'template', arg.loc.start.offset, common_1.combineLastMapping], 'on', ...(0, camelized_1.generateCamelized)((0, shared_1.capitalize)(arg.loc.source), arg.loc.start.offset, common_1.combineLastMapping), `'`);
|
||||
}
|
||||
}
|
||||
function* generateEventExpression(options, ctx, prop) {
|
||||
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
let prefix = '(';
|
||||
let suffix = ')';
|
||||
let isFirstMapping = true;
|
||||
const ast = (0, common_1.createTsAst)(options.ts, prop.exp, prop.exp.content);
|
||||
const _isCompoundExpression = isCompoundExpression(options.ts, ast);
|
||||
if (_isCompoundExpression) {
|
||||
yield `(...[$event]) => {${common_1.newLine}`;
|
||||
ctx.addLocalVariable('$event');
|
||||
prefix = '';
|
||||
suffix = '';
|
||||
for (const blockCondition of ctx.blockConditions) {
|
||||
prefix += `if (!(${blockCondition})) return${common_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, offset => {
|
||||
if (_isCompoundExpression && isFirstMapping) {
|
||||
isFirstMapping = false;
|
||||
ctx.inlayHints.push({
|
||||
blockName: 'template',
|
||||
offset,
|
||||
setting: 'vue.inlayHints.inlineHandlerLeading',
|
||||
label: '$event =>',
|
||||
paddingRight: true,
|
||||
tooltip: [
|
||||
'`$event` is a hidden parameter, you can use it in this callback.',
|
||||
'To hide this hint, set `vue.inlayHints.inlineHandlerLeading` to `false` in IDE settings.',
|
||||
'[More info](https://github.com/vuejs/language-tools/issues/2445#issuecomment-1444771420)',
|
||||
].join('\n\n'),
|
||||
});
|
||||
}
|
||||
return ctx.codeFeatures.all;
|
||||
}, prefix, suffix);
|
||||
if (_isCompoundExpression) {
|
||||
ctx.removeLocalVariable('$event');
|
||||
yield common_1.endOfLine;
|
||||
yield* ctx.generateAutoImportCompletion();
|
||||
yield `}`;
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield `() => {}`;
|
||||
}
|
||||
}
|
||||
function isCompoundExpression(ts, ast) {
|
||||
let result = true;
|
||||
if (ast.statements.length === 0) {
|
||||
result = false;
|
||||
}
|
||||
else if (ast.statements.length === 1) {
|
||||
ts.forEachChild(ast, child_1 => {
|
||||
if (ts.isExpressionStatement(child_1)) {
|
||||
ts.forEachChild(child_1, child_2 => {
|
||||
if (ts.isArrowFunction(child_2)) {
|
||||
result = false;
|
||||
}
|
||||
else if (isPropertyAccessOrId(ts, child_2)) {
|
||||
result = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (ts.isFunctionDeclaration(child_1)) {
|
||||
result = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function isPropertyAccessOrId(ts, node) {
|
||||
if (ts.isIdentifier(node)) {
|
||||
return true;
|
||||
}
|
||||
if (ts.isPropertyAccessExpression(node)) {
|
||||
return isPropertyAccessOrId(ts, node.expression);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//# sourceMappingURL=elementEvents.js.map
|
||||
9
node_modules/@vue/language-core/lib/codegen/template/elementProps.d.ts
generated
vendored
Normal file
9
node_modules/@vue/language-core/lib/codegen/template/elementProps.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], enableCodeFeatures: boolean, propsFailedExps?: {
|
||||
node: CompilerDOM.SimpleExpressionNode;
|
||||
prefix: string;
|
||||
suffix: string;
|
||||
}[]): Generator<Code>;
|
||||
288
node_modules/@vue/language-core/lib/codegen/template/elementProps.js
generated
vendored
Normal file
288
node_modules/@vue/language-core/lib/codegen/template/elementProps.js
generated
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateElementProps = generateElementProps;
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const shared_1 = require("@vue/shared");
|
||||
const minimatch_1 = require("minimatch");
|
||||
const muggle_string_1 = require("muggle-string");
|
||||
const shared_2 = require("../../utils/shared");
|
||||
const common_1 = require("../common");
|
||||
const camelized_1 = require("./camelized");
|
||||
const elementEvents_1 = require("./elementEvents");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const objectProperty_1 = require("./objectProperty");
|
||||
const inlayHints_1 = require("../inlayHints");
|
||||
function* generateElementProps(options, ctx, node, props, enableCodeFeatures, propsFailedExps) {
|
||||
const isComponent = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
|
||||
for (const prop of props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.name === 'on') {
|
||||
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& !prop.arg.loc.source.startsWith('[')
|
||||
&& !prop.arg.loc.source.endsWith(']')) {
|
||||
if (!isComponent) {
|
||||
yield `...{ `;
|
||||
yield* (0, elementEvents_1.generateEventArg)(ctx, prop.arg, true);
|
||||
yield `: `;
|
||||
yield* (0, elementEvents_1.generateEventExpression)(options, ctx, prop);
|
||||
yield `}, `;
|
||||
}
|
||||
else {
|
||||
yield `...{ '${(0, shared_1.camelize)('on-' + prop.arg.loc.source)}': {} as any }, `;
|
||||
}
|
||||
}
|
||||
else if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& prop.arg.loc.source.startsWith('[')
|
||||
&& prop.arg.loc.source.endsWith(']')) {
|
||||
propsFailedExps?.push({ node: prop.arg, prefix: '(', suffix: ')' });
|
||||
propsFailedExps?.push({ node: prop.exp, prefix: '() => {', suffix: '}' });
|
||||
}
|
||||
else if (!prop.arg
|
||||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
propsFailedExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const prop of props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& ((prop.name === 'bind' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION)
|
||||
|| prop.name === 'model')
|
||||
&& (!prop.exp || prop.exp.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION)) {
|
||||
let propName;
|
||||
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
propName = prop.arg.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY
|
||||
? prop.arg.content
|
||||
: prop.arg.loc.source;
|
||||
}
|
||||
else {
|
||||
propName = getModelValuePropName(node, options.vueCompilerOptions.target, options.vueCompilerOptions);
|
||||
}
|
||||
if (propName === undefined
|
||||
|| options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern))) {
|
||||
if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
||||
propsFailedExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (prop.modifiers.some(m => m.content === 'prop' || m.content === 'attr')) {
|
||||
propName = propName.substring(1);
|
||||
}
|
||||
const shouldSpread = propName === 'style' || propName === 'class';
|
||||
const shouldCamelize = isComponent
|
||||
&& (!prop.arg || (prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)) // isStatic
|
||||
&& (0, shared_2.hyphenateAttr)(propName) === propName
|
||||
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern));
|
||||
if (shouldSpread) {
|
||||
yield `...{ `;
|
||||
}
|
||||
const codeInfo = ctx.codeFeatures.withoutHighlightAndCompletion;
|
||||
const codes = (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
|
||||
? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, {
|
||||
...codeInfo,
|
||||
verification: options.vueCompilerOptions.strictTemplates
|
||||
? codeInfo.verification
|
||||
: {
|
||||
shouldReport(_source, code) {
|
||||
if (String(code) === '2353' || String(code) === '2561') {
|
||||
return false;
|
||||
}
|
||||
return typeof codeInfo.verification === 'object'
|
||||
? codeInfo.verification.shouldReport?.(_source, code) ?? true
|
||||
: true;
|
||||
},
|
||||
},
|
||||
navigation: codeInfo.navigation
|
||||
? {
|
||||
resolveRenameNewName: shared_1.camelize,
|
||||
resolveRenameEditText: shouldCamelize ? shared_2.hyphenateAttr : undefined,
|
||||
}
|
||||
: false,
|
||||
}, prop.loc.name_2 ?? (prop.loc.name_2 = {}), shouldCamelize)
|
||||
: (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.verification, propName)), `: (`, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, prop.arg?.loc.start.offset === prop.exp?.loc.start.offset, enableCodeFeatures), `)`);
|
||||
if (!enableCodeFeatures) {
|
||||
yield (0, muggle_string_1.toString)([...codes]);
|
||||
}
|
||||
else {
|
||||
yield* codes;
|
||||
}
|
||||
if (shouldSpread) {
|
||||
yield ` }`;
|
||||
}
|
||||
yield `, `;
|
||||
}
|
||||
else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
||||
if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))
|
||||
// Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom always adds it (#3881)
|
||||
|| (options.vueCompilerOptions.target < 3
|
||||
&& prop.name === 'persisted'
|
||||
&& node.tag.toLowerCase() === 'transition')) {
|
||||
continue;
|
||||
}
|
||||
const shouldSpread = prop.name === 'style' || prop.name === 'class';
|
||||
const shouldCamelize = isComponent
|
||||
&& (0, shared_2.hyphenateAttr)(prop.name) === prop.name
|
||||
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern));
|
||||
if (shouldSpread) {
|
||||
yield `...{ `;
|
||||
}
|
||||
const codeInfo = shouldCamelize
|
||||
? {
|
||||
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
||||
navigation: ctx.codeFeatures.withoutHighlightAndCompletion.navigation
|
||||
? {
|
||||
resolveRenameNewName: shared_1.camelize,
|
||||
resolveRenameEditText: shared_2.hyphenateAttr,
|
||||
}
|
||||
: false,
|
||||
}
|
||||
: {
|
||||
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
||||
};
|
||||
if (!options.vueCompilerOptions.strictTemplates) {
|
||||
const verification = codeInfo.verification;
|
||||
codeInfo.verification = {
|
||||
shouldReport(_source, code) {
|
||||
if (String(code) === '2353' || String(code) === '2561') {
|
||||
return false;
|
||||
}
|
||||
return typeof verification === 'object'
|
||||
? verification.shouldReport?.(_source, code) ?? true
|
||||
: true;
|
||||
},
|
||||
};
|
||||
}
|
||||
const codes = (0, common_1.conditionWrapWith)(enableCodeFeatures, prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, codeInfo, prop.loc.name_1 ?? (prop.loc.name_1 = {}), shouldCamelize), `: (`, ...(prop.value
|
||||
? generateAttrValue(prop.value, ctx.codeFeatures.all)
|
||||
: [`true`]), `)`);
|
||||
if (!enableCodeFeatures) {
|
||||
yield (0, muggle_string_1.toString)([...codes]);
|
||||
}
|
||||
else {
|
||||
yield* codes;
|
||||
}
|
||||
if (shouldSpread) {
|
||||
yield ` }`;
|
||||
}
|
||||
yield `, `;
|
||||
}
|
||||
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.name === 'bind'
|
||||
&& !prop.arg
|
||||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
const codes = (0, common_1.conditionWrapWith)(enableCodeFeatures, prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, `...`, ...(0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')'));
|
||||
if (!enableCodeFeatures) {
|
||||
yield (0, muggle_string_1.toString)([...codes]);
|
||||
}
|
||||
else {
|
||||
yield* codes;
|
||||
}
|
||||
yield `, `;
|
||||
}
|
||||
else {
|
||||
// comment this line to avoid affecting comments in prop expressions
|
||||
// tsCodeGen.addText("/* " + [prop.type, prop.name, prop.arg?.loc.source, prop.exp?.loc.source, prop.loc.source].join(", ") + " */ ");
|
||||
}
|
||||
}
|
||||
}
|
||||
function* generatePropExp(options, ctx, prop, exp, features, isShorthand, enableCodeFeatures) {
|
||||
if (isShorthand && features.completion) {
|
||||
features = {
|
||||
...features,
|
||||
completion: undefined,
|
||||
};
|
||||
}
|
||||
if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
|
||||
if (!isShorthand) { // vue 3.4+
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, exp.loc.source, exp.loc, exp.loc.start.offset, features, '(', ')');
|
||||
}
|
||||
else {
|
||||
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
||||
if (common_1.variableNameRegex.test(propVariableName)) {
|
||||
if (!ctx.hasLocalVariable(propVariableName)) {
|
||||
ctx.accessExternalVariable(propVariableName, exp.loc.start.offset);
|
||||
yield `__VLS_ctx.`;
|
||||
}
|
||||
yield* (0, camelized_1.generateCamelized)(exp.loc.source, exp.loc.start.offset, features);
|
||||
if (enableCodeFeatures) {
|
||||
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.loc, propVariableName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield `{}`;
|
||||
}
|
||||
}
|
||||
function* generateAttrValue(attrNode, features) {
|
||||
const char = attrNode.loc.source.startsWith("'") ? "'" : '"';
|
||||
yield char;
|
||||
let start = attrNode.loc.start.offset;
|
||||
let end = attrNode.loc.end.offset;
|
||||
let content = attrNode.loc.source;
|
||||
if ((content.startsWith('"') && content.endsWith('"'))
|
||||
|| (content.startsWith("'") && content.endsWith("'"))) {
|
||||
start++;
|
||||
end--;
|
||||
content = content.slice(1, -1);
|
||||
}
|
||||
if (needToUnicode(content)) {
|
||||
yield* (0, common_1.wrapWith)(start, end, features, toUnicode(content));
|
||||
}
|
||||
else {
|
||||
yield [content, 'template', start, features];
|
||||
}
|
||||
yield char;
|
||||
}
|
||||
function needToUnicode(str) {
|
||||
return str.includes('\\') || str.includes('\n');
|
||||
}
|
||||
function toUnicode(str) {
|
||||
return str.split('').map(value => {
|
||||
const temp = value.charCodeAt(0).toString(16).padStart(4, '0');
|
||||
if (temp.length > 2) {
|
||||
return '\\u' + temp;
|
||||
}
|
||||
return value;
|
||||
}).join('');
|
||||
}
|
||||
function getModelValuePropName(node, vueVersion, vueCompilerOptions) {
|
||||
for (const modelName in vueCompilerOptions.experimentalModelPropName) {
|
||||
const tags = vueCompilerOptions.experimentalModelPropName[modelName];
|
||||
for (const tag in tags) {
|
||||
if (node.tag === tag || node.tag === (0, shared_2.hyphenateTag)(tag)) {
|
||||
const v = tags[tag];
|
||||
if (typeof v === 'object') {
|
||||
const arr = Array.isArray(v) ? v : [v];
|
||||
for (const attrs of arr) {
|
||||
let failed = false;
|
||||
for (const attr in attrs) {
|
||||
const attrNode = node.props.find(prop => prop.type === CompilerDOM.NodeTypes.ATTRIBUTE && prop.name === attr);
|
||||
if (!attrNode || attrNode.value?.content !== attrs[attr]) {
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!failed) {
|
||||
// all match
|
||||
return modelName || undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const modelName in vueCompilerOptions.experimentalModelPropName) {
|
||||
const tags = vueCompilerOptions.experimentalModelPropName[modelName];
|
||||
for (const tag in tags) {
|
||||
if (node.tag === tag || node.tag === (0, shared_2.hyphenateTag)(tag)) {
|
||||
const attrs = tags[tag];
|
||||
if (attrs === true) {
|
||||
return modelName || undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vueVersion < 3 ? 'value' : 'modelValue';
|
||||
}
|
||||
//# sourceMappingURL=elementProps.js.map
|
||||
21
node_modules/@vue/language-core/lib/codegen/template/index.d.ts
generated
vendored
Normal file
21
node_modules/@vue/language-core/lib/codegen/template/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type * as ts from 'typescript';
|
||||
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
||||
import { TemplateCodegenContext } from './context';
|
||||
export interface TemplateCodegenOptions {
|
||||
ts: typeof ts;
|
||||
compilerOptions: ts.CompilerOptions;
|
||||
vueCompilerOptions: VueCompilerOptions;
|
||||
template: NonNullable<Sfc['template']>;
|
||||
edited: boolean;
|
||||
scriptSetupBindingNames: Set<string>;
|
||||
scriptSetupImportComponentNames: Set<string>;
|
||||
destructuredPropNames: Set<string>;
|
||||
templateRefNames: Set<string>;
|
||||
hasDefineSlots?: boolean;
|
||||
slotsAssignName?: string;
|
||||
propsAssignName?: string;
|
||||
inheritAttrs: boolean;
|
||||
}
|
||||
export declare function generateTemplate(options: TemplateCodegenOptions): Generator<Code, TemplateCodegenContext>;
|
||||
export declare function forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator<CompilerDOM.ElementNode>;
|
||||
139
node_modules/@vue/language-core/lib/codegen/template/index.js
generated
vendored
Normal file
139
node_modules/@vue/language-core/lib/codegen/template/index.js
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateTemplate = generateTemplate;
|
||||
exports.forEachElementNode = forEachElementNode;
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const common_1 = require("../common");
|
||||
const context_1 = require("./context");
|
||||
const element_1 = require("./element");
|
||||
const objectProperty_1 = require("./objectProperty");
|
||||
const stringLiteralKey_1 = require("./stringLiteralKey");
|
||||
const templateChild_1 = require("./templateChild");
|
||||
const styleScopedClasses_1 = require("./styleScopedClasses");
|
||||
function* generateTemplate(options) {
|
||||
const ctx = (0, context_1.createTemplateCodegenContext)(options);
|
||||
if (options.slotsAssignName) {
|
||||
ctx.addLocalVariable(options.slotsAssignName);
|
||||
}
|
||||
if (options.propsAssignName) {
|
||||
ctx.addLocalVariable(options.propsAssignName);
|
||||
}
|
||||
ctx.addLocalVariable('$el');
|
||||
ctx.addLocalVariable('$refs');
|
||||
yield* generatePreResolveComponents(options);
|
||||
if (options.template.ast) {
|
||||
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast, undefined, undefined, undefined);
|
||||
}
|
||||
yield* (0, styleScopedClasses_1.generateStyleScopedClasses)(ctx);
|
||||
if (!options.hasDefineSlots) {
|
||||
yield `var __VLS_slots!:`;
|
||||
yield* generateSlotsType(options, ctx);
|
||||
yield common_1.endOfLine;
|
||||
}
|
||||
yield* ctx.generateAutoImportCompletion();
|
||||
yield* generateInheritedAttrs(ctx);
|
||||
yield* generateRefs(ctx);
|
||||
yield* generateRootEl(ctx);
|
||||
return ctx;
|
||||
}
|
||||
function* generateSlotsType(options, ctx) {
|
||||
for (const { expVar, varName } of ctx.dynamicSlots) {
|
||||
ctx.hasSlot = true;
|
||||
yield `Partial<Record<NonNullable<typeof ${expVar}>, (_: typeof ${varName}) => any>> &${common_1.newLine}`;
|
||||
}
|
||||
yield `{${common_1.newLine}`;
|
||||
for (const slot of ctx.slots) {
|
||||
ctx.hasSlot = true;
|
||||
if (slot.name && slot.loc !== undefined) {
|
||||
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.loc, ctx.codeFeatures.withoutHighlightAndCompletion, slot.nodeLoc);
|
||||
}
|
||||
else {
|
||||
yield* (0, common_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
||||
}
|
||||
yield `?(_: typeof ${slot.varName}): any,${common_1.newLine}`;
|
||||
}
|
||||
yield `}`;
|
||||
}
|
||||
function* generateInheritedAttrs(ctx) {
|
||||
yield 'var __VLS_inheritedAttrs!: {}';
|
||||
for (const varName of ctx.inheritedAttrVars) {
|
||||
yield ` & typeof ${varName}`;
|
||||
}
|
||||
yield common_1.endOfLine;
|
||||
}
|
||||
function* generateRefs(ctx) {
|
||||
yield `const __VLS_refs = {${common_1.newLine}`;
|
||||
for (const [name, [varName, offset]] of ctx.templateRefs) {
|
||||
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(name, offset, ctx.codeFeatures.navigationAndCompletion);
|
||||
yield `: ${varName},${common_1.newLine}`;
|
||||
}
|
||||
yield `}${common_1.endOfLine}`;
|
||||
yield `var $refs!: typeof __VLS_refs${common_1.endOfLine}`;
|
||||
}
|
||||
function* generateRootEl(ctx) {
|
||||
if (ctx.singleRootElType) {
|
||||
yield `var $el!: ${ctx.singleRootElType}${common_1.endOfLine}`;
|
||||
}
|
||||
else {
|
||||
yield `var $el!: any${common_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
function* generatePreResolveComponents(options) {
|
||||
yield `let __VLS_resolvedLocalAndGlobalComponents!: Required<{}`;
|
||||
if (options.template.ast) {
|
||||
const components = new Set();
|
||||
for (const node of forEachElementNode(options.template.ast)) {
|
||||
if (node.tagType === CompilerDOM.ElementTypes.COMPONENT
|
||||
&& node.tag.toLowerCase() !== 'component'
|
||||
&& !node.tag.includes('.') // namespace tag
|
||||
) {
|
||||
if (components.has(node.tag)) {
|
||||
continue;
|
||||
}
|
||||
components.add(node.tag);
|
||||
yield common_1.newLine;
|
||||
yield ` & __VLS_WithComponent<'${(0, element_1.getCanonicalComponentName)(node.tag)}', typeof __VLS_localComponents, `;
|
||||
yield (0, element_1.getPossibleOriginalComponentNames)(node.tag, false)
|
||||
.map(name => `"${name}"`)
|
||||
.join(', ');
|
||||
yield `>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
yield `>${common_1.endOfLine}`;
|
||||
}
|
||||
function* forEachElementNode(node) {
|
||||
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
||||
for (const child of node.children) {
|
||||
yield* forEachElementNode(child);
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
||||
const patchForNode = (0, templateChild_1.getVForNode)(node);
|
||||
if (patchForNode) {
|
||||
yield* forEachElementNode(patchForNode);
|
||||
}
|
||||
else {
|
||||
yield node;
|
||||
for (const child of node.children) {
|
||||
yield* forEachElementNode(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
||||
// v-if / v-else-if / v-else
|
||||
for (let i = 0; i < node.branches.length; i++) {
|
||||
const branch = node.branches[i];
|
||||
for (const childNode of branch.children) {
|
||||
yield* forEachElementNode(childNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.FOR) {
|
||||
// v-for
|
||||
for (const child of node.children) {
|
||||
yield* forEachElementNode(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
6
node_modules/@vue/language-core/lib/codegen/template/interpolation.d.ts
generated
vendored
Normal file
6
node_modules/@vue/language-core/lib/codegen/template/interpolation.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import type * as ts from 'typescript';
|
||||
import type { Code, VueCodeInformation } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateInterpolation(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, _code: string, astHolder: any, start: number | undefined, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, prefix: string, suffix: string): Generator<Code>;
|
||||
export declare function forEachInterpolationSegment(ts: typeof import('typescript'), destructuredPropNames: Set<string> | undefined, templateRefNames: Set<string> | undefined, ctx: TemplateCodegenContext, code: string, offset: number | undefined, ast: ts.SourceFile): Generator<[fragment: string, offset: number | undefined, type?: 'errorMappingOnly' | 'startText' | 'endText']>;
|
||||
222
node_modules/@vue/language-core/lib/codegen/template/interpolation.js
generated
vendored
Normal file
222
node_modules/@vue/language-core/lib/codegen/template/interpolation.js
generated
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateInterpolation = generateInterpolation;
|
||||
exports.forEachInterpolationSegment = forEachInterpolationSegment;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
|
||||
const common_1 = require("../common");
|
||||
function* generateInterpolation(options, ctx, _code, astHolder, start, data, prefix, suffix) {
|
||||
const code = prefix + _code + suffix;
|
||||
const ast = (0, common_1.createTsAst)(options.ts, astHolder, code);
|
||||
for (let [section, offset, type] of forEachInterpolationSegment(options.ts, options.destructuredPropNames, options.templateRefNames, ctx, code, start !== undefined ? start - prefix.length : undefined, ast)) {
|
||||
if (offset === undefined) {
|
||||
yield section;
|
||||
}
|
||||
else {
|
||||
offset -= prefix.length;
|
||||
let addSuffix = '';
|
||||
const overLength = offset + section.length - _code.length;
|
||||
if (overLength > 0) {
|
||||
addSuffix = section.substring(section.length - overLength);
|
||||
section = section.substring(0, section.length - overLength);
|
||||
}
|
||||
if (offset < 0) {
|
||||
yield section.substring(0, -offset);
|
||||
section = section.substring(-offset);
|
||||
offset = 0;
|
||||
}
|
||||
const shouldSkip = section.length === 0 && (type === 'startText' || type === 'endText');
|
||||
if (!shouldSkip) {
|
||||
if (start !== undefined
|
||||
&& data) {
|
||||
yield [
|
||||
section,
|
||||
'template',
|
||||
start + offset,
|
||||
type === 'errorMappingOnly'
|
||||
? ctx.codeFeatures.verification
|
||||
: typeof data === 'function' ? data(start + offset) : data,
|
||||
];
|
||||
}
|
||||
else {
|
||||
yield section;
|
||||
}
|
||||
}
|
||||
yield addSuffix;
|
||||
}
|
||||
}
|
||||
}
|
||||
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, code, offset, ast) {
|
||||
let ctxVars = [];
|
||||
const varCb = (id, isShorthand) => {
|
||||
const text = (0, scriptSetupRanges_1.getNodeText)(ts, id, ast);
|
||||
if (ctx.hasLocalVariable(text) ||
|
||||
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
||||
(0, shared_1.isGloballyWhitelisted)(text) ||
|
||||
text === 'require' ||
|
||||
text.startsWith('__VLS_')) {
|
||||
// localVarOffsets.push(localVar.getStart(ast));
|
||||
}
|
||||
else {
|
||||
ctxVars.push({
|
||||
text,
|
||||
isShorthand: isShorthand,
|
||||
offset: (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start,
|
||||
});
|
||||
if (destructuredPropNames?.has(text)) {
|
||||
return;
|
||||
}
|
||||
if (offset !== undefined) {
|
||||
ctx.accessExternalVariable(text, offset + (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start);
|
||||
}
|
||||
else {
|
||||
ctx.accessExternalVariable(text);
|
||||
}
|
||||
}
|
||||
};
|
||||
ts.forEachChild(ast, node => walkIdentifiers(ts, node, ast, varCb, ctx));
|
||||
ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
|
||||
if (ctxVars.length) {
|
||||
if (ctxVars[0].isShorthand) {
|
||||
yield [code.substring(0, ctxVars[0].offset + ctxVars[0].text.length), 0];
|
||||
yield [': ', undefined];
|
||||
}
|
||||
else if (ctxVars[0].offset > 0) {
|
||||
yield [code.substring(0, ctxVars[0].offset), 0, 'startText'];
|
||||
}
|
||||
for (let i = 0; i < ctxVars.length - 1; i++) {
|
||||
const curVar = ctxVars[i];
|
||||
const nextVar = ctxVars[i + 1];
|
||||
yield* generateVar(code, destructuredPropNames, templateRefNames, curVar, nextVar);
|
||||
if (nextVar.isShorthand) {
|
||||
yield [code.substring(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
|
||||
yield [': ', undefined];
|
||||
}
|
||||
else {
|
||||
yield [code.substring(curVar.offset + curVar.text.length, nextVar.offset), curVar.offset + curVar.text.length];
|
||||
}
|
||||
}
|
||||
const lastVar = ctxVars.at(-1);
|
||||
yield* generateVar(code, destructuredPropNames, templateRefNames, lastVar);
|
||||
if (lastVar.offset + lastVar.text.length < code.length) {
|
||||
yield [code.substring(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield [code, 0];
|
||||
}
|
||||
}
|
||||
function* generateVar(code, destructuredPropNames, templateRefNames, curVar, nextVar = curVar) {
|
||||
// fix https://github.com/vuejs/language-tools/issues/1205
|
||||
// fix https://github.com/vuejs/language-tools/issues/1264
|
||||
yield ['', nextVar.offset, 'errorMappingOnly'];
|
||||
const isDestructuredProp = destructuredPropNames?.has(curVar.text) ?? false;
|
||||
const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
|
||||
if (isTemplateRef) {
|
||||
yield [`__VLS_unref(`, undefined];
|
||||
yield [code.substring(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
||||
yield [`)`, undefined];
|
||||
}
|
||||
else {
|
||||
if (!isDestructuredProp) {
|
||||
yield [`__VLS_ctx.`, undefined];
|
||||
}
|
||||
yield [code.substring(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
||||
}
|
||||
}
|
||||
function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true) {
|
||||
if (ts.isIdentifier(node)) {
|
||||
cb(node, false);
|
||||
}
|
||||
else if (ts.isShorthandPropertyAssignment(node)) {
|
||||
cb(node.name, true);
|
||||
}
|
||||
else if (ts.isPropertyAccessExpression(node)) {
|
||||
walkIdentifiers(ts, node.expression, ast, cb, ctx, blockVars, false);
|
||||
}
|
||||
else if (ts.isVariableDeclaration(node)) {
|
||||
(0, common_1.collectVars)(ts, node.name, ast, blockVars);
|
||||
for (const varName of blockVars) {
|
||||
ctx.addLocalVariable(varName);
|
||||
}
|
||||
if (node.initializer) {
|
||||
walkIdentifiers(ts, node.initializer, ast, cb, ctx, blockVars, false);
|
||||
}
|
||||
}
|
||||
else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
||||
processFunction(ts, node, ast, cb, ctx);
|
||||
}
|
||||
else if (ts.isObjectLiteralExpression(node)) {
|
||||
for (const prop of node.properties) {
|
||||
if (ts.isPropertyAssignment(prop)) {
|
||||
// fix https://github.com/vuejs/language-tools/issues/1176
|
||||
if (ts.isComputedPropertyName(prop.name)) {
|
||||
walkIdentifiers(ts, prop.name.expression, ast, cb, ctx, blockVars, false);
|
||||
}
|
||||
walkIdentifiers(ts, prop.initializer, ast, cb, ctx, blockVars, false);
|
||||
}
|
||||
// fix https://github.com/vuejs/language-tools/issues/1156
|
||||
else if (ts.isShorthandPropertyAssignment(prop)) {
|
||||
walkIdentifiers(ts, prop, ast, cb, ctx, blockVars, false);
|
||||
}
|
||||
// fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
||||
else if (ts.isSpreadAssignment(prop)) {
|
||||
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
|
||||
walkIdentifiers(ts, prop.expression, ast, cb, ctx, blockVars, false);
|
||||
}
|
||||
// fix https://github.com/vuejs/language-tools/issues/4604
|
||||
else if (ts.isFunctionLike(prop) && prop.body) {
|
||||
processFunction(ts, prop, ast, cb, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ts.isTypeReferenceNode(node)) {
|
||||
// fix https://github.com/vuejs/language-tools/issues/1422
|
||||
ts.forEachChild(node, node => walkIdentifiersInTypeReference(ts, node, cb));
|
||||
}
|
||||
else {
|
||||
const _blockVars = blockVars;
|
||||
if (ts.isBlock(node)) {
|
||||
blockVars = [];
|
||||
}
|
||||
ts.forEachChild(node, node => walkIdentifiers(ts, node, ast, cb, ctx, blockVars, false));
|
||||
if (ts.isBlock(node)) {
|
||||
for (const varName of blockVars) {
|
||||
ctx.removeLocalVariable(varName);
|
||||
}
|
||||
}
|
||||
blockVars = _blockVars;
|
||||
}
|
||||
if (isRoot) {
|
||||
for (const varName of blockVars) {
|
||||
ctx.removeLocalVariable(varName);
|
||||
}
|
||||
}
|
||||
}
|
||||
function processFunction(ts, node, ast, cb, ctx) {
|
||||
const functionArgs = [];
|
||||
for (const param of node.parameters) {
|
||||
(0, common_1.collectVars)(ts, param.name, ast, functionArgs);
|
||||
if (param.type) {
|
||||
walkIdentifiers(ts, param.type, ast, cb, ctx);
|
||||
}
|
||||
}
|
||||
for (const varName of functionArgs) {
|
||||
ctx.addLocalVariable(varName);
|
||||
}
|
||||
if (node.body) {
|
||||
walkIdentifiers(ts, node.body, ast, cb, ctx);
|
||||
}
|
||||
for (const varName of functionArgs) {
|
||||
ctx.removeLocalVariable(varName);
|
||||
}
|
||||
}
|
||||
function walkIdentifiersInTypeReference(ts, node, cb) {
|
||||
if (ts.isTypeQueryNode(node) && ts.isIdentifier(node.exprName)) {
|
||||
cb(node.exprName, false);
|
||||
}
|
||||
else {
|
||||
ts.forEachChild(node, node => walkIdentifiersInTypeReference(ts, node, cb));
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=interpolation.js.map
|
||||
4
node_modules/@vue/language-core/lib/codegen/template/objectProperty.d.ts
generated
vendored
Normal file
4
node_modules/@vue/language-core/lib/codegen/template/objectProperty.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { Code, VueCodeInformation } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateObjectProperty(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset: number, features: VueCodeInformation, astHolder?: any, shouldCamelize?: boolean, shouldBeConstant?: boolean): Generator<Code>;
|
||||
35
node_modules/@vue/language-core/lib/codegen/template/objectProperty.js
generated
vendored
Normal file
35
node_modules/@vue/language-core/lib/codegen/template/objectProperty.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateObjectProperty = generateObjectProperty;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const common_1 = require("../common");
|
||||
const camelized_1 = require("./camelized");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const stringLiteralKey_1 = require("./stringLiteralKey");
|
||||
function* generateObjectProperty(options, ctx, code, offset, features, astHolder, shouldCamelize = false, shouldBeConstant = false) {
|
||||
if (code.startsWith('[') && code.endsWith(']') && astHolder) {
|
||||
if (shouldBeConstant) {
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, code.slice(1, -1), astHolder, offset + 1, features, `[__VLS_tryAsConstant(`, `)]`);
|
||||
}
|
||||
else {
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, code, astHolder, offset, features, '', '');
|
||||
}
|
||||
}
|
||||
else if (shouldCamelize) {
|
||||
if (common_1.variableNameRegex.test((0, shared_1.camelize)(code))) {
|
||||
yield* (0, camelized_1.generateCamelized)(code, offset, features);
|
||||
}
|
||||
else {
|
||||
yield* (0, common_1.wrapWith)(offset, offset + code.length, features, `"`, ...(0, camelized_1.generateCamelized)(code, offset, common_1.combineLastMapping), `"`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (common_1.variableNameRegex.test(code)) {
|
||||
yield [code, 'template', offset, features];
|
||||
}
|
||||
else {
|
||||
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(code, offset, features);
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=objectProperty.js.map
|
||||
4
node_modules/@vue/language-core/lib/codegen/template/propertyAccess.d.ts
generated
vendored
Normal file
4
node_modules/@vue/language-core/lib/codegen/template/propertyAccess.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { Code, VueCodeInformation } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generatePropertyAccess(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset?: number, features?: VueCodeInformation, astHolder?: any): Generator<Code>;
|
||||
23
node_modules/@vue/language-core/lib/codegen/template/propertyAccess.js
generated
vendored
Normal file
23
node_modules/@vue/language-core/lib/codegen/template/propertyAccess.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generatePropertyAccess = generatePropertyAccess;
|
||||
const common_1 = require("../common");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const stringLiteralKey_1 = require("./stringLiteralKey");
|
||||
function* generatePropertyAccess(options, ctx, code, offset, features, astHolder) {
|
||||
if (!options.compilerOptions.noPropertyAccessFromIndexSignature && common_1.variableNameRegex.test(code)) {
|
||||
yield `.`;
|
||||
yield offset !== undefined && features
|
||||
? [code, 'template', offset, features]
|
||||
: code;
|
||||
}
|
||||
else if (code.startsWith('[') && code.endsWith(']')) {
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, code, astHolder, offset, features, '', '');
|
||||
}
|
||||
else {
|
||||
yield `[`;
|
||||
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(code, offset, features);
|
||||
yield `]`;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=propertyAccess.js.map
|
||||
5
node_modules/@vue/language-core/lib/codegen/template/slotOutlet.d.ts
generated
vendored
Normal file
5
node_modules/@vue/language-core/lib/codegen/template/slotOutlet.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateSlotOutlet(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.SlotOutletNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
||||
75
node_modules/@vue/language-core/lib/codegen/template/slotOutlet.js
generated
vendored
Normal file
75
node_modules/@vue/language-core/lib/codegen/template/slotOutlet.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateSlotOutlet = generateSlotOutlet;
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const common_1 = require("../common");
|
||||
const elementChildren_1 = require("./elementChildren");
|
||||
const elementProps_1 = require("./elementProps");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const inlayHints_1 = require("../inlayHints");
|
||||
function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxVar) {
|
||||
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
||||
const varSlot = ctx.getInternalVariable();
|
||||
const nameProp = node.props.find(prop => {
|
||||
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
||||
return prop.name === 'name';
|
||||
}
|
||||
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.name === 'bind'
|
||||
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
return prop.arg.content === 'name';
|
||||
}
|
||||
});
|
||||
if (options.hasDefineSlots) {
|
||||
yield `__VLS_normalizeSlot(`;
|
||||
yield* (0, common_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, common_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value
|
||||
? `'${nameProp.value.content}'`
|
||||
: nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
? nameProp.exp.content
|
||||
: `('default' as const)`), `]`);
|
||||
yield `)?.(`;
|
||||
yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${common_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true), `}`);
|
||||
yield `)${common_1.endOfLine}`;
|
||||
}
|
||||
else {
|
||||
yield `var ${varSlot} = {${common_1.newLine}`;
|
||||
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
|
||||
yield `}${common_1.endOfLine}`;
|
||||
if (nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
||||
&& nameProp.value) {
|
||||
ctx.slots.push({
|
||||
name: nameProp.value.content,
|
||||
loc: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
|
||||
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
||||
varName: varSlot,
|
||||
nodeLoc: node.loc,
|
||||
});
|
||||
}
|
||||
else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
const isShortHand = nameProp.arg?.loc.start.offset === nameProp.exp.loc.start.offset;
|
||||
if (isShortHand) {
|
||||
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(nameProp.exp.loc, 'name'));
|
||||
}
|
||||
const slotExpVar = ctx.getInternalVariable();
|
||||
yield `var ${slotExpVar} = `;
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, nameProp.exp.content, nameProp.exp, nameProp.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
||||
yield ` as const${common_1.endOfLine}`;
|
||||
ctx.dynamicSlots.push({
|
||||
expVar: slotExpVar,
|
||||
varName: varSlot,
|
||||
});
|
||||
}
|
||||
else {
|
||||
ctx.slots.push({
|
||||
name: 'default',
|
||||
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
||||
varName: varSlot,
|
||||
nodeLoc: node.loc,
|
||||
});
|
||||
}
|
||||
}
|
||||
yield* ctx.generateAutoImportCompletion();
|
||||
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
|
||||
}
|
||||
//# sourceMappingURL=slotOutlet.js.map
|
||||
2
node_modules/@vue/language-core/lib/codegen/template/stringLiteralKey.d.ts
generated
vendored
Normal file
2
node_modules/@vue/language-core/lib/codegen/template/stringLiteralKey.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { Code, VueCodeInformation } from '../../types';
|
||||
export declare function generateStringLiteralKey(code: string, offset?: number, info?: VueCodeInformation): Generator<Code>;
|
||||
13
node_modules/@vue/language-core/lib/codegen/template/stringLiteralKey.js
generated
vendored
Normal file
13
node_modules/@vue/language-core/lib/codegen/template/stringLiteralKey.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateStringLiteralKey = generateStringLiteralKey;
|
||||
const common_1 = require("../common");
|
||||
function* generateStringLiteralKey(code, offset, info) {
|
||||
if (offset === undefined || !info) {
|
||||
yield `"${code}"`;
|
||||
}
|
||||
else {
|
||||
yield* (0, common_1.wrapWith)(offset, offset + code.length, info, `"`, [code, 'template', offset, common_1.combineLastMapping], `"`);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=stringLiteralKey.js.map
|
||||
3
node_modules/@vue/language-core/lib/codegen/template/styleScopedClasses.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/codegen/template/styleScopedClasses.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
export declare function generateStyleScopedClasses(ctx: TemplateCodegenContext, withDot?: boolean): Generator<Code>;
|
||||
72
node_modules/@vue/language-core/lib/codegen/template/styleScopedClasses.js
generated
vendored
Normal file
72
node_modules/@vue/language-core/lib/codegen/template/styleScopedClasses.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateStyleScopedClasses = generateStyleScopedClasses;
|
||||
const common_1 = require("../common");
|
||||
function* generateStyleScopedClasses(ctx, withDot = false) {
|
||||
for (const offset of ctx.emptyClassOffsets) {
|
||||
yield `__VLS_styleScopedClasses['`;
|
||||
yield [
|
||||
'',
|
||||
'template',
|
||||
offset,
|
||||
ctx.codeFeatures.additionalCompletion,
|
||||
];
|
||||
yield `']${common_1.endOfLine}`;
|
||||
}
|
||||
for (const { source, className, offset } of ctx.scopedClasses) {
|
||||
yield `__VLS_styleScopedClasses[`;
|
||||
yield [
|
||||
'',
|
||||
source,
|
||||
offset - (withDot ? 1 : 0),
|
||||
ctx.codeFeatures.navigation,
|
||||
];
|
||||
yield `'`;
|
||||
// fix https://github.com/vuejs/language-tools/issues/4537
|
||||
yield* escapeString(source, className, offset, ['\\', '\'']);
|
||||
yield `'`;
|
||||
yield [
|
||||
'',
|
||||
source,
|
||||
offset + className.length,
|
||||
ctx.codeFeatures.navigationWithoutRename,
|
||||
];
|
||||
yield `]${common_1.endOfLine}`;
|
||||
}
|
||||
yield common_1.newLine;
|
||||
function* escapeString(source, className, offset, escapeTargets) {
|
||||
let count = 0;
|
||||
const currentEscapeTargets = [...escapeTargets];
|
||||
const firstEscapeTarget = currentEscapeTargets.shift();
|
||||
const splitted = className.split(firstEscapeTarget);
|
||||
for (let i = 0; i < splitted.length; i++) {
|
||||
const part = splitted[i];
|
||||
const partLength = part.length;
|
||||
if (escapeTargets.length > 0) {
|
||||
yield* escapeString(source, part, offset + count, [...currentEscapeTargets]);
|
||||
}
|
||||
else {
|
||||
yield [
|
||||
part,
|
||||
source,
|
||||
offset + count,
|
||||
ctx.codeFeatures.navigationAndAdditionalCompletion,
|
||||
];
|
||||
}
|
||||
if (i !== splitted.length - 1) {
|
||||
yield '\\';
|
||||
yield [
|
||||
firstEscapeTarget,
|
||||
source,
|
||||
offset + count + partLength,
|
||||
ctx.codeFeatures.navigationAndAdditionalCompletion,
|
||||
];
|
||||
count += partLength + 1;
|
||||
}
|
||||
else {
|
||||
count += partLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=styleScopedClasses.js.map
|
||||
7
node_modules/@vue/language-core/lib/codegen/template/templateChild.d.ts
generated
vendored
Normal file
7
node_modules/@vue/language-core/lib/codegen/template/templateChild.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, currentComponent: CompilerDOM.ElementNode | undefined, prevNode: CompilerDOM.TemplateChildNode | undefined, componentCtxVar: string | undefined, isVForChild?: boolean): Generator<Code>;
|
||||
export declare function getVForNode(node: CompilerDOM.ElementNode): CompilerDOM.ForNode | undefined;
|
||||
export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number];
|
||||
167
node_modules/@vue/language-core/lib/codegen/template/templateChild.js
generated
vendored
Normal file
167
node_modules/@vue/language-core/lib/codegen/template/templateChild.js
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateTemplateChild = generateTemplateChild;
|
||||
exports.getVForNode = getVForNode;
|
||||
exports.parseInterpolationNode = parseInterpolationNode;
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const common_1 = require("../common");
|
||||
const element_1 = require("./element");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const slotOutlet_1 = require("./slotOutlet");
|
||||
const vFor_1 = require("./vFor");
|
||||
const vIf_1 = require("./vIf");
|
||||
// @ts-ignore
|
||||
const transformContext = {
|
||||
onError: () => { },
|
||||
helperString: str => str.toString(),
|
||||
replaceNode: () => { },
|
||||
cacheHandlers: false,
|
||||
prefixIdentifiers: false,
|
||||
scopes: {
|
||||
vFor: 0,
|
||||
vOnce: 0,
|
||||
vPre: 0,
|
||||
vSlot: 0,
|
||||
},
|
||||
expressionPlugins: ['typescript'],
|
||||
};
|
||||
function* generateTemplateChild(options, ctx, node, currentComponent, prevNode, componentCtxVar, isVForChild = false) {
|
||||
if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
|
||||
const commentText = prevNode.content.trim().split(' ')[0];
|
||||
if (commentText.match(/^@vue-skip\b[\s\S]*/)) {
|
||||
yield `// @vue-skip${common_1.newLine}`;
|
||||
return;
|
||||
}
|
||||
else if (commentText.match(/^@vue-ignore\b[\s\S]*/)) {
|
||||
yield* ctx.ignoreError();
|
||||
}
|
||||
else if (commentText.match(/^@vue-expect-error\b[\s\S]*/)) {
|
||||
yield* ctx.expectError(prevNode);
|
||||
}
|
||||
}
|
||||
const shouldInheritRootNodeAttrs = options.inheritAttrs;
|
||||
const cur = node;
|
||||
if (cur.codegenNode?.type === CompilerDOM.NodeTypes.JS_CACHE_EXPRESSION) {
|
||||
cur.codegenNode = cur.codegenNode.value;
|
||||
}
|
||||
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
||||
let prev;
|
||||
if (shouldInheritRootNodeAttrs && node.children.length === 1 && node.children[0].type === CompilerDOM.NodeTypes.ELEMENT) {
|
||||
ctx.singleRootNode = node.children[0];
|
||||
}
|
||||
for (const childNode of node.children) {
|
||||
yield* generateTemplateChild(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
||||
prev = childNode;
|
||||
}
|
||||
yield* ctx.resetDirectiveComments('end of root');
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
||||
const vForNode = getVForNode(node);
|
||||
const vIfNode = getVIfNode(node);
|
||||
if (vForNode) {
|
||||
yield* (0, vFor_1.generateVFor)(options, ctx, vForNode, currentComponent, componentCtxVar);
|
||||
}
|
||||
else if (vIfNode) {
|
||||
yield* (0, vIf_1.generateVIf)(options, ctx, vIfNode, currentComponent, componentCtxVar);
|
||||
}
|
||||
else {
|
||||
if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
|
||||
yield* (0, slotOutlet_1.generateSlotOutlet)(options, ctx, node, currentComponent, componentCtxVar);
|
||||
}
|
||||
else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
|
||||
|| node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
|
||||
yield* (0, element_1.generateElement)(options, ctx, node, currentComponent, componentCtxVar, isVForChild);
|
||||
}
|
||||
else {
|
||||
yield* (0, element_1.generateComponent)(options, ctx, node, currentComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
||||
// {{ var }}
|
||||
yield* generateTemplateChild(options, ctx, node.content, currentComponent, undefined, componentCtxVar);
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
||||
// {{ ... }} {{ ... }}
|
||||
for (const childNode of node.children) {
|
||||
if (typeof childNode === 'object') {
|
||||
yield* generateTemplateChild(options, ctx, childNode, currentComponent, undefined, componentCtxVar);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
||||
// {{ ... }}
|
||||
const [content, start] = parseInterpolationNode(node, options.template.content);
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, content, node.content.loc, start, ctx.codeFeatures.all, `(`, `)${common_1.endOfLine}`);
|
||||
yield* ctx.resetDirectiveComments('end of INTERPOLATION');
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
||||
// v-if / v-else-if / v-else
|
||||
yield* (0, vIf_1.generateVIf)(options, ctx, node, currentComponent, componentCtxVar);
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.FOR) {
|
||||
// v-for
|
||||
yield* (0, vFor_1.generateVFor)(options, ctx, node, currentComponent, componentCtxVar);
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.TEXT) {
|
||||
// not needed progress
|
||||
}
|
||||
}
|
||||
// TODO: track https://github.com/vuejs/vue-next/issues/3498
|
||||
function getVForNode(node) {
|
||||
const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.name === 'for');
|
||||
if (forDirective) {
|
||||
let forNode;
|
||||
CompilerDOM.processFor(node, forDirective, transformContext, _forNode => {
|
||||
forNode = { ..._forNode };
|
||||
return undefined;
|
||||
});
|
||||
if (forNode) {
|
||||
forNode.children = [{
|
||||
...node,
|
||||
props: node.props.filter(prop => prop !== forDirective),
|
||||
}];
|
||||
return forNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
function getVIfNode(node) {
|
||||
const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.name === 'if');
|
||||
if (forDirective) {
|
||||
let ifNode;
|
||||
CompilerDOM.processIf(node, forDirective, transformContext, _ifNode => {
|
||||
ifNode = { ..._ifNode };
|
||||
return undefined;
|
||||
});
|
||||
if (ifNode) {
|
||||
for (const branch of ifNode.branches) {
|
||||
branch.children = [{
|
||||
...node,
|
||||
props: node.props.filter(prop => prop !== forDirective),
|
||||
}];
|
||||
}
|
||||
return ifNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
function parseInterpolationNode(node, template) {
|
||||
let content = node.content.loc.source;
|
||||
let start = node.content.loc.start.offset;
|
||||
let leftCharacter;
|
||||
let rightCharacter;
|
||||
// fix https://github.com/vuejs/language-tools/issues/1787
|
||||
while ((leftCharacter = template.substring(start - 1, start)).trim() === '' && leftCharacter.length) {
|
||||
start--;
|
||||
content = leftCharacter + content;
|
||||
}
|
||||
while ((rightCharacter = template.substring(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
|
||||
content = content + rightCharacter;
|
||||
}
|
||||
return [
|
||||
content,
|
||||
start,
|
||||
];
|
||||
}
|
||||
//# sourceMappingURL=templateChild.js.map
|
||||
12
node_modules/@vue/language-core/lib/codegen/template/vFor.d.ts
generated
vendored
Normal file
12
node_modules/@vue/language-core/lib/codegen/template/vFor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateVFor(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ForNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
||||
export declare function parseVForNode(node: CompilerDOM.ForNode): {
|
||||
leftExpressionRange: {
|
||||
start: number;
|
||||
end: number;
|
||||
} | undefined;
|
||||
leftExpressionText: string | undefined;
|
||||
};
|
||||
85
node_modules/@vue/language-core/lib/codegen/template/vFor.js
generated
vendored
Normal file
85
node_modules/@vue/language-core/lib/codegen/template/vFor.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateVFor = generateVFor;
|
||||
exports.parseVForNode = parseVForNode;
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const common_1 = require("../common");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const templateChild_1 = require("./templateChild");
|
||||
function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
|
||||
const { source } = node.parseResult;
|
||||
const { leftExpressionRange, leftExpressionText } = parseVForNode(node);
|
||||
const forBlockVars = [];
|
||||
yield `for (const [`;
|
||||
if (leftExpressionRange && leftExpressionText) {
|
||||
const collectAst = (0, common_1.createTsAst)(options.ts, node.parseResult, `const [${leftExpressionText}]`);
|
||||
(0, common_1.collectVars)(options.ts, collectAst, collectAst, forBlockVars);
|
||||
yield [
|
||||
leftExpressionText,
|
||||
'template',
|
||||
leftExpressionRange.start,
|
||||
ctx.codeFeatures.all,
|
||||
];
|
||||
}
|
||||
yield `] of `;
|
||||
if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
yield `__VLS_getVForSourceType(`;
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, source.content, source.loc, source.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
||||
yield `!)`; // #3102
|
||||
}
|
||||
else {
|
||||
yield `{} as any`;
|
||||
}
|
||||
yield `) {${common_1.newLine}`;
|
||||
for (const varName of forBlockVars) {
|
||||
ctx.addLocalVariable(varName);
|
||||
}
|
||||
let isFragment = true;
|
||||
for (const argument of node.codegenNode?.children.arguments ?? []) {
|
||||
if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION
|
||||
&& argument.returns?.type === CompilerDOM.NodeTypes.VNODE_CALL
|
||||
&& argument.returns?.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
|
||||
if (argument.returns.tag !== CompilerDOM.FRAGMENT) {
|
||||
isFragment = false;
|
||||
continue;
|
||||
}
|
||||
for (const prop of argument.returns.props.properties) {
|
||||
if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& !prop.value.isStatic) {
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.value.content, prop.value.loc, prop.value.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
||||
yield common_1.endOfLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isFragment) {
|
||||
yield* ctx.resetDirectiveComments('end of v-for start');
|
||||
}
|
||||
let prev;
|
||||
for (const childNode of node.children) {
|
||||
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar, true);
|
||||
prev = childNode;
|
||||
}
|
||||
for (const varName of forBlockVars) {
|
||||
ctx.removeLocalVariable(varName);
|
||||
}
|
||||
yield* ctx.generateAutoImportCompletion();
|
||||
yield `}${common_1.newLine}`;
|
||||
}
|
||||
function parseVForNode(node) {
|
||||
const { value, key, index } = node.parseResult;
|
||||
const leftExpressionRange = (value || key || index)
|
||||
? {
|
||||
start: (value ?? key ?? index).loc.start.offset,
|
||||
end: (index ?? key ?? value).loc.end.offset,
|
||||
}
|
||||
: undefined;
|
||||
const leftExpressionText = leftExpressionRange
|
||||
? node.loc.source.substring(leftExpressionRange.start - node.loc.start.offset, leftExpressionRange.end - node.loc.start.offset)
|
||||
: undefined;
|
||||
return {
|
||||
leftExpressionRange,
|
||||
leftExpressionText,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=vFor.js.map
|
||||
5
node_modules/@vue/language-core/lib/codegen/template/vIf.d.ts
generated
vendored
Normal file
5
node_modules/@vue/language-core/lib/codegen/template/vIf.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateVIf(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.IfNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
||||
57
node_modules/@vue/language-core/lib/codegen/template/vIf.js
generated
vendored
Normal file
57
node_modules/@vue/language-core/lib/codegen/template/vIf.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateVIf = generateVIf;
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const muggle_string_1 = require("muggle-string");
|
||||
const common_1 = require("../common");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const templateChild_1 = require("./templateChild");
|
||||
function* generateVIf(options, ctx, node, currentComponent, componentCtxVar) {
|
||||
let originalBlockConditionsLength = ctx.blockConditions.length;
|
||||
for (let i = 0; i < node.branches.length; i++) {
|
||||
const branch = node.branches[i];
|
||||
if (i === 0) {
|
||||
yield `if `;
|
||||
}
|
||||
else if (branch.condition) {
|
||||
yield `else if `;
|
||||
}
|
||||
else {
|
||||
yield `else `;
|
||||
}
|
||||
let addedBlockCondition = false;
|
||||
if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
const codes = [
|
||||
...(0, interpolation_1.generateInterpolation)(options, ctx, branch.condition.content, branch.condition.loc, branch.condition.loc.start.offset, ctx.codeFeatures.all, '(', ')'),
|
||||
];
|
||||
for (const code of codes) {
|
||||
yield code;
|
||||
}
|
||||
ctx.blockConditions.push((0, muggle_string_1.toString)(codes));
|
||||
addedBlockCondition = true;
|
||||
yield ` `;
|
||||
}
|
||||
yield `{${common_1.newLine}`;
|
||||
if (isFragment(node)) {
|
||||
yield* ctx.resetDirectiveComments('end of v-if start');
|
||||
}
|
||||
let prev;
|
||||
for (const childNode of branch.children) {
|
||||
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
||||
prev = childNode;
|
||||
}
|
||||
yield* ctx.generateAutoImportCompletion();
|
||||
yield `}${common_1.newLine}`;
|
||||
if (addedBlockCondition) {
|
||||
ctx.blockConditions[ctx.blockConditions.length - 1] = `!(${ctx.blockConditions[ctx.blockConditions.length - 1]})`;
|
||||
}
|
||||
}
|
||||
ctx.blockConditions.length = originalBlockConditionsLength;
|
||||
}
|
||||
function isFragment(node) {
|
||||
return node.codegenNode
|
||||
&& 'consequent' in node.codegenNode
|
||||
&& 'tag' in node.codegenNode.consequent
|
||||
&& node.codegenNode.consequent.tag === CompilerDOM.FRAGMENT;
|
||||
}
|
||||
//# sourceMappingURL=vIf.js.map
|
||||
6
node_modules/@vue/language-core/lib/languagePlugin.d.ts
generated
vendored
Normal file
6
node_modules/@vue/language-core/lib/languagePlugin.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { LanguagePlugin } from '@volar/language-core';
|
||||
import type * as ts from 'typescript';
|
||||
import type { VueCompilerOptions } from './types';
|
||||
import { VueVirtualCode } from './virtualFile/vueFile';
|
||||
export declare function createVueLanguagePlugin<T>(ts: typeof import('typescript'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, asFileName: (scriptId: T) => string): LanguagePlugin<T, VueVirtualCode>;
|
||||
export declare function getAllExtensions(options: VueCompilerOptions): string[];
|
||||
122
node_modules/@vue/language-core/lib/languagePlugin.js
generated
vendored
Normal file
122
node_modules/@vue/language-core/lib/languagePlugin.js
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
"use strict";
|
||||
/// <reference types="@volar/typescript" />
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createVueLanguagePlugin = createVueLanguagePlugin;
|
||||
exports.getAllExtensions = getAllExtensions;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const plugins_1 = require("./plugins");
|
||||
const CompilerVue2 = require("./utils/vue2TemplateCompiler");
|
||||
const vueFile_1 = require("./virtualFile/vueFile");
|
||||
const fileRegistries = [];
|
||||
function getVueFileRegistry(key, plugins) {
|
||||
let fileRegistry = fileRegistries.find(r => r.key === key
|
||||
&& r.plugins.length === plugins.length
|
||||
&& r.plugins.every(plugin => plugins.includes(plugin)))?.files;
|
||||
if (!fileRegistry) {
|
||||
fileRegistry = new Map();
|
||||
fileRegistries.push({
|
||||
key: key,
|
||||
plugins: plugins,
|
||||
files: fileRegistry,
|
||||
});
|
||||
}
|
||||
return fileRegistry;
|
||||
}
|
||||
function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
|
||||
const values = [
|
||||
...Object.keys(vueCompilerOptions)
|
||||
.sort()
|
||||
.filter(key => key !== 'plugins')
|
||||
.map(key => [key, vueCompilerOptions[key]]),
|
||||
[...new Set(plugins.map(plugin => plugin.requiredCompilerOptions ?? []).flat())]
|
||||
.sort()
|
||||
.map(key => [key, compilerOptions[key]]),
|
||||
];
|
||||
return JSON.stringify(values);
|
||||
}
|
||||
function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) {
|
||||
const pluginContext = {
|
||||
modules: {
|
||||
'@vue/compiler-dom': vueCompilerOptions.target < 3
|
||||
? {
|
||||
...CompilerDOM,
|
||||
compile: CompilerVue2.compile,
|
||||
}
|
||||
: CompilerDOM,
|
||||
typescript: ts,
|
||||
},
|
||||
compilerOptions,
|
||||
vueCompilerOptions,
|
||||
};
|
||||
const plugins = (0, plugins_1.createPlugins)(pluginContext);
|
||||
const fileRegistry = getVueFileRegistry(getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins), vueCompilerOptions.plugins);
|
||||
return {
|
||||
getLanguageId(scriptId) {
|
||||
const fileName = asFileName(scriptId);
|
||||
for (const plugin of plugins) {
|
||||
const languageId = plugin.getLanguageId?.(fileName);
|
||||
if (languageId) {
|
||||
return languageId;
|
||||
}
|
||||
}
|
||||
},
|
||||
createVirtualCode(scriptId, languageId, snapshot) {
|
||||
const fileName = asFileName(scriptId);
|
||||
if (plugins.some(plugin => plugin.isValidFile?.(fileName, languageId))) {
|
||||
const code = fileRegistry.get(fileName);
|
||||
if (code) {
|
||||
code.update(snapshot);
|
||||
return code;
|
||||
}
|
||||
else {
|
||||
const code = new vueFile_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts);
|
||||
fileRegistry.set(fileName, code);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
},
|
||||
updateVirtualCode(_fileId, code, snapshot) {
|
||||
code.update(snapshot);
|
||||
return code;
|
||||
},
|
||||
typescript: {
|
||||
extraFileExtensions: getAllExtensions(vueCompilerOptions)
|
||||
.map(ext => ({
|
||||
extension: ext.slice(1),
|
||||
isMixedContent: true,
|
||||
scriptKind: 7,
|
||||
})),
|
||||
getServiceScript(root) {
|
||||
for (const code of (0, language_core_1.forEachEmbeddedCode)(root)) {
|
||||
if (/script_(js|jsx|ts|tsx)/.test(code.id)) {
|
||||
const lang = code.id.substring('script_'.length);
|
||||
return {
|
||||
code,
|
||||
extension: '.' + lang,
|
||||
scriptKind: lang === 'js' ? ts.ScriptKind.JS
|
||||
: lang === 'jsx' ? ts.ScriptKind.JSX
|
||||
: lang === 'tsx' ? ts.ScriptKind.TSX
|
||||
: ts.ScriptKind.TS,
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
function getAllExtensions(options) {
|
||||
const result = new Set();
|
||||
for (const key in options) {
|
||||
if (key === 'extensions' || key.endsWith('Extensions')) {
|
||||
const value = options[key];
|
||||
if (Array.isArray(value) && value.every(v => typeof v === 'string')) {
|
||||
for (const ext of value) {
|
||||
result.add(ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return [...result];
|
||||
}
|
||||
//# sourceMappingURL=languagePlugin.js.map
|
||||
18
node_modules/@vue/language-core/lib/parsers/scriptRanges.d.ts
generated
vendored
Normal file
18
node_modules/@vue/language-core/lib/parsers/scriptRanges.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { TextRange } from '../types';
|
||||
import type * as ts from 'typescript';
|
||||
export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> {
|
||||
}
|
||||
export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, hasScriptSetup: boolean, withNode: boolean): {
|
||||
exportDefault: (TextRange & {
|
||||
expression: TextRange;
|
||||
args: TextRange;
|
||||
argsNode: ts.ObjectLiteralExpression | undefined;
|
||||
componentsOption: TextRange | undefined;
|
||||
componentsOptionNode: ts.ObjectLiteralExpression | undefined;
|
||||
directivesOption: TextRange | undefined;
|
||||
nameOption: TextRange | undefined;
|
||||
inheritAttrsOption: string | undefined;
|
||||
}) | undefined;
|
||||
classBlockEnd: number | undefined;
|
||||
bindings: TextRange[];
|
||||
};
|
||||
79
node_modules/@vue/language-core/lib/parsers/scriptRanges.js
generated
vendored
Normal file
79
node_modules/@vue/language-core/lib/parsers/scriptRanges.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseScriptRanges = parseScriptRanges;
|
||||
const scriptSetupRanges_1 = require("./scriptSetupRanges");
|
||||
function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
||||
let exportDefault;
|
||||
let classBlockEnd;
|
||||
const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast) : [];
|
||||
ts.forEachChild(ast, raw => {
|
||||
if (ts.isExportAssignment(raw)) {
|
||||
let node = raw;
|
||||
while (isAsExpression(node.expression) || ts.isParenthesizedExpression(node.expression)) { // fix https://github.com/vuejs/language-tools/issues/1882
|
||||
node = node.expression;
|
||||
}
|
||||
let obj;
|
||||
if (ts.isObjectLiteralExpression(node.expression)) {
|
||||
obj = node.expression;
|
||||
}
|
||||
else if (ts.isCallExpression(node.expression) && node.expression.arguments.length) {
|
||||
const arg0 = node.expression.arguments[0];
|
||||
if (ts.isObjectLiteralExpression(arg0)) {
|
||||
obj = arg0;
|
||||
}
|
||||
}
|
||||
if (obj) {
|
||||
let componentsOptionNode;
|
||||
let directivesOptionNode;
|
||||
let nameOptionNode;
|
||||
let inheritAttrsOption;
|
||||
ts.forEachChild(obj, node => {
|
||||
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
|
||||
const name = (0, scriptSetupRanges_1.getNodeText)(ts, node.name, ast);
|
||||
if (name === 'components' && ts.isObjectLiteralExpression(node.initializer)) {
|
||||
componentsOptionNode = node.initializer;
|
||||
}
|
||||
else if (name === 'directives' && ts.isObjectLiteralExpression(node.initializer)) {
|
||||
directivesOptionNode = node.initializer;
|
||||
}
|
||||
else if (name === 'name') {
|
||||
nameOptionNode = node.initializer;
|
||||
}
|
||||
else if (name === 'inheritAttrs') {
|
||||
inheritAttrsOption = (0, scriptSetupRanges_1.getNodeText)(ts, node.initializer, ast);
|
||||
}
|
||||
}
|
||||
});
|
||||
exportDefault = {
|
||||
..._getStartEnd(raw),
|
||||
expression: _getStartEnd(node.expression),
|
||||
args: _getStartEnd(obj),
|
||||
argsNode: withNode ? obj : undefined,
|
||||
componentsOption: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined,
|
||||
componentsOptionNode: withNode ? componentsOptionNode : undefined,
|
||||
directivesOption: directivesOptionNode ? _getStartEnd(directivesOptionNode) : undefined,
|
||||
nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
|
||||
inheritAttrsOption,
|
||||
};
|
||||
}
|
||||
}
|
||||
if (ts.isClassDeclaration(raw)
|
||||
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)
|
||||
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.DefaultKeyword)) {
|
||||
classBlockEnd = raw.end - 1;
|
||||
}
|
||||
});
|
||||
return {
|
||||
exportDefault,
|
||||
classBlockEnd,
|
||||
bindings,
|
||||
};
|
||||
function _getStartEnd(node) {
|
||||
return (0, scriptSetupRanges_1.getStartEnd)(ts, node, ast);
|
||||
}
|
||||
// isAsExpression is missing in tsc
|
||||
function isAsExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.AsExpression;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=scriptRanges.js.map
|
||||
91
node_modules/@vue/language-core/lib/parsers/scriptSetupRanges.d.ts
generated
vendored
Normal file
91
node_modules/@vue/language-core/lib/parsers/scriptSetupRanges.d.ts
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
import type * as ts from 'typescript';
|
||||
import type { VueCompilerOptions, TextRange } from '../types';
|
||||
export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRanges> {
|
||||
}
|
||||
export declare function parseScriptSetupRanges(ts: typeof import('typescript'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
|
||||
leadingCommentEndOffset: number;
|
||||
importSectionEndOffset: number;
|
||||
bindings: TextRange[];
|
||||
importComponentNames: Set<string>;
|
||||
props: {
|
||||
name?: string;
|
||||
destructured?: Set<string>;
|
||||
destructuredRest?: string;
|
||||
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
||||
exp: TextRange;
|
||||
arg?: TextRange;
|
||||
typeArg?: TextRange;
|
||||
}> & {
|
||||
statement: TextRange;
|
||||
};
|
||||
withDefaults?: TextRange & {
|
||||
arg?: TextRange;
|
||||
};
|
||||
};
|
||||
slots: {
|
||||
name?: string;
|
||||
isObjectBindingPattern?: boolean;
|
||||
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
||||
exp: TextRange;
|
||||
arg?: TextRange;
|
||||
typeArg?: TextRange;
|
||||
}> & {
|
||||
statement: TextRange;
|
||||
};
|
||||
};
|
||||
emits: {
|
||||
name?: string;
|
||||
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
||||
exp: TextRange;
|
||||
arg?: TextRange;
|
||||
typeArg?: TextRange;
|
||||
}> & {
|
||||
statement: TextRange;
|
||||
hasUnionTypeArg?: boolean;
|
||||
};
|
||||
};
|
||||
expose: {
|
||||
name?: string;
|
||||
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
||||
exp: TextRange;
|
||||
arg?: TextRange;
|
||||
typeArg?: TextRange;
|
||||
}>;
|
||||
};
|
||||
options: {
|
||||
name?: string;
|
||||
inheritAttrs?: string;
|
||||
};
|
||||
cssModules: {
|
||||
define: ReturnType<(node: ts.CallExpression) => TextRange & {
|
||||
exp: TextRange;
|
||||
arg?: TextRange;
|
||||
typeArg?: TextRange;
|
||||
}>;
|
||||
}[];
|
||||
defineProp: {
|
||||
localName: TextRange | undefined;
|
||||
name: TextRange | undefined;
|
||||
type: TextRange | undefined;
|
||||
modifierType?: TextRange | undefined;
|
||||
runtimeType: TextRange | undefined;
|
||||
defaultValue: TextRange | undefined;
|
||||
required: boolean;
|
||||
isModel?: boolean;
|
||||
}[];
|
||||
templateRefs: {
|
||||
name?: string;
|
||||
define: ReturnType<(node: ts.CallExpression) => TextRange & {
|
||||
exp: TextRange;
|
||||
arg?: TextRange;
|
||||
typeArg?: TextRange;
|
||||
}>;
|
||||
}[];
|
||||
};
|
||||
export declare function parseBindingRanges(ts: typeof import('typescript'), sourceFile: ts.SourceFile): TextRange[];
|
||||
export declare function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, sourceFile: ts.SourceFile): TextRange[];
|
||||
export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, sourceFile: ts.SourceFile): {
|
||||
start: number;
|
||||
end: number;
|
||||
};
|
||||
export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, sourceFile: ts.SourceFile): string;
|
||||
439
node_modules/@vue/language-core/lib/parsers/scriptSetupRanges.js
generated
vendored
Normal file
439
node_modules/@vue/language-core/lib/parsers/scriptSetupRanges.js
generated
vendored
Normal file
@@ -0,0 +1,439 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseScriptSetupRanges = parseScriptSetupRanges;
|
||||
exports.parseBindingRanges = parseBindingRanges;
|
||||
exports.findBindingVars = findBindingVars;
|
||||
exports.getStartEnd = getStartEnd;
|
||||
exports.getNodeText = getNodeText;
|
||||
const common_1 = require("../codegen/common");
|
||||
function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
||||
let foundNonImportExportNode = false;
|
||||
let importSectionEndOffset = 0;
|
||||
const props = {};
|
||||
const slots = {};
|
||||
const emits = {};
|
||||
const expose = {};
|
||||
const options = {};
|
||||
const cssModules = [];
|
||||
const templateRefs = [];
|
||||
const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition');
|
||||
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
|
||||
const defineProp = [];
|
||||
const text = ast.text;
|
||||
const leadingCommentEndOffset = ts.getLeadingCommentRanges(text, 0)?.reverse()[0].end ?? 0;
|
||||
const importComponentNames = new Set();
|
||||
let bindings = parseBindingRanges(ts, ast);
|
||||
ts.forEachChild(ast, node => {
|
||||
const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) && node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword);
|
||||
if (!foundNonImportExportNode
|
||||
&& !ts.isImportDeclaration(node)
|
||||
&& !isTypeExport
|
||||
&& !ts.isEmptyStatement(node)
|
||||
// fix https://github.com/vuejs/language-tools/issues/1223
|
||||
&& !ts.isImportEqualsDeclaration(node)) {
|
||||
const commentRanges = ts.getLeadingCommentRanges(text, node.pos);
|
||||
if (commentRanges?.length) {
|
||||
const commentRange = commentRanges.sort((a, b) => a.pos - b.pos)[0];
|
||||
importSectionEndOffset = commentRange.pos;
|
||||
}
|
||||
else {
|
||||
importSectionEndOffset = getStartEnd(ts, node, ast).start;
|
||||
}
|
||||
foundNonImportExportNode = true;
|
||||
}
|
||||
if (ts.isImportDeclaration(node)
|
||||
&& node.importClause?.name
|
||||
&& !node.importClause.isTypeOnly) {
|
||||
const moduleName = getNodeText(ts, node.moduleSpecifier, ast).slice(1, -1);
|
||||
if (vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
|
||||
importComponentNames.add(getNodeText(ts, node.importClause.name, ast));
|
||||
}
|
||||
}
|
||||
});
|
||||
ts.forEachChild(ast, child => visitNode(child, [ast]));
|
||||
const templateRefNames = new Set(templateRefs.map(ref => ref.name));
|
||||
bindings = bindings.filter(range => {
|
||||
const name = text.substring(range.start, range.end);
|
||||
return !templateRefNames.has(name);
|
||||
});
|
||||
return {
|
||||
leadingCommentEndOffset,
|
||||
importSectionEndOffset,
|
||||
bindings,
|
||||
importComponentNames,
|
||||
props,
|
||||
slots,
|
||||
emits,
|
||||
expose,
|
||||
options,
|
||||
cssModules,
|
||||
defineProp,
|
||||
templateRefs,
|
||||
};
|
||||
function _getStartEnd(node) {
|
||||
return getStartEnd(ts, node, ast);
|
||||
}
|
||||
function parseDefineFunction(node) {
|
||||
return {
|
||||
..._getStartEnd(node),
|
||||
exp: _getStartEnd(node.expression),
|
||||
arg: node.arguments.length ? _getStartEnd(node.arguments[0]) : undefined,
|
||||
typeArg: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
||||
};
|
||||
}
|
||||
function visitNode(node, parents) {
|
||||
const parent = parents[parents.length - 1];
|
||||
if (ts.isCallExpression(node)
|
||||
&& ts.isIdentifier(node.expression)) {
|
||||
const callText = getNodeText(ts, node.expression, ast);
|
||||
if (vueCompilerOptions.macros.defineModel.includes(callText)) {
|
||||
let localName;
|
||||
let propName;
|
||||
let options;
|
||||
if (ts.isVariableDeclaration(parent) &&
|
||||
ts.isIdentifier(parent.name)) {
|
||||
localName = _getStartEnd(parent.name);
|
||||
}
|
||||
if (node.arguments.length >= 2) {
|
||||
propName = _getStartEnd(node.arguments[0]);
|
||||
options = node.arguments[1];
|
||||
}
|
||||
else if (node.arguments.length >= 1) {
|
||||
if (ts.isStringLiteral(node.arguments[0])) {
|
||||
propName = _getStartEnd(node.arguments[0]);
|
||||
}
|
||||
else {
|
||||
options = node.arguments[0];
|
||||
}
|
||||
}
|
||||
let runtimeType;
|
||||
let defaultValue;
|
||||
let required = false;
|
||||
if (options && ts.isObjectLiteralExpression(options)) {
|
||||
for (const property of options.properties) {
|
||||
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
|
||||
continue;
|
||||
}
|
||||
const text = getNodeText(ts, property.name, ast);
|
||||
if (text === 'type') {
|
||||
runtimeType = _getStartEnd(property.initializer);
|
||||
}
|
||||
else if (text === 'default') {
|
||||
defaultValue = _getStartEnd(property.initializer);
|
||||
}
|
||||
else if (text === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
||||
required = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
defineProp.push({
|
||||
localName,
|
||||
name: propName,
|
||||
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
||||
modifierType: node.typeArguments && node.typeArguments?.length >= 2 ? _getStartEnd(node.typeArguments[1]) : undefined,
|
||||
runtimeType,
|
||||
defaultValue,
|
||||
required,
|
||||
isModel: true,
|
||||
});
|
||||
}
|
||||
else if (callText === 'defineProp') {
|
||||
let localName;
|
||||
let propName;
|
||||
let options;
|
||||
if (ts.isVariableDeclaration(parent) &&
|
||||
ts.isIdentifier(parent.name)) {
|
||||
localName = _getStartEnd(parent.name);
|
||||
}
|
||||
let runtimeType;
|
||||
let defaultValue;
|
||||
let required = false;
|
||||
if (definePropProposalA) {
|
||||
if (node.arguments.length >= 2) {
|
||||
options = node.arguments[1];
|
||||
}
|
||||
if (node.arguments.length >= 1) {
|
||||
propName = _getStartEnd(node.arguments[0]);
|
||||
}
|
||||
if (options && ts.isObjectLiteralExpression(options)) {
|
||||
for (const property of options.properties) {
|
||||
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
|
||||
continue;
|
||||
}
|
||||
const text = getNodeText(ts, property.name, ast);
|
||||
if (text === 'type') {
|
||||
runtimeType = _getStartEnd(property.initializer);
|
||||
}
|
||||
else if (text === 'default') {
|
||||
defaultValue = _getStartEnd(property.initializer);
|
||||
}
|
||||
else if (text === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
||||
required = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (definePropProposalB) {
|
||||
if (node.arguments.length >= 3) {
|
||||
options = node.arguments[2];
|
||||
}
|
||||
if (node.arguments.length >= 2) {
|
||||
if (node.arguments[1].kind === ts.SyntaxKind.TrueKeyword) {
|
||||
required = true;
|
||||
}
|
||||
}
|
||||
if (node.arguments.length >= 1) {
|
||||
defaultValue = _getStartEnd(node.arguments[0]);
|
||||
}
|
||||
if (options && ts.isObjectLiteralExpression(options)) {
|
||||
for (const property of options.properties) {
|
||||
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
|
||||
continue;
|
||||
}
|
||||
const text = getNodeText(ts, property.name, ast);
|
||||
if (text === 'type') {
|
||||
runtimeType = _getStartEnd(property.initializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
defineProp.push({
|
||||
localName,
|
||||
name: propName,
|
||||
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
||||
runtimeType,
|
||||
defaultValue,
|
||||
required,
|
||||
});
|
||||
}
|
||||
else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
|
||||
slots.define = {
|
||||
...parseDefineFunction(node),
|
||||
statement: getStatementRange(ts, parents, node, ast)
|
||||
};
|
||||
if (ts.isVariableDeclaration(parent)) {
|
||||
if (ts.isIdentifier(parent.name)) {
|
||||
slots.name = getNodeText(ts, parent.name, ast);
|
||||
}
|
||||
else {
|
||||
slots.isObjectBindingPattern = ts.isObjectBindingPattern(parent.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|
||||
emits.define = {
|
||||
...parseDefineFunction(node),
|
||||
statement: getStatementRange(ts, parents, node, ast)
|
||||
};
|
||||
if (ts.isVariableDeclaration(parent)) {
|
||||
emits.name = getNodeText(ts, parent.name, ast);
|
||||
}
|
||||
if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0]) && node.typeArguments[0].members.at(0)) {
|
||||
for (const member of node.typeArguments[0].members) {
|
||||
if (ts.isCallSignatureDeclaration(member) && member.parameters[0].type && ts.isUnionTypeNode(member.parameters[0].type)) {
|
||||
emits.define.hasUnionTypeArg = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
|
||||
expose.define = parseDefineFunction(node);
|
||||
}
|
||||
else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
||||
if (ts.isVariableDeclaration(parent)) {
|
||||
if (ts.isObjectBindingPattern(parent.name)) {
|
||||
props.destructured = new Set();
|
||||
const identifiers = (0, common_1.collectIdentifiers)(ts, parent.name, []);
|
||||
for (const [id, isRest] of identifiers) {
|
||||
const name = getNodeText(ts, id, ast);
|
||||
if (isRest) {
|
||||
props.destructuredRest = name;
|
||||
}
|
||||
else {
|
||||
props.destructured.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
props.name = getNodeText(ts, parent.name, ast);
|
||||
}
|
||||
}
|
||||
props.define = {
|
||||
...parseDefineFunction(node),
|
||||
statement: getStatementRange(ts, parents, node, ast),
|
||||
};
|
||||
if (node.arguments.length) {
|
||||
props.define.arg = _getStartEnd(node.arguments[0]);
|
||||
}
|
||||
if (node.typeArguments?.length) {
|
||||
props.define.typeArg = _getStartEnd(node.typeArguments[0]);
|
||||
}
|
||||
}
|
||||
else if (vueCompilerOptions.macros.withDefaults.includes(callText)) {
|
||||
props.withDefaults = _getStartEnd(node);
|
||||
if (node.arguments.length >= 2) {
|
||||
const arg = node.arguments[1];
|
||||
props.withDefaults.arg = _getStartEnd(arg);
|
||||
}
|
||||
if (ts.isVariableDeclaration(parent)) {
|
||||
props.name = getNodeText(ts, parent.name, ast);
|
||||
}
|
||||
}
|
||||
else if (vueCompilerOptions.macros.defineOptions.includes(callText)) {
|
||||
if (node.arguments.length && ts.isObjectLiteralExpression(node.arguments[0])) {
|
||||
const obj = node.arguments[0];
|
||||
ts.forEachChild(obj, node => {
|
||||
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
|
||||
const name = getNodeText(ts, node.name, ast);
|
||||
if (name === 'inheritAttrs') {
|
||||
options.inheritAttrs = getNodeText(ts, node.initializer, ast);
|
||||
}
|
||||
}
|
||||
});
|
||||
for (const prop of node.arguments[0].properties) {
|
||||
if ((ts.isPropertyAssignment(prop)) && getNodeText(ts, prop.name, ast) === 'name' && ts.isStringLiteral(prop.initializer)) {
|
||||
options.name = prop.initializer.text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (vueCompilerOptions.composibles.useTemplateRef.includes(callText) && node.arguments.length && !node.typeArguments?.length) {
|
||||
const define = parseDefineFunction(node);
|
||||
let name;
|
||||
if (ts.isVariableDeclaration(parent)) {
|
||||
name = getNodeText(ts, parent.name, ast);
|
||||
}
|
||||
templateRefs.push({
|
||||
name,
|
||||
define
|
||||
});
|
||||
}
|
||||
else if (vueCompilerOptions.composibles.useCssModule.includes(callText)) {
|
||||
const define = parseDefineFunction(node);
|
||||
cssModules.push({
|
||||
define
|
||||
});
|
||||
}
|
||||
}
|
||||
ts.forEachChild(node, child => {
|
||||
parents.push(node);
|
||||
visitNode(child, parents);
|
||||
parents.pop();
|
||||
});
|
||||
}
|
||||
}
|
||||
function parseBindingRanges(ts, sourceFile) {
|
||||
const bindings = [];
|
||||
ts.forEachChild(sourceFile, node => {
|
||||
if (ts.isVariableStatement(node)) {
|
||||
for (const node_2 of node.declarationList.declarations) {
|
||||
const vars = _findBindingVars(node_2.name);
|
||||
for (const _var of vars) {
|
||||
bindings.push(_var);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ts.isFunctionDeclaration(node)) {
|
||||
if (node.name && ts.isIdentifier(node.name)) {
|
||||
bindings.push(_getStartEnd(node.name));
|
||||
}
|
||||
}
|
||||
else if (ts.isClassDeclaration(node)) {
|
||||
if (node.name) {
|
||||
bindings.push(_getStartEnd(node.name));
|
||||
}
|
||||
}
|
||||
else if (ts.isEnumDeclaration(node)) {
|
||||
bindings.push(_getStartEnd(node.name));
|
||||
}
|
||||
if (ts.isImportDeclaration(node)) {
|
||||
if (node.importClause && !node.importClause.isTypeOnly) {
|
||||
if (node.importClause.name) {
|
||||
bindings.push(_getStartEnd(node.importClause.name));
|
||||
}
|
||||
if (node.importClause.namedBindings) {
|
||||
if (ts.isNamedImports(node.importClause.namedBindings)) {
|
||||
for (const element of node.importClause.namedBindings.elements) {
|
||||
if (element.isTypeOnly) {
|
||||
continue;
|
||||
}
|
||||
bindings.push(_getStartEnd(element.name));
|
||||
}
|
||||
}
|
||||
else if (ts.isNamespaceImport(node.importClause.namedBindings)) {
|
||||
bindings.push(_getStartEnd(node.importClause.namedBindings.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return bindings;
|
||||
function _getStartEnd(node) {
|
||||
return getStartEnd(ts, node, sourceFile);
|
||||
}
|
||||
function _findBindingVars(left) {
|
||||
return findBindingVars(ts, left, sourceFile);
|
||||
}
|
||||
}
|
||||
function findBindingVars(ts, left, sourceFile) {
|
||||
const vars = [];
|
||||
worker(left);
|
||||
return vars;
|
||||
function worker(_node) {
|
||||
if (ts.isIdentifier(_node)) {
|
||||
vars.push(getStartEnd(ts, _node, sourceFile));
|
||||
}
|
||||
// { ? } = ...
|
||||
// [ ? ] = ...
|
||||
else if (ts.isObjectBindingPattern(_node) || ts.isArrayBindingPattern(_node)) {
|
||||
for (const property of _node.elements) {
|
||||
if (ts.isBindingElement(property)) {
|
||||
worker(property.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
// { foo: ? } = ...
|
||||
else if (ts.isPropertyAssignment(_node)) {
|
||||
worker(_node.initializer);
|
||||
}
|
||||
// { foo } = ...
|
||||
else if (ts.isShorthandPropertyAssignment(_node)) {
|
||||
vars.push(getStartEnd(ts, _node.name, sourceFile));
|
||||
}
|
||||
// { ...? } = ...
|
||||
// [ ...? ] = ...
|
||||
else if (ts.isSpreadAssignment(_node) || ts.isSpreadElement(_node)) {
|
||||
worker(_node.expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
function getStartEnd(ts, node, sourceFile) {
|
||||
return {
|
||||
start: ts.getTokenPosOfNode(node, sourceFile),
|
||||
end: node.end,
|
||||
};
|
||||
}
|
||||
function getNodeText(ts, node, sourceFile) {
|
||||
const { start, end } = getStartEnd(ts, node, sourceFile);
|
||||
return sourceFile.text.substring(start, end);
|
||||
}
|
||||
function getStatementRange(ts, parents, node, sourceFile) {
|
||||
let statementRange;
|
||||
for (let i = parents.length - 1; i >= 0; i--) {
|
||||
if (ts.isStatement(parents[i])) {
|
||||
const statement = parents[i];
|
||||
ts.forEachChild(statement, child => {
|
||||
const range = getStartEnd(ts, child, sourceFile);
|
||||
statementRange ??= range;
|
||||
statementRange.end = range.end;
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!statementRange) {
|
||||
statementRange = getStartEnd(ts, node, sourceFile);
|
||||
}
|
||||
return statementRange;
|
||||
}
|
||||
//# sourceMappingURL=scriptSetupRanges.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { VueLanguagePlugin } from './types';
|
||||
export * from './plugins/shared';
|
||||
export declare function createPlugins(pluginContext: Parameters<VueLanguagePlugin>[0]): import("./types").VueLanguagePluginReturn[];
|
||||
83
node_modules/@vue/language-core/lib/plugins.js
generated
vendored
Normal file
83
node_modules/@vue/language-core/lib/plugins.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createPlugins = createPlugins;
|
||||
const file_html_1 = require("./plugins/file-html");
|
||||
const file_md_1 = require("./plugins/file-md");
|
||||
const file_vue_1 = require("./plugins/file-vue");
|
||||
const vue_root_tags_1 = require("./plugins/vue-root-tags");
|
||||
const vue_script_js_1 = require("./plugins/vue-script-js");
|
||||
const vue_sfc_customblocks_1 = require("./plugins/vue-sfc-customblocks");
|
||||
const vue_sfc_scripts_1 = require("./plugins/vue-sfc-scripts");
|
||||
const vue_sfc_styles_1 = require("./plugins/vue-sfc-styles");
|
||||
const vue_sfc_template_1 = require("./plugins/vue-sfc-template");
|
||||
const vue_template_html_1 = require("./plugins/vue-template-html");
|
||||
const vue_template_inline_css_1 = require("./plugins/vue-template-inline-css");
|
||||
const vue_template_inline_ts_1 = require("./plugins/vue-template-inline-ts");
|
||||
const vue_tsx_1 = require("./plugins/vue-tsx");
|
||||
const types_1 = require("./types");
|
||||
__exportStar(require("./plugins/shared"), exports);
|
||||
function createPlugins(pluginContext) {
|
||||
const plugins = [
|
||||
file_vue_1.default,
|
||||
file_md_1.default,
|
||||
file_html_1.default,
|
||||
vue_root_tags_1.default,
|
||||
vue_script_js_1.default,
|
||||
vue_template_html_1.default,
|
||||
vue_template_inline_css_1.default,
|
||||
vue_template_inline_ts_1.default,
|
||||
vue_sfc_styles_1.default,
|
||||
vue_sfc_customblocks_1.default,
|
||||
vue_sfc_scripts_1.default,
|
||||
vue_sfc_template_1.default,
|
||||
vue_tsx_1.default,
|
||||
...pluginContext.vueCompilerOptions.plugins,
|
||||
];
|
||||
const pluginInstances = plugins
|
||||
.flatMap(plugin => {
|
||||
try {
|
||||
const instance = plugin(pluginContext);
|
||||
const moduleName = plugin.__moduleName;
|
||||
if (Array.isArray(instance)) {
|
||||
for (let i = 0; i < instance.length; i++) {
|
||||
instance[i].name ??= `${moduleName} (${i})`;
|
||||
}
|
||||
}
|
||||
else {
|
||||
instance.name ??= moduleName;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
catch (err) {
|
||||
console.warn('[Vue] Failed to create plugin', err);
|
||||
}
|
||||
})
|
||||
.filter(plugin => !!plugin)
|
||||
.sort((a, b) => {
|
||||
const aOrder = a.order ?? 0;
|
||||
const bOrder = b.order ?? 0;
|
||||
return aOrder - bOrder;
|
||||
});
|
||||
return pluginInstances.filter(plugin => {
|
||||
if (!types_1.validVersions.includes(plugin.version)) {
|
||||
console.warn(`[Vue] Plugin ${plugin.name} is not compatible with the current Vue language tools version. (version: ${plugin.version}, supported versions: ${JSON.stringify(types_1.validVersions)})`);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=plugins.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/file-html.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/file-html.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
89
node_modules/@vue/language-core/lib/plugins/file-html.js
generated
vendored
Normal file
89
node_modules/@vue/language-core/lib/plugins/file-html.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const sfcBlockReg = /\<(script|style)\b([\s\S]*?)\>([\s\S]*?)\<\/\1\>/g;
|
||||
const langReg = /\blang\s*=\s*(['\"]?)(\S*)\b\1/;
|
||||
const plugin = ({ vueCompilerOptions }) => {
|
||||
return {
|
||||
version: 2.1,
|
||||
getLanguageId(fileName) {
|
||||
if (vueCompilerOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) {
|
||||
return 'html';
|
||||
}
|
||||
},
|
||||
isValidFile(_fileName, languageId) {
|
||||
return languageId === 'html';
|
||||
},
|
||||
parseSFC2(fileName, languageId, content) {
|
||||
if (languageId !== 'html') {
|
||||
return;
|
||||
}
|
||||
let sfc = {
|
||||
descriptor: {
|
||||
filename: fileName,
|
||||
source: content,
|
||||
template: null,
|
||||
script: null,
|
||||
scriptSetup: null,
|
||||
styles: [],
|
||||
customBlocks: [],
|
||||
cssVars: [],
|
||||
shouldForceReload: () => false,
|
||||
slotted: false,
|
||||
},
|
||||
errors: [],
|
||||
};
|
||||
let templateContent = content;
|
||||
for (const match of content.matchAll(sfcBlockReg)) {
|
||||
const matchText = match[0];
|
||||
const tag = match[1];
|
||||
const attrs = match[2];
|
||||
const lang = attrs.match(langReg)?.[2];
|
||||
const content = match[3];
|
||||
const contentStart = match.index + matchText.indexOf(content);
|
||||
if (tag === 'style') {
|
||||
sfc.descriptor.styles.push({
|
||||
attrs: {},
|
||||
content,
|
||||
loc: {
|
||||
start: { column: -1, line: -1, offset: contentStart },
|
||||
end: { column: -1, line: -1, offset: contentStart + content.length },
|
||||
source: content,
|
||||
},
|
||||
type: 'style',
|
||||
lang,
|
||||
});
|
||||
}
|
||||
// ignore `<script src="...">`
|
||||
else if (tag === 'script' && attrs.indexOf('src=') === -1) {
|
||||
let type = attrs.indexOf('type=') >= 0 ? 'scriptSetup' : 'script';
|
||||
sfc.descriptor[type] = {
|
||||
attrs: {},
|
||||
content,
|
||||
loc: {
|
||||
start: { column: -1, line: -1, offset: contentStart },
|
||||
end: { column: -1, line: -1, offset: contentStart + content.length },
|
||||
source: content,
|
||||
},
|
||||
type: 'script',
|
||||
lang,
|
||||
};
|
||||
}
|
||||
templateContent = templateContent.substring(0, match.index) + ' '.repeat(matchText.length) + templateContent.substring(match.index + matchText.length);
|
||||
}
|
||||
sfc.descriptor.template = {
|
||||
attrs: {},
|
||||
content: templateContent,
|
||||
loc: {
|
||||
start: { column: -1, line: -1, offset: 0 },
|
||||
end: { column: -1, line: -1, offset: templateContent.length },
|
||||
source: templateContent,
|
||||
},
|
||||
type: 'template',
|
||||
ast: {},
|
||||
};
|
||||
return sfc;
|
||||
}
|
||||
};
|
||||
};
|
||||
exports.default = plugin;
|
||||
//# sourceMappingURL=file-html.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/file-md.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/file-md.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
93
node_modules/@vue/language-core/lib/plugins/file-md.js
generated
vendored
Normal file
93
node_modules/@vue/language-core/lib/plugins/file-md.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const muggle_string_1 = require("muggle-string");
|
||||
const buildMappings_1 = require("../utils/buildMappings");
|
||||
const parseSfc_1 = require("../utils/parseSfc");
|
||||
const codeblockReg = /(`{3,})[\s\S]+?\1/g;
|
||||
const inlineCodeblockReg = /`[^\n`]+?`/g;
|
||||
const scriptSetupReg = /\\\<[\s\S]+?\>\n?/g;
|
||||
const sfcBlockReg = /\<(script|style)\b[\s\S]*?\>([\s\S]*?)\<\/\1\>/g;
|
||||
const angleBracketReg = /\<\S*\:\S*\>/g;
|
||||
const linkReg = /\[[\s\S]*?\]\([\s\S]*?\)/g;
|
||||
const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
|
||||
const plugin = ({ vueCompilerOptions }) => {
|
||||
return {
|
||||
version: 2.1,
|
||||
getLanguageId(fileName) {
|
||||
if (vueCompilerOptions.vitePressExtensions.some(ext => fileName.endsWith(ext))) {
|
||||
return 'markdown';
|
||||
}
|
||||
},
|
||||
isValidFile(_fileName, languageId) {
|
||||
return languageId === 'markdown';
|
||||
},
|
||||
parseSFC2(_fileName, languageId, content) {
|
||||
if (languageId !== 'markdown') {
|
||||
return;
|
||||
}
|
||||
content = content
|
||||
// code block
|
||||
.replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
|
||||
// inline code block
|
||||
.replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
|
||||
// # \<script setup>
|
||||
.replace(scriptSetupReg, match => ' '.repeat(match.length))
|
||||
// <<< https://vitepress.dev/guide/markdown#import-code-snippets
|
||||
.replace(codeSnippetImportReg, match => ' '.repeat(match.length));
|
||||
const codes = [];
|
||||
for (const match of content.matchAll(sfcBlockReg)) {
|
||||
if (match.index !== undefined) {
|
||||
const matchText = match[0];
|
||||
codes.push([matchText, undefined, match.index]);
|
||||
codes.push('\n\n');
|
||||
content = content.substring(0, match.index) + ' '.repeat(matchText.length) + content.substring(match.index + matchText.length);
|
||||
}
|
||||
}
|
||||
content = content
|
||||
// angle bracket: <http://foo.com>
|
||||
.replace(angleBracketReg, match => ' '.repeat(match.length))
|
||||
// [foo](http://foo.com)
|
||||
.replace(linkReg, match => ' '.repeat(match.length));
|
||||
codes.push('<template>\n');
|
||||
codes.push([content, undefined, 0]);
|
||||
codes.push('\n</template>');
|
||||
const file2VueSourceMap = (0, language_core_1.defaultMapperFactory)((0, buildMappings_1.buildMappings)(codes));
|
||||
const sfc = (0, parseSfc_1.parse)((0, muggle_string_1.toString)(codes));
|
||||
if (sfc.descriptor.template) {
|
||||
sfc.descriptor.template.lang = 'md';
|
||||
transformRange(sfc.descriptor.template);
|
||||
}
|
||||
if (sfc.descriptor.script) {
|
||||
transformRange(sfc.descriptor.script);
|
||||
}
|
||||
if (sfc.descriptor.scriptSetup) {
|
||||
transformRange(sfc.descriptor.scriptSetup);
|
||||
}
|
||||
for (const style of sfc.descriptor.styles) {
|
||||
transformRange(style);
|
||||
}
|
||||
for (const customBlock of sfc.descriptor.customBlocks) {
|
||||
transformRange(customBlock);
|
||||
}
|
||||
return sfc;
|
||||
function transformRange(block) {
|
||||
const { start, end } = block.loc;
|
||||
const startOffset = start.offset;
|
||||
const endOffset = end.offset;
|
||||
start.offset = -1;
|
||||
end.offset = -1;
|
||||
for (const [offset] of file2VueSourceMap.toSourceLocation(startOffset)) {
|
||||
start.offset = offset;
|
||||
break;
|
||||
}
|
||||
for (const [offset] of file2VueSourceMap.toSourceLocation(endOffset)) {
|
||||
end.offset = offset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
exports.default = plugin;
|
||||
//# sourceMappingURL=file-md.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/file-vue.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/file-vue.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
58
node_modules/@vue/language-core/lib/plugins/file-vue.js
generated
vendored
Normal file
58
node_modules/@vue/language-core/lib/plugins/file-vue.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const parseSfc_1 = require("../utils/parseSfc");
|
||||
const plugin = ({ vueCompilerOptions }) => {
|
||||
return {
|
||||
version: 2.1,
|
||||
getLanguageId(fileName) {
|
||||
if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
|
||||
return 'vue';
|
||||
}
|
||||
},
|
||||
isValidFile(_fileName, languageId) {
|
||||
return languageId === 'vue';
|
||||
},
|
||||
parseSFC2(_fileName, languageId, content) {
|
||||
if (languageId !== 'vue') {
|
||||
return;
|
||||
}
|
||||
return (0, parseSfc_1.parse)(content);
|
||||
},
|
||||
updateSFC(sfc, change) {
|
||||
const blocks = [
|
||||
sfc.descriptor.template,
|
||||
sfc.descriptor.script,
|
||||
sfc.descriptor.scriptSetup,
|
||||
...sfc.descriptor.styles,
|
||||
...sfc.descriptor.customBlocks,
|
||||
].filter((block) => !!block);
|
||||
const hitBlock = blocks.find(block => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset);
|
||||
if (!hitBlock) {
|
||||
return;
|
||||
}
|
||||
const oldContent = hitBlock.content;
|
||||
const newContent = hitBlock.content =
|
||||
hitBlock.content.substring(0, change.start - hitBlock.loc.start.offset)
|
||||
+ change.newText
|
||||
+ hitBlock.content.substring(change.end - hitBlock.loc.start.offset);
|
||||
// #3449
|
||||
const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
|
||||
const insertedEndTag = !!oldContent.match(endTagRegex) !== !!newContent.match(endTagRegex);
|
||||
if (insertedEndTag) {
|
||||
return;
|
||||
}
|
||||
const lengthDiff = change.newText.length - (change.end - change.start);
|
||||
for (const block of blocks) {
|
||||
if (block.loc.start.offset > change.end) {
|
||||
block.loc.start.offset += lengthDiff;
|
||||
}
|
||||
if (block.loc.end.offset >= change.end) {
|
||||
block.loc.end.offset += lengthDiff;
|
||||
}
|
||||
}
|
||||
return sfc;
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.default = plugin;
|
||||
//# sourceMappingURL=file-vue.js.map
|
||||
2
node_modules/@vue/language-core/lib/plugins/shared.d.ts
generated
vendored
Normal file
2
node_modules/@vue/language-core/lib/plugins/shared.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { CodeInformation } from '@volar/language-core';
|
||||
export declare const allCodeFeatures: CodeInformation;
|
||||
12
node_modules/@vue/language-core/lib/plugins/shared.js
generated
vendored
Normal file
12
node_modules/@vue/language-core/lib/plugins/shared.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.allCodeFeatures = void 0;
|
||||
exports.allCodeFeatures = {
|
||||
verification: true,
|
||||
completion: true,
|
||||
semantic: true,
|
||||
navigation: true,
|
||||
structure: true,
|
||||
format: true,
|
||||
};
|
||||
//# sourceMappingURL=shared.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/vue-root-tags.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/vue-root-tags.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
51
node_modules/@vue/language-core/lib/plugins/vue-root-tags.js
generated
vendored
Normal file
51
node_modules/@vue/language-core/lib/plugins/vue-root-tags.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const muggle_string_1 = require("muggle-string");
|
||||
const shared_1 = require("./shared");
|
||||
const plugin = () => {
|
||||
return {
|
||||
version: 2.1,
|
||||
getEmbeddedCodes() {
|
||||
return [{
|
||||
id: 'root_tags',
|
||||
lang: 'vue-root-tags',
|
||||
}];
|
||||
},
|
||||
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
||||
if (embeddedFile.id === 'root_tags') {
|
||||
embeddedFile.content.push([sfc.content, undefined, 0, shared_1.allCodeFeatures]);
|
||||
for (const block of [
|
||||
sfc.script,
|
||||
sfc.scriptSetup,
|
||||
sfc.template,
|
||||
...sfc.styles,
|
||||
...sfc.customBlocks,
|
||||
]) {
|
||||
if (!block) {
|
||||
continue;
|
||||
}
|
||||
let content = block.content;
|
||||
if (content.endsWith('\r\n')) {
|
||||
content = content.slice(0, -2);
|
||||
}
|
||||
else if (content.endsWith('\n')) {
|
||||
content = content.slice(0, -1);
|
||||
}
|
||||
const offset = content.lastIndexOf('\n') + 1;
|
||||
// fix folding range end position failed to mapping
|
||||
(0, muggle_string_1.replaceSourceRange)(embeddedFile.content, undefined, block.startTagEnd, block.endTagStart, sfc.content.substring(block.startTagEnd, block.startTagEnd + offset), [
|
||||
'',
|
||||
undefined,
|
||||
block.startTagEnd + offset,
|
||||
{ structure: true },
|
||||
], sfc.content.substring(block.startTagEnd + offset, block.endTagStart));
|
||||
}
|
||||
}
|
||||
else {
|
||||
embeddedFile.parentCodeId ??= 'root_tags';
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.default = plugin;
|
||||
//# sourceMappingURL=vue-root-tags.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/vue-script-js.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/vue-script-js.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
15
node_modules/@vue/language-core/lib/plugins/vue-script-js.js
generated
vendored
Normal file
15
node_modules/@vue/language-core/lib/plugins/vue-script-js.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const plugin = ({ modules }) => {
|
||||
return {
|
||||
version: 2.1,
|
||||
compileSFCScript(lang, script) {
|
||||
if (lang === 'js' || lang === 'ts' || lang === 'jsx' || lang === 'tsx') {
|
||||
const ts = modules.typescript;
|
||||
return ts.createSourceFile('test.' + lang, script, 99);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.default = plugin;
|
||||
//# sourceMappingURL=vue-script-js.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/vue-sfc-customblocks.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/vue-sfc-customblocks.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
28
node_modules/@vue/language-core/lib/plugins/vue-sfc-customblocks.js
generated
vendored
Normal file
28
node_modules/@vue/language-core/lib/plugins/vue-sfc-customblocks.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const shared_1 = require("./shared");
|
||||
const plugin = () => {
|
||||
return {
|
||||
version: 2.1,
|
||||
getEmbeddedCodes(_fileName, sfc) {
|
||||
return sfc.customBlocks.map((customBlock, i) => ({
|
||||
id: 'custom_block_' + i,
|
||||
lang: customBlock.lang,
|
||||
}));
|
||||
},
|
||||
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
||||
if (embeddedFile.id.startsWith('custom_block_')) {
|
||||
const index = parseInt(embeddedFile.id.slice('custom_block_'.length));
|
||||
const customBlock = sfc.customBlocks[index];
|
||||
embeddedFile.content.push([
|
||||
customBlock.content,
|
||||
customBlock.name,
|
||||
0,
|
||||
shared_1.allCodeFeatures,
|
||||
]);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.default = plugin;
|
||||
//# sourceMappingURL=vue-sfc-customblocks.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/vue-sfc-scripts.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/vue-sfc-scripts.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
35
node_modules/@vue/language-core/lib/plugins/vue-sfc-scripts.js
generated
vendored
Normal file
35
node_modules/@vue/language-core/lib/plugins/vue-sfc-scripts.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const plugin = () => {
|
||||
return {
|
||||
version: 2.1,
|
||||
getEmbeddedCodes(_fileName, sfc) {
|
||||
const names = [];
|
||||
if (sfc.script) {
|
||||
names.push({ id: 'script_raw', lang: sfc.script.lang });
|
||||
}
|
||||
if (sfc.scriptSetup) {
|
||||
names.push({ id: 'scriptsetup_raw', lang: sfc.scriptSetup.lang });
|
||||
}
|
||||
return names;
|
||||
},
|
||||
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
||||
const script = embeddedFile.id === 'script_raw' ? sfc.script
|
||||
: embeddedFile.id === 'scriptsetup_raw' ? sfc.scriptSetup
|
||||
: undefined;
|
||||
if (script) {
|
||||
embeddedFile.content.push([
|
||||
script.content,
|
||||
script.name,
|
||||
0,
|
||||
{
|
||||
structure: true,
|
||||
format: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.default = plugin;
|
||||
//# sourceMappingURL=vue-sfc-scripts.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/vue-sfc-styles.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/vue-sfc-styles.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
54
node_modules/@vue/language-core/lib/plugins/vue-sfc-styles.js
generated
vendored
Normal file
54
node_modules/@vue/language-core/lib/plugins/vue-sfc-styles.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const shared_1 = require("./shared");
|
||||
const plugin = () => {
|
||||
return {
|
||||
version: 2.1,
|
||||
getEmbeddedCodes(_fileName, sfc) {
|
||||
const result = [];
|
||||
for (let i = 0; i < sfc.styles.length; i++) {
|
||||
const style = sfc.styles[i];
|
||||
if (style) {
|
||||
result.push({
|
||||
id: 'style_' + i,
|
||||
lang: style.lang,
|
||||
});
|
||||
if (style.cssVars.length) {
|
||||
result.push({
|
||||
id: 'style_' + i + '_inline_ts',
|
||||
lang: 'ts',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
||||
if (embeddedFile.id.startsWith('style_')) {
|
||||
const index = parseInt(embeddedFile.id.split('_')[1]);
|
||||
const style = sfc.styles[index];
|
||||
if (embeddedFile.id.endsWith('_inline_ts')) {
|
||||
embeddedFile.parentCodeId = 'style_' + index;
|
||||
for (const cssVar of style.cssVars) {
|
||||
embeddedFile.content.push('(', [
|
||||
cssVar.text,
|
||||
style.name,
|
||||
cssVar.offset,
|
||||
shared_1.allCodeFeatures,
|
||||
], ');\n');
|
||||
}
|
||||
}
|
||||
else {
|
||||
embeddedFile.content.push([
|
||||
style.content,
|
||||
style.name,
|
||||
0,
|
||||
shared_1.allCodeFeatures,
|
||||
]);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.default = plugin;
|
||||
//# sourceMappingURL=vue-sfc-styles.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/vue-sfc-template.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/vue-sfc-template.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
29
node_modules/@vue/language-core/lib/plugins/vue-sfc-template.js
generated
vendored
Normal file
29
node_modules/@vue/language-core/lib/plugins/vue-sfc-template.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const shared_1 = require("./shared");
|
||||
const plugin = () => {
|
||||
return {
|
||||
version: 2.1,
|
||||
getEmbeddedCodes(_fileName, sfc) {
|
||||
if (sfc.template?.lang === 'html') {
|
||||
return [{
|
||||
id: 'template',
|
||||
lang: sfc.template.lang,
|
||||
}];
|
||||
}
|
||||
return [];
|
||||
},
|
||||
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
||||
if (embeddedFile.id === 'template' && sfc.template?.lang === 'html') {
|
||||
embeddedFile.content.push([
|
||||
sfc.template.content,
|
||||
sfc.template.name,
|
||||
0,
|
||||
shared_1.allCodeFeatures,
|
||||
]);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.default = plugin;
|
||||
//# sourceMappingURL=vue-sfc-template.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/vue-template-html.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/vue-template-html.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
197
node_modules/@vue/language-core/lib/plugins/vue-template-html.js
generated
vendored
Normal file
197
node_modules/@vue/language-core/lib/plugins/vue-template-html.js
generated
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const shouldAddSuffix = /(?<=<[^>/]+)$/;
|
||||
const plugin = ({ modules }) => {
|
||||
return {
|
||||
version: 2.1,
|
||||
compileSFCTemplate(lang, template, options) {
|
||||
if (lang === 'html' || lang === 'md') {
|
||||
const compiler = modules['@vue/compiler-dom'];
|
||||
let addedSuffix = false;
|
||||
// #4583
|
||||
if (shouldAddSuffix.test(template)) {
|
||||
template += '>';
|
||||
addedSuffix = true;
|
||||
}
|
||||
const result = compiler.compile(template, {
|
||||
...options,
|
||||
comments: true,
|
||||
});
|
||||
// @ts-expect-error
|
||||
result.__addedSuffix = addedSuffix;
|
||||
return result;
|
||||
}
|
||||
},
|
||||
updateSFCTemplate(oldResult, change) {
|
||||
oldResult.code = oldResult.code.slice(0, change.start)
|
||||
+ change.newText
|
||||
+ oldResult.code.slice(change.end);
|
||||
// @ts-expect-error
|
||||
if (oldResult.__addedSuffix) {
|
||||
const originalTemplate = oldResult.code.slice(0, -1); // remove added '>'
|
||||
if (!shouldAddSuffix.test(originalTemplate)) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
const CompilerDOM = modules['@vue/compiler-dom'];
|
||||
const lengthDiff = change.newText.length - (change.end - change.start);
|
||||
let hitNodes = [];
|
||||
if (tryUpdateNode(oldResult.ast) && hitNodes.length) {
|
||||
hitNodes = hitNodes.sort((a, b) => a.loc.source.length - b.loc.source.length);
|
||||
const hitNode = hitNodes[0];
|
||||
if (hitNode.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
return oldResult;
|
||||
}
|
||||
}
|
||||
function tryUpdateNode(node) {
|
||||
if (withinChangeRange(node.loc)) {
|
||||
hitNodes.push(node);
|
||||
}
|
||||
if (tryUpdateNodeLoc(node.loc)) {
|
||||
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
||||
for (const child of node.children) {
|
||||
if (!tryUpdateNode(child)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
||||
if (withinChangeRange(node.loc)) {
|
||||
// if not self closing, should not hit tag name
|
||||
const start = node.loc.start.offset + 2;
|
||||
const end = node.loc.start.offset + node.loc.source.lastIndexOf('</');
|
||||
if (!withinChangeRange({ start: { offset: start }, end: { offset: end }, source: '' })) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (const prop of node.props) {
|
||||
if (!tryUpdateNode(prop)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (const child of node.children) {
|
||||
if (!tryUpdateNode(child)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
||||
if (node.value && !tryUpdateNode(node.value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.DIRECTIVE) {
|
||||
if (node.arg && withinChangeRange(node.arg.loc) && node.name === 'slot') {
|
||||
return false;
|
||||
}
|
||||
if (node.exp && withinChangeRange(node.exp.loc) && node.name === 'for') { // #2266
|
||||
return false;
|
||||
}
|
||||
if (node.arg && !tryUpdateNode(node.arg)) {
|
||||
return false;
|
||||
}
|
||||
if (node.exp && !tryUpdateNode(node.exp)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
||||
if (!tryUpdateNode(node.content)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
||||
for (const childNode of node.children) {
|
||||
if (typeof childNode === 'object') {
|
||||
if (!tryUpdateNode(childNode)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
||||
for (const branch of node.branches) {
|
||||
if (branch.condition && !tryUpdateNode(branch.condition)) {
|
||||
return false;
|
||||
}
|
||||
for (const child of branch.children) {
|
||||
if (!tryUpdateNode(child)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.FOR) {
|
||||
for (const child of [
|
||||
node.parseResult.source,
|
||||
node.parseResult.value,
|
||||
node.parseResult.key,
|
||||
node.parseResult.index,
|
||||
]) {
|
||||
if (child) {
|
||||
if (!tryUpdateNode(child)) {
|
||||
return false;
|
||||
}
|
||||
if (child.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
const content = child.content.trim();
|
||||
if (content.startsWith('(') || content.endsWith(')')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const child of node.children) {
|
||||
if (!tryUpdateNode(child)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
||||
if (!tryUpdateNode(node.content)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
if (withinChangeRange(node.loc)) { // TODO: review this (slot name?)
|
||||
if (node.isStatic) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
node.content = node.loc.source;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function tryUpdateNodeLoc(loc) {
|
||||
delete loc.__endOffset;
|
||||
if (withinChangeRange(loc)) {
|
||||
loc.source =
|
||||
loc.source.substring(0, change.start - loc.start.offset)
|
||||
+ change.newText
|
||||
+ loc.source.substring(change.end - loc.start.offset);
|
||||
loc.__endOffset = loc.end.offset;
|
||||
loc.end.offset += lengthDiff;
|
||||
return true;
|
||||
}
|
||||
else if (change.end <= loc.start.offset) {
|
||||
loc.__endOffset = loc.end.offset;
|
||||
loc.start.offset += lengthDiff;
|
||||
loc.end.offset += lengthDiff;
|
||||
return true;
|
||||
}
|
||||
else if (change.start >= loc.end.offset) {
|
||||
return true; // no need update
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function withinChangeRange(loc) {
|
||||
const originalLocEnd = loc.__endOffset ?? loc.end.offset;
|
||||
return change.start >= loc.start.offset && change.end <= originalLocEnd;
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.default = plugin;
|
||||
//# sourceMappingURL=vue-template-html.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/vue-template-inline-css.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/vue-template-inline-css.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
55
node_modules/@vue/language-core/lib/plugins/vue-template-inline-css.js
generated
vendored
Normal file
55
node_modules/@vue/language-core/lib/plugins/vue-template-inline-css.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const template_1 = require("../codegen/template");
|
||||
const shared_1 = require("./shared");
|
||||
const codeFeatures = {
|
||||
...shared_1.allCodeFeatures,
|
||||
format: false,
|
||||
structure: false,
|
||||
};
|
||||
const plugin = () => {
|
||||
return {
|
||||
version: 2.1,
|
||||
getEmbeddedCodes(_fileName, sfc) {
|
||||
if (!sfc.template?.ast) {
|
||||
return [];
|
||||
}
|
||||
return [{ id: 'template_inline_css', lang: 'css' }];
|
||||
},
|
||||
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
||||
if (embeddedFile.id !== 'template_inline_css' || !sfc.template?.ast) {
|
||||
return;
|
||||
}
|
||||
embeddedFile.parentCodeId = 'template';
|
||||
embeddedFile.content.push(...generate(sfc.template.ast));
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.default = plugin;
|
||||
function* generate(templateAst) {
|
||||
for (const node of (0, template_1.forEachElementNode)(templateAst)) {
|
||||
for (const prop of node.props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.name === 'bind'
|
||||
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& prop.arg.content === 'style'
|
||||
&& prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
||||
const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1]; // " | '
|
||||
const start = prop.arg.loc.source.indexOf(endCrt) + 1;
|
||||
const end = prop.arg.loc.source.lastIndexOf(endCrt);
|
||||
const content = prop.arg.loc.source.substring(start, end);
|
||||
yield `x { `;
|
||||
yield [
|
||||
content,
|
||||
'template',
|
||||
prop.arg.loc.start.offset + start,
|
||||
codeFeatures,
|
||||
];
|
||||
yield ` }\n`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=vue-template-inline-css.js.map
|
||||
3
node_modules/@vue/language-core/lib/plugins/vue-template-inline-ts.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/plugins/vue-template-inline-ts.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { VueLanguagePlugin } from '../types';
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
152
node_modules/@vue/language-core/lib/plugins/vue-template-inline-ts.js
generated
vendored
Normal file
152
node_modules/@vue/language-core/lib/plugins/vue-template-inline-ts.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const common_1 = require("../codegen/common");
|
||||
const elementEvents_1 = require("../codegen/template/elementEvents");
|
||||
const templateChild_1 = require("../codegen/template/templateChild");
|
||||
const vFor_1 = require("../codegen/template/vFor");
|
||||
const CompilerDOM = require("@vue/compiler-dom");
|
||||
const codeFeatures = {
|
||||
format: true,
|
||||
};
|
||||
const formatBrackets = {
|
||||
normal: ['`${', '}`;'],
|
||||
if: ['if (', ') { }'],
|
||||
for: ['for (', ') { }'],
|
||||
// fix https://github.com/vuejs/language-tools/issues/3572
|
||||
params: ['(', ') => {};'],
|
||||
// fix https://github.com/vuejs/language-tools/issues/1210
|
||||
// fix https://github.com/vuejs/language-tools/issues/2305
|
||||
curly: ['0 +', '+ 0;'],
|
||||
event: ['() => ', ';'],
|
||||
};
|
||||
const plugin = ctx => {
|
||||
const parseds = new WeakMap();
|
||||
return {
|
||||
version: 2.1,
|
||||
getEmbeddedCodes(_fileName, sfc) {
|
||||
if (!sfc.template?.ast) {
|
||||
return [];
|
||||
}
|
||||
const parsed = parse(sfc);
|
||||
parseds.set(sfc, parsed);
|
||||
const result = [];
|
||||
for (const [id] of parsed) {
|
||||
result.push({ id, lang: 'ts' });
|
||||
}
|
||||
return result;
|
||||
},
|
||||
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
||||
// access template content to watch change
|
||||
(() => sfc.template?.content)();
|
||||
const parsed = parseds.get(sfc);
|
||||
if (parsed) {
|
||||
const codes = parsed.get(embeddedFile.id);
|
||||
if (codes) {
|
||||
embeddedFile.content.push(...codes);
|
||||
embeddedFile.parentCodeId = 'template';
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
function parse(sfc) {
|
||||
const data = new Map();
|
||||
if (!sfc.template?.ast) {
|
||||
return data;
|
||||
}
|
||||
const templateContent = sfc.template.content;
|
||||
let i = 0;
|
||||
sfc.template.ast.children.forEach(visit);
|
||||
return data;
|
||||
function visit(node) {
|
||||
if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
||||
for (const prop of node.props) {
|
||||
if (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE) {
|
||||
continue;
|
||||
}
|
||||
const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset; // vue 3.4+
|
||||
if (isShorthand) {
|
||||
continue;
|
||||
}
|
||||
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && !prop.arg.isStatic) {
|
||||
addFormatCodes(prop.arg.content, prop.arg.loc.start.offset, formatBrackets.normal);
|
||||
}
|
||||
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
|
||||
) {
|
||||
if (prop.name === 'on' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
const ast = (0, common_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content);
|
||||
addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)
|
||||
? formatBrackets.event
|
||||
: formatBrackets.normal);
|
||||
}
|
||||
else {
|
||||
addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const child of node.children) {
|
||||
visit(child);
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
||||
for (let i = 0; i < node.branches.length; i++) {
|
||||
const branch = node.branches[i];
|
||||
if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
addFormatCodes(branch.condition.content, branch.condition.loc.start.offset, formatBrackets.if);
|
||||
}
|
||||
for (const childNode of branch.children) {
|
||||
visit(childNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.FOR) {
|
||||
const { leftExpressionRange, leftExpressionText } = (0, vFor_1.parseVForNode)(node);
|
||||
const { source } = node.parseResult;
|
||||
if (leftExpressionRange && leftExpressionText && source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
const start = leftExpressionRange.start;
|
||||
const end = source.loc.start.offset + source.content.length;
|
||||
addFormatCodes(templateContent.substring(start, end), start, formatBrackets.for);
|
||||
}
|
||||
for (const child of node.children) {
|
||||
visit(child);
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
||||
// {{ var }}
|
||||
visit(node.content);
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
||||
// {{ ... }} {{ ... }}
|
||||
for (const childNode of node.children) {
|
||||
if (typeof childNode === 'object') {
|
||||
visit(childNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
||||
// {{ ... }}
|
||||
const [content, start] = (0, templateChild_1.parseInterpolationNode)(node, templateContent);
|
||||
const lines = content.split('\n');
|
||||
addFormatCodes(content, start, lines.length <= 1 ? formatBrackets.curly : [
|
||||
lines[0].trim() === '' ? '(' : formatBrackets.curly[0],
|
||||
lines[lines.length - 1].trim() === '' ? ');' : formatBrackets.curly[1],
|
||||
]);
|
||||
}
|
||||
}
|
||||
function addFormatCodes(code, offset, wrapper) {
|
||||
const id = 'template_inline_ts_' + i++;
|
||||
data.set(id, [
|
||||
wrapper[0],
|
||||
[
|
||||
code,
|
||||
'template',
|
||||
offset,
|
||||
codeFeatures,
|
||||
],
|
||||
wrapper[1],
|
||||
]);
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.default = plugin;
|
||||
//# sourceMappingURL=vue-template-inline-ts.js.map
|
||||
174
node_modules/@vue/language-core/lib/plugins/vue-tsx.d.ts
generated
vendored
Normal file
174
node_modules/@vue/language-core/lib/plugins/vue-tsx.d.ts
generated
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
import type { Mapping } from '@volar/language-core';
|
||||
import type { Code, Sfc, VueLanguagePlugin } from '../types';
|
||||
export declare const tsCodegen: WeakMap<Sfc, {
|
||||
scriptRanges: import("alien-signals").ISignal<{
|
||||
exportDefault: (import("../types").TextRange & {
|
||||
expression: import("../types").TextRange;
|
||||
args: import("../types").TextRange;
|
||||
argsNode: import("typescript").ObjectLiteralExpression | undefined;
|
||||
componentsOption: import("../types").TextRange | undefined;
|
||||
componentsOptionNode: import("typescript").ObjectLiteralExpression | undefined;
|
||||
directivesOption: import("../types").TextRange | undefined;
|
||||
nameOption: import("../types").TextRange | undefined;
|
||||
inheritAttrsOption: string | undefined;
|
||||
}) | undefined;
|
||||
classBlockEnd: number | undefined;
|
||||
bindings: import("../types").TextRange[];
|
||||
} | undefined>;
|
||||
scriptSetupRanges: import("alien-signals").ISignal<{
|
||||
leadingCommentEndOffset: number;
|
||||
importSectionEndOffset: number;
|
||||
bindings: import("../types").TextRange[];
|
||||
importComponentNames: Set<string>;
|
||||
props: {
|
||||
name?: string;
|
||||
destructured?: Set<string>;
|
||||
destructuredRest?: string;
|
||||
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
||||
exp: import("../types").TextRange;
|
||||
arg?: import("../types").TextRange;
|
||||
typeArg?: import("../types").TextRange;
|
||||
}> & {
|
||||
statement: import("../types").TextRange;
|
||||
};
|
||||
withDefaults?: import("../types").TextRange & {
|
||||
arg?: import("../types").TextRange;
|
||||
};
|
||||
};
|
||||
slots: {
|
||||
name?: string;
|
||||
isObjectBindingPattern?: boolean;
|
||||
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
||||
exp: import("../types").TextRange;
|
||||
arg?: import("../types").TextRange;
|
||||
typeArg?: import("../types").TextRange;
|
||||
}> & {
|
||||
statement: import("../types").TextRange;
|
||||
};
|
||||
};
|
||||
emits: {
|
||||
name?: string;
|
||||
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
||||
exp: import("../types").TextRange;
|
||||
arg?: import("../types").TextRange;
|
||||
typeArg?: import("../types").TextRange;
|
||||
}> & {
|
||||
statement: import("../types").TextRange;
|
||||
hasUnionTypeArg?: boolean;
|
||||
};
|
||||
};
|
||||
expose: {
|
||||
name?: string;
|
||||
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
||||
exp: import("../types").TextRange;
|
||||
arg?: import("../types").TextRange;
|
||||
typeArg?: import("../types").TextRange;
|
||||
}>;
|
||||
};
|
||||
options: {
|
||||
name?: string;
|
||||
inheritAttrs?: string;
|
||||
};
|
||||
cssModules: {
|
||||
define: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
||||
exp: import("../types").TextRange;
|
||||
arg?: import("../types").TextRange;
|
||||
typeArg?: import("../types").TextRange;
|
||||
}>;
|
||||
}[];
|
||||
defineProp: {
|
||||
localName: import("../types").TextRange | undefined;
|
||||
name: import("../types").TextRange | undefined;
|
||||
type: import("../types").TextRange | undefined;
|
||||
modifierType?: import("../types").TextRange | undefined;
|
||||
runtimeType: import("../types").TextRange | undefined;
|
||||
defaultValue: import("../types").TextRange | undefined;
|
||||
required: boolean;
|
||||
isModel?: boolean;
|
||||
}[];
|
||||
templateRefs: {
|
||||
name?: string;
|
||||
define: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
||||
exp: import("../types").TextRange;
|
||||
arg?: import("../types").TextRange;
|
||||
typeArg?: import("../types").TextRange;
|
||||
}>;
|
||||
}[];
|
||||
} | undefined>;
|
||||
lang: import("alien-signals").ISignal<string>;
|
||||
generatedScript: import("alien-signals").ISignal<{
|
||||
codes: Code[];
|
||||
linkedCodeMappings: Mapping<unknown>[];
|
||||
generatedTemplate: boolean;
|
||||
generatedPropsType: boolean;
|
||||
scriptSetupGeneratedOffset: number | undefined;
|
||||
bypassDefineComponent: boolean;
|
||||
bindingNames: Set<string>;
|
||||
localTypes: {
|
||||
generate: (names: string[]) => Generator<string, void, unknown>;
|
||||
getUsedNames(): Set<string>;
|
||||
readonly PrettifyLocal: string;
|
||||
readonly OmitKeepDiscriminatedUnion: string;
|
||||
readonly WithDefaults: string;
|
||||
readonly WithTemplateSlots: string;
|
||||
readonly PropsChildren: string;
|
||||
readonly TypePropsToOption: string;
|
||||
readonly OmitIndexSignature: string;
|
||||
};
|
||||
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
||||
}>;
|
||||
generatedTemplate: import("alien-signals").ISignal<{
|
||||
codes: Code[];
|
||||
slots: {
|
||||
name: string;
|
||||
loc?: number;
|
||||
tagRange: [number, number];
|
||||
varName: string;
|
||||
nodeLoc: any;
|
||||
}[];
|
||||
dynamicSlots: {
|
||||
expVar: string;
|
||||
varName: string;
|
||||
}[];
|
||||
codeFeatures: {
|
||||
all: import("../types").VueCodeInformation;
|
||||
verification: import("../types").VueCodeInformation;
|
||||
completion: import("../types").VueCodeInformation;
|
||||
additionalCompletion: import("../types").VueCodeInformation;
|
||||
navigation: import("../types").VueCodeInformation;
|
||||
navigationWithoutRename: import("../types").VueCodeInformation;
|
||||
navigationAndCompletion: import("../types").VueCodeInformation;
|
||||
navigationAndAdditionalCompletion: import("../types").VueCodeInformation;
|
||||
withoutHighlight: import("../types").VueCodeInformation;
|
||||
withoutHighlightAndCompletion: import("../types").VueCodeInformation;
|
||||
withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
|
||||
};
|
||||
accessExternalVariables: Map<string, Set<number>>;
|
||||
hasSlotElements: Set<import("@vue/compiler-dom").ElementNode>;
|
||||
blockConditions: string[];
|
||||
usedComponentCtxVars: Set<string>;
|
||||
scopedClasses: {
|
||||
source: string;
|
||||
className: string;
|
||||
offset: number;
|
||||
}[];
|
||||
emptyClassOffsets: number[];
|
||||
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
||||
hasSlot: boolean;
|
||||
inheritedAttrVars: Set<unknown>;
|
||||
templateRefs: Map<string, [varName: string, offset: number]>;
|
||||
singleRootElType: string | undefined;
|
||||
singleRootNode: import("@vue/compiler-dom").ElementNode | undefined;
|
||||
accessExternalVariable(name: string, offset?: number): void;
|
||||
hasLocalVariable: (name: string) => boolean;
|
||||
addLocalVariable: (name: string) => void;
|
||||
removeLocalVariable: (name: string) => void;
|
||||
getInternalVariable: () => string;
|
||||
ignoreError: () => Generator<Code>;
|
||||
expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code>;
|
||||
resetDirectiveComments: (endStr: string) => Generator<Code>;
|
||||
generateAutoImportCompletion: () => Generator<Code>;
|
||||
} | undefined>;
|
||||
}>;
|
||||
declare const plugin: VueLanguagePlugin;
|
||||
export default plugin;
|
||||
198
node_modules/@vue/language-core/lib/plugins/vue-tsx.js
generated
vendored
Normal file
198
node_modules/@vue/language-core/lib/plugins/vue-tsx.js
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.tsCodegen = void 0;
|
||||
const alien_signals_1 = require("alien-signals");
|
||||
const script_1 = require("../codegen/script");
|
||||
const template_1 = require("../codegen/template");
|
||||
const scriptRanges_1 = require("../parsers/scriptRanges");
|
||||
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
||||
exports.tsCodegen = new WeakMap();
|
||||
const fileEditTimes = new Map();
|
||||
const plugin = ctx => {
|
||||
let appendedGlobalTypes = false;
|
||||
return {
|
||||
version: 2.1,
|
||||
requiredCompilerOptions: [
|
||||
'noPropertyAccessFromIndexSignature',
|
||||
'exactOptionalPropertyTypes',
|
||||
],
|
||||
getEmbeddedCodes(fileName, sfc) {
|
||||
const tsx = useTsx(fileName, sfc);
|
||||
const files = [];
|
||||
if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang.get())) {
|
||||
files.push({ id: 'script_' + tsx.lang.get(), lang: tsx.lang.get() });
|
||||
}
|
||||
return files;
|
||||
},
|
||||
resolveEmbeddedCode(fileName, sfc, embeddedFile) {
|
||||
const _tsx = useTsx(fileName, sfc);
|
||||
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
||||
const tsx = _tsx.generatedScript.get();
|
||||
if (tsx) {
|
||||
const content = [...tsx.codes];
|
||||
embeddedFile.content = content;
|
||||
embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
function useTsx(fileName, sfc) {
|
||||
if (!exports.tsCodegen.has(sfc)) {
|
||||
let appendGlobalTypes = false;
|
||||
if (!ctx.vueCompilerOptions.__setupedGlobalTypes && !appendedGlobalTypes) {
|
||||
appendGlobalTypes = true;
|
||||
appendedGlobalTypes = true;
|
||||
}
|
||||
exports.tsCodegen.set(sfc, createTsx(fileName, sfc, ctx, appendGlobalTypes));
|
||||
}
|
||||
return exports.tsCodegen.get(sfc);
|
||||
}
|
||||
};
|
||||
exports.default = plugin;
|
||||
function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
||||
const ts = ctx.modules.typescript;
|
||||
const lang = (0, alien_signals_1.computed)(() => {
|
||||
return !_sfc.script && !_sfc.scriptSetup ? 'ts'
|
||||
: _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
|
||||
: _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
|
||||
: 'js';
|
||||
});
|
||||
const scriptRanges = (0, alien_signals_1.computed)(() => _sfc.script
|
||||
? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
|
||||
: undefined);
|
||||
const scriptSetupRanges = (0, alien_signals_1.computed)(() => _sfc.scriptSetup
|
||||
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, ctx.vueCompilerOptions)
|
||||
: undefined);
|
||||
const generatedTemplate = (0, alien_signals_1.computed)(() => {
|
||||
if (ctx.vueCompilerOptions.skipTemplateCodegen || !_sfc.template) {
|
||||
return;
|
||||
}
|
||||
const codes = [];
|
||||
const codegen = (0, template_1.generateTemplate)({
|
||||
ts,
|
||||
compilerOptions: ctx.compilerOptions,
|
||||
vueCompilerOptions: ctx.vueCompilerOptions,
|
||||
template: _sfc.template,
|
||||
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
||||
scriptSetupBindingNames: scriptSetupBindingNames.get(),
|
||||
scriptSetupImportComponentNames: scriptSetupImportComponentNames.get(),
|
||||
destructuredPropNames: destructuredPropNames.get(),
|
||||
templateRefNames: templateRefNames.get(),
|
||||
hasDefineSlots: hasDefineSlots.get(),
|
||||
slotsAssignName: slotsAssignName.get(),
|
||||
propsAssignName: propsAssignName.get(),
|
||||
inheritAttrs: inheritAttrs.get(),
|
||||
});
|
||||
let current = codegen.next();
|
||||
while (!current.done) {
|
||||
const code = current.value;
|
||||
codes.push(code);
|
||||
current = codegen.next();
|
||||
}
|
||||
return {
|
||||
...current.value,
|
||||
codes: codes,
|
||||
};
|
||||
});
|
||||
const scriptSetupBindingNames = (0, alien_signals_1.computed)(oldNames => {
|
||||
const newNames = new Set();
|
||||
const bindings = scriptSetupRanges.get()?.bindings;
|
||||
if (_sfc.scriptSetup && bindings) {
|
||||
for (const binding of bindings) {
|
||||
newNames.add(_sfc.scriptSetup?.content.substring(binding.start, binding.end));
|
||||
}
|
||||
}
|
||||
if (newNames && oldNames && twoSetsEqual(newNames, oldNames)) {
|
||||
return oldNames;
|
||||
}
|
||||
return newNames;
|
||||
});
|
||||
const scriptSetupImportComponentNames = (0, alien_signals_1.computed)(oldNames => {
|
||||
const newNames = scriptSetupRanges.get()?.importComponentNames ?? new Set();
|
||||
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
||||
return oldNames;
|
||||
}
|
||||
return newNames;
|
||||
});
|
||||
const destructuredPropNames = (0, alien_signals_1.computed)(oldNames => {
|
||||
const newNames = scriptSetupRanges.get()?.props.destructured ?? new Set();
|
||||
const rest = scriptSetupRanges.get()?.props.destructuredRest;
|
||||
if (rest) {
|
||||
newNames.add(rest);
|
||||
}
|
||||
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
||||
return oldNames;
|
||||
}
|
||||
return newNames;
|
||||
});
|
||||
const templateRefNames = (0, alien_signals_1.computed)(oldNames => {
|
||||
const newNames = new Set(scriptSetupRanges.get()?.templateRefs
|
||||
.map(({ name }) => name)
|
||||
.filter(name => name !== undefined));
|
||||
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
||||
return oldNames;
|
||||
}
|
||||
return newNames;
|
||||
});
|
||||
const hasDefineSlots = (0, alien_signals_1.computed)(() => !!scriptSetupRanges.get()?.slots.define);
|
||||
const slotsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.slots.name);
|
||||
const propsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.props.name);
|
||||
const inheritAttrs = (0, alien_signals_1.computed)(() => {
|
||||
const value = scriptSetupRanges.get()?.options.inheritAttrs ?? scriptRanges.get()?.exportDefault?.inheritAttrsOption;
|
||||
return value !== 'false';
|
||||
});
|
||||
const generatedScript = (0, alien_signals_1.computed)(() => {
|
||||
const codes = [];
|
||||
const linkedCodeMappings = [];
|
||||
let generatedLength = 0;
|
||||
const codegen = (0, script_1.generateScript)({
|
||||
ts,
|
||||
fileName,
|
||||
sfc: _sfc,
|
||||
lang: lang.get(),
|
||||
scriptRanges: scriptRanges.get(),
|
||||
scriptSetupRanges: scriptSetupRanges.get(),
|
||||
templateCodegen: generatedTemplate.get(),
|
||||
compilerOptions: ctx.compilerOptions,
|
||||
vueCompilerOptions: ctx.vueCompilerOptions,
|
||||
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
||||
getGeneratedLength: () => generatedLength,
|
||||
linkedCodeMappings,
|
||||
appendGlobalTypes,
|
||||
});
|
||||
fileEditTimes.set(fileName, (fileEditTimes.get(fileName) ?? 0) + 1);
|
||||
let current = codegen.next();
|
||||
while (!current.done) {
|
||||
const code = current.value;
|
||||
codes.push(code);
|
||||
generatedLength += typeof code === 'string'
|
||||
? code.length
|
||||
: code[0].length;
|
||||
current = codegen.next();
|
||||
}
|
||||
return {
|
||||
...current.value,
|
||||
codes,
|
||||
linkedCodeMappings,
|
||||
};
|
||||
});
|
||||
return {
|
||||
scriptRanges,
|
||||
scriptSetupRanges,
|
||||
lang,
|
||||
generatedScript,
|
||||
generatedTemplate,
|
||||
};
|
||||
}
|
||||
function twoSetsEqual(a, b) {
|
||||
if (a.size !== b.size) {
|
||||
return false;
|
||||
}
|
||||
for (const file of a) {
|
||||
if (!b.has(file)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//# sourceMappingURL=vue-tsx.js.map
|
||||
141
node_modules/@vue/language-core/lib/types.d.ts
generated
vendored
Normal file
141
node_modules/@vue/language-core/lib/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
import type { CodeInformation } from '@volar/language-core';
|
||||
import type * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { SFCParseResult } from '@vue/compiler-sfc';
|
||||
import type { Segment } from 'muggle-string';
|
||||
import type * as ts from 'typescript';
|
||||
import type { VueEmbeddedCode } from './virtualFile/embeddedFile';
|
||||
export type { SFCParseResult } from '@vue/compiler-sfc';
|
||||
export { VueEmbeddedCode };
|
||||
export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
|
||||
target?: 'auto' | 2 | 2.7 | 3 | 3.3;
|
||||
plugins?: string[];
|
||||
};
|
||||
export interface VueCodeInformation extends CodeInformation {
|
||||
__combineLastMapping?: boolean;
|
||||
__combineOffsetMapping?: number;
|
||||
}
|
||||
export type Code = Segment<VueCodeInformation>;
|
||||
export interface VueCompilerOptions {
|
||||
target: number;
|
||||
lib: string;
|
||||
extensions: string[];
|
||||
vitePressExtensions: string[];
|
||||
petiteVueExtensions: string[];
|
||||
jsxSlots: boolean;
|
||||
strictTemplates: boolean;
|
||||
skipTemplateCodegen: boolean;
|
||||
fallthroughAttributes: boolean;
|
||||
dataAttributes: string[];
|
||||
htmlAttributes: string[];
|
||||
optionsWrapper: [string, string] | [];
|
||||
macros: {
|
||||
defineProps: string[];
|
||||
defineSlots: string[];
|
||||
defineEmits: string[];
|
||||
defineExpose: string[];
|
||||
defineModel: string[];
|
||||
defineOptions: string[];
|
||||
withDefaults: string[];
|
||||
};
|
||||
composibles: {
|
||||
useCssModule: string[];
|
||||
useTemplateRef: string[];
|
||||
};
|
||||
plugins: VueLanguagePlugin[];
|
||||
experimentalDefinePropProposal: 'kevinEdition' | 'johnsonEdition' | false;
|
||||
experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
|
||||
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
|
||||
__setupedGlobalTypes?: true | {
|
||||
absolutePath: string;
|
||||
};
|
||||
__test?: boolean;
|
||||
}
|
||||
export declare const validVersions: readonly [2, 2.1];
|
||||
export type VueLanguagePluginReturn = {
|
||||
version: typeof validVersions[number];
|
||||
name?: string;
|
||||
order?: number;
|
||||
requiredCompilerOptions?: string[];
|
||||
getLanguageId?(fileName: string): string | undefined;
|
||||
isValidFile?(fileName: string, languageId: string): boolean;
|
||||
parseSFC?(fileName: string, content: string): SFCParseResult | undefined;
|
||||
parseSFC2?(fileName: string, languageId: string, content: string): SFCParseResult | undefined;
|
||||
updateSFC?(oldResult: SFCParseResult, textChange: {
|
||||
start: number;
|
||||
end: number;
|
||||
newText: string;
|
||||
}): SFCParseResult | undefined;
|
||||
resolveTemplateCompilerOptions?(options: CompilerDOM.CompilerOptions): CompilerDOM.CompilerOptions;
|
||||
compileSFCScript?(lang: string, script: string): ts.SourceFile | undefined;
|
||||
compileSFCTemplate?(lang: string, template: string, options: CompilerDOM.CompilerOptions): CompilerDOM.CodegenResult | undefined;
|
||||
updateSFCTemplate?(oldResult: CompilerDOM.CodegenResult, textChange: {
|
||||
start: number;
|
||||
end: number;
|
||||
newText: string;
|
||||
}): CompilerDOM.CodegenResult | undefined;
|
||||
getEmbeddedCodes?(fileName: string, sfc: Sfc): {
|
||||
id: string;
|
||||
lang: string;
|
||||
}[];
|
||||
resolveEmbeddedCode?(fileName: string, sfc: Sfc, embeddedFile: VueEmbeddedCode): void;
|
||||
};
|
||||
export type VueLanguagePlugin = (ctx: {
|
||||
modules: {
|
||||
typescript: typeof import('typescript');
|
||||
'@vue/compiler-dom': typeof import('@vue/compiler-dom');
|
||||
};
|
||||
compilerOptions: ts.CompilerOptions;
|
||||
vueCompilerOptions: VueCompilerOptions;
|
||||
}) => VueLanguagePluginReturn | VueLanguagePluginReturn[];
|
||||
export interface SfcBlock {
|
||||
name: string;
|
||||
start: number;
|
||||
end: number;
|
||||
startTagEnd: number;
|
||||
endTagStart: number;
|
||||
lang: string;
|
||||
content: string;
|
||||
attrs: Record<string, string | true>;
|
||||
}
|
||||
export interface SFCStyleOverride {
|
||||
module?: {
|
||||
name: string;
|
||||
offset?: number;
|
||||
};
|
||||
}
|
||||
export interface Sfc {
|
||||
content: string;
|
||||
template: SfcBlock & {
|
||||
ast: CompilerDOM.RootNode | undefined;
|
||||
errors: CompilerDOM.CompilerError[];
|
||||
warnings: CompilerDOM.CompilerError[];
|
||||
} | undefined;
|
||||
script: (SfcBlock & {
|
||||
src: string | undefined;
|
||||
srcOffset: number;
|
||||
ast: ts.SourceFile;
|
||||
}) | undefined;
|
||||
scriptSetup: SfcBlock & {
|
||||
generic: string | undefined;
|
||||
genericOffset: number;
|
||||
ast: ts.SourceFile;
|
||||
} | undefined;
|
||||
styles: readonly (SfcBlock & SFCStyleOverride & {
|
||||
scoped: boolean;
|
||||
cssVars: {
|
||||
text: string;
|
||||
offset: number;
|
||||
}[];
|
||||
classNames: {
|
||||
text: string;
|
||||
offset: number;
|
||||
}[];
|
||||
})[];
|
||||
customBlocks: readonly (SfcBlock & {
|
||||
type: string;
|
||||
})[];
|
||||
}
|
||||
export interface TextRange {
|
||||
start: number;
|
||||
end: number;
|
||||
}
|
||||
5
node_modules/@vue/language-core/lib/types.js
generated
vendored
Normal file
5
node_modules/@vue/language-core/lib/types.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.validVersions = void 0;
|
||||
exports.validVersions = [2, 2.1];
|
||||
//# sourceMappingURL=types.js.map
|
||||
3
node_modules/@vue/language-core/lib/utils/buildMappings.d.ts
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/utils/buildMappings.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { Segment } from 'muggle-string';
|
||||
import type { Mapping } from '@volar/language-core';
|
||||
export declare function buildMappings<T>(chunks: Segment<T>[]): Mapping<T>[];
|
||||
23
node_modules/@vue/language-core/lib/utils/buildMappings.js
generated
vendored
Normal file
23
node_modules/@vue/language-core/lib/utils/buildMappings.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildMappings = buildMappings;
|
||||
function buildMappings(chunks) {
|
||||
let length = 0;
|
||||
const mappings = [];
|
||||
for (const segment of chunks) {
|
||||
if (typeof segment === 'string') {
|
||||
length += segment.length;
|
||||
}
|
||||
else {
|
||||
mappings.push({
|
||||
sourceOffsets: [segment[2]],
|
||||
generatedOffsets: [length],
|
||||
lengths: [segment[0].length],
|
||||
data: segment[3],
|
||||
});
|
||||
length += segment[0].length;
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
//# sourceMappingURL=buildMappings.js.map
|
||||
1
node_modules/@vue/language-core/lib/utils/findDestructuredProps.d.ts
generated
vendored
Normal file
1
node_modules/@vue/language-core/lib/utils/findDestructuredProps.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
3
node_modules/@vue/language-core/lib/utils/findDestructuredProps.js
generated
vendored
Normal file
3
node_modules/@vue/language-core/lib/utils/findDestructuredProps.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=findDestructuredProps.js.map
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user