@veryfront/ext-parser-babel 0.1.1248-rc.13706 → 0.1.1248
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/esm/parser-only.d.ts.map +1 -1
- package/esm/parser-only.js +32 -3
- package/package.json +2 -2
package/esm/parser-only.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;AAqDD;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,4BAA4B;IACvE,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;CA4B/C"}
|
package/esm/parser-only.js
CHANGED
|
@@ -32,7 +32,7 @@ function pickPlugins(filePath) {
|
|
|
32
32
|
"classProperties",
|
|
33
33
|
"classPrivateProperties",
|
|
34
34
|
"classPrivateMethods",
|
|
35
|
-
"decorators
|
|
35
|
+
"decorators",
|
|
36
36
|
"decoratorAutoAccessors",
|
|
37
37
|
"deprecatedImportAssert",
|
|
38
38
|
"dynamicImport",
|
|
@@ -48,6 +48,15 @@ function pickPlugins(filePath) {
|
|
|
48
48
|
plugins.push("jsx");
|
|
49
49
|
return plugins;
|
|
50
50
|
}
|
|
51
|
+
function pickLegacyDecoratorPlugins(filePath) {
|
|
52
|
+
return pickPlugins(filePath).map((plugin) => plugin === "decorators" ? "decorators-legacy" : plugin);
|
|
53
|
+
}
|
|
54
|
+
function isBabelSyntaxError(error) {
|
|
55
|
+
if (typeof error !== "object" || error === null)
|
|
56
|
+
return false;
|
|
57
|
+
const code = Object.getOwnPropertyDescriptor(error, "code")?.value;
|
|
58
|
+
return code === "BABEL_PARSER_SYNTAX_ERROR";
|
|
59
|
+
}
|
|
51
60
|
/**
|
|
52
61
|
* Babel-backed parser with the same parse behavior as {@link BabelCodeParser},
|
|
53
62
|
* without loading traversal, generation, or extension runtime dependencies.
|
|
@@ -55,12 +64,32 @@ function pickPlugins(filePath) {
|
|
|
55
64
|
export class BabelParseOnlyParser {
|
|
56
65
|
parse(options) {
|
|
57
66
|
const filePath = options.filePath?.toLowerCase() ?? "";
|
|
58
|
-
const
|
|
67
|
+
const parseOptions = {
|
|
59
68
|
sourceType: "unambiguous",
|
|
60
69
|
allowReturnOutsideFunction: options.allowReturnOutsideFunction === true ||
|
|
61
70
|
/\.(?:cjs|js)$/.test(filePath),
|
|
62
71
|
plugins: pickPlugins(parseablePath(options.filePath)),
|
|
63
|
-
}
|
|
72
|
+
};
|
|
73
|
+
const ast = (() => {
|
|
74
|
+
try {
|
|
75
|
+
return parser.parse(options.code, parseOptions);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (!isBabelSyntaxError(error))
|
|
79
|
+
throw error;
|
|
80
|
+
try {
|
|
81
|
+
return parser.parse(options.code, {
|
|
82
|
+
...parseOptions,
|
|
83
|
+
plugins: pickLegacyDecoratorPlugins(parseablePath(options.filePath)),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Preserve the primary parser's diagnostic when neither supported
|
|
88
|
+
// decorator dialect accepts the source.
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
})();
|
|
64
93
|
const node = ast;
|
|
65
94
|
return Promise.resolve(node);
|
|
66
95
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veryfront/ext-parser-babel",
|
|
3
|
-
"version": "0.1.1248
|
|
3
|
+
"version": "0.1.1248",
|
|
4
4
|
"description": "Veryfront first-party extension package for ext-parser-babel",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"veryfront",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@babel/types": "7.29.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"veryfront": "^0.1.1248
|
|
57
|
+
"veryfront": "^0.1.1248"
|
|
58
58
|
},
|
|
59
59
|
"type": "module",
|
|
60
60
|
"types": "./esm/index.d.ts",
|