Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.

This commit is contained in:
becarta
2025-05-23 12:43:00 +02:00
parent f40db0f5c9
commit a544759a3b
11127 changed files with 1647032 additions and 0 deletions

146
node_modules/magicast/dist/helpers.cjs generated vendored Normal file
View File

@@ -0,0 +1,146 @@
'use strict';
const index = require('./index.cjs');
require('node:fs');
require('fs');
require('source-map-js');
require('@babel/parser');
function deepMergeObject(magicast, object) {
if (typeof object === "object") {
for (const key in object) {
if (typeof magicast[key] === "object" && typeof object[key] === "object") {
deepMergeObject(magicast[key], object[key]);
} else {
magicast[key] = object[key];
}
}
}
}
function getDefaultExportOptions(magicast) {
return configFromNode(magicast.exports.default);
}
function getConfigFromVariableDeclaration(magicast) {
if (magicast.exports.default.$type !== "identifier") {
throw new index.MagicastError(
`Not supported: Cannot modify this kind of default export (${magicast.exports.default.$type})`
);
}
const configDecalarationId = magicast.exports.default.$name;
for (const node of magicast.$ast.body) {
if (node.type === "VariableDeclaration") {
for (const declaration of node.declarations) {
if (declaration.id.type === "Identifier" && declaration.id.name === configDecalarationId && declaration.init) {
const init = declaration.init.type === "TSSatisfiesExpression" ? declaration.init.expression : declaration.init;
const code = index.generateCode(init).code;
const configExpression = index.parseExpression(code);
return {
declaration,
config: configFromNode(configExpression)
};
}
}
}
}
throw new index.MagicastError("Couldn't find config declaration");
}
function configFromNode(node) {
if (node.$type === "function-call") {
return node.$args[0];
}
return node;
}
function addNuxtModule(magicast, name, optionsKey, options) {
const config = getDefaultExportOptions(magicast);
config.modules || (config.modules = []);
if (!config.modules.includes(name)) {
config.modules.push(name);
}
if (optionsKey) {
config[optionsKey] || (config[optionsKey] = {});
deepMergeObject(config[optionsKey], options);
}
}
function addVitePlugin(magicast, plugin) {
const config = getDefaultExportOptions(magicast);
if (config.$type === "identifier") {
insertPluginIntoVariableDeclarationConfig(magicast, plugin);
} else {
insertPluginIntoConfig(plugin, config);
}
magicast.imports.$prepend({
from: plugin.from,
local: plugin.constructor,
imported: plugin.imported || "default"
});
return true;
}
function findVitePluginCall(magicast, plugin) {
const _plugin = typeof plugin === "string" ? { from: plugin, imported: "default" } : plugin;
const config = getDefaultExportOptions(magicast);
const constructor = magicast.imports.$items.find(
(i) => i.from === _plugin.from && i.imported === (_plugin.imported || "default")
)?.local;
return config.plugins?.find(
(p) => p && p.$type === "function-call" && p.$callee === constructor
);
}
function updateVitePluginConfig(magicast, plugin, handler) {
const item = findVitePluginCall(magicast, plugin);
if (!item) {
return false;
}
if (typeof handler === "function") {
item.$args = handler(item.$args);
} else if (item.$args[0]) {
deepMergeObject(item.$args[0], handler);
} else {
item.$args[0] = handler;
}
return true;
}
function insertPluginIntoVariableDeclarationConfig(magicast, plugin) {
const { config: configObject, declaration } = getConfigFromVariableDeclaration(magicast);
insertPluginIntoConfig(plugin, configObject);
if (declaration.init) {
if (declaration.init.type === "ObjectExpression") {
declaration.init = index.generateCode(configObject).code;
} else if (declaration.init.type === "CallExpression" && declaration.init.callee.type === "Identifier") {
declaration.init = index.generateCode(
index.builders.functionCall(declaration.init.callee.name, configObject)
).code;
} else if (declaration.init.type === "TSSatisfiesExpression") {
if (declaration.init.expression.type === "ObjectExpression") {
declaration.init.expression = index.generateCode(configObject).code;
}
if (declaration.init.expression.type === "CallExpression" && declaration.init.expression.callee.type === "Identifier") {
declaration.init.expression = index.generateCode(
index.builders.functionCall(
declaration.init.expression.callee.name,
configObject
)
).code;
}
}
}
}
function insertPluginIntoConfig(plugin, config) {
const insertionIndex = plugin.index ?? config.plugins?.length ?? 0;
config.plugins || (config.plugins = []);
config.plugins.splice(
insertionIndex,
0,
plugin.options ? index.builders.functionCall(plugin.constructor, plugin.options) : index.builders.functionCall(plugin.constructor)
);
}
exports.addNuxtModule = addNuxtModule;
exports.addVitePlugin = addVitePlugin;
exports.deepMergeObject = deepMergeObject;
exports.findVitePluginCall = findVitePluginCall;
exports.getConfigFromVariableDeclaration = getConfigFromVariableDeclaration;
exports.getDefaultExportOptions = getDefaultExportOptions;
exports.updateVitePluginConfig = updateVitePluginConfig;

70
node_modules/magicast/dist/helpers.d.cts generated vendored Normal file
View File

