P0-1: 删除 docker-compose-override.yml + deploy-server 两份 workers=2→1(预防性修复,服务器根 compose 已是 workers=1)
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
MIT License
|
||||
-----------
|
||||
|
||||
Copyright (C) 2018-2022 Guy Bedford
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,403 @@
|
||||
# ES Module Lexer
|
||||
|
||||
[![Build Status][actions-image]][actions-url]
|
||||
|
||||
A JS module syntax lexer used in [es-module-shims](https://github.com/guybedford/es-module-shims).
|
||||
|
||||
Outputs the list of exports and locations of import specifiers, including dynamic import and import meta handling.
|
||||
|
||||
Supports new syntax features including import attributes and source phase imports.
|
||||
|
||||
A very small single JS file (~7KiB gzipped) that includes inlined Web Assembly for very fast source analysis of ECMAScript module syntax only.
|
||||
|
||||
For an example of the performance, Angular 1 (720KiB) is fully parsed in 5ms, in comparison to the fastest JS parser, Acorn which takes over 100ms.
|
||||
|
||||
_Comprehensively handles the JS language grammar while remaining small and fast. - ~10ms per MB of JS cold and ~5ms per MB of JS warm, [see benchmarks](#benchmarks) for more info._
|
||||
|
||||
> [Built with](https://github.com/guybedford/es-module-lexer/blob/main/chompfile.toml) [Chomp](https://chompbuild.com/)
|
||||
|
||||
### Usage
|
||||
|
||||
```
|
||||
npm install es-module-lexer
|
||||
```
|
||||
|
||||
See [src/lexer.ts](src/lexer.ts) for the type definitions.
|
||||
|
||||
For use in CommonJS:
|
||||
|
||||
```js
|
||||
const { init, parse } = require('es-module-lexer');
|
||||
|
||||
(async () => {
|
||||
// either await init, or call parse asynchronously
|
||||
// this is necessary for the Web Assembly boot
|
||||
await init;
|
||||
|
||||
const source = 'export var p = 5';
|
||||
const [imports, exports] = parse(source);
|
||||
|
||||
// Returns "p"
|
||||
source.slice(exports[0].s, exports[0].e);
|
||||
// Returns "p"
|
||||
source.slice(exports[0].ls, exports[0].le);
|
||||
})();
|
||||
```
|
||||
|
||||
An ES module version is also available:
|
||||
|
||||
```js
|
||||
import { init, parse } from 'es-module-lexer';
|
||||
|
||||
(async () => {
|
||||
await init;
|
||||
|
||||
const source = `
|
||||
import { name } from 'mod\\u1011';
|
||||
import json from './json.json' with { type: 'json' }
|
||||
export var p = 5;
|
||||
export function q () {
|
||||
|
||||
};
|
||||
export { x as 'external name' } from 'external';
|
||||
|
||||
// Comments provided to demonstrate edge cases
|
||||
import /*comment!*/ ( 'asdf', { with: { type: 'json' }});
|
||||
import /*comment!*/.meta.asdf;
|
||||
|
||||
// Source phase imports:
|
||||
import source mod from './mod.wasm';
|
||||
import.source('./mod.wasm');
|
||||
`;
|
||||
|
||||
const [imports, exports] = parse(source, 'optional-sourcename');
|
||||
|
||||
// Returns "modထ"
|
||||
imports[0].n
|
||||
// Returns "mod\u1011"
|
||||
source.slice(imports[0].s, imports[0].e);
|
||||
// "s" = start
|
||||
// "e" = end
|
||||
|
||||
// Returns "import { name } from 'mod'"
|
||||
source.slice(imports[0].ss, imports[0].se);
|
||||
// "ss" = statement start
|
||||
// "se" = statement end
|
||||
|
||||
// Returns "{ type: 'json' }"
|
||||
source.slice(imports[1].a, imports[1].se);
|
||||
// "a" = attribute start, -1 for no import attributes
|
||||
|
||||
// Parsed import attributes are available in `at`
|
||||
// Returns [['type', 'json']]
|
||||
imports[1].at;
|
||||
// Returns 'json'
|
||||
imports[1].at[0][1];
|
||||
|
||||
// Returns null (no attributes)
|
||||
imports[0].at;
|
||||
|
||||
// Returns "external"
|
||||
source.slice(imports[2].s, imports[2].e);
|
||||
|
||||
// Returns "p"
|
||||
source.slice(exports[0].s, exports[0].e);
|
||||
// Returns "p"
|
||||
source.slice(exports[0].ls, exports[0].le);
|
||||
// Returns "q"
|
||||
source.slice(exports[1].s, exports[1].e);
|
||||
// Returns "q"
|
||||
source.slice(exports[1].ls, exports[1].le);
|
||||
|
||||
// "ss" = export statement start (only the start is tracked, not the end)
|
||||
// Returns "export"
|
||||
source.slice(exports[0].ss, exports[0].ss + 6);
|
||||
|
||||
// Returns "'external name'"
|
||||
source.slice(exports[2].s, exports[2].e);
|
||||
// Returns -1
|
||||
exports[2].ls;
|
||||
// Returns -1
|
||||
exports[2].le;
|
||||
|
||||
// Import type is provided by `t` value
|
||||
// (1 for static, 2, for dynamic)
|
||||
// Returns true
|
||||
imports[2].t == 2;
|
||||
|
||||
// Returns "asdf" (only for string literal dynamic imports)
|
||||
imports[2].n
|
||||
// Returns "import /*comment!*/ ( 'asdf', { with: { type: 'json' } })"
|
||||
source.slice(imports[3].ss, imports[3].se);
|
||||
// Returns "'asdf'"
|
||||
source.slice(imports[3].s, imports[3].e);
|
||||
// Returns "( 'asdf', { with: { type: 'json' } })"
|
||||
source.slice(imports[3].d, imports[3].se);
|
||||
// Returns "{ with: { type: 'json' } }"
|
||||
source.slice(imports[3].a, imports[3].se - 1);
|
||||
|
||||
// For non-string dynamic import expressions:
|
||||
// - n will be undefined
|
||||
// - a is currently -1 even if there is an import attribute
|
||||
// - e is currently the character before the closing )
|
||||
|
||||
// For nested dynamic imports, the se value of the outer import is -1 as end tracking does not
|
||||
// currently support nested dynamic immports
|
||||
|
||||
// import.meta is indicated by imports[3].d === -2
|
||||
// Returns true
|
||||
imports[4].d === -2;
|
||||
// Returns "import /*comment!*/.meta"
|
||||
source.slice(imports[4].s, imports[4].e);
|
||||
// ss and se are the same for import meta
|
||||
|
||||
// Returns "'./mod.wasm'"
|
||||
source.slice(imports[5].s, imports[5].e);
|
||||
|
||||
// Import type 4 and 5 for static and dynamic source phase
|
||||
imports[5].t === 4;
|
||||
imports[6].t === 5;
|
||||
})();
|
||||
```
|
||||
|
||||
### CSP asm.js Build
|
||||
|
||||
The default version of the library uses Wasm and (safe) eval usage for performance and a minimal footprint.
|
||||
|
||||
Neither of these represent security escalation possibilities since there are no execution string injection vectors, but that can still violate existing CSP policies for applications.
|
||||
|
||||
For a version that works with CSP eval disabled, use the `es-module-lexer/js` build:
|
||||
|
||||
```js
|
||||
import { parse } from 'es-module-lexer/js';
|
||||
```
|
||||
|
||||
Instead of Web Assembly, this uses an asm.js build which is almost as fast as the Wasm version ([see benchmarks below](#benchmarks)).
|
||||
|
||||
### Minimal Build
|
||||
|
||||
For size-sensitive embedders, the `es-module-lexer/minimal` build drops certain features to reduce the binary size. This is used for example by [es-module-shims](https://github.com/guybedford/es-module-shims):
|
||||
|
||||
```js
|
||||
import { parse } from 'es-module-lexer/minimal';
|
||||
```
|
||||
|
||||
Compared to the full build:
|
||||
|
||||
* `parse` returns a two-element `[imports, exports]` tuple only - the third and fourth facade and `hasModuleSyntax` booleans are dropped.
|
||||
* Imports drop the parsed attribute list `at` (the attribute source remains recoverable via the `a` attributes index).
|
||||
* Exports drop the statement start `ss`.
|
||||
|
||||
All other fields are identical to the full build. For CSP eval disabled support, the equivalent asm.js build is available as `es-module-lexer/minimal/js`.
|
||||
|
||||
### Import Attributes
|
||||
|
||||
The `a` field provides the index of the start of the `{` attributes bracket, or -1 for no attributes.
|
||||
|
||||
The list of attribute key and value pairs are provided on the `at` field (full build only):
|
||||
|
||||
```js
|
||||
const [imports] = parse(`
|
||||
import json from './foo.json' with { type: 'json' };
|
||||
import './foo.css' with { type: 'css' };
|
||||
import pkg from 'pkg' with { type: 'json', integrity: 'sha384-...' };
|
||||
`);
|
||||
|
||||
// Returns [['type', 'json']]
|
||||
imports[0].at;
|
||||
|
||||
// Returns [['type', 'css']]
|
||||
imports[1].at;
|
||||
|
||||
// Multiple attributes
|
||||
// Returns [['type', 'json'], ['integrity', 'sha384-...']]
|
||||
imports[2].at;
|
||||
```
|
||||
|
||||
The `at` field is an array of `[key, value]` tuples, or `null` if there are no attributes.
|
||||
|
||||
Both keys and values support escape sequences:
|
||||
|
||||
```js
|
||||
const [imports] = parse(`
|
||||
import foo from './foo.js' with { "custom-key": "value" };
|
||||
import bar from './bar.js' with { "key\\nwith\\nnewlines": "value\\twith\\ttabs" };
|
||||
`);
|
||||
|
||||
// Quoted keys are unquoted
|
||||
// Returns [['custom-key', 'value']]
|
||||
imports[0].at;
|
||||
|
||||
// Escape sequences are processed
|
||||
// Returns [['key\nwith\nnewlines', 'value\twith\ttabs']]
|
||||
imports[1].at;
|
||||
```
|
||||
|
||||
### Escape Sequences
|
||||
|
||||
To handle escape sequences in specifier strings, the `.n` field of imported specifiers will be provided where possible.
|
||||
|
||||
For dynamic import expressions, this field will be empty if not a valid JS string.
|
||||
|
||||
### Facade Detection
|
||||
|
||||
Facade modules that only use import / export syntax can be detected via the third return value (full build only):
|
||||
|
||||
```js
|
||||
const [,, facade] = parse(`
|
||||
export * from 'external';
|
||||
import * as ns from 'external2';
|
||||
export { a as b } from 'external3';
|
||||
export { ns };
|
||||
`);
|
||||
facade === true;
|
||||
```
|
||||
|
||||
### ESM Detection
|
||||
|
||||
Modules that uses ESM syntaxes can be detected via the fourth return value (full build only):
|
||||
|
||||
```js
|
||||
const [,,, hasModuleSyntax] = parse(`
|
||||
export {}
|
||||
`);
|
||||
hasModuleSyntax === true;
|
||||
```
|
||||
|
||||
Dynamic imports are ignored since they can be used in Non-ESM files.
|
||||
|
||||
```js
|
||||
const [,,, hasModuleSyntax] = parse(`
|
||||
import('./foo.js')
|
||||
`);
|
||||
hasModuleSyntax === false;
|
||||
```
|
||||
|
||||
### Environment Support
|
||||
|
||||
Node.js 10+, and [all browsers with Web Assembly support](https://caniuse.com/#feat=wasm).
|
||||
|
||||
### Grammar Support
|
||||
|
||||
* Token state parses all line comments, block comments, strings, template strings, blocks, parens and punctuators.
|
||||
* Division operator / regex token ambiguity is handled via backtracking checks against punctuator prefixes, including closing brace or paren backtracking.
|
||||
* Always correctly parses valid JS source, but may parse invalid JS source without errors.
|
||||
|
||||
### Limitations
|
||||
|
||||
The lexing approach is designed to deal with the full language grammar including RegEx / division operator ambiguity through backtracking and paren / brace tracking.
|
||||
|
||||
Because it lexes rather than fully parses, the analysis is not a validation pass: valid JS source is always analyzed correctly, but some invalid source is accepted without an error rather than rejected. For example `export const = 1` lexes to an empty exports list instead of throwing. Callers that need to reject invalid source should run a validating parser separately.
|
||||
|
||||
Multiple exports per declaration (`export var a = 'asdf', q = z`) and renamed destructured exports (`export var { a: b } = asdf`) are detected correctly; earlier versions missed `q` and `b` in these forms.
|
||||
|
||||
### Benchmarks
|
||||
|
||||
Benchmarks can be run with `npm run bench`.
|
||||
|
||||
Current results for a high spec machine:
|
||||
|
||||
#### Wasm Build
|
||||
|
||||
```
|
||||
Module load time
|
||||
> 5ms
|
||||
Cold Run, All Samples
|
||||
test/samples/*.js (3123 KiB)
|
||||
> 18ms
|
||||
|
||||
Warm Runs (average of 25 runs)
|
||||
test/samples/angular.js (739 KiB)
|
||||
> 3ms
|
||||
test/samples/angular.min.js (188 KiB)
|
||||
> 1ms
|
||||
test/samples/d3.js (508 KiB)
|
||||
> 3ms
|
||||
test/samples/d3.min.js (274 KiB)
|
||||
> 2ms
|
||||
test/samples/magic-string.js (35 KiB)
|
||||
> 0ms
|
||||
test/samples/magic-string.min.js (20 KiB)
|
||||
> 0ms
|
||||
test/samples/rollup.js (929 KiB)
|
||||
> 4.32ms
|
||||
test/samples/rollup.min.js (429 KiB)
|
||||
> 2.16ms
|
||||
|
||||
Warm Runs, All Samples (average of 25 runs)
|
||||
test/samples/*.js (3123 KiB)
|
||||
> 14.16ms
|
||||
```
|
||||
|
||||
#### JS Build (asm.js)
|
||||
|
||||
```
|
||||
Module load time
|
||||
> 2ms
|
||||
Cold Run, All Samples
|
||||
test/samples/*.js (3123 KiB)
|
||||
> 34ms
|
||||
|
||||
Warm Runs (average of 25 runs)
|
||||
test/samples/angular.js (739 KiB)
|
||||
> 3ms
|
||||
test/samples/angular.min.js (188 KiB)
|
||||
> 1ms
|
||||
test/samples/d3.js (508 KiB)
|
||||
> 3ms
|
||||
test/samples/d3.min.js (274 KiB)
|
||||
> 2ms
|
||||
test/samples/magic-string.js (35 KiB)
|
||||
> 0ms
|
||||
test/samples/magic-string.min.js (20 KiB)
|
||||
> 0ms
|
||||
test/samples/rollup.js (929 KiB)
|
||||
> 5ms
|
||||
test/samples/rollup.min.js (429 KiB)
|
||||
> 3.04ms
|
||||
|
||||
Warm Runs, All Samples (average of 25 runs)
|
||||
test/samples/*.js (3123 KiB)
|
||||
> 17.12ms
|
||||
```
|
||||
|
||||
### Building
|
||||
|
||||
This project uses [Chomp](https://chompbuild.com) for building.
|
||||
|
||||
With Chomp installed, download the WASI SDK 12.0 from https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-12.
|
||||
|
||||
- [Linux](https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz)
|
||||
- [Windows (MinGW)](https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-mingw.tar.gz)
|
||||
- [macOS](https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-macos.tar.gz)
|
||||
|
||||
Locate the WASI-SDK as a sibling folder, or customize the path via the `WASI_PATH` environment variable.
|
||||
|
||||
Emscripten emsdk is also assumed to be a sibling folder or via the `EMSDK_PATH` environment variable.
|
||||
|
||||
Example setup:
|
||||
|
||||
```
|
||||
git clone https://github.com:guybedford/es-module-lexer
|
||||
git clone https://github.com/emscripten-core/emsdk
|
||||
cd emsdk
|
||||
git checkout 1.40.1-fastcomp
|
||||
./emsdk install 1.40.1-fastcomp
|
||||
cd ..
|
||||
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz
|
||||
gunzip wasi-sdk-12.0-linux.tar.gz
|
||||
tar -xf wasi-sdk-12.0-linux.tar
|
||||
mv wasi-sdk-12.0-linux.tar wasi-sdk-12.0
|
||||
cargo install chompbuild
|
||||
cd es-module-lexer
|
||||
chomp test
|
||||
```
|
||||
|
||||
For the `asm.js` build, git clone `emsdk` from is assumed to be a sibling folder as well.
|
||||
|
||||
### License
|
||||
|
||||
MIT
|
||||
|
||||
[actions-image]: https://github.com/guybedford/es-module-lexer/actions/workflows/build.yml/badge.svg
|
||||
[actions-url]: https://github.com/guybedford/es-module-lexer/actions/workflows/build.yml
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "es-module-lexer",
|
||||
"version": "2.3.0",
|
||||
"description": "Lexes ES modules returning their import/export metadata",
|
||||
"main": "dist/lexer.cjs",
|
||||
"module": "dist/lexer.js",
|
||||
"types": "types/lexer.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./types/lexer.d.ts",
|
||||
"module": "./dist/lexer.js",
|
||||
"import": "./dist/lexer.js",
|
||||
"require": "./dist/lexer.cjs"
|
||||
},
|
||||
"./js": {
|
||||
"types": "./types/lexer.d.ts",
|
||||
"default": "./dist/lexer.asm.js"
|
||||
},
|
||||
"./minimal": {
|
||||
"types": "./types/lexer.minimal.d.ts",
|
||||
"module": "./dist/lexer.minimal.js",
|
||||
"import": "./dist/lexer.minimal.js",
|
||||
"require": "./dist/lexer.minimal.cjs"
|
||||
},
|
||||
"./minimal/js": {
|
||||
"types": "./types/lexer.minimal.d.ts",
|
||||
"default": "./dist/lexer.minimal.asm.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm install -g chomp ; chomp build",
|
||||
"test": "npm install -g chomp ; chomp test"
|
||||
},
|
||||
"author": "Guy Bedford",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.29.7",
|
||||
"@babel/core": "^7.29.7",
|
||||
"@babel/plugin-transform-modules-commonjs": "^7.29.7",
|
||||
"@swc/cli": "^0.8.1",
|
||||
"@swc/core": "^1.15.41",
|
||||
"@types/node": "^25.9.3",
|
||||
"kleur": "^4.1.5",
|
||||
"mocha": "^11.7.6",
|
||||
"terser": "^5.48.0",
|
||||
"typescript": "^6.0.3"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"types",
|
||||
"lexer.js"
|
||||
],
|
||||
"type": "module",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/guybedford/es-module-lexer.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/guybedford/es-module-lexer/issues"
|
||||
},
|
||||
"homepage": "https://github.com/guybedford/es-module-lexer#readme",
|
||||
"directories": {
|
||||
"lib": "lib",
|
||||
"test": "test"
|
||||
},
|
||||
"keywords": []
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
export declare enum ImportType {
|
||||
/**
|
||||
* A normal static using any syntax variations
|
||||
* import .. from 'module'
|
||||
*/
|
||||
Static = 1,
|
||||
/**
|
||||
* A dynamic import expression `import(specifier)`
|
||||
* or `import(specifier, opts)`
|
||||
*/
|
||||
Dynamic = 2,
|
||||
/**
|
||||
* An import.meta expression
|
||||
*/
|
||||
ImportMeta = 3,
|
||||
/**
|
||||
* A source phase import
|
||||
* import source x from 'module'
|
||||
*/
|
||||
StaticSourcePhase = 4,
|
||||
/**
|
||||
* A dynamic source phase import
|
||||
* import.source('module')
|
||||
*/
|
||||
DynamicSourcePhase = 5,
|
||||
/**
|
||||
* A defer phase import
|
||||
* import defer * as x from 'module'
|
||||
*/
|
||||
StaticDeferPhase = 6,
|
||||
/**
|
||||
* A dynamic defer phase import
|
||||
* import.defer('module')
|
||||
*/
|
||||
DynamicDeferPhase = 7
|
||||
}
|
||||
export interface ImportSpecifier {
|
||||
/**
|
||||
* Module name
|
||||
*
|
||||
* To handle escape sequences in specifier strings, the .n field of imported specifiers will be provided where possible.
|
||||
*
|
||||
* For dynamic import expressions, this field will be empty if not a valid JS string.
|
||||
* For static import expressions, this field will always be populated.
|
||||
*
|
||||
* @example
|
||||
* const [imports1, exports1] = parse(String.raw`import './\u0061\u0062.js'`);
|
||||
* imports1[0].n;
|
||||
* // Returns "./ab.js"
|
||||
*
|
||||
* const [imports2, exports2] = parse(`import("./ab.js")`);
|
||||
* imports2[0].n;
|
||||
* // Returns "./ab.js"
|
||||
*
|
||||
* const [imports3, exports3] = parse(`import("./" + "ab.js")`);
|
||||
* imports3[0].n;
|
||||
* // Returns undefined
|
||||
*/
|
||||
readonly n: string | undefined;
|
||||
/**
|
||||
* Type of import statement
|
||||
*/
|
||||
readonly t: ImportType;
|
||||
/**
|
||||
* Start of module specifier
|
||||
*
|
||||
* @example
|
||||
* const source = `import { a } from 'asdf'`;
|
||||
* const [imports, exports] = parse(source);
|
||||
* source.substring(imports[0].s, imports[0].e);
|
||||
* // Returns "asdf"
|
||||
*/
|
||||
readonly s: number;
|
||||
/**
|
||||
* End of module specifier
|
||||
*/
|
||||
readonly e: number;
|
||||
/**
|
||||
* Start of import statement
|
||||
*
|
||||
* @example
|
||||
* const source = `import { a } from 'asdf'`;
|
||||
* const [imports, exports] = parse(source);
|
||||
* source.substring(imports[0].ss, imports[0].se);
|
||||
* // Returns "import { a } from 'asdf';"
|
||||
*/
|
||||
readonly ss: number;
|
||||
/**
|
||||
* End of import statement
|
||||
*/
|
||||
readonly se: number;
|
||||
/**
|
||||
* If this import keyword is a dynamic import, this is the start value.
|
||||
* If this import keyword is a static import, this is -1.
|
||||
* If this import keyword is an import.meta expresion, this is -2.
|
||||
*/
|
||||
readonly d: number;
|
||||
/**
|
||||
* If this import has an import attribute, this is the start value.
|
||||
* Otherwise this is `-1`.
|
||||
*/
|
||||
readonly a: number;
|
||||
/**
|
||||
* Parsed import attributes as an array of [key, value] tuples.
|
||||
* If this import has no attributes, this is `null`.
|
||||
*
|
||||
* @example
|
||||
* const source = `import foo from 'bar' with { type: "json" }`;
|
||||
* const [imports] = parse(source);
|
||||
* imports[0].at;
|
||||
* // Returns [['type', 'json']]
|
||||
*
|
||||
* @example
|
||||
* const source = `import foo from 'bar' with { type: "json", integrity: "sha384-..." }`;
|
||||
* const [imports] = parse(source);
|
||||
* imports[0].at;
|
||||
* // Returns [['type', 'json'], ['integrity', 'sha384-...']]
|
||||
*/
|
||||
readonly at: ReadonlyArray<readonly [string, string]> | null;
|
||||
}
|
||||
export interface ExportSpecifier {
|
||||
/**
|
||||
* Exported name
|
||||
*
|
||||
* @example
|
||||
* const source = `export default []`;
|
||||
* const [imports, exports] = parse(source);
|
||||
* exports[0].n;
|
||||
* // Returns "default"
|
||||
*
|
||||
* @example
|
||||
* const source = `export const asdf = 42`;
|
||||
* const [imports, exports] = parse(source);
|
||||
* exports[0].n;
|
||||
* // Returns "asdf"
|
||||
*/
|
||||
readonly n: string;
|
||||
/**
|
||||
* Local name, or undefined.
|
||||
*
|
||||
* @example
|
||||
* const source = `export default []`;
|
||||
* const [imports, exports] = parse(source);
|
||||
* exports[0].ln;
|
||||
* // Returns undefined
|
||||
*
|
||||
* @example
|
||||
* const asdf = 42;
|
||||
* const source = `export { asdf as a }`;
|
||||
* const [imports, exports] = parse(source);
|
||||
* exports[0].ln;
|
||||
* // Returns "asdf"
|
||||
*/
|
||||
readonly ln: string | undefined;
|
||||
/**
|
||||
* Start of exported name
|
||||
*
|
||||
* @example
|
||||
* const source = `export default []`;
|
||||
* const [imports, exports] = parse(source);
|
||||
* source.substring(exports[0].s, exports[0].e);
|
||||
* // Returns "default"
|
||||
*
|
||||
* @example
|
||||
* const source = `export { 42 as asdf }`;
|
||||
* const [imports, exports] = parse(source);
|
||||
* source.substring(exports[0].s, exports[0].e);
|
||||
* // Returns "asdf"
|
||||
*/
|
||||
readonly s: number;
|
||||
/**
|
||||
* End of exported name
|
||||
*/
|
||||
readonly e: number;
|
||||
/**
|
||||
* Start of local name, or -1.
|
||||
*
|
||||
* @example
|
||||
* const asdf = 42;
|
||||
* const source = `export { asdf as a }`;
|
||||
* const [imports, exports] = parse(source);
|
||||
* source.substring(exports[0].ls, exports[0].le);
|
||||
* // Returns "asdf"
|
||||
*/
|
||||
readonly ls: number;
|
||||
/**
|
||||
* End of local name, or -1.
|
||||
*/
|
||||
readonly le: number;
|
||||
/**
|
||||
* Start of the export statement.
|
||||
*
|
||||
* Only the statement start is provided; the statement end is not tracked
|
||||
* (see https://github.com/guybedford/es-module-lexer/issues/112). Every
|
||||
* specifier of a statement reports the same start, so `export { a, b }`
|
||||
* returns the same `ss` for both `a` and `b`.
|
||||
*
|
||||
* @example
|
||||
* const source = `export { a, b } from 'mod'`;
|
||||
* const [imports, exports] = parse(source);
|
||||
* source.slice(exports[0].ss, exports[0].ss + 6);
|
||||
* // Returns "export"
|
||||
*/
|
||||
readonly ss: number;
|
||||
}
|
||||
export interface ParseError extends Error {
|
||||
idx: number;
|
||||
}
|
||||
/**
|
||||
* Outputs the list of exports and locations of import specifiers,
|
||||
* including dynamic import and import meta handling.
|
||||
*
|
||||
* @param source Source code to parser
|
||||
* @param name Optional sourcename
|
||||
* @returns Tuple contaning imports list and exports list.
|
||||
*/
|
||||
export declare function parse(source: string, name?: string): readonly [
|
||||
imports: ReadonlyArray<ImportSpecifier>,
|
||||
exports: ReadonlyArray<ExportSpecifier>,
|
||||
facade: boolean,
|
||||
hasModuleSyntax: boolean
|
||||
];
|
||||
/**
|
||||
* Wait for init to resolve before calling `parse`.
|
||||
*/
|
||||
export declare const init: Promise<void>;
|
||||
export declare const initSync: () => void;
|
||||
@@ -0,0 +1,46 @@
|
||||
// Type definitions for the es-module-lexer minimal build (es-module-lexer/minimal).
|
||||
// Auto-generated by build/gen-min-dts.mjs — do not edit.
|
||||
import { ImportType, ImportSpecifier, ParseError } from './lexer.js';
|
||||
export { ImportType, ImportSpecifier, ParseError };
|
||||
|
||||
/**
|
||||
* Export specifier — minimal build.
|
||||
*
|
||||
* Identical to the full ExportSpecifier except that the export statement start
|
||||
* (`ss`) is not tracked in the minimal build.
|
||||
*/
|
||||
export interface ExportSpecifier {
|
||||
/** Exported name */
|
||||
readonly n: string;
|
||||
/** Local name, or undefined */
|
||||
readonly ln: string | undefined;
|
||||
/** Start of exported name */
|
||||
readonly s: number;
|
||||
/** End of exported name */
|
||||
readonly e: number;
|
||||
/** Start of local name, or -1 */
|
||||
readonly ls: number;
|
||||
/** End of local name, or -1 */
|
||||
readonly le: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the lexical analysis of the source — minimal build.
|
||||
*
|
||||
* Returns a 2-tuple of imports and exports. Unlike the full build, the minimal
|
||||
* build does not emit the facade / hasModuleSyntax flags, and ImportSpecifier
|
||||
* `at` is always null (read assertions via `source.slice(a, se - 1)`).
|
||||
*
|
||||
* @param source Source code to parse
|
||||
* @param name Optional sourcename
|
||||
*/
|
||||
export declare function parse(source: string, name?: string): readonly [
|
||||
imports: ReadonlyArray<ImportSpecifier>,
|
||||
exports: ReadonlyArray<ExportSpecifier>
|
||||
];
|
||||
|
||||
/**
|
||||
* Wait for init to resolve before calling `parse`.
|
||||
*/
|
||||
export declare const init: Promise<void>;
|
||||
export declare const initSync: () => void;
|
||||
Reference in New Issue
Block a user