fix: vite
This commit is contained in:
7
node_modules/esrap/LICENSE
generated
vendored
Normal file
7
node_modules/esrap/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2023-2025 [these people](https://github.com/sveltejs/esrap/graphs/contributors)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
78
node_modules/esrap/README.md
generated
vendored
Normal file
78
node_modules/esrap/README.md
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
# esrap
|
||||
|
||||
Parse in reverse. AST goes in, code comes out.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import { print } from 'esrap';
|
||||
|
||||
const { code, map } = print({
|
||||
type: 'Program',
|
||||
body: [
|
||||
{
|
||||
type: 'ExpressionStatement',
|
||||
expression: {
|
||||
callee: {
|
||||
type: 'Identifier',
|
||||
name: 'alert'
|
||||
},
|
||||
arguments: [
|
||||
{
|
||||
type: 'Literal',
|
||||
value: 'hello world!'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
console.log(code); // alert('hello world!');
|
||||
```
|
||||
|
||||
If the nodes of the input AST have `loc` properties (e.g. the AST was generated with [`acorn`](https://github.com/acornjs/acorn/tree/master/acorn/#interface) with the `locations` option set), sourcemap mappings will be created.
|
||||
|
||||
## Options
|
||||
|
||||
You can pass the following options:
|
||||
|
||||
```js
|
||||
const { code, map } = print(ast, {
|
||||
// Populate the `sources` field of the resulting sourcemap
|
||||
// (note that the AST is assumed to come from a single file)
|
||||
sourceMapSource: 'input.js',
|
||||
|
||||
// Populate the `sourcesContent` field of the resulting sourcemap
|
||||
sourceMapContent: fs.readFileSync('input.js', 'utf-8'),
|
||||
|
||||
// Whether to encode the `mappings` field of the resulting sourcemap
|
||||
// as a VLQ string, rather than an unencoded array. Defaults to `true`
|
||||
sourceMapEncodeMappings: false,
|
||||
|
||||
// String to use for indentation — defaults to '\t'
|
||||
indent: ' ',
|
||||
|
||||
// Whether to wrap strings in single or double quotes — defaults to 'single'.
|
||||
// This only applies to string literals with no `raw` value, which generally
|
||||
// means the AST node was generated programmatically, rather than parsed
|
||||
// from an original source
|
||||
quotes: 'single'
|
||||
});
|
||||
```
|
||||
|
||||
## TypeScript
|
||||
|
||||
`esrap` can also print TypeScript nodes, assuming they match the ESTree-like [`@typescript-eslint/types`](https://www.npmjs.com/package/@typescript-eslint/types).
|
||||
|
||||
## Why not just use Prettier?
|
||||
|
||||
Because it's ginormous.
|
||||
|
||||
## Developing
|
||||
|
||||
This repo uses [pnpm](https://pnpm.io). Once it's installed, do `pnpm install` to install dependencies, and `pnpm test` to run the tests.
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
48
node_modules/esrap/package.json
generated
vendored
Normal file
48
node_modules/esrap/package.json
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "esrap",
|
||||
"version": "1.4.3",
|
||||
"description": "Parse in reverse",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sveltejs/esrap.git"
|
||||
},
|
||||
"type": "module",
|
||||
"files": [
|
||||
"src",
|
||||
"types"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./types/index.d.ts",
|
||||
"default": "./src/index.js"
|
||||
}
|
||||
},
|
||||
"types": "./types/index.d.ts",
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^2.27.11",
|
||||
"@typescript-eslint/types": "^8.2.0",
|
||||
"@vitest/ui": "^2.1.1",
|
||||
"acorn": "^8.11.3",
|
||||
"acorn-typescript": "^1.4.13",
|
||||
"dts-buddy": "^0.5.4",
|
||||
"prettier": "^3.0.3",
|
||||
"typescript": "^5.7.2",
|
||||
"vitest": "^2.1.1",
|
||||
"zimmerframe": "^1.0.0"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/sourcemap-codec": "^1.4.15"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"changeset:version": "changeset version",
|
||||
"changeset:publish": "changeset publish",
|
||||
"check": "tsc",
|
||||
"sandbox": "node test/sandbox/index.js",
|
||||
"test": "vitest --run",
|
||||
"test:ui": "vitest --ui"
|
||||
}
|
||||
}
|
||||
1625
node_modules/esrap/src/handlers.js
generated
vendored
Normal file
1625
node_modules/esrap/src/handlers.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
159
node_modules/esrap/src/index.js
generated
vendored
Normal file
159
node_modules/esrap/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
/** @import { TSESTree } from '@typescript-eslint/types' */
|
||||
/** @import { Command, PrintOptions, State } from './types' */
|
||||
import { handle } from './handlers.js';
|
||||
import { encode } from '@jridgewell/sourcemap-codec';
|
||||
|
||||
/** @type {(str: string) => string} str */
|
||||
let btoa = () => {
|
||||
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
||||
};
|
||||
|
||||
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
||||
btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
|
||||
// @ts-expect-error
|
||||
} else if (typeof Buffer === 'function') {
|
||||
// @ts-expect-error
|
||||
btoa = (str) => Buffer.from(str, 'utf-8').toString('base64');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ type: string, [key: string]: any }} node
|
||||
* @param {PrintOptions} opts
|
||||
* @returns {{ code: string, map: any }} // TODO
|
||||
*/
|
||||
export function print(node, opts = {}) {
|
||||
if (Array.isArray(node)) {
|
||||
return print(
|
||||
{
|
||||
type: 'Program',
|
||||
body: node,
|
||||
sourceType: 'module'
|
||||
},
|
||||
opts
|
||||
);
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
const state = {
|
||||
commands: [],
|
||||
comments: [],
|
||||
multiline: false,
|
||||
quote: opts.quotes === 'double' ? '"' : "'"
|
||||
};
|
||||
|
||||
handle(/** @type {TSESTree.Node} */ (node), state);
|
||||
|
||||
/** @typedef {[number, number, number, number]} Segment */
|
||||
|
||||
let code = '';
|
||||
let current_column = 0;
|
||||
|
||||
/** @type {Segment[][]} */
|
||||
let mappings = [];
|
||||
|
||||
/** @type {Segment[]} */
|
||||
let current_line = [];
|
||||
|
||||
/** @param {string} str */
|
||||
function append(str) {
|
||||
code += str;
|
||||
|
||||
for (let i = 0; i < str.length; i += 1) {
|
||||
if (str[i] === '\n') {
|
||||
mappings.push(current_line);
|
||||
current_line = [];
|
||||
current_column = 0;
|
||||
} else {
|
||||
current_column += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let newline = '\n';
|
||||
const indent = opts.indent ?? '\t';
|
||||
|
||||
/** @param {Command} command */
|
||||
function run(command) {
|
||||
if (typeof command === 'string') {
|
||||
append(command);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Array.isArray(command)) {
|
||||
for (let i = 0; i < command.length; i += 1) {
|
||||
run(command[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
switch (command.type) {
|
||||
case 'Location':
|
||||
current_line.push([
|
||||
current_column,
|
||||
0, // source index is always zero
|
||||
command.line - 1,
|
||||
command.column
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'Newline':
|
||||
append(newline);
|
||||
break;
|
||||
|
||||
case 'Indent':
|
||||
newline += indent;
|
||||
break;
|
||||
|
||||
case 'Dedent':
|
||||
newline = newline.slice(0, -indent.length);
|
||||
break;
|
||||
|
||||
case 'Comment':
|
||||
if (command.comment.type === 'Line') {
|
||||
append(`//${command.comment.value}`);
|
||||
} else {
|
||||
append(`/*${command.comment.value.replace(/\n/g, newline)}*/`);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < state.commands.length; i += 1) {
|
||||
run(state.commands[i]);
|
||||
}
|
||||
|
||||
mappings.push(current_line);
|
||||
|
||||
const map = {
|
||||
version: 3,
|
||||
/** @type {string[]} */
|
||||
names: [],
|
||||
sources: [opts.sourceMapSource || null],
|
||||
sourcesContent: [opts.sourceMapContent || null],
|
||||
mappings:
|
||||
opts.sourceMapEncodeMappings == undefined || opts.sourceMapEncodeMappings
|
||||
? encode(mappings)
|
||||
: mappings
|
||||
};
|
||||
|
||||
Object.defineProperties(map, {
|
||||
toString: {
|
||||
enumerable: false,
|
||||
value: function toString() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
},
|
||||
toUrl: {
|
||||
enumerable: false,
|
||||
value: function toUrl() {
|
||||
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
code,
|
||||
map
|
||||
};
|
||||
}
|
||||
2
node_modules/esrap/src/public.d.ts
generated
vendored
Normal file
2
node_modules/esrap/src/public.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export { PrintOptions } from './types';
|
||||
export * from './index';
|
||||
77
node_modules/esrap/src/types.d.ts
generated
vendored
Normal file
77
node_modules/esrap/src/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
import { TSESTree } from '@typescript-eslint/types';
|
||||
|
||||
type Handler<T> = (node: T, state: State) => undefined;
|
||||
|
||||
export type Handlers = {
|
||||
[T in TSESTree.Node['type']]: Handler<Extract<TSESTree.Node, { type: T }>>;
|
||||
};
|
||||
|
||||
export type TypeAnnotationNodes =
|
||||
| TSESTree.TypeNode
|
||||
| TSESTree.TypeElement
|
||||
| TSESTree.TSTypeAnnotation
|
||||
| TSESTree.TSPropertySignature
|
||||
| TSESTree.TSTypeParameter
|
||||
| TSESTree.TSTypeParameterDeclaration
|
||||
| TSESTree.TSTypeParameterInstantiation
|
||||
| TSESTree.TSEnumMember
|
||||
| TSESTree.TSInterfaceHeritage
|
||||
| TSESTree.TSClassImplements
|
||||
| TSExpressionWithTypeArguments;
|
||||
|
||||
type TSExpressionWithTypeArguments = {
|
||||
type: 'TSExpressionWithTypeArguments';
|
||||
expression: any;
|
||||
};
|
||||
|
||||
// `@typescript-eslint/types` differs from the official `estree` spec by handling
|
||||
// comments differently. This is a node which we can use to ensure type saftey.
|
||||
export type NodeWithComments = {
|
||||
leadingComments?: TSESTree.Comment[] | undefined;
|
||||
trailingComments?: TSESTree.Comment[] | undefined;
|
||||
} & TSESTree.Node;
|
||||
|
||||
export interface State {
|
||||
commands: Command[];
|
||||
comments: TSESTree.Comment[];
|
||||
multiline: boolean;
|
||||
quote: "'" | '"';
|
||||
}
|
||||
|
||||
export interface Location {
|
||||
type: 'Location';
|
||||
line: number;
|
||||
column: number;
|
||||
}
|
||||
|
||||
export interface Newline {
|
||||
type: 'Newline';
|
||||
}
|
||||
|
||||
export interface Indent {
|
||||
type: 'Indent';
|
||||
}
|
||||
|
||||
export interface Dedent {
|
||||
type: 'Dedent';
|
||||
}
|
||||
|
||||
export interface IndentChange {
|
||||
type: 'IndentChange';
|
||||
offset: number;
|
||||
}
|
||||
|
||||
export interface CommentChunk {
|
||||
type: 'Comment';
|
||||
comment: TSESTree.Comment;
|
||||
}
|
||||
|
||||
export type Command = string | Location | Newline | Indent | Dedent | CommentChunk | Command[];
|
||||
|
||||
export interface PrintOptions {
|
||||
sourceMapSource?: string;
|
||||
sourceMapContent?: string;
|
||||
sourceMapEncodeMappings?: boolean; // default true
|
||||
indent?: string; // default tab
|
||||
quotes?: 'single' | 'double'; // default single
|
||||
}
|
||||
23
node_modules/esrap/types/index.d.ts
generated
vendored
Normal file
23
node_modules/esrap/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
declare module 'esrap' {
|
||||
export interface PrintOptions {
|
||||
sourceMapSource?: string;
|
||||
sourceMapContent?: string;
|
||||
sourceMapEncodeMappings?: boolean; // default true
|
||||
indent?: string; // default tab
|
||||
quotes?: 'single' | 'double'; // default single
|
||||
}
|
||||
/**
|
||||
* @returns // TODO
|
||||
*/
|
||||
export function print(node: {
|
||||
type: string;
|
||||
[key: string]: any;
|
||||
}, opts?: PrintOptions): {
|
||||
code: string;
|
||||
map: any;
|
||||
};
|
||||
|
||||
export {};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
18
node_modules/esrap/types/index.d.ts.map
generated
vendored
Normal file
18
node_modules/esrap/types/index.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"version": 3,
|
||||
"file": "index.d.ts",
|
||||
"names": [
|
||||
"PrintOptions",
|
||||
"print"
|
||||
],
|
||||
"sources": [
|
||||
"../src/types.d.ts",
|
||||
"../src/index.js"
|
||||
],
|
||||
"sourcesContent": [
|
||||
null,
|
||||
null
|
||||
],
|
||||
"mappings": ";kBAsEiBA,YAAYA;;;;;;;;;;iBC/CbC,KAAKA",
|
||||
"ignoreList": []
|
||||
}
|
||||
Reference in New Issue
Block a user