Initial import with skill sheet working

This commit is contained in:
2024-12-04 00:11:23 +01:00
commit 9050c80ab4
4488 changed files with 671048 additions and 0 deletions

242
node_modules/parse-imports/dist/index.cjs generated vendored Normal file
View File

@@ -0,0 +1,242 @@
var esModuleLexer = require('es-module-lexer');
var assert = require('node:assert');
var slashes = require('slashes');
var module$1 = require('node:module');
var node_path = require('node:path');
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
const separatorRegex = /^(?:\s+|,)$/u;
const skipSeparators = (imported, i) => {
while (i < imported.length && separatorRegex.test(imported[i])) {
i++;
}
return i;
};
const skipNonSeparators = (imported, i) => {
while (i < imported.length && !separatorRegex.test(imported[i])) {
i++;
}
return i;
};
const parseDefaultImport = (importClauseString, i) => {
const startIndex = i;
i = skipNonSeparators(importClauseString, i);
return {
defaultImport: importClauseString.slice(startIndex, i),
i
};
};
const parseNamedImports = (importClauseString, i) => {
const startIndex = ++i;
while (i < importClauseString.length && importClauseString[i] !== `}`) {
i++;
}
const namedImports = importClauseString.slice(startIndex, i++).split(`,`).map(namedImport => {
namedImport = namedImport.trim();
if (namedImport.includes(` `)) {
const components = namedImport.split(` `);
return {
specifier: components[0],
binding: components.at(-1)
};
}
return {
specifier: namedImport,
binding: namedImport
};
}).filter(({
specifier
}) => specifier.length > 0);
return {
namedImports,
i
};
};
const parseNamespaceImport = (importClauseString, i) => {
i++;
i = skipSeparators(importClauseString, i);
i += `as`.length;
i = skipSeparators(importClauseString, i);
const startIndex = i;
i = skipNonSeparators(importClauseString, i);
return {
namespaceImport: importClauseString.slice(startIndex, i),
i
};
};
// Assumes import clause is syntactically valid
const parseImportClause = importClauseString => {
let defaultImport;
let namespaceImport;
const namedImports = [];
for (let i = 0; i < importClauseString.length; i++) {
if (separatorRegex.test(importClauseString[i])) {
continue;
}
if (importClauseString[i] === `{`) {
let newNamedImports;
({
namedImports: newNamedImports,
i
} = parseNamedImports(importClauseString, i));
namedImports.push(...newNamedImports);
} else if (importClauseString[i] === `*`) {
({
namespaceImport,
i
} = parseNamespaceImport(importClauseString, i));
} else {
({
defaultImport,
i
} = parseDefaultImport(importClauseString, i));
}
}
return {
default: defaultImport,
namespace: namespaceImport,
named: namedImports
};
};
// Assumes the string is syntactically valid
const isConstantStringLiteral = stringLiteral => {
const quote = [`'`, `"`, `\``].find(quoteCandidate => stringLiteral.startsWith(quoteCandidate) && stringLiteral.endsWith(quoteCandidate));
if (quote == null) {
return false;
}
for (let i = 1; i < stringLiteral.length - 1; i++) {
// Check for end of string literal before end of stringLiteral
if (stringLiteral[i] === quote && stringLiteral[i - 1] !== `\\`) {
return false;
}
// Check for interpolated value in template literal
if (quote === `\`` && stringLiteral.slice(i, i + 2) === `\${` && stringLiteral[i - 1] !== `\\`) {
return false;
}
}
return true;
};
const builtinModules = new Set(module$1.builtinModules);
const parseType = moduleSpecifier => {
if (moduleSpecifier.length === 0) {
return `invalid`;
}
if (moduleSpecifier.startsWith(`/`)) {
return `absolute`;
}
if (moduleSpecifier.startsWith(`.`)) {
return `relative`;
}
if (builtinModules.has(moduleSpecifier)) {
return `builtin`;
}
return `package`;
};
const require$1 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
const resolve = (from, to) => {
try {
return require$1.resolve(to, {
paths: [node_path.dirname(from)]
});
} catch {
return undefined;
}
};
const parseModuleSpecifier = (moduleSpecifierString, {
isDynamicImport,
resolveFrom
}) => {
assert(isDynamicImport || isConstantStringLiteral(moduleSpecifierString));
const {
isConstant,
value
} = !isDynamicImport || isConstantStringLiteral(moduleSpecifierString) ? {
isConstant: true,
value: slashes.removeSlashes(moduleSpecifierString.slice(1, -1))
} : {
isConstant: false,
value: undefined
};
return {
type: isConstant ? parseType(value) : `unknown`,
isConstant,
code: moduleSpecifierString,
value,
resolved: typeof resolveFrom === `string` && isConstant ? resolve(resolveFrom, value) : undefined
};
};
const wasmLoadPromise = esModuleLexer.init;
const parseImports = async (code, options) => {
await wasmLoadPromise;
return parseImportsSync(code, options);
};
const parseImportsSync = (code, {
resolveFrom
} = {}) => {
const result = esModuleLexer.parse(code, resolveFrom == null ? undefined : resolveFrom);
if (!Array.isArray(result)) {
throw new TypeError(`Expected WASM to be loaded before calling parseImportsSync`);
}
const [imports] = result;
return {
*[Symbol.iterator]() {
for (let {
d: dynamicImportStartIndex,
ss: statementStartIndex,
s: moduleSpecifierStartIndex,
e: moduleSpecifierEndIndexExclusive
} of imports) {
const isImportMeta = dynamicImportStartIndex === -2;
if (isImportMeta) {
continue;
}
const isDynamicImport = dynamicImportStartIndex > -1;
// Include string literal quotes in character range
if (!isDynamicImport) {
moduleSpecifierStartIndex--;
moduleSpecifierEndIndexExclusive++;
}
const moduleSpecifierString = code.slice(moduleSpecifierStartIndex, moduleSpecifierEndIndexExclusive);
const moduleSpecifier = {
startIndex: moduleSpecifierStartIndex,
endIndex: moduleSpecifierEndIndexExclusive,
...parseModuleSpecifier(moduleSpecifierString, {
isDynamicImport,
resolveFrom
})
};
let importClause;
if (!isDynamicImport) {
let importClauseString = code.slice(statementStartIndex + `import`.length, moduleSpecifierStartIndex).trim();
if (importClauseString.endsWith(`from`)) {
importClauseString = importClauseString.slice(0, Math.max(0, importClauseString.length - `from`.length));
}
importClause = parseImportClause(importClauseString);
}
yield {
startIndex: statementStartIndex,
// Include the closing parenthesis for dynamic import
endIndex: isDynamicImport ? moduleSpecifierEndIndexExclusive + 1 : moduleSpecifierEndIndexExclusive,
isDynamicImport,
moduleSpecifier,
importClause
};
}
}
};
};
exports.parseImports = parseImports;
exports.parseImportsSync = parseImportsSync;
exports.wasmLoadPromise = wasmLoadPromise;

