@veryfront/ext-parser-babel 0.1.1185 → 0.1.1189
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/esm/index.d.ts +3 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +6 -33
- package/esm/parser-only.d.ts +24 -0
- package/esm/parser-only.d.ts.map +1 -0
- package/esm/parser-only.js +47 -0
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -25,6 +25,15 @@ export default defineConfig({
|
|
|
25
25
|
|
|
26
26
|
Core's `src/transforms/plugins/babel-node-positions.ts` is a thin shim that resolves this contract at call time. When the extension is not installed and the shim is invoked, Veryfront throws an install-suggestion error directing the user to add `@veryfront/ext-parser-babel`.
|
|
27
27
|
|
|
28
|
+
## Parser-only entry
|
|
29
|
+
|
|
30
|
+
Permission-constrained workers that only need AST parsing can import
|
|
31
|
+
`BabelParseOnlyParser` from `@veryfront/ext-parser-babel/parser-only`. This
|
|
32
|
+
entry preserves the full parser's language and file-extension behavior without
|
|
33
|
+
loading Babel traversal, code generation, JSX transformation, extension
|
|
34
|
+
lifecycle, or debug dependencies. It does not read environment variables or
|
|
35
|
+
request filesystem/network permissions.
|
|
36
|
+
|
|
28
37
|
## Configuration
|
|
29
38
|
|
|
30
|
-
No factory options. The extension
|
|
39
|
+
No factory options. The extension takes no config.
|
package/esm/index.d.ts
CHANGED
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
* @module extensions/ext-parser-babel
|
|
15
15
|
*/
|
|
16
16
|
import type { ExtensionFactory } from "veryfront/extensions";
|
|
17
|
-
import type { ASTNode, CodeParser, FunctionDirectiveOptions, GenerateOptions, GenerateResult, InjectJsxNodePositionsOptions,
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
import type { ASTNode, CodeParser, FunctionDirectiveOptions, GenerateOptions, GenerateResult, InjectJsxNodePositionsOptions, TraverseVisitor } from "veryfront/extensions/parser";
|
|
18
|
+
import { BabelParseOnlyParser } from "./parser-only.js";
|
|
19
|
+
declare class BabelCodeParser extends BabelParseOnlyParser implements CodeParser {
|
|
20
20
|
traverse(ast: ASTNode, visitor: TraverseVisitor): void;
|
|
21
21
|
generate(ast: ASTNode, options?: GenerateOptions): Promise<GenerateResult>;
|
|
22
22
|
hasFunctionDirective(options: FunctionDirectiveOptions): Promise<boolean>;
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,wBAAwB,EACxB,eAAe,EACf,cAAc,EACd,6BAA6B,EAC7B,eAAe,EAChB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAwDxD,cAAM,eAAgB,SAAQ,oBAAqB,YAAW,UAAU;IACtE,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,IAAI;IAItD,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAWpE,oBAAoB,CACxB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,OAAO,CAAC;IAcnB,sBAAsB,CACpB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,6BAA6B,GACrC,MAAM;CAGV;AAED,QAAA,MAAM,QAAQ,EAAE,gBAiBf,CAAC;AAEF,eAAe,QAAQ,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @module extensions/ext-parser-babel
|
|
15
15
|
*/
|
|
16
|
-
import * as parser from "@babel/parser";
|
|
17
16
|
import * as traverseModule from "@babel/traverse";
|
|
18
17
|
import * as generateModule from "@babel/generator";
|
|
19
18
|
import { injectNodePositions } from "./inject-node-positions.js";
|
|
19
|
+
import { BabelParseOnlyParser } from "./parser-only.js";
|
|
20
20
|
function resolveDefaultExport(mod) {
|
|
21
21
|
const m = mod;
|
|
22
22
|
if (typeof m.default === "function")
|
|
@@ -41,41 +41,13 @@ function isRecord(value) {
|
|
|
41
41
|
}
|
|
42
42
|
function functionHasDirective(node, directive) {
|
|
43
43
|
const body = node.body;
|
|
44
|
-
if (!isRecord(body) || body.type !== "BlockStatement" ||
|
|
44
|
+
if (!isRecord(body) || body.type !== "BlockStatement" ||
|
|
45
|
+
!Array.isArray(body.directives)) {
|
|
45
46
|
return false;
|
|
46
47
|
}
|
|
47
48
|
return body.directives.some((entry) => isRecord(entry) && isRecord(entry.value) && entry.value.value === directive);
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
-
const normalizedPath = filePath?.toLowerCase() ?? "";
|
|
51
|
-
const isTypeScript = /\.(?:tsx?|[cm]ts)$/.test(normalizedPath);
|
|
52
|
-
const supportsJsx = !filePath || /\.(?:tsx|jsx|js|mjs|cjs)$/.test(normalizedPath);
|
|
53
|
-
const plugins = [
|
|
54
|
-
"classProperties",
|
|
55
|
-
"classPrivateProperties",
|
|
56
|
-
"classPrivateMethods",
|
|
57
|
-
"decorators-legacy",
|
|
58
|
-
"decoratorAutoAccessors",
|
|
59
|
-
"deprecatedImportAssert",
|
|
60
|
-
"dynamicImport",
|
|
61
|
-
"importAttributes",
|
|
62
|
-
"topLevelAwait",
|
|
63
|
-
];
|
|
64
|
-
if (isTypeScript || !filePath)
|
|
65
|
-
plugins.push("typescript");
|
|
66
|
-
if (supportsJsx)
|
|
67
|
-
plugins.push("jsx");
|
|
68
|
-
return plugins;
|
|
69
|
-
}
|
|
70
|
-
class BabelCodeParser {
|
|
71
|
-
parse(options) {
|
|
72
|
-
const ast = parser.parse(options.code, {
|
|
73
|
-
sourceType: "unambiguous",
|
|
74
|
-
allowReturnOutsideFunction: options.filePath?.toLowerCase().endsWith(".cjs") === true,
|
|
75
|
-
plugins: pickPlugins(options.filePath),
|
|
76
|
-
});
|
|
77
|
-
return Promise.resolve(ast);
|
|
78
|
-
}
|
|
50
|
+
class BabelCodeParser extends BabelParseOnlyParser {
|
|
79
51
|
traverse(ast, visitor) {
|
|
80
52
|
traverse(ast, visitor);
|
|
81
53
|
}
|
|
@@ -93,8 +65,9 @@ class BabelCodeParser {
|
|
|
93
65
|
const ast = await this.parse(options);
|
|
94
66
|
let found = false;
|
|
95
67
|
const visit = (path) => {
|
|
96
|
-
if (!found && functionHasDirective(path.node, options.directive))
|
|
68
|
+
if (!found && functionHasDirective(path.node, options.directive)) {
|
|
97
69
|
found = true;
|
|
70
|
+
}
|
|
98
71
|
};
|
|
99
72
|
const visitor = {};
|
|
100
73
|
for (const nodeType of FUNCTION_NODE_TYPES)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser-only Babel entry for permission-constrained workers.
|
|
3
|
+
*
|
|
4
|
+
* This module deliberately imports only `@babel/parser`. In particular, it
|
|
5
|
+
* must remain independent of the full extension entry's traversal, generation,
|
|
6
|
+
* JSX transformation, extension lifecycle, and environment-sensitive debug
|
|
7
|
+
* dependency graphs.
|
|
8
|
+
*
|
|
9
|
+
* @module extensions/ext-parser-babel/parser-only
|
|
10
|
+
*/
|
|
11
|
+
import type { ASTNode, ParseOptions } from "veryfront/extensions/parser";
|
|
12
|
+
/** The parse-only subset shared with the full `CodeParser` contract. */
|
|
13
|
+
export interface BabelParseOnlyParserContract {
|
|
14
|
+
/** Parse source code into a Babel-compatible abstract syntax tree. */
|
|
15
|
+
parse(options: ParseOptions): Promise<ASTNode>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Babel-backed parser with the same parse behavior as {@link BabelCodeParser},
|
|
19
|
+
* without loading traversal, generation, or extension runtime dependencies.
|
|
20
|
+
*/
|
|
21
|
+
export declare class BabelParseOnlyParser implements BabelParseOnlyParserContract {
|
|
22
|
+
parse(options: ParseOptions): Promise<ASTNode>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=parser-only.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser-only.d.ts","sourceRoot":"","sources":["../src/parser-only.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEzE,wEAAwE;AACxE,MAAM,WAAW,4BAA4B;IAC3C,sEAAsE;IACtE,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAChD;AAuBD;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,4BAA4B;IACvE,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;CAQ/C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser-only Babel entry for permission-constrained workers.
|
|
3
|
+
*
|
|
4
|
+
* This module deliberately imports only `@babel/parser`. In particular, it
|
|
5
|
+
* must remain independent of the full extension entry's traversal, generation,
|
|
6
|
+
* JSX transformation, extension lifecycle, and environment-sensitive debug
|
|
7
|
+
* dependency graphs.
|
|
8
|
+
*
|
|
9
|
+
* @module extensions/ext-parser-babel/parser-only
|
|
10
|
+
*/
|
|
11
|
+
import * as parser from "@babel/parser";
|
|
12
|
+
function pickPlugins(filePath) {
|
|
13
|
+
const normalizedPath = filePath?.toLowerCase() ?? "";
|
|
14
|
+
const isTypeScript = /\.(?:tsx?|[cm]ts)$/.test(normalizedPath);
|
|
15
|
+
const supportsJsx = !filePath ||
|
|
16
|
+
/\.(?:tsx|jsx|js|mjs|cjs)$/.test(normalizedPath);
|
|
17
|
+
const plugins = [
|
|
18
|
+
"classProperties",
|
|
19
|
+
"classPrivateProperties",
|
|
20
|
+
"classPrivateMethods",
|
|
21
|
+
"decorators-legacy",
|
|
22
|
+
"decoratorAutoAccessors",
|
|
23
|
+
"deprecatedImportAssert",
|
|
24
|
+
"dynamicImport",
|
|
25
|
+
"importAttributes",
|
|
26
|
+
"topLevelAwait",
|
|
27
|
+
];
|
|
28
|
+
if (isTypeScript || !filePath)
|
|
29
|
+
plugins.push("typescript");
|
|
30
|
+
if (supportsJsx)
|
|
31
|
+
plugins.push("jsx");
|
|
32
|
+
return plugins;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Babel-backed parser with the same parse behavior as {@link BabelCodeParser},
|
|
36
|
+
* without loading traversal, generation, or extension runtime dependencies.
|
|
37
|
+
*/
|
|
38
|
+
export class BabelParseOnlyParser {
|
|
39
|
+
parse(options) {
|
|
40
|
+
const ast = parser.parse(options.code, {
|
|
41
|
+
sourceType: "unambiguous",
|
|
42
|
+
allowReturnOutsideFunction: options.filePath?.toLowerCase().endsWith(".cjs") === true,
|
|
43
|
+
plugins: pickPlugins(options.filePath),
|
|
44
|
+
});
|
|
45
|
+
return Promise.resolve(ast);
|
|
46
|
+
}
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veryfront/ext-parser-babel",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1189",
|
|
4
4
|
"description": "Veryfront first-party extension package for ext-parser-babel",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"veryfront",
|
|
@@ -23,11 +23,15 @@
|
|
|
23
23
|
".": {
|
|
24
24
|
"import": "./esm/index.js",
|
|
25
25
|
"types": "./esm/index.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./parser-only": {
|
|
28
|
+
"import": "./esm/parser-only.js",
|
|
29
|
+
"types": "./esm/parser-only.d.ts"
|
|
26
30
|
}
|
|
27
31
|
},
|
|
28
32
|
"scripts": {},
|
|
29
33
|
"engines": {
|
|
30
|
-
"node": ">=
|
|
34
|
+
"node": ">=22.3.0"
|
|
31
35
|
},
|
|
32
36
|
"publishConfig": {
|
|
33
37
|
"access": "public"
|
|
@@ -48,7 +52,7 @@
|
|
|
48
52
|
"@babel/types": "7.29.0"
|
|
49
53
|
},
|
|
50
54
|
"peerDependencies": {
|
|
51
|
-
"veryfront": "^0.1.
|
|
55
|
+
"veryfront": "^0.1.1189"
|
|
52
56
|
},
|
|
53
57
|
"type": "module",
|
|
54
58
|
"types": "./esm/index.d.ts",
|