@@ -0,0 +1,70 @@
import { a as Proxified, P as ProxifiedModule, e as ProxifiedFunctionCall, h as ProxifiedObject } from './shared/magicast.54e2233d.cjs';
import { VariableDeclarator } from '@babel/types';
declare function deepMergeObject(magicast: Proxified<any>, object: any): void;
declare function addNuxtModule(magicast: ProxifiedModule<any>, name: string, optionsKey?: string, options?: any): void;
interface AddVitePluginOptions {
/**
* The import path of the plugin
*/
from: string;
/**
* The import name of the plugin
* @default "default"
*/
imported?: string;
/**
* The name of local variable
*/
constructor: string;
/**
* The options of the plugin
*/
options?: Record<string, any>;
/**
* The index in the plugins array where the plugin should be inserted at.
* By default, the plugin is appended to the array.
*/
index?: number;
}
interface UpdateVitePluginConfigOptions {
/**
* The import path of the plugin
*/
from: string;
/**
* The import name of the plugin
* @default "default"
*/
imported?: string;
}
declare function addVitePlugin(magicast: ProxifiedModule<any>, plugin: AddVitePluginOptions): boolean;
declare function findVitePluginCall(magicast: ProxifiedModule<any>, plugin: UpdateVitePluginConfigOptions | string): ProxifiedFunctionCall | undefined;
declare function updateVitePluginConfig(magicast: ProxifiedModule<any>, plugin: UpdateVitePluginConfigOptions | string, handler: Record<string, any> | ((args: any[]) => any[])): boolean;
declare function getDefaultExportOptions(magicast: ProxifiedModule<any>): ProxifiedObject<any>;
/**
* Returns the vite config object from a variable declaration thats
* exported as the default export.
*
* Example:
*
* ```js
* const config = {};
* export default config;
* ```
*
* @param magicast the module
*
* @returns an object containing the proxified config object and the
* declaration "parent" to attach the modified config to later.
* If no config declaration is found, undefined is returned.
*/
declare function getConfigFromVariableDeclaration(magicast: ProxifiedModule<any>): {
declaration: VariableDeclarator;
config: ProxifiedObject<any> | undefined;
};
export { type AddVitePluginOptions, type UpdateVitePluginConfigOptions, addNuxtModule, addVitePlugin, deepMergeObject, findVitePluginCall, getConfigFromVariableDeclaration, getDefaultExportOptions, updateVitePluginConfig };

70
node_modules/magicast/dist/helpers.d.mts generated vendored Normal file
View File

@@ -0,0 +1,70 @@
import { a as Proxified, P as ProxifiedModule, e as ProxifiedFunctionCall, h as ProxifiedObject } from './shared/magicast.54e2233d.mjs';
import { VariableDeclarator } from '@babel/types';
declare function deepMergeObject(magicast: Proxified<any>, object: any): void;
declare function addNuxtModule(magicast: ProxifiedModule<any>, name: string, optionsKey?: string, options?: any): void;
interface AddVitePluginOptions {
/**
* The import path of the plugin
*/
from: string;
/**
* The import name of the plugin
* @default "default"
*/
imported?: string;
/**
* The name of local variable
*/
constructor: string;
/**
* The options of the plugin
*/
options?: Record<string, any>;
/**
* The index in the plugins array where the plugin should be inserted at.
* By default, the plugin is appended to the array.
*/
index?: number;
}
interface UpdateVitePluginConfigOptions {
/**
* The import path of the plugin
*/
from: string;
/**
* The import name of the plugin
* @default "default"
*/
imported?: string;
}
declare function addVitePlugin(magicast: ProxifiedModule<any>, plugin: AddVitePluginOptions): boolean;
declare function findVitePluginCall(magicast: ProxifiedModule<any>, plugin: UpdateVitePluginConfigOptions | string): ProxifiedFunctionCall | undefined;
declare function updateVitePluginConfig(magicast: ProxifiedModule<any>, plugin: UpdateVitePluginConfigOptions | string, handler: Record<string, any> | ((args: any[]) => any[])): boolean;
declare function getDefaultExportOptions(magicast: ProxifiedModule<any>): ProxifiedObject<any>;
/**
* Returns the vite config object from a variable declaration thats
* exported as the default export.
*
* Example:
*
* ```js
* const config = {};
* export default config;
* ```
*
* @param magicast the module
*
* @returns an object containing the proxified config object and the
* declaration "parent" to attach the modified config to later.
* If no config declaration is found, undefined is returned.
*/
declare function getConfigFromVariableDeclaration(magicast: ProxifiedModule<any>): {
declaration: VariableDeclarator;
config: ProxifiedObject<any> | undefined;
};
export { type AddVitePluginOptions, type UpdateVitePluginConfigOptions, addNuxtModule, addVitePlugin, deepMergeObject, findVitePluginCall, getConfigFromVariableDeclaration, getDefaultExportOptions, updateVitePluginConfig };

70
node_modules/magicast/dist/helpers.d.ts generated vendored Normal file
View File

@@ -0,0 +1,70 @@
import { a as Proxified, P as ProxifiedModule, e as ProxifiedFunctionCall, h as ProxifiedObject } from './shared/magicast.54e2233d.js';
import { VariableDeclarator } from '@babel/types';
declare function deepMergeObject(magicast: Proxified<any>, object: any): void;
declare function addNuxtModule(magicast: ProxifiedModule<any>, name: string, optionsKey?: string, options?: any): void;
interface AddVitePluginOptions {
/**
* The import path of the plugin
*/
from: string;
/**
* The import name of the plugin
* @default "default"
*/
imported?: string;
/**
* The name of local variable
*/
constructor: string;
/**
* The options of the plugin
*/
options?: Record<string, any>;
/**
* The index in the plugins array where the plugin should be inserted at.
* By default, the plugin is appended to the array.
*/
index?: number;
}
interface UpdateVitePluginConfigOptions {
/**
* The import path of the plugin
*/
from: string;
/**
* The import name of the plugin
* @default "default"
*/
imported?: string;
}
declare function addVitePlugin(magicast: ProxifiedModule<any>, plugin: AddVitePluginOptions): boolean;
declare function findVitePluginCall(magicast: ProxifiedModule<any>, plugin: UpdateVitePluginConfigOptions | string): ProxifiedFunctionCall | undefined;
declare function updateVitePluginConfig(magicast: ProxifiedModule<any>, plugin: UpdateVitePluginConfigOptions | string, handler: Record<string, any> | ((args: any[]) => any[])): boolean;
declare function getDefaultExportOptions(magicast: ProxifiedModule<any>): ProxifiedObject<any>;
/**
* Returns the vite config object from a variable declaration thats
* exported as the default export.
*
* Example:
*
* ```js
* const config = {};
* export default config;
* ```
*
* @param magicast the module
*
* @returns an object containing the proxified config object and the
* declaration "parent" to attach the modified config to later.
* If no config declaration is found, undefined is returned.
*/
declare function getConfigFromVariableDeclaration(magicast: ProxifiedModule<any>): {
declaration: VariableDeclarator;
config: ProxifiedObject<any> | undefined;
};
export { type AddVitePluginOptions, type UpdateVitePluginConfigOptions, addNuxtModule, addVitePlugin, deepMergeObject, findVitePluginCall, getConfigFromVariableDeclaration, getDefaultExportOptions, updateVitePluginConfig };

138
node_modules/magicast/dist/helpers.mjs generated vendored Normal file
View File

@@ -0,0 +1,138 @@
import { MagicastError, generateCode, parseExpression, builders } from './index.mjs';
import 'node:fs';
import 'fs';
import 'source-map-js';
import '@babel/parser';
function deepMergeObject(magicast, object) {
if (typeof object === "object") {
for (const key in object) {
if (typeof magicast[key] === "object" && typeof object[key] === "object") {
deepMergeObject(magicast[key], object[key]);
} else {
magicast[key] = object[key];
}
}
}
}
function getDefaultExportOptions(magicast) {
return configFromNode(magicast.exports.default);
}
function getConfigFromVariableDeclaration(magicast) {
if (magicast.exports.default.$type !== "identifier") {
throw new MagicastError(
`Not supported: Cannot modify this kind of default export (${magicast.exports.default.$type})`
);
}
const configDecalarationId = magicast.exports.default.$name;
for (const node of magicast.$ast.body) {
if (node.type === "VariableDeclaration") {
for (const declaration of node.declarations) {
if (declaration.id.type === "Identifier" && declaration.id.name === configDecalarationId && declaration.init) {
const init = declaration.init.type === "TSSatisfiesExpression" ? declaration.init.expression : declaration.init;
const code = generateCode(init).code;
const configExpression = parseExpression(code);
return {
declaration,
config: configFromNode(configExpression)
};
}
}
}
}
throw new MagicastError("Couldn't find config declaration");
}
function configFromNode(node) {
if (node.$type === "function-call") {
return node.$args[0];
}
return node;
}
function addNuxtModule(magicast, name, optionsKey, options) {
const config = getDefaultExportOptions(magicast);
config.modules || (config.modules = []);
if (!config.modules.includes(name)) {
config.modules.push(name);
}
if (optionsKey) {
config[optionsKey] || (config[optionsKey] = {});
deepMergeObject(config[optionsKey], options);
}
}
function addVitePlugin(magicast, plugin) {
const config = getDefaultExportOptions(magicast);
if (config.$type === "identifier") {
insertPluginIntoVariableDeclarationConfig(magicast, plugin);
} else {
insertPluginIntoConfig(plugin, config);
}
magicast.imports.$prepend({
from: plugin.from,
local: plugin.constructor,
imported: plugin.imported || "default"
});
return true;
}
function findVitePluginCall(magicast, plugin) {
const _plugin = typeof plugin === "string" ? { from: plugin, imported: "default" } : plugin;
const config = getDefaultExportOptions(magicast);
const constructor = magicast.imports.$items.find(
(i) => i.from === _plugin.from && i.imported === (_plugin.imported || "default")
)?.local;
return config.plugins?.find(
(p) => p && p.$type === "function-call" && p.$callee === constructor
);
}
function updateVitePluginConfig(magicast, plugin, handler) {
const item = findVitePluginCall(magicast, plugin);
if (!item) {
return false;
}
if (typeof handler === "function") {
item.$args = handler(item.$args);
} else if (item.$args[0]) {
deepMergeObject(item.$args[0], handler);
} else {
item.$args[0] = handler;
}
return true;
}
function insertPluginIntoVariableDeclarationConfig(magicast, plugin) {
const { config: configObject, declaration } = getConfigFromVariableDeclaration(magicast);
insertPluginIntoConfig(plugin, configObject);
if (declaration.init) {
if (declaration.init.type === "ObjectExpression") {
declaration.init = generateCode(configObject).code;
} else if (declaration.init.type === "CallExpression" && declaration.init.callee.type === "Identifier") {
declaration.init = generateCode(
builders.functionCall(declaration.init.callee.name, configObject)
).code;
} else if (declaration.init.type === "TSSatisfiesExpression") {
if (declaration.init.expression.type === "ObjectExpression") {
declaration.init.expression = generateCode(configObject).code;
}
if (declaration.init.expression.type === "CallExpression" && declaration.init.expression.callee.type === "Identifier") {
declaration.init.expression = generateCode(
builders.functionCall(
declaration.init.expression.callee.name,
configObject
)
).code;
}
}
}
}
function insertPluginIntoConfig(plugin, config) {
const insertionIndex = plugin.index ?? config.plugins?.length ?? 0;
config.plugins || (config.plugins = []);
config.plugins.splice(
insertionIndex,
0,
plugin.options ? builders.functionCall(plugin.constructor, plugin.options) : builders.functionCall(plugin.constructor)
);
}
export { addNuxtModule, addVitePlugin, deepMergeObject, findVitePluginCall, getConfigFromVariableDeclaration, getDefaultExportOptions, updateVitePluginConfig };

8933
node_modules/magicast/dist/index.cjs generated vendored Normal file

File diff suppressed because it is too large Load Diff

53
node_modules/magicast/dist/index.d.cts generated vendored Normal file
View File

