first commit
This commit is contained in:
commit
eb2f504652
32490 changed files with 5731109 additions and 0 deletions
15
node_modules/@vue/language-core/out/parsers/scriptRanges.d.ts
generated
vendored
Normal file
15
node_modules/@vue/language-core/out/parsers/scriptRanges.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import type { TextRange } from '../types';
|
||||
import type * as ts from 'typescript/lib/tsserverlibrary';
|
||||
export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> {
|
||||
}
|
||||
export declare function parseScriptRanges(ts: typeof import('typescript/lib/tsserverlibrary'), ast: ts.SourceFile, hasScriptSetup: boolean, withNode: boolean): {
|
||||
exportDefault: (TextRange & {
|
||||
expression: TextRange;
|
||||
args: TextRange;
|
||||
argsNode: ts.ObjectLiteralExpression | undefined;
|
||||
componentsOption: TextRange | undefined;
|
||||
componentsOptionNode: ts.ObjectLiteralExpression | undefined;
|
||||
nameOption: TextRange | undefined;
|
||||
}) | undefined;
|
||||
bindings: TextRange[];
|
||||
};
|
||||
58
node_modules/@vue/language-core/out/parsers/scriptRanges.js
generated
vendored
Normal file
58
node_modules/@vue/language-core/out/parsers/scriptRanges.js
generated
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseScriptRanges = void 0;
|
||||
const scriptSetupRanges_1 = require("./scriptSetupRanges");
|
||||
function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
||||
let exportDefault;
|
||||
const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast, false) : [];
|
||||
ast.forEachChild(raw => {
|
||||
if (ts.isExportAssignment(raw)) {
|
||||
let node = raw;
|
||||
while (ts.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 nameOptionNode;
|
||||
obj.forEachChild(node => {
|
||||
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
|
||||
if (node.name.escapedText === 'components' && ts.isObjectLiteralExpression(node.initializer)) {
|
||||
componentsOptionNode = node.initializer;
|
||||
}
|
||||
if (node.name.escapedText === 'name') {
|
||||
nameOptionNode = node.initializer;
|
||||
}
|
||||
}
|
||||
});
|
||||
exportDefault = {
|
||||
..._getStartEnd(raw),
|
||||
expression: _getStartEnd(node.expression),
|
||||
args: _getStartEnd(obj),
|
||||
argsNode: withNode ? obj : undefined,
|
||||
componentsOption: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined,
|
||||
componentsOptionNode: withNode ? componentsOptionNode : undefined,
|
||||
nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
return {
|
||||
exportDefault,
|
||||
bindings,
|
||||
};
|
||||
function _getStartEnd(node) {
|
||||
return (0, scriptSetupRanges_1.getStartEnd)(node, ast);
|
||||
}
|
||||
}
|
||||
exports.parseScriptRanges = parseScriptRanges;
|
||||
//# sourceMappingURL=scriptRanges.js.map
|
||||
33
node_modules/@vue/language-core/out/parsers/scriptSetupRanges.d.ts
generated
vendored
Normal file
33
node_modules/@vue/language-core/out/parsers/scriptSetupRanges.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import type * as ts from 'typescript/lib/tsserverlibrary';
|
||||
import type { VueCompilerOptions, TextRange } from '../types';
|
||||
export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRanges> {
|
||||
}
|
||||
export declare function parseScriptSetupRanges(ts: typeof import('typescript/lib/tsserverlibrary'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
|
||||
leadingCommentEndOffset: number;
|
||||
importSectionEndOffset: number;
|
||||
bindings: TextRange[];
|
||||
withDefaultsArg: TextRange | undefined;
|
||||
defineProps: TextRange | undefined;
|
||||
propsAssignName: string | undefined;
|
||||
propsRuntimeArg: TextRange | undefined;
|
||||
propsTypeArg: TextRange | undefined;
|
||||
slotsTypeArg: TextRange | undefined;
|
||||
emitsAssignName: string | undefined;
|
||||
emitsRuntimeArg: TextRange | undefined;
|
||||
emitsTypeArg: TextRange | undefined;
|
||||
emitsTypeNums: number;
|
||||
exposeRuntimeArg: TextRange | undefined;
|
||||
defineProp: {
|
||||
name: TextRange | undefined;
|
||||
nameIsString: boolean;
|
||||
type: TextRange | undefined;
|
||||
defaultValue: TextRange | undefined;
|
||||
required: boolean;
|
||||
}[];
|
||||
};
|
||||
export declare function parseBindingRanges(ts: typeof import('typescript/lib/tsserverlibrary'), sourceFile: ts.SourceFile, isType: boolean): TextRange[];
|
||||
export declare function findBindingVars(ts: typeof import('typescript/lib/tsserverlibrary'), left: ts.BindingName, sourceFile: ts.SourceFile): TextRange[];
|
||||
export declare function getStartEnd(node: ts.Node, sourceFile: ts.SourceFile): {
|
||||
start: number;
|
||||
end: number;
|
||||
};
|
||||
305
node_modules/@vue/language-core/out/parsers/scriptSetupRanges.js
generated
vendored
Normal file
305
node_modules/@vue/language-core/out/parsers/scriptSetupRanges.js
generated
vendored
Normal file
|
|
@ -0,0 +1,305 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getStartEnd = exports.findBindingVars = exports.parseBindingRanges = exports.parseScriptSetupRanges = void 0;
|
||||
function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
||||
let foundNonImportExportNode = false;
|
||||
let importSectionEndOffset = 0;
|
||||
let withDefaultsArg;
|
||||
let propsAssignName;
|
||||
let defineProps;
|
||||
let propsRuntimeArg;
|
||||
let propsTypeArg;
|
||||
let slotsTypeArg;
|
||||
let emitsAssignName;
|
||||
let emitsRuntimeArg;
|
||||
let emitsTypeArg;
|
||||
let exposeRuntimeArg;
|
||||
let emitsTypeNums = -1;
|
||||
const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition');
|
||||
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
|
||||
const defineProp = [];
|
||||
const bindings = parseBindingRanges(ts, ast, false);
|
||||
const text = ast.getFullText();
|
||||
const leadingCommentEndOffset = ts.getLeadingCommentRanges(text, 0)?.reverse()[0].end ?? 0;
|
||||
ast.forEachChild(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.getFullStart());
|
||||
if (commentRanges?.length) {
|
||||
const commentRange = commentRanges.sort((a, b) => a.pos - b.pos)[0];
|
||||
importSectionEndOffset = commentRange.pos;
|
||||
}
|
||||
else {
|
||||
importSectionEndOffset = node.getStart(ast);
|
||||
}
|
||||
foundNonImportExportNode = true;
|
||||
}
|
||||
});
|
||||
ast.forEachChild(child => visitNode(child, ast));
|
||||
return {
|
||||
leadingCommentEndOffset,
|
||||
importSectionEndOffset,
|
||||
bindings,
|
||||
withDefaultsArg,
|
||||
defineProps,
|
||||
propsAssignName,
|
||||
propsRuntimeArg,
|
||||
propsTypeArg,
|
||||
slotsTypeArg,
|
||||
emitsAssignName,
|
||||
emitsRuntimeArg,
|
||||
emitsTypeArg,
|
||||
emitsTypeNums,
|
||||
exposeRuntimeArg,
|
||||
defineProp,
|
||||
};
|
||||
function _getStartEnd(node) {
|
||||
return getStartEnd(node, ast);
|
||||
}
|
||||
function visitNode(node, parent) {
|
||||
if (ts.isCallExpression(node)
|
||||
&& ts.isIdentifier(node.expression)) {
|
||||
const callText = node.expression.getText(ast);
|
||||
if (callText === 'defineModel') {
|
||||
let name;
|
||||
let options;
|
||||
if (node.arguments.length >= 2) {
|
||||
name = _getStartEnd(node.arguments[0]);
|
||||
options = node.arguments[1];
|
||||
}
|
||||
else if (node.arguments.length >= 1) {
|
||||
if (ts.isStringLiteral(node.arguments[0])) {
|
||||
name = _getStartEnd(node.arguments[0]);
|
||||
}
|
||||
else {
|
||||
options = node.arguments[0];
|
||||
}
|
||||
}
|
||||
let required = false;
|
||||
if (options && ts.isObjectLiteralExpression(options)) {
|
||||
for (const property of options.properties) {
|
||||
if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && property.name.getText(ast) === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
||||
required = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
defineProp.push({
|
||||
name,
|
||||
nameIsString: true,
|
||||
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
||||
defaultValue: undefined,
|
||||
required,
|
||||
});
|
||||
}
|
||||
else if (callText === 'defineProp') {
|
||||
if (definePropProposalA) {
|
||||
let required = false;
|
||||
if (node.arguments.length >= 2) {
|
||||
const secondArg = node.arguments[1];
|
||||
if (ts.isObjectLiteralExpression(secondArg)) {
|
||||
for (const property of secondArg.properties) {
|
||||
if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && property.name.getText(ast) === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
||||
required = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node.arguments.length >= 1) {
|
||||
defineProp.push({
|
||||
name: _getStartEnd(node.arguments[0]),
|
||||
nameIsString: true,
|
||||
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
||||
defaultValue: undefined,
|
||||
required,
|
||||
});
|
||||
}
|
||||
else if (ts.isVariableDeclaration(parent)) {
|
||||
defineProp.push({
|
||||
name: _getStartEnd(parent.name),
|
||||
nameIsString: false,
|
||||
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
||||
defaultValue: undefined,
|
||||
required,
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (definePropProposalB && ts.isVariableDeclaration(parent)) {
|
||||
defineProp.push({
|
||||
name: _getStartEnd(parent.name),
|
||||
nameIsString: false,
|
||||
defaultValue: node.arguments.length >= 1 ? _getStartEnd(node.arguments[0]) : undefined,
|
||||
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
||||
required: node.arguments.length >= 2 && node.arguments[1].kind === ts.SyntaxKind.TrueKeyword,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (vueCompilerOptions.macros.defineProps.includes(callText)
|
||||
|| vueCompilerOptions.macros.defineSlots.includes(callText)
|
||||
|| vueCompilerOptions.macros.defineEmits.includes(callText)
|
||||
|| vueCompilerOptions.macros.defineExpose.includes(callText)) {
|
||||
if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
||||
defineProps = _getStartEnd(node);
|
||||
}
|
||||
if (node.arguments.length) {
|
||||
const runtimeArg = node.arguments[0];
|
||||
if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
||||
propsRuntimeArg = _getStartEnd(runtimeArg);
|
||||
if (ts.isVariableDeclaration(parent)) {
|
||||
propsAssignName = parent.name.getText(ast);
|
||||
}
|
||||
}
|
||||
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|
||||
emitsRuntimeArg = _getStartEnd(runtimeArg);
|
||||
if (ts.isVariableDeclaration(parent)) {
|
||||
emitsAssignName = parent.name.getText(ast);
|
||||
}
|
||||
}
|
||||
else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
|
||||
exposeRuntimeArg = _getStartEnd(runtimeArg);
|
||||
}
|
||||
}
|
||||
if (node.typeArguments?.length) {
|
||||
const typeArg = node.typeArguments[0];
|
||||
if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
||||
propsTypeArg = _getStartEnd(typeArg);
|
||||
if (ts.isVariableDeclaration(parent)) {
|
||||
propsAssignName = parent.name.getText(ast);
|
||||
}
|
||||
}
|
||||
if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
|
||||
slotsTypeArg = _getStartEnd(typeArg);
|
||||
}
|
||||
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|
||||
emitsTypeArg = _getStartEnd(typeArg);
|
||||
if (ts.isTypeLiteralNode(typeArg)) {
|
||||
emitsTypeNums = typeArg.members.length;
|
||||
}
|
||||
if (ts.isVariableDeclaration(parent)) {
|
||||
emitsAssignName = parent.name.getText(ast);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (vueCompilerOptions.macros.withDefaults.includes(callText)) {
|
||||
if (node.arguments.length >= 2) {
|
||||
const arg = node.arguments[1];
|
||||
withDefaultsArg = _getStartEnd(arg);
|
||||
}
|
||||
if (ts.isVariableDeclaration(parent)) {
|
||||
propsAssignName = parent.name.getText(ast);
|
||||
}
|
||||
}
|
||||
}
|
||||
node.forEachChild(child => visitNode(child, node));
|
||||
}
|
||||
}
|
||||
exports.parseScriptSetupRanges = parseScriptSetupRanges;
|
||||
function parseBindingRanges(ts, sourceFile, isType) {
|
||||
const bindings = [];
|
||||
sourceFile.forEachChild(node => {
|
||||
if (!isType) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ts.isTypeAliasDeclaration(node)) {
|
||||
bindings.push(_getStartEnd(node.name));
|
||||
}
|
||||
else if (ts.isInterfaceDeclaration(node)) {
|
||||
bindings.push(_getStartEnd(node.name));
|
||||
}
|
||||
}
|
||||
if (ts.isImportDeclaration(node)) {
|
||||
if (node.importClause && (isType || !node.importClause.isTypeOnly)) {
|
||||
if (node.importClause.name && !isType) {
|
||||
bindings.push(_getStartEnd(node.importClause.name));
|
||||
}
|
||||
if (node.importClause.namedBindings) {
|
||||
if (ts.isNamedImports(node.importClause.namedBindings)) {
|
||||
for (const element of node.importClause.namedBindings.elements) {
|
||||
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(node, sourceFile);
|
||||
}
|
||||
function _findBindingVars(left) {
|
||||
return findBindingVars(ts, left, sourceFile);
|
||||
}
|
||||
}
|
||||
exports.parseBindingRanges = parseBindingRanges;
|
||||
function findBindingVars(ts, left, sourceFile) {
|
||||
const vars = [];
|
||||
worker(left);
|
||||
return vars;
|
||||
function worker(_node) {
|
||||
if (ts.isIdentifier(_node)) {
|
||||
vars.push(getStartEnd(_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(_node.name, sourceFile));
|
||||
}
|
||||
// { ...? } = ...
|
||||
// [ ...? ] = ...
|
||||
else if (ts.isSpreadAssignment(_node) || ts.isSpreadElement(_node)) {
|
||||
worker(_node.expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.findBindingVars = findBindingVars;
|
||||
function getStartEnd(node, sourceFile) {
|
||||
return {
|
||||
start: node.getStart(sourceFile),
|
||||
end: node.getEnd(),
|
||||
};
|
||||
}
|
||||
exports.getStartEnd = getStartEnd;
|
||||
//# sourceMappingURL=scriptSetupRanges.js.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue