🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

1
node_modules/estree-util-attach-comments/index.d.ts generated vendored Normal file
View file

@ -0,0 +1 @@
export {attachComments} from './lib/index.js'

1
node_modules/estree-util-attach-comments/index.js generated vendored Normal file
View file

@ -0,0 +1 @@
export {attachComments} from './lib/index.js'

View file

@ -0,0 +1,53 @@
/**
* Attach semistandard estree comment nodes to the tree.
*
* This mutates the given `tree`.
* It takes `comments`, walks the tree, and adds comments as close as possible
* to where they originated.
*
* Comment nodes are given two boolean fields: `leading` (`true` for
* `/* a *\/ b`) and `trailing` (`true` for `a /* b *\/`).
* Both fields are `false` for dangling comments: `[/* a *\/]`.
* This is what `recast` uses too, and is somewhat similar to Babel, which is
* not estree but instead uses `leadingComments`, `trailingComments`, and
* `innerComments` arrays on nodes.
*
* The algorithm checks any node: even recent (or future) proposals or
* nonstandard syntax such as JSX, because it ducktypes to find nodes instead
* of having a list of visitor keys.
*
* The algorithm supports `loc` fields (line/column), `range` fields (offsets),
* and direct `start` / `end` fields.
*
* @template {EstreeNode} Tree
* Node type.
* @param {Tree} tree
* Tree to attach to.
* @param {Array<EstreeComment> | null | undefined} [comments]
* List of comments.
* @returns {Tree}
* Given tree.
*/
export function attachComments<Tree extends import('estree').BaseNode>(
tree: Tree,
comments?: Array<EstreeComment> | null | undefined
): Tree
export type EstreeNode = import('estree').BaseNode
export type EstreeComment = import('estree').Comment
/**
* Info passed around.
*/
export type State = {
/**
* Comments.
*/
comments: Array<EstreeComment>
/**
* Index of comment.
*/
index: number
}
export type Fields = {
leading: boolean
trailing: boolean
}

191
node_modules/estree-util-attach-comments/lib/index.js generated vendored Normal file
View file