@@ -0,0 +1,53 @@
import { O as Options, P as ProxifiedModule, a as Proxified, G as GenerateOptions } from './shared/magicast.54e2233d.cjs';
export { C as CodeFormatOptions, I as ImportItemInput, L as Loc, b as ParsedFileNode, d as ProxifiedArray, g as ProxifiedArrowFunctionExpression, e as ProxifiedFunctionCall, i as ProxifiedIdentifier, m as ProxifiedImportItem, l as ProxifiedImportsMap, j as ProxifiedLogicalExpression, k as ProxifiedMemberExpression, f as ProxifiedNewExpression, h as ProxifiedObject, n as ProxifiedValue, c as ProxyBase, o as ProxyType, T as Token, p as detectCodeFormat } from './shared/magicast.54e2233d.cjs';
import { Node } from '@babel/types';
export { Node as ASTNode } from '@babel/types';
declare function parseModule<Exports extends object = any>(code: string, options?: Options): ProxifiedModule<Exports>;
declare function parseExpression<T>(code: string, options?: Options): Proxified<T>;
declare function generateCode(node: {
$ast: Node;
} | Node | ProxifiedModule<any>, options?: GenerateOptions): {
code: string;
map?: any;
};
declare function loadFile<Exports extends object = any>(filename: string, options?: Options): Promise<ProxifiedModule<Exports>>;
declare function writeFile(node: {
$ast: Node;
} | Node, filename: string, options?: Options): Promise<void>;
interface MagicastErrorOptions {
ast?: Node;
code?: string;
}
declare class MagicastError extends Error {
rawMessage: string;
options?: MagicastErrorOptions;
constructor(message: string, options?: MagicastErrorOptions);
}
declare const builders: {
/**
* Create a function call node.
*/
functionCall(callee: string, ...args: any[]): Proxified;
/**
* Create a new expression node.
*/
newExpression(callee: string, ...args: any[]): Proxified;
/**
* Create a proxified version of a literal value.
*/
literal(value: any): Proxified;
/**
* Parse a raw expression and return a proxified version of it.
*
* ```ts
* const obj = builders.raw("{ foo: 1 }");
* console.log(obj.foo); // 1
* ```
*/
raw(code: string): Proxified;
};
export { GenerateOptions, MagicastError, type MagicastErrorOptions, Proxified, ProxifiedModule, builders, generateCode, loadFile, parseExpression, parseModule, writeFile };

53
node_modules/magicast/dist/index.d.mts generated vendored Normal file
View File

@@ -0,0 +1,53 @@
import { O as Options, P as ProxifiedModule, a as Proxified, G as GenerateOptions } from './shared/magicast.54e2233d.mjs';
export { C as CodeFormatOptions, I as ImportItemInput, L as Loc, b as ParsedFileNode, d as ProxifiedArray, g as ProxifiedArrowFunctionExpression, e as ProxifiedFunctionCall, i as ProxifiedIdentifier, m as ProxifiedImportItem, l as ProxifiedImportsMap, j as ProxifiedLogicalExpression, k as ProxifiedMemberExpression, f as ProxifiedNewExpression, h as ProxifiedObject, n as ProxifiedValue, c as ProxyBase, o as ProxyType, T as Token, p as detectCodeFormat } from './shared/magicast.54e2233d.mjs';
import { Node } from '@babel/types';
export { Node as ASTNode } from '@babel/types';
declare function parseModule<Exports extends object = any>(code: string, options?: Options): ProxifiedModule<Exports>;
declare function parseExpression<T>(code: string, options?: Options): Proxified<T>;
declare function generateCode(node: {
$ast: Node;
} | Node | ProxifiedModule<any>, options?: GenerateOptions): {
code: string;
map?: any;
};
declare function loadFile<Exports extends object = any>(filename: string, options?: Options): Promise<ProxifiedModule<Exports>>;
declare function writeFile(node: {
$ast: Node;
} | Node, filename: string, options?: Options): Promise<void>;
interface MagicastErrorOptions {
ast?: Node;
code?: string;
}
declare class MagicastError extends Error {
rawMessage: string;
options?: MagicastErrorOptions;
constructor(message: string, options?: MagicastErrorOptions);
}
declare const builders: {
/**
* Create a function call node.
*/
functionCall(callee: string, ...args: any[]): Proxified;
/**
* Create a new expression node.
*/
newExpression(callee: string, ...args: any[]): Proxified;
/**
* Create a proxified version of a literal value.
*/
literal(value: any): Proxified;
/**
* Parse a raw expression and return a proxified version of it.
*
* ```ts
* const obj = builders.raw("{ foo: 1 }");
* console.log(obj.foo); // 1
* ```
*/
raw(code: string): Proxified;
};
export { GenerateOptions, MagicastError, type MagicastErrorOptions, Proxified, ProxifiedModule, builders, generateCode, loadFile, parseExpression, parseModule, writeFile };

53
node_modules/magicast/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,53 @@
import { O as Options, P as ProxifiedModule, a as Proxified, G as GenerateOptions } from './shared/magicast.54e2233d.js';
export { C as CodeFormatOptions, I as ImportItemInput, L as Loc, b as ParsedFileNode, d as ProxifiedArray, g as ProxifiedArrowFunctionExpression, e as ProxifiedFunctionCall, i as ProxifiedIdentifier, m as ProxifiedImportItem, l as ProxifiedImportsMap, j as ProxifiedLogicalExpression, k as ProxifiedMemberExpression, f as ProxifiedNewExpression, h as ProxifiedObject, n as ProxifiedValue, c as ProxyBase, o as ProxyType, T as Token, p as detectCodeFormat } from './shared/magicast.54e2233d.js';
import { Node } from '@babel/types';
export { Node as ASTNode } from '@babel/types';
declare function parseModule<Exports extends object = any>(code: string, options?: Options): ProxifiedModule<Exports>;
declare function parseExpression<T>(code: string, options?: Options): Proxified<T>;
declare function generateCode(node: {
$ast: Node;
} | Node | ProxifiedModule<any>, options?: GenerateOptions): {
code: string;
map?: any;
};
declare function loadFile<Exports extends object = any>(filename: string, options?: Options): Promise<ProxifiedModule<Exports>>;
declare function writeFile(node: {
$ast: Node;
} | Node, filename: string, options?: Options): Promise<void>;
interface MagicastErrorOptions {
ast?: Node;
code?: string;
}
declare class MagicastError extends Error {
rawMessage: string;
options?: MagicastErrorOptions;
constructor(message: string, options?: MagicastErrorOptions);
}
declare const builders: {
/**
* Create a function call node.
*/
functionCall(callee: string, ...args: any[]): Proxified;
/**
* Create a new expression node.
*/
newExpression(callee: string, ...args: any[]): Proxified;
/**
* Create a proxified version of a literal value.
*/
literal(value: any): Proxified;
/**
* Parse a raw expression and return a proxified version of it.
*
* ```ts
* const obj = builders.raw("{ foo: 1 }");
* console.log(obj.foo); // 1
* ```
*/
raw(code: string): Proxified;
};
export { GenerateOptions, MagicastError, type MagicastErrorOptions, Proxified, ProxifiedModule, builders, generateCode, loadFile, parseExpression, parseModule, writeFile };