150
node_modules/parse-imports/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,150 @@
/** Options for parsing imports. */
type Options = {
/**
* If set to a file path, then {@link Import.moduleSpecifier.resolved} of
* returned instances will be set to the result of calling
* `require.resolve(moduleSpecifier.value)` from the given file path.
* Otherwise, will be undefined.
*/
readonly resolveFrom?: string
}
/**
* A type representing what kind of module a specifier refers to.
*
* - 'unknown' if the module specifier is not a simple constant string literal
* - 'invalid' if the module specifier is the empty string
* - 'absolute' if the module specifier is an absolute file path
* - 'relative' if the module specifier is a relative file path
* - 'builtin' if the module specifier is the name of a builtin Node.js package
* - 'package' otherwise
*/
type ModuleSpecifierType =
| 'invalid'
| 'absolute'
| 'relative'
| 'builtin'
| 'package'
| 'unknown'
/**
* A type representing an import in JavaScript code.
*
* `code.substring(startIndex, endIndex)` returns the full import statement or
* expression.
*/
type Import = {
/** The start index of the import in the JavaScript (inclusive). */
startIndex: number
/** The end index of the import in the JavaScript (exclusive). */
endIndex: number
/** Whether the import is a dynamic import (e.g. `import('module')`). */
isDynamicImport: boolean
/**
* A type representing the code specifiying the module being imported.
*
* `code.substring(moduleSpecifier.startIndex, moduleSpecifier.endIndex)`
* returns the module specifier including quotes.
*/
moduleSpecifier: {
/**
* What kind of module the specifier refers to.
*
* 'unknown' when `moduleSpecifier.isConstant` is false.
*/
type: ModuleSpecifierType
/** The start index of the specifier in the JavaScript (inclusive). */
startIndex: number
/** The end index of the specifier in the JavaScript (exclusive). */
endIndex: number
/**
* True when the import is not a dynamic import (`isDynamicImport` is
* false), or when the import is a dynamic import where the specifier is a
* simple string literal (e.g. import('fs'), import("fs"), import(`fs`)).
*/
isConstant: boolean
/**
* The module specifier as it was written in the code. For non-constant
* dynamic imports it could be a complex expression.
*/
code: string
/**
* `code` without string literal quotes and unescaped if `isConstant` is
* true. Otherwise, it is undefined.
*/
value?: string
/** Set if the `resolveFrom` option is set and `value` is not undefined. */
resolved?: string
}
/**
* A type representing what is being imported from the module.
*
* Undefined if `isDynamicImport` is true.
*/
importClause?: {
/**
* The default import identifier or undefined if the import statement does
* not have a default import.
*/
default?: string
/**
* An array of objects representing the named imports of the import
* statement. It is empty if the import statement does not have any named
* imports. Each object in the array has a specifier field set to the
* imported identifier and a binding field set to the identifier for
* accessing the imported value.
* For example, `import { a, x as y } from 'something'` would have the
* following array:
* ```
* [{ specifier: 'a', binding: 'a' }, { specifier: 'x', binding: 'y' }]
* ```
*/
named: { specifier: string; binding: string }[]
/**
* The namespace import identifier or undefined if the import statement does
* not have a namespace import.
*/
namespace?: string
}
}
/**
* A promise that resolves once WASM has finished loading.
*
* Await this promise to be certain calling `parseImportsSync` is safe.
*/
declare const wasmLoadPromise: Promise<void>
/**
* Returns a promise resolving to a lazy iterable/iterator that iterates over
* the imports in `code`.
*/
declare const parseImports: (
code: string,
options?: Options,
) => Promise<Iterable<Import>>
/**
* Returns a lazy iterable/iterator that iterates over the imports in `code`.
*
* @throws if called before WASM has finished loading. Await `wasmLoadPromise`
* to be sure it has finished.
*/
declare const parseImportsSync: (
code: string,
options?: Options,
) => Iterable<Import>
export { type Import, type ModuleSpecifierType, type Options, parseImports, parseImportsSync, wasmLoadPromise };