@ -0,0 +1,191 @@
/**
* @typedef {import('estree').BaseNode} EstreeNode
* @typedef {import('estree').Comment} EstreeComment
*
* @typedef State
* Info passed around.
* @property {Array<EstreeComment>} comments
* Comments.
* @property {number} index
* Index of comment.
*
* @typedef Fields
* @property {boolean} leading
* @property {boolean} trailing
*/
const own = {}.hasOwnProperty
/**
* Attach semistandard estree comment nodes to the tree.
*
* This mutates the given `tree`.
* It takes `comments`, walks the tree, and adds comments as close as possible
* to where they originated.
*
* Comment nodes are given two boolean fields: `leading` (`true` for
* `/* a *\/ b`) and `trailing` (`true` for `a /* b *\/`).
* Both fields are `false` for dangling comments: `[/* a *\/]`.
* This is what `recast` uses too, and is somewhat similar to Babel, which is
* not estree but instead uses `leadingComments`, `trailingComments`, and
* `innerComments` arrays on nodes.
*
* The algorithm checks any node: even recent (or future) proposals or
* nonstandard syntax such as JSX, because it ducktypes to find nodes instead
* of having a list of visitor keys.
*
* The algorithm supports `loc` fields (line/column), `range` fields (offsets),
* and direct `start` / `end` fields.
*
* @template {EstreeNode} Tree
* Node type.
* @param {Tree} tree
* Tree to attach to.
* @param {Array<EstreeComment> | null | undefined} [comments]
* List of comments.
* @returns {Tree}
* Given tree.
*/
// To do: next major: dont return given `tree`.
export function attachComments(tree, comments) {
const list = (comments || []).concat().sort(compare)
if (list.length > 0) walk(tree, {comments: list, index: 0})
return tree
}
/**
* Attach semistandard estree comment nodes to the tree.
*
* @param {EstreeNode} node
* Node.
* @param {State} state
* Info passed around.
* @returns {void}
* Nothing.
*/
function walk(node, state) {
// Done, we can quit.
if (state.index === state.comments.length) {
return
}
/** @type {Array<EstreeNode>} */
const children = []
/** @type {Array<EstreeComment>} */
const comments = []
/** @type {string} */
let key
// Find all children of `node`
for (key in node) {
if (own.call(node, key)) {
/** @type {EstreeNode | Array<EstreeNode>} */
// @ts-expect-error: indexable.
const value = node[key]
// Ignore comments.
if (value && typeof value === 'object' && key !== 'comments') {
if (Array.isArray(value)) {
let index = -1
while (++index < value.length) {
if (value[index] && typeof value[index].type === 'string') {
children.push(value[index])
}
}
} else if (typeof value.type === 'string') {
children.push(value)
}
}
}
}
// Sort the children.
children.sort(compare)
// Initial comments.
comments.push(...slice(state, node, false, {leading: true, trailing: false}))
let index = -1
while (++index < children.length) {
walk(children[index], state)
}
// Dangling or trailing comments.
comments.push(
...slice(state, node, true, {
leading: false,
trailing: children.length > 0
})
)
if (comments.length > 0) {
// @ts-expect-error, yes, because theyre nonstandard.
node.comments = comments
}
}
/**
* @param {State} state
* Info passed around.
* @param {EstreeNode} node
* Node.
* @param {boolean} compareEnd
* Whether to compare on the end (default is on start).
* @param {Fields} fields
* Fields.
* @returns {Array<EstreeComment>}
* Slice from `state.comments`.
*/
function slice(state, node, compareEnd, fields) {
/** @type {Array<EstreeComment>} */
const result = []
while (
state.comments[state.index] &&
compare(state.comments[state.index], node, compareEnd) < 1
) {
result.push(Object.assign({}, state.comments[state.index++], fields))
}
return result
}
/**
* Sort two nodes (or comments).
*
* @param {EstreeNode | EstreeComment} left
* A node.
* @param {EstreeNode | EstreeComment} right
* The other node.
* @param {boolean | undefined} [compareEnd=false]
* Compare on `end` of `right`, default is to compare on `start`.
* @returns {number}
* Sorting.
*/
function compare(left, right, compareEnd) {
const field = compareEnd ? 'end' : 'start'
// Offsets.
if (left.range && right.range) {
return left.range[0] - right.range[compareEnd ? 1 : 0]
}
// Points.
if (left.loc && left.loc.start && right.loc && right.loc[field]) {
return (
left.loc.start.line - right.loc[field].line ||
left.loc.start.column - right.loc[field].column
)
}
// Just `start` (and `end`) on nodes.
// Default in most parsers.
if ('start' in left && field in right) {
// @ts-expect-error Added by Acorn
return left.start - right[field]
}
return Number.NaN
}

22
node_modules/estree-util-attach-comments/license generated vendored Normal file
View file

@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
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.

85
node_modules/estree-util-attach-comments/package.json generated vendored Normal file
View file

@ -0,0 +1,85 @@
{
"name": "estree-util-attach-comments",
"version": "2.1.1",
"description": "Attach comments to estree nodes",
"license": "MIT",
"keywords": [
"estree",
"ast",
"ecmascript",
"javascript",
"tree",
"comment",
"acorn",
"espree",
"recast"
],
"repository": "syntax-tree/estree-util-attach-comments",
"bugs": "https://github.com/syntax-tree/estree-util-attach-comments/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/estree": "^1.0.0"
},
"devDependencies": {
"@types/acorn": "^4.0.0",
"@types/node": "^18.0.0",
"acorn": "^8.0.0",
"c8": "^7.0.0",
"estree-util-visit": "^1.0.0",
"prettier": "^2.0.0",
"recast": "^0.22.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.53.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true,
"rules": {
"max-depth": "off"
}
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}

233
node_modules/estree-util-attach-comments/readme.md generated vendored Normal file
View file