8907
node_modules/magicast/dist/index.mjs generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,270 @@
import { Node, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportDeclaration, Program } from '@babel/types';
/**
* All Recast API functions take second parameter with configuration options,
* documented in options.js
*/
interface Options extends DeprecatedOptions {
/**
* If you want to use a different branch of esprima, or any other module
* that supports a .parse function, pass that module object to
* recast.parse as options.parser (legacy synonym: options.esprima).
* @default require("recast/parsers/esprima")
*/
parser?: any;
/**
* Number of spaces the pretty-printer should use per tab for
* indentation. If you do not pass this option explicitly, it will be
* (quite reliably!) inferred from the original code.
* @default 4
*/
tabWidth?: number;
/**
* If you really want the pretty-printer to use tabs instead of spaces,
* make this option true.
* @default false
*/
useTabs?: boolean;
/**
* The reprinting code leaves leading whitespace untouched unless it has
* to reindent a line, or you pass false for this option.
* @default true
*/
reuseWhitespace?: boolean;
/**
* Override this option to use a different line terminator, e.g. \r\n.
* @default require("os").EOL || "\n"
*/
lineTerminator?: string;
/**
* Some of the pretty-printer code (such as that for printing function
* parameter lists) makes a valiant attempt to prevent really long
* lines. You can adjust the limit by changing this option; however,
* there is no guarantee that line length will fit inside this limit.
* @default 74
*/
wrapColumn?: number;
/**
* Pass a string as options.sourceFileName to recast.parse to tell the
* reprinter to keep track of reused code so that it can construct a
* source map automatically.
* @default null
*/
sourceFileName?: string | null;
/**
* Pass a string as options.sourceMapName to recast.print, and (provided
* you passed options.sourceFileName earlier) the PrintResult of
* recast.print will have a .map property for the generated source map.
* @default null
*/
sourceMapName?: string | null;
/**
* If provided, this option will be passed along to the source map
* generator as a root directory for relative source file paths.
* @default null
*/
sourceRoot?: string | null;
/**
* If you provide a source map that was generated from a previous call
* to recast.print as options.inputSourceMap, the old source map will be
* composed with the new source map.
* @default null
*/
inputSourceMap?: string | null;
/**
* If you want esprima to generate .range information (recast only uses
* .loc internally), pass true for this option.
* @default false
*/
range?: boolean;
/**
* If you want esprima not to throw exceptions when it encounters
* non-fatal errors, keep this option true.
* @default true
*/
tolerant?: boolean;
/**
* If you want to override the quotes used in string literals, specify
* either "single", "double", or "auto" here ("auto" will select the one
* which results in the shorter literal) Otherwise, use double quotes.
* @default null
*/
quote?: "single" | "double" | "auto" | null;
/**
* Controls the printing of trailing commas in object literals, array
* expressions and function parameters.
*
* This option could either be:
* * Boolean - enable/disable in all contexts (objects, arrays and function params).
* * Object - enable/disable per context.
*
* Example:
* trailingComma: {
* objects: true,
* arrays: true,
* parameters: false,
* }
*
* @default false
*/
trailingComma?: boolean;
/**
* Controls the printing of spaces inside array brackets.
* See: http://eslint.org/docs/rules/array-bracket-spacing
* @default false
*/
arrayBracketSpacing?: boolean;
/**
* Controls the printing of spaces inside object literals,
* destructuring assignments, and import/export specifiers.
* See: http://eslint.org/docs/rules/object-curly-spacing
* @default true
*/
objectCurlySpacing?: boolean;
/**
* If you want parenthesis to wrap single-argument arrow function
* parameter lists, pass true for this option.
* @default false
*/
arrowParensAlways?: boolean;
/**
* There are 2 supported syntaxes (`,` and `;`) in Flow Object Types;
* The use of commas is in line with the more popular style and matches
* how objects are defined in JS, making it a bit more natural to write.
* @default true
*/
flowObjectCommas?: boolean;
/**
* Whether to return an array of .tokens on the root AST node.
* @default true
*/
tokens?: boolean;
}
interface DeprecatedOptions {
/** @deprecated */
esprima?: any;
}
interface CodeFormatOptions {
tabWidth?: number;
useTabs?: boolean;
wrapColumn?: number;
quote?: "single" | "double";
trailingComma?: boolean;
arrayBracketSpacing?: boolean;
objectCurlySpacing?: boolean;
arrowParensAlways?: boolean;
useSemi?: boolean;
}
declare function detectCodeFormat(code: string, userStyles?: CodeFormatOptions): CodeFormatOptions;
interface ProxyBase {
$ast: Node;
}
type ProxifiedArray<T extends any[] = unknown[]> = {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "array";
};
type ProxifiedFunctionCall<Args extends any[] = unknown[]> = ProxyBase & {
$type: "function-call";
$args: ProxifiedArray<Args>;
$callee: string;
};
type ProxifiedNewExpression<Args extends any[] = unknown[]> = ProxyBase & {
$type: "new-expression";
$args: ProxifiedArray<Args>;
$callee: string;
};
type ProxifiedArrowFunctionExpression<Params extends any[] = unknown[]> = ProxyBase & {
$type: "arrow-function-expression";
$params: ProxifiedArray<Params>;
$body: ProxifiedValue;
};
type ProxifiedObject<T extends object = object> = {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "object";
};
type ProxifiedIdentifier = ProxyBase & {
$type: "identifier";
$name: string;
};
type ProxifiedLogicalExpression = ProxyBase & {
$type: "logicalExpression";
};
type ProxifiedMemberExpression = ProxyBase & {
$type: "memberExpression";
};
type Proxified<T = any> = T extends number | string | null | undefined | boolean | bigint | symbol ? T : T extends any[] ? {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "array";
} : T extends object ? ProxyBase & {
[K in keyof T]: Proxified<T[K]>;
} & {
$type: "object";
} : T;
type ProxifiedModule<T extends object = Record<string, any>> = ProxyBase & {
$type: "module";
$code: string;
exports: ProxifiedObject<T>;
imports: ProxifiedImportsMap;
generate: (options?: GenerateOptions) => {
code: string;
map?: any;
};
};
type ProxifiedImportsMap = Record<string, ProxifiedImportItem> & ProxyBase & {
$type: "imports";
/** @deprecated Use `$prepend` instead */
$add: (item: ImportItemInput) => void;
$prepend: (item: ImportItemInput) => void;
$append: (item: ImportItemInput) => void;
$items: ProxifiedImportItem[];
};
interface ProxifiedImportItem extends ProxyBase {
$type: "import";
$ast: ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier;
$declaration: ImportDeclaration;
imported: string;
local: string;
from: string;
}
interface ImportItemInput {
local?: string;
imported: string;
from: string;
}
type ProxifiedValue = ProxifiedArray | ProxifiedFunctionCall | ProxifiedNewExpression | ProxifiedIdentifier | ProxifiedLogicalExpression | ProxifiedMemberExpression | ProxifiedObject | ProxifiedModule | ProxifiedImportsMap | ProxifiedImportItem | ProxifiedArrowFunctionExpression;
type ProxyType = ProxifiedValue["$type"];
interface Loc {
start?: {
line?: number;
column?: number;
token?: number;
};
end?: {
line?: number;
column?: number;
token?: number;
};
lines?: any;
}
interface Token {
type: string;
value: string;
loc?: Loc;
}
interface ParsedFileNode {
type: "file";
program: Program;
loc: Loc;
comments: null | any;
}
type GenerateOptions = Options & {
format?: false | CodeFormatOptions;
};
export { type CodeFormatOptions as C, type GenerateOptions as G, type ImportItemInput as I, type Loc as L, type Options as O, type ProxifiedModule as P, type Token as T, type Proxified as a, type ParsedFileNode as b, type ProxyBase as c, type ProxifiedArray as d, type ProxifiedFunctionCall as e, type ProxifiedNewExpression as f, type ProxifiedArrowFunctionExpression as g, type ProxifiedObject as h, type ProxifiedIdentifier as i, type ProxifiedLogicalExpression as j, type ProxifiedMemberExpression as k, type ProxifiedImportsMap as l, type ProxifiedImportItem as m, type ProxifiedValue as n, type ProxyType as o, detectCodeFormat as p };

