mirror of
https://github.com/morluto/rea.git
synced 2026-11-30 10:27:42 +00:00
fix(deps): parse classes extending module with Babel 8.1.3 (#14924)
* fix(deps): parse classes extending module with Babel 8.1.3 * fix(javascript): preserve omitted call argument positions after recovery * fix(javascript): restore explicit nulls in recovered argument lists
This commit is contained in:
1 parent
132b53f2e6
commit
9005a43f34
7 files changed
+151
-37
No files matched your search
@@ -200,11 +200,11 @@ Full runtime copyright/license/NOTICE texts: npm-runtime-notices.txt.
|
||||
Package: https://www.npmjs.com/package/@babel/traverse/v/8.1.2
|
||||
Archive: https://registry.npmjs.org/@babel/traverse/-/traverse-8.1.2.tgz
|
||||
Integrity: sha512-J8OoydypQO6HGgRYiiHPMj0iBfz2XpSm5hkmd0+OEHWgQFzYL8TEvYq2y4Gu8vxRCa7g06BilFZ0Imiye5jzzg==
|
||||
@babel/helper-string-parser@8.1.2 | runtime | MIT
|
||||
@babel/helper-string-parser@8.1.3 | runtime | MIT
|
||||
Lockfile path: node_modules/@babel/helper-string-parser
|
||||
Package: https://www.npmjs.com/package/@babel/helper-string-parser/v/8.1.2
|
||||
Archive: https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-8.1.2.tgz
|
||||
Integrity: sha512-TRz5Z0MgfIfWqwEIq/pCpUpEXQxUt2Ig2ZbxG3SdmhSbHMAFFYGOix0kI4JLV371/TA+qWnQ4xWHPWjojkyRFA==
|
||||
Package: https://www.npmjs.com/package/@babel/helper-string-parser/v/8.1.3
|
||||
Archive: https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-8.1.3.tgz
|
||||
Integrity: sha512-5HTuREtgj0xIc345zU4gtD2+3vIPkZpJw7wUYytt/mzBTQN2mWpGr1nxYiocYa2E8sWggRkrSg/k7BK51pAxIg==
|
||||
@babel/helper-validator-identifier@8.0.6 | runtime | MIT
|
||||
Lockfile path: node_modules/@babel/helper-validator-identifier
|
||||
Package: https://www.npmjs.com/package/@babel/helper-validator-identifier/v/8.0.6
|
||||
@@ -220,11 +220,11 @@ Full runtime copyright/license/NOTICE texts: npm-runtime-notices.txt.
|
||||
Package: https://www.npmjs.com/package/@babel/helpers/v/8.1.2
|
||||
Archive: https://registry.npmjs.org/@babel/helpers/-/helpers-8.1.2.tgz
|
||||
Integrity: sha512-BmtiG8H9OUWSTFOgl9jtPYmfDi6uc21Pf4GUxkgGoZnzMIzpDnhkl5gsGJW6wb1jmKCyU565F8IYe5mwOTctfw==
|
||||
@babel/parser@8.1.2 | runtime | MIT
|
||||
@babel/parser@8.1.3 | runtime | MIT
|
||||
Lockfile path: node_modules/@babel/parser
|
||||
Package: https://www.npmjs.com/package/@babel/parser/v/8.1.2
|
||||
Archive: https://registry.npmjs.org/@babel/parser/-/parser-8.1.2.tgz
|
||||
Integrity: sha512-ZDKU7vaX0VORd2BhaO+3FKr/30TKjbUy3SMZcydiPngnAb+MesgUoh5SJcE5EwEyBj14M5J6fK56GuBqvYmOpw==
|
||||
Package: https://www.npmjs.com/package/@babel/parser/v/8.1.3
|
||||
Archive: https://registry.npmjs.org/@babel/parser/-/parser-8.1.3.tgz
|
||||
Integrity: sha512-v3ck2WN7jn8gEJlEfIDEwTM8dCBjOac1CZjolvB6/r0O1ome6E7xS2cDQEOQqESRQZWWrLrhnjxD0qjmZ8QBgg==
|
||||
@babel/plugin-proposal-decorators@8.0.2 | development | MIT
|
||||
Lockfile path: node_modules/@babel/plugin-proposal-decorators
|
||||
Package: https://www.npmjs.com/package/@babel/plugin-proposal-decorators/v/8.0.2
|
||||
@@ -305,11 +305,11 @@ Full runtime copyright/license/NOTICE texts: npm-runtime-notices.txt.
|
||||
Package: https://www.npmjs.com/package/@babel/traverse/v/8.0.10
|
||||
Archive: https://registry.npmjs.org/@babel/traverse/-/traverse-8.0.10.tgz
|
||||
Integrity: sha512-t5DaGzMi9WlhMSFT2YavI8gl8yGihoQymSQUkIq9+MUh5tO3Vx9KHwr5gMCzeBdYkvs00xNvr18PxtQTRayucA==
|
||||
@babel/types@8.1.2 | runtime | MIT
|
||||
@babel/types@8.1.3 | runtime | MIT
|
||||
Lockfile path: node_modules/@babel/types
|
||||
Package: https://www.npmjs.com/package/@babel/types/v/8.1.2
|
||||
Archive: https://registry.npmjs.org/@babel/types/-/types-8.1.2.tgz
|
||||
Integrity: sha512-uXt6qt2f5G61jZwNIzK1RKu7l5Xjt1VXtPPOGuVveha9fxbx0QM94U1kM4pFZKTRLjWK+X8vmwjwbIemJjiQTA==
|
||||
Package: https://www.npmjs.com/package/@babel/types/v/8.1.3
|
||||
Archive: https://registry.npmjs.org/@babel/types/-/types-8.1.3.tgz
|
||||
Integrity: sha512-eBREGwDHRPHtdsg44t071GE2KRDEuJrf0J2uT5/qvJPB2+pfPZOKlx93dMZOFkE7QW5G0JWoczySD7a01Jf0iw==
|
||||
@bcoe/v8-coverage@1.0.2 | development | MIT
|
||||
Lockfile path: node_modules/@bcoe/v8-coverage
|
||||
Package: https://www.npmjs.com/package/@bcoe/v8-coverage/v/1.0.2
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
REA third-party npm runtime copyright, license and NOTICE texts
|
||||
Collected from integrity-verified locked npm archives. Release-specific supplements and upstream notice gaps are identified in their entries.
|
||||
External engines are separately obtained; see THIRD_PARTY_NOTICES.md.
|
||||
Runtime dependency fingerprint (SHA-256): 38d3a3024c0d4c9ad5d3450e4d3247671bc68cb4ddcb9885e48898072b15c41a
|
||||
Runtime dependency fingerprint (SHA-256): e298ab4084421f9c78894fdada2fc051eb44a999e1810b408f0d5d074ea0a1c1
|
||||
|
||||
===== @babel/helper-string-parser@8.1.2 =====
|
||||
===== @babel/helper-string-parser@8.1.3 =====
|
||||
Declared license: MIT
|
||||
Archive: https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-8.1.2.tgz
|
||||
Integrity: sha512-TRz5Z0MgfIfWqwEIq/pCpUpEXQxUt2Ig2ZbxG3SdmhSbHMAFFYGOix0kI4JLV371/TA+qWnQ4xWHPWjojkyRFA==
|
||||
Archive: https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-8.1.3.tgz
|
||||
Integrity: sha512-5HTuREtgj0xIc345zU4gtD2+3vIPkZpJw7wUYytt/mzBTQN2mWpGr1nxYiocYa2E8sWggRkrSg/k7BK51pAxIg==
|
||||
Scope: npm runtime dependency, including optional platform packages.
|
||||
|
||||
--- package/LICENSE ---
|
||||
@@ -65,10 +65,10 @@ 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.
|
||||
|
||||
===== @babel/parser@8.1.2 =====
|
||||
===== @babel/parser@8.1.3 =====
|
||||
Declared license: MIT
|
||||
Archive: https://registry.npmjs.org/@babel/parser/-/parser-8.1.2.tgz
|
||||
Integrity: sha512-ZDKU7vaX0VORd2BhaO+3FKr/30TKjbUy3SMZcydiPngnAb+MesgUoh5SJcE5EwEyBj14M5J6fK56GuBqvYmOpw==
|
||||
Archive: https://registry.npmjs.org/@babel/parser/-/parser-8.1.3.tgz
|
||||
Integrity: sha512-v3ck2WN7jn8gEJlEfIDEwTM8dCBjOac1CZjolvB6/r0O1ome6E7xS2cDQEOQqESRQZWWrLrhnjxD0qjmZ8QBgg==
|
||||
Scope: npm runtime dependency, including optional platform packages.
|
||||
|
||||
--- package/LICENSE ---
|
||||
@@ -93,10 +93,10 @@ 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.
|
||||
|
||||
===== @babel/types@8.1.2 =====
|
||||
===== @babel/types@8.1.3 =====
|
||||
Declared license: MIT
|
||||
Archive: https://registry.npmjs.org/@babel/types/-/types-8.1.2.tgz
|
||||
Integrity: sha512-uXt6qt2f5G61jZwNIzK1RKu7l5Xjt1VXtPPOGuVveha9fxbx0QM94U1kM4pFZKTRLjWK+X8vmwjwbIemJjiQTA==
|
||||
Archive: https://registry.npmjs.org/@babel/types/-/types-8.1.3.tgz
|
||||
Integrity: sha512-eBREGwDHRPHtdsg44t071GE2KRDEuJrf0J2uT5/qvJPB2+pfPZOKlx93dMZOFkE7QW5G0JWoczySD7a01Jf0iw==
|
||||
Scope: npm runtime dependency, including optional platform packages.
|
||||
|
||||
--- package/LICENSE ---
|
||||
|
||||
Generated
+13
-13
@@ -9,8 +9,8 @@
|
||||
"version": "6.10.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/parser": "8.1.2",
|
||||
"@babel/types": "8.1.2",
|
||||
"@babel/parser": "8.1.3",
|
||||
"@babel/types": "8.1.3",
|
||||
"@bufbuild/protobuf": "2.17.0",
|
||||
"@clack/prompts": "1.9.0",
|
||||
"@jridgewell/trace-mapping": "0.3.31",
|
||||
@@ -707,9 +707,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-string-parser": {
|
||||
"version": "8.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-8.1.2.tgz",
|
||||
"integrity": "sha512-TRz5Z0MgfIfWqwEIq/pCpUpEXQxUt2Ig2ZbxG3SdmhSbHMAFFYGOix0kI4JLV371/TA+qWnQ4xWHPWjojkyRFA==",
|
||||
"version": "8.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-8.1.3.tgz",
|
||||
"integrity": "sha512-5HTuREtgj0xIc345zU4gtD2+3vIPkZpJw7wUYytt/mzBTQN2mWpGr1nxYiocYa2E8sWggRkrSg/k7BK51pAxIg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "^22.18.0 || >=24.11.0"
|
||||
@@ -749,12 +749,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/parser": {
|
||||
"version": "8.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-8.1.2.tgz",
|
||||
"integrity": "sha512-ZDKU7vaX0VORd2BhaO+3FKr/30TKjbUy3SMZcydiPngnAb+MesgUoh5SJcE5EwEyBj14M5J6fK56GuBqvYmOpw==",
|
||||
"version": "8.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-8.1.3.tgz",
|
||||
"integrity": "sha512-v3ck2WN7jn8gEJlEfIDEwTM8dCBjOac1CZjolvB6/r0O1ome6E7xS2cDQEOQqESRQZWWrLrhnjxD0qjmZ8QBgg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/types": "8.1.2"
|
||||
"@babel/types": "^8.1.3"
|
||||
},
|
||||
"bin": {
|
||||
"parser": "bin/babel-parser.js"
|
||||
@@ -1043,12 +1043,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/types": {
|
||||
"version": "8.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@babel/types/-/types-8.1.2.tgz",
|
||||
"integrity": "sha512-uXt6qt2f5G61jZwNIzK1RKu7l5Xjt1VXtPPOGuVveha9fxbx0QM94U1kM4pFZKTRLjWK+X8vmwjwbIemJjiQTA==",
|
||||
"version": "8.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@babel/types/-/types-8.1.3.tgz",
|
||||
"integrity": "sha512-eBREGwDHRPHtdsg44t071GE2KRDEuJrf0J2uT5/qvJPB2+pfPZOKlx93dMZOFkE7QW5G0JWoczySD7a01Jf0iw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/helper-string-parser": "^8.1.2",
|
||||
"@babel/helper-string-parser": "^8.1.3",
|
||||
"@babel/helper-validator-identifier": "^8.0.6"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
+2
-2
@@ -379,8 +379,8 @@
|
||||
"*.{json,md,yml,yaml}": "oxfmt --no-error-on-unmatched-pattern"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/parser": "8.1.2",
|
||||
"@babel/types": "8.1.2",
|
||||
"@babel/parser": "8.1.3",
|
||||
"@babel/types": "8.1.3",
|
||||
"@bufbuild/protobuf": "2.17.0",
|
||||
"@clack/prompts": "1.9.0",
|
||||
"@jridgewell/trace-mapping": "0.3.31",
|
||||
|
||||
@@ -46,6 +46,17 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it("retains later arguments when a recovered .call omits its receiver", () => {
|
||||
expect(invocationKinds('Object.keys.call(, "kept")')).toEqual([
|
||||
expect.objectContaining({
|
||||
path: ["intrinsic", "Object", "keys"],
|
||||
arguments: [
|
||||
expect.objectContaining({ type: "StringLiteral", value: "kept" }),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps a comma-expression intrinsic call unknown when its receiver is erased", () => {
|
||||
expect(
|
||||
invocationKinds(
|
||||
|
||||
@@ -11,6 +11,47 @@ import {
|
||||
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
|
||||
import { analyzeParsedJavaScriptStaticSource } from "../../../tests/fixtures/javascriptStaticAnalysis.js";
|
||||
|
||||
it("parses a class extending a local binding named module", () => {
|
||||
const source = "const module = Array; class Cards extends module {}";
|
||||
const path = "cards.mjs";
|
||||
for (const file of [
|
||||
parseJavaScriptSource(source, path),
|
||||
parseRecoveredJavaScript(source, path, {}).file,
|
||||
]) {
|
||||
expect(file?.errors).toHaveLength(0);
|
||||
expect(file?.program.body[1]).toMatchObject({
|
||||
type: "ClassDeclaration",
|
||||
superClass: { type: "Identifier", name: "module" },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps omitted call arguments with their own list", () => {
|
||||
const source = 'outer<Pair<A, B>>(, inner(, "a,b"), /* , */ , (1, 2),,)';
|
||||
for (const file of [
|
||||
parseJavaScriptSource(source, "example.ts"),
|
||||
parseRecoveredJavaScript(source, "example.ts", {}).file,
|
||||
]) {
|
||||
const statement = file?.program.body[0];
|
||||
if (
|
||||
!t.isExpressionStatement(statement) ||
|
||||
!t.isCallExpression(statement.expression)
|
||||
)
|
||||
throw new Error("Expected the outer call");
|
||||
const outer = statement.expression;
|
||||
expect(outer.arguments.map((arg) => arg?.type ?? null)).toStrictEqual([
|
||||
null,
|
||||
"CallExpression",
|
||||
null,
|
||||
"SequenceExpression",
|
||||
null,
|
||||
]);
|
||||
const inner = outer.arguments[1];
|
||||
if (!t.isCallExpression(inner)) throw new Error("Expected the inner call");
|
||||
expect(inner.arguments).toMatchObject([null, { type: "StringLiteral" }]);
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
["class C extends (this.marker, Object) {}", true],
|
||||
["class C { [this.marker]() {} }", true],
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { posix } from "node:path";
|
||||
import { parse, type ParserOptions, type ParserPlugin } from "@babel/parser";
|
||||
import * as t from "@babel/types";
|
||||
import { isRecord } from "../../kernel/isRecord.js";
|
||||
import { isJavaScriptSourcePath } from "./javascriptArtifactFiles.js";
|
||||
import { ParseFailureError } from "../parseFailure.js";
|
||||
import { javaScriptDefinitionExpression } from "./javascriptAstValues.js";
|
||||
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
|
||||
import {
|
||||
explicitJavaScriptLoaderMode,
|
||||
hasCaseVariantJavaScriptLoaderSuffix,
|
||||
@@ -255,12 +257,72 @@ const parserOptionsForLoader = (
|
||||
return parserOptions;
|
||||
};
|
||||
|
||||
/** Babel drops omitted arguments from recovered calls but diagnoses their commas. */
|
||||
const restoreOmittedArguments = (
|
||||
program: t.Program,
|
||||
errors: readonly { reasonCode: string; details: unknown; pos: number }[],
|
||||
): void => {
|
||||
const commas = errors
|
||||
.filter(
|
||||
({ reasonCode, details }) =>
|
||||
reasonCode === "UnexpectedToken" &&
|
||||
isRecord(details) &&
|
||||
details.unexpected === ",",
|
||||
)
|
||||
.map(({ pos }) => pos - 1)
|
||||
.sort((a, b) => a - b);
|
||||
if (commas.length === 0) return;
|
||||
|
||||
const countBefore = (offset: number): number => {
|
||||
let low = 0;
|
||||
let high = commas.length;
|
||||
while (low < high) {
|
||||
const mid = low + Math.floor((high - low) / 2);
|
||||
if (commas[mid]! < offset) low = mid + 1;
|
||||
else high = mid;
|
||||
}
|
||||
return low;
|
||||
};
|
||||
// Recovery in Babel 8.1.2 represented each omission with an explicit null.
|
||||
const appendOmissions = (slots: (t.Node | null)[], count: number): void => {
|
||||
for (let i = 0; i < count; i++) slots.push(null);
|
||||
};
|
||||
traverseJavaScriptAst(program, {
|
||||
enter(node) {
|
||||
if (
|
||||
!t.isCallExpression(node) &&
|
||||
!t.isOptionalCallExpression(node) &&
|
||||
!t.isNewExpression(node)
|
||||
)
|
||||
return;
|
||||
const start = node.typeArguments?.end ?? node.callee.end;
|
||||
if (start == null || node.end == null) return;
|
||||
let cursor = countBefore(start);
|
||||
const end = countBefore(node.end);
|
||||
if (cursor === end) return;
|
||||
|
||||
// Only gaps between argument spans belong to this list. A diagnostic
|
||||
// inside an argument belongs to a nested expression.
|
||||
const slots: typeof node.arguments = [];
|
||||
for (const argument of node.arguments) {
|
||||
if (argument.start == null || argument.end == null) return;
|
||||
appendOmissions(slots, countBefore(argument.start) - cursor);
|
||||
slots.push(argument);
|
||||
cursor = countBefore(argument.end);
|
||||
}
|
||||
appendOmissions(slots, end - cursor);
|
||||
if (slots.length !== node.arguments.length) node.arguments = slots;
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/** Keep optional Babel metadata omitted in the parser-owned File representation. */
|
||||
const parseBabelFile = (
|
||||
source: string,
|
||||
options: ParserOptions,
|
||||
): ParsedJavaScriptSource => {
|
||||
const { comments, tokens, errors, ...file } = parse(source, options);
|
||||
if (errors.length > 0) restoreOmittedArguments(file.program, errors);
|
||||
return {
|
||||
...file,
|
||||
// Babel couples the ambiguous generic-arrow diagnostic with a legacy
|
||||
|
||||
Reference in new issue
Block a user