@ -0,0 +1,233 @@
# estree-util-attach-comments
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[estree][] utility attach semistandard comment nodes (such as from [acorn][]) to
the nodes in that tree.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`attachComments(tree, comments)`](#attachcommentstree-comments)
* [Types](#types)
* [Compatibility](#compatibility)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a utility that you can use to embed comment nodes *inside* a
tree.
This is useful because certain estree parsers give you an array (espree and
acorn) whereas other estree tools expect comments to be embedded on nodes in the
tree.
This package uses one `comments` array where each comment has `leading` and
`trailing` fields, as applied by `acorn`, but does not support the slightly
different non-standard comments made by `espree`.
## When should I use this?
You can use this package when working with comments from Acorn and later working
with a tool such as recast or Babel.
## Install
This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
```sh
npm install estree-util-attach-comments
```
In Deno with [`esm.sh`][esmsh]:
```js
import {attachComments} from 'https://esm.sh/estree-util-attach-comments@2'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {attachComments} from 'https://esm.sh/estree-util-attach-comments@2?bundle'
</script>
```
## Use
Say our document `index.js` contains:
```js
/* 1 */ function /* 2 */ a /* 3 */ (/* 4 */b) /* 5 */ { /* 6 */ return /* 7 */ b + /* 8 */ 1 /* 9 */ }
```
…and our module `example.js` looks as follows:
```js
import fs from 'node:fs/promises'
import * as acorn from 'acorn'
import recast from 'recast'
import {attachComments} from 'estree-util-attach-comments'
const code = String(await fs.readFile('index.js'))
const comments = []
const tree = acorn.parse(code, {ecmaVersion: 2020, onComment: comments})
attachComments(tree, comments)
console.log(recast.print(tree).code)
```
Yields:
```js
/* 1 */
function /* 2 */
a(
/* 3 */
/* 4 */
b
) /* 5 */
{
/* 6 */
return (
/* 7 */
b + /* 8 */
1
);
}/* 9 */
```
> 👉 **Note**: the lines are added by `recast` in this case.
> And, some of these weird comments are off, but theyre pretty close.
## API
This package exports the identifier [`attachComments`][attachcomments].
There is no default export.
### `attachComments(tree, comments)`
Attach semistandard estree comment nodes to the tree.
This mutates the given [`tree`][estree].
It takes `comments`, walks the tree, and adds comments as close as possible
to where they originated.
Comment nodes are given two boolean fields: `leading` (`true` for `/* a */ b`)
and `trailing` (`true` for `a /* b */`).
Both fields are `false` for dangling comments: `[/* a */]`.
This is what `recast` uses too, and is somewhat similar to Babel, which is not
estree but instead uses `leadingComments`, `trailingComments`, and
`innerComments` arrays on nodes.
The algorithm checks any node: even recent (or future) proposals or nonstandard
syntax such as JSX, because it ducktypes to find nodes instead of having a list
of visitor keys.
The algorithm supports `loc` fields (line/column), `range` fields (offsets),
and direct `start` / `end` fields.
###### Parameters
* `tree` ([`Program`][program])
— tree to attach to
* `comments` (`Array<EstreeComment>`)
— list of comments
###### Returns
The given `tree` ([`Program`][program]).
## Types
This package is fully typed with [TypeScript][].
It exports no additional types.
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
## Contribute
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
ways to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/syntax-tree/estree-util-attach-comments/workflows/main/badge.svg
[build]: https://github.com/syntax-tree/estree-util-attach-comments/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/estree-util-attach-comments.svg
[coverage]: https://codecov.io/github/syntax-tree/estree-util-attach-comments
[downloads-badge]: https://img.shields.io/npm/dm/estree-util-attach-comments.svg
[downloads]: https://www.npmjs.com/package/estree-util-attach-comments
[size-badge]: https://img.shields.io/bundlephobia/minzip/estree-util-attach-comments.svg
[size]: https://bundlephobia.com/result?p=estree-util-attach-comments
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/syntax-tree/unist/discussions
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[typescript]: https://www.typescriptlang.org
[license]: license
[author]: https://wooorm.com
[health]: https://github.com/syntax-tree/.github
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
[acorn]: https://github.com/acornjs/acorn
[estree]: https://github.com/estree/estree
[program]: https://github.com/estree/estree/blob/master/es5.md#programs
[attachcomments]: #attachcommentstree-comments