View File

@@ -0,0 +1,270 @@
import { Node, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportDeclaration, Program } from '@babel/types';
/**
* All Recast API functions take second parameter with configuration options,
* documented in options.js
*/
interface Options extends DeprecatedOptions {
/**
* If you want to use a different branch of esprima, or any other module
* that supports a .parse function, pass that module object to
* recast.parse as options.parser (legacy synonym: options.esprima).
* @default require("recast/parsers/esprima")
*/
parser?: any;
/**
* Number of spaces the pretty-printer should use per tab for
* indentation. If you do not pass this option explicitly, it will be
* (quite reliably!) inferred from the original code.
* @default 4
*/
tabWidth?: number;
/**
* If you really want the pretty-printer to use tabs instead of spaces,
* make this option true.
* @default false
*/
useTabs?: boolean;
/**
* The reprinting code leaves leading whitespace untouched unless it has
* to reindent a line, or you pass false for this option.
* @default true
*/
reuseWhitespace?: boolean;
/**
* Override this option to use a different line terminator, e.g. \r\n.
* @default require("os").EOL || "\n"
*/
lineTerminator?: string;
/**
* Some of the pretty-printer code (such as that for printing function
* parameter lists) makes a valiant attempt to prevent really long
* lines. You can adjust the limit by changing this option; however,
* there is no guarantee that line length will fit inside this limit.
* @default 74
*/
wrapColumn?: number;
/**
* Pass a string as options.sourceFileName to recast.parse to tell the
* reprinter to keep track of reused code so that it can construct a
* source map automatically.
* @default null
*/
sourceFileName?: string | null;
/**
* Pass a string as options.sourceMapName to recast.print, and (provided
* you passed options.sourceFileName earlier) the PrintResult of
* recast.print will have a .map property for the generated source map.
* @default null
*/
sourceMapName?: string | null;
/**
* If provided, this option will be passed along to the source map
* generator as a root directory for relative source file paths.
* @default null
*/
sourceRoot?: string | null;
/**
* If you provide a source map that was generated from a previous call
* to recast.print as options.inputSourceMap, the old source map will be
* composed with the new source map.
* @default null
*/
inputSourceMap?: string | null;
/**
* If you want esprima to generate .range information (recast only uses
* .loc internally), pass true for this option.
* @default false
*/
range?: boolean;
/**
* If you want esprima not to throw exceptions when it encounters
* non-fatal errors, keep this option true.
* @default true
*/
tolerant?: boolean;
/**
* If you want to override the quotes used in string literals, specify
* either "single", "double", or "auto" here ("auto" will select the one
* which results in the shorter literal) Otherwise, use double quotes.
* @default null
*/
quote?: "single" | "double" | "auto" | null;
/**
* Controls the printing of trailing commas in object literals, array
* expressions and function parameters.
*
* This option could either be:
* * Boolean - enable/disable in all contexts (objects, arrays and function params).
* * Object - enable/disable per context.
*
* Example:
* trailingComma: {
* objects: true,
* arrays: true,
* parameters: false,
* }
*
* @default false
*/
trailingComma?: boolean;
/**
* Controls the printing of spaces inside array brackets.
* See: http://eslint.org/docs/rules/array-bracket-spacing
* @default false
*/
arrayBracketSpacing?: boolean;
/**
* Controls the printing of spaces inside object literals,
* destructuring assignments, and import/export specifiers.
* See: http://eslint.org/docs/rules/object-curly-spacing
* @default true
*/
objectCurlySpacing?: boolean;
/**
* If you want parenthesis to wrap single-argument arrow function
* parameter lists, pass true for this option.
* @default false
*/
arrowParensAlways?: boolean;
/**
* There are 2 supported syntaxes (`,` and `;`) in Flow Object Types;
* The use of commas is in line with the more popular style and matches
* how objects are defined in JS, making it a bit more natural to write.
* @default true
*/
flowObjectCommas?: boolean;
/**
* Whether to return an array of .tokens on the root AST node.
* @default true
*/
tokens?: boolean;
}
interface DeprecatedOptions {
/** @deprecated */
esprima?: any;
}
interface CodeFormatOptions {
tabWidth?: number;
useTabs?: boolean;
wrapColumn?: number;
quote?: "single" | "double";
trailingComma?: boolean;
arrayBracketSpacing?: boolean;
objectCurlySpacing?: boolean;
arrowParensAlways?: boolean;
useSemi?: boolean;
}
declare function detectCodeFormat(code: string, userStyles?: CodeFormatOptions): CodeFormatOptions;
interface ProxyBase {
$ast: Node;
}
type ProxifiedArray<T extends any[] = unknown[]> = {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "array";
};
type ProxifiedFunctionCall<Args extends any[] = unknown[]> = ProxyBase & {
$type: "function-call";
$args: ProxifiedArray<Args>;
$callee: string;
};
type ProxifiedNewExpression<Args extends any[] = unknown[]> = ProxyBase & {
$type: "new-expression";
$args: ProxifiedArray<Args>;
$callee: string;
};
type ProxifiedArrowFunctionExpression<Params extends any[] = unknown[]> = ProxyBase & {
$type: "arrow-function-expression";
$params: ProxifiedArray<Params>;
$body: ProxifiedValue;
};
type ProxifiedObject<T extends object = object> = {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "object";
};
type ProxifiedIdentifier = ProxyBase & {
$type: "identifier";
$name: string;
};
type ProxifiedLogicalExpression = ProxyBase & {
$type: "logicalExpression";
};
type ProxifiedMemberExpression = ProxyBase & {
$type: "memberExpression";
};
type Proxified<T = any> = T extends number | string | null | undefined | boolean | bigint | symbol ? T : T extends any[] ? {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "array";
} : T extends object ? ProxyBase & {
[K in keyof T]: Proxified<T[K]>;
} & {
$type: "object";
} : T;
type ProxifiedModule<T extends object = Record<string, any>> = ProxyBase & {
$type: "module";
$code: string;
exports: ProxifiedObject<T>;
imports: ProxifiedImportsMap;
generate: (options?: GenerateOptions) => {
code: string;
map?: any;
};
};
type ProxifiedImportsMap = Record<string, ProxifiedImportItem> & ProxyBase & {
$type: "imports";
/** @deprecated Use `$prepend` instead */
$add: (item: ImportItemInput) => void;
$prepend: (item: ImportItemInput) => void;
$append: (item: ImportItemInput) => void;
$items: ProxifiedImportItem[];
};
interface ProxifiedImportItem extends ProxyBase {
$type: "import";
$ast: ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier;
$declaration: ImportDeclaration;
imported: string;
local: string;
from: string;
}
interface ImportItemInput {
local?: string;
imported: string;
from: string;
}
type ProxifiedValue = ProxifiedArray | ProxifiedFunctionCall | ProxifiedNewExpression | ProxifiedIdentifier | ProxifiedLogicalExpression | ProxifiedMemberExpression | ProxifiedObject | ProxifiedModule | ProxifiedImportsMap | ProxifiedImportItem | ProxifiedArrowFunctionExpression;
type ProxyType = ProxifiedValue["$type"];
interface Loc {
start?: {
line?: number;
column?: number;
token?: number;
};
end?: {
line?: number;
column?: number;
token?: number;
};
lines?: any;
}
interface Token {
type: string;
value: string;
loc?: Loc;
}
interface ParsedFileNode {
type: "file";
program: Program;
loc: Loc;
comments: null | any;
}
type GenerateOptions = Options & {
format?: false | CodeFormatOptions;
};
export { type CodeFormatOptions as C, type GenerateOptions as G, type ImportItemInput as I, type Loc as L, type Options as O, type ProxifiedModule as P, type Token as T, type Proxified as a, type ParsedFileNode as b, type ProxyBase as c, type ProxifiedArray as d, type ProxifiedFunctionCall as e, type ProxifiedNewExpression as f, type ProxifiedArrowFunctionExpression as g, type ProxifiedObject as h, type ProxifiedIdentifier as i, type ProxifiedLogicalExpression as j, type ProxifiedMemberExpression as k, type ProxifiedImportsMap as l, type ProxifiedImportItem as m, type ProxifiedValue as n, type ProxyType as o, detectCodeFormat as p };