239
node_modules/parse-imports/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,239 @@
import { init, parse } from 'es-module-lexer';
import assert from 'node:assert';
import { removeSlashes } from 'slashes';
import module, { createRequire } from 'node:module';
import { dirname } from 'node:path';
const separatorRegex = /^(?:\s+|,)$/u;
const skipSeparators = (imported, i) => {
while (i < imported.length && separatorRegex.test(imported[i])) {
i++;
}
return i;
};
const skipNonSeparators = (imported, i) => {
while (i < imported.length && !separatorRegex.test(imported[i])) {
i++;
}
return i;
};
const parseDefaultImport = (importClauseString, i) => {
const startIndex = i;
i = skipNonSeparators(importClauseString, i);
return {
defaultImport: importClauseString.slice(startIndex, i),
i
};
};
const parseNamedImports = (importClauseString, i) => {
const startIndex = ++i;
while (i < importClauseString.length && importClauseString[i] !== `}`) {
i++;
}
const namedImports = importClauseString.slice(startIndex, i++).split(`,`).map(namedImport => {
namedImport = namedImport.trim();
if (namedImport.includes(` `)) {
const components = namedImport.split(` `);
return {
specifier: components[0],
binding: components.at(-1)
};
}
return {
specifier: namedImport,
binding: namedImport
};
}).filter(({
specifier
}) => specifier.length > 0);
return {
namedImports,
i
};
};
const parseNamespaceImport = (importClauseString, i) => {
i++;
i = skipSeparators(importClauseString, i);
i += `as`.length;
i = skipSeparators(importClauseString, i);
const startIndex = i;
i = skipNonSeparators(importClauseString, i);
return {
namespaceImport: importClauseString.slice(startIndex, i),
i
};
};
// Assumes import clause is syntactically valid
const parseImportClause = importClauseString => {
let defaultImport;
let namespaceImport;
const namedImports = [];
for (let i = 0; i < importClauseString.length; i++) {
if (separatorRegex.test(importClauseString[i])) {
continue;
}
if (importClauseString[i] === `{`) {
let newNamedImports;
({
namedImports: newNamedImports,
i
} = parseNamedImports(importClauseString, i));
namedImports.push(...newNamedImports);
} else if (importClauseString[i] === `*`) {
({
namespaceImport,
i
} = parseNamespaceImport(importClauseString, i));
} else {
({
defaultImport,
i
} = parseDefaultImport(importClauseString, i));
}
}
return {
default: defaultImport,
namespace: namespaceImport,
named: namedImports
};
};
// Assumes the string is syntactically valid
const isConstantStringLiteral = stringLiteral => {
const quote = [`'`, `"`, `\``].find(quoteCandidate => stringLiteral.startsWith(quoteCandidate) && stringLiteral.endsWith(quoteCandidate));
if (quote == null) {
return false;
}
for (let i = 1; i < stringLiteral.length - 1; i++) {
// Check for end of string literal before end of stringLiteral
if (stringLiteral[i] === quote && stringLiteral[i - 1] !== `\\`) {
return false;
}
// Check for interpolated value in template literal
if (quote === `\`` && stringLiteral.slice(i, i + 2) === `\${` && stringLiteral[i - 1] !== `\\`) {
return false;
}
}
return true;
};
const builtinModules = new Set(module.builtinModules);
const parseType = moduleSpecifier => {
if (moduleSpecifier.length === 0) {
return `invalid`;
}
if (moduleSpecifier.startsWith(`/`)) {
return `absolute`;
}
if (moduleSpecifier.startsWith(`.`)) {
return `relative`;
}
if (builtinModules.has(moduleSpecifier)) {
return `builtin`;
}
return `package`;
};
const require = createRequire(import.meta.url);
const resolve = (from, to) => {
try {
return require.resolve(to, {
paths: [dirname(from)]
});
} catch {
return undefined;
}
};
const parseModuleSpecifier = (moduleSpecifierString, {
isDynamicImport,
resolveFrom
}) => {
assert(isDynamicImport || isConstantStringLiteral(moduleSpecifierString));
const {
isConstant,
value
} = !isDynamicImport || isConstantStringLiteral(moduleSpecifierString) ? {
isConstant: true,
value: removeSlashes(moduleSpecifierString.slice(1, -1))
} : {
isConstant: false,
value: undefined
};
return {
type: isConstant ? parseType(value) : `unknown`,
isConstant,
code: moduleSpecifierString,
value,
resolved: typeof resolveFrom === `string` && isConstant ? resolve(resolveFrom, value) : undefined
};
};
const wasmLoadPromise = init;
const parseImports = async (code, options) => {
await wasmLoadPromise;
return parseImportsSync(code, options);
};
const parseImportsSync = (code, {
resolveFrom
} = {}) => {
const result = parse(code, resolveFrom == null ? undefined : resolveFrom);
if (!Array.isArray(result)) {
throw new TypeError(`Expected WASM to be loaded before calling parseImportsSync`);
}
const [imports] = result;
return {
*[Symbol.iterator]() {
for (let {
d: dynamicImportStartIndex,
ss: statementStartIndex,
s: moduleSpecifierStartIndex,
e: moduleSpecifierEndIndexExclusive
} of imports) {
const isImportMeta = dynamicImportStartIndex === -2;
if (isImportMeta) {
continue;
}
const isDynamicImport = dynamicImportStartIndex > -1;
// Include string literal quotes in character range
if (!isDynamicImport) {
moduleSpecifierStartIndex--;
moduleSpecifierEndIndexExclusive++;
}
const moduleSpecifierString = code.slice(moduleSpecifierStartIndex, moduleSpecifierEndIndexExclusive);
const moduleSpecifier = {
startIndex: moduleSpecifierStartIndex,
endIndex: moduleSpecifierEndIndexExclusive,
...parseModuleSpecifier(moduleSpecifierString, {
isDynamicImport,
resolveFrom
})
};
let importClause;
if (!isDynamicImport) {
let importClauseString = code.slice(statementStartIndex + `import`.length, moduleSpecifierStartIndex).trim();
if (importClauseString.endsWith(`from`)) {
importClauseString = importClauseString.slice(0, Math.max(0, importClauseString.length - `from`.length));
}
importClause = parseImportClause(importClauseString);
}
yield {
startIndex: statementStartIndex,
// Include the closing parenthesis for dynamic import
endIndex: isDynamicImport ? moduleSpecifierEndIndexExclusive + 1 : moduleSpecifierEndIndexExclusive,
isDynamicImport,
moduleSpecifier,
importClause
};
}
}
};
};
export { parseImports, parseImportsSync, wasmLoadPromise };