View File

@@ -0,0 +1,270 @@
import { Node, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportDeclaration, Program } from '@babel/types';
/**
* All Recast API functions take second parameter with configuration options,
* documented in options.js
*/
interface Options extends DeprecatedOptions {
/**
* If you want to use a different branch of esprima, or any other module
* that supports a .parse function, pass that module object to
* recast.parse as options.parser (legacy synonym: options.esprima).
* @default require("recast/parsers/esprima")
*/
parser?: any;
/**
* Number of spaces the pretty-printer should use per tab for
* indentation. If you do not pass this option explicitly, it will be
* (quite reliably!) inferred from the original code.
* @default 4
*/
tabWidth?: number;
/**
* If you really want the pretty-printer to use tabs instead of spaces,
* make this option true.
* @default false
*/
useTabs?: boolean;
/**
* The reprinting code leaves leading whitespace untouched unless it has
* to reindent a line, or you pass false for this option.
* @default true
*/
reuseWhitespace?: boolean;
/**
* Override this option to use a different line terminator, e.g. \r\n.
* @default require("os").EOL || "\n"
*/
lineTerminator?: string;
/**
* Some of the pretty-printer code (such as that for printing function
* parameter lists) makes a valiant attempt to prevent really long
* lines. You can adjust the limit by changing this option; however,
* there is no guarantee that line length will fit inside this limit.
* @default 74
*/
wrapColumn?: number;
/**
* Pass a string as options.sourceFileName to recast.parse to tell the
* reprinter to keep track of reused code so that it can construct a
* source map automatically.
* @default null
*/
sourceFileName?: string | null;
/**
* Pass a string as options.sourceMapName to recast.print, and (provided
* you passed options.sourceFileName earlier) the PrintResult of
* recast.print will have a .map property for the generated source map.
* @default null
*/
sourceMapName?: string | null;
/**
* If provided, this option will be passed along to the source map
* generator as a root directory for relative source file paths.
* @default null
*/
sourceRoot?: string | null;
/**
* If you provide a source map that was generated from a previous call
* to recast.print as options.inputSourceMap, the old source map will be
* composed with the new source map.
* @default null
*/
inputSourceMap?: string | null;
/**
* If you want esprima to generate .range information (recast only uses
* .loc internally), pass true for this option.
* @default false
*/
range?: boolean;
/**
* If you want esprima not to throw exceptions when it encounters
* non-fatal errors, keep this option true.
* @default true
*/
tolerant?: boolean;
/**
* If you want to override the quotes used in string literals, specify
* either "single", "double", or "auto" here ("auto" will select the one
* which results in the shorter literal) Otherwise, use double quotes.
* @default null
*/
quote?: "single" | "double" | "auto" | null;
/**
* Controls the printing of trailing commas in object literals, array
* expressions and function parameters.
*
* This option could either be:
* * Boolean - enable/disable in all contexts (objects, arrays and function params).
* * Object - enable/disable per context.
*
* Example:
* trailingComma: {
* objects: true,
* arrays: true,
* parameters: false,
* }
*
* @default false
*/
trailingComma?: boolean;
/**
* Controls the printing of spaces inside array brackets.
* See: http://eslint.org/docs/rules/array-bracket-spacing
* @default false
*/
arrayBracketSpacing?: boolean;
/**
* Controls the printing of spaces inside object literals,
* destructuring assignments, and import/export specifiers.
* See: http://eslint.org/docs/rules/object-curly-spacing
* @default true
*/
objectCurlySpacing?: boolean;
/**
* If you want parenthesis to wrap single-argument arrow function
* parameter lists, pass true for this option.
* @default false
*/
arrowParensAlways?: boolean;
/**
* There are 2 supported syntaxes (`,` and `;`) in Flow Object Types;
* The use of commas is in line with the more popular style and matches
* how objects are defined in JS, making it a bit more natural to write.
* @default true
*/
flowObjectCommas?: boolean;
/**
* Whether to return an array of .tokens on the root AST node.
* @default true
*/
tokens?: boolean;
}
interface DeprecatedOptions {
/** @deprecated */
esprima?: any;
}
interface CodeFormatOptions {
tabWidth?: number;
useTabs?: boolean;
wrapColumn?: number;
quote?: "single" | "double";
trailingComma?: boolean;
arrayBracketSpacing?: boolean;
objectCurlySpacing?: boolean;
arrowParensAlways?: boolean;
useSemi?: boolean;
}
declare function detectCodeFormat(code: string, userStyles?: CodeFormatOptions): CodeFormatOptions;
interface ProxyBase {
$ast: Node;
}
type ProxifiedArray<T extends any[] = unknown[]> = {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "array";
};
type ProxifiedFunctionCall<Args extends any[] = unknown[]> = ProxyBase & {
$type: "function-call";
$args: ProxifiedArray<Args>;
$callee: string;
};
type ProxifiedNewExpression<Args extends any[] = unknown[]> = ProxyBase & {
$type: "new-expression";
$args: ProxifiedArray<Args>;
$callee: string;
};
type ProxifiedArrowFunctionExpression<Params extends any[] = unknown[]> = ProxyBase & {
$type: "arrow-function-expression";
$params: ProxifiedArray<Params>;
$body: ProxifiedValue;
};
type ProxifiedObject<T extends object = object> = {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "object";
};
type ProxifiedIdentifier = ProxyBase & {
$type: "identifier";
$name: string;
};
type ProxifiedLogicalExpression = ProxyBase & {
$type: "logicalExpression";
};
type ProxifiedMemberExpression = ProxyBase & {
$type: "memberExpression";
};
type Proxified<T = any> = T extends number | string | null | undefined | boolean | bigint | symbol ? T : T extends any[] ? {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "array";
} : T extends object ? ProxyBase & {
[K in keyof T]: Proxified<T[K]>;
} & {
$type: "object";
} : T;
type ProxifiedModule<T extends object = Record<string, any>> = ProxyBase & {
$type: "module";
$code: string;
exports: ProxifiedObject<T>;
imports: ProxifiedImportsMap;
generate: (options?: GenerateOptions) => {
code: string;
map?: any;
};
};
type ProxifiedImportsMap = Record<string, ProxifiedImportItem> & ProxyBase & {
$type: "imports";
/** @deprecated Use `$prepend` instead */
$add: (item: ImportItemInput) => void;
$prepend: (item: ImportItemInput) => void;
$append: (item: ImportItemInput) => void;
$items: ProxifiedImportItem[];
};
interface ProxifiedImportItem extends ProxyBase {
$type: "import";
$ast: ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier;
$declaration: ImportDeclaration;
imported: string;
local: string;
from: string;
}
interface ImportItemInput {
local?: string;
imported: string;
from: string;
}
type ProxifiedValue = ProxifiedArray | ProxifiedFunctionCall | ProxifiedNewExpression | ProxifiedIdentifier | ProxifiedLogicalExpression | ProxifiedMemberExpression | ProxifiedObject | ProxifiedModule | ProxifiedImportsMap | ProxifiedImportItem | ProxifiedArrowFunctionExpression;
type ProxyType = ProxifiedValue["$type"];
interface Loc {
start?: {
line?: number;
column?: number;
token?: number;
};
end?: {
line?: number;
column?: number;
token?: number;
};
lines?: any;
}
interface Token {
type: string;
value: string;
loc?: Loc;
}
interface ParsedFileNode {
type: "file";
program: Program;
loc: Loc;
comments: null | any;
}
type GenerateOptions = Options & {
format?: false | CodeFormatOptions;
};
export { type CodeFormatOptions as C, type GenerateOptions as G, type ImportItemInput as I, type Loc as L, type Options as O, type ProxifiedModule as P, type Token as T, type Proxified as a, type ParsedFileNode as b, type ProxyBase as c, type ProxifiedArray as d, type ProxifiedFunctionCall as e, type ProxifiedNewExpression as f, type ProxifiedArrowFunctionExpression as g, type ProxifiedObject as h, type ProxifiedIdentifier as i, type ProxifiedLogicalExpression as j, type ProxifiedMemberExpression as k, type ProxifiedImportsMap as l, type ProxifiedImportItem as m, type ProxifiedValue as n, type ProxyType as o, detectCodeFormat as p };