first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

191
node_modules/hermes-parser/dist/utils/Builders.js generated vendored Normal file
View File

@@ -0,0 +1,191 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EMPTY_PARENT = void 0;
exports.callExpression = callExpression;
exports.conjunction = conjunction;
exports.createDefaultPosition = createDefaultPosition;
exports.disjunction = disjunction;
exports.etc = etc;
exports.ident = ident;
exports.iife = iife;
exports.nullLiteral = nullLiteral;
exports.numberLiteral = numberLiteral;
exports.stringLiteral = stringLiteral;
exports.throwStatement = throwStatement;
exports.typeofExpression = typeofExpression;
exports.variableDeclaration = variableDeclaration;
// Rely on the mapper to fix up parent relationships.
const EMPTY_PARENT = null;
exports.EMPTY_PARENT = EMPTY_PARENT;
function createDefaultPosition() {
return {
line: 1,
column: 0
};
}
function etc({
loc,
range,
parent
} = {}) {
return {
loc: {
start: (loc == null ? void 0 : loc.start) != null ? loc.start : createDefaultPosition(),
end: (loc == null ? void 0 : loc.end) != null ? loc.end : createDefaultPosition()
},
range: range != null ? range : [0, 0],
parent: parent != null ? parent : EMPTY_PARENT
};
}
function ident(name, info) {
return {
type: 'Identifier',
name,
optional: false,
typeAnnotation: null,
...etc(info)
};
}
function stringLiteral(value, info) {
return {
type: 'Literal',
value,
raw: `"${value}"`,
literalType: 'string',
...etc(info)
};
}
function numberLiteral(value, info) {
return {
type: 'Literal',
value,
raw: String(value),
literalType: 'numeric',
...etc(info)
};
}
function nullLiteral(info) {
return {
type: 'Literal',
value: null,
raw: 'null',
literalType: 'null',
...etc(info)
};
}
function conjunction(tests) {
if (tests.length === 0) {
throw new Error('Must have at least one test.');
}
return tests.reduce((acc, test) => ({
type: 'LogicalExpression',
left: acc,
right: test,
operator: '&&',
...etc()
}));
}
function disjunction(tests) {
if (tests.length === 0) {
throw new Error('Must have at least one test.');
}
return tests.reduce((acc, test) => ({
type: 'LogicalExpression',
left: acc,
right: test,
operator: '||',
...etc()
}));
}
function variableDeclaration(kind, id, init, info) {
return {
type: 'VariableDeclaration',
kind,
declarations: [{
type: 'VariableDeclarator',
init,
id,
...etc(),
parent: EMPTY_PARENT
}],
...etc(info)
};
}
function callExpression(callee, args, info) {
return {
type: 'CallExpression',
callee,
arguments: args,
typeArguments: null,
optional: false,
...etc(info)
};
}
function throwStatement(arg, info) {
return {
type: 'ThrowStatement',
argument: callExpression(ident('Error'), [arg]),
...etc(info)
};
}
function iife(statements, params = [], args = []) {
const callee = {
type: 'ArrowFunctionExpression',
params,
expression: false,
async: false,
predicate: null,
returnType: null,
typeParameters: null,
id: null,
body: {
type: 'BlockStatement',
body: statements,
...etc()
},
...etc()
};
return callExpression(callee, args);
}
function typeofExpression(arg, kind) {
return {
type: 'BinaryExpression',
left: {
type: 'UnaryExpression',
operator: 'typeof',
argument: arg,
prefix: true,
...etc()
},
right: stringLiteral(kind),
operator: '===',
...etc()
};
}

218
node_modules/hermes-parser/dist/utils/Builders.js.flow generated vendored Normal file
View File

@@ -0,0 +1,218 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/
'use strict';
import type {
ArrowFunctionExpression,
BinaryExpression,
BindingName,
CallExpression,
ESNode,
Expression,
Identifier,
LogicalExpression,
NullLiteral,
NumericLiteral,
Position,
Range,
SourceLocation,
SpreadElement,
Statement,
StringLiteral,
Super,
ThrowStatement,
VariableDeclaration,
} from 'hermes-estree';
// Rely on the mapper to fix up parent relationships.
export const EMPTY_PARENT: $FlowFixMe = null;
export function createDefaultPosition(): Position {
return {
line: 1,
column: 0,
};
}
export type Etc = {
parent?: ESNode,
loc?: SourceLocation,
range?: Range,
};
export function etc({loc, range, parent}: Etc = {}): {
parent: ESNode,
loc: SourceLocation,
range: Range,
} {
return {
loc: {
start: loc?.start != null ? loc.start : createDefaultPosition(),
end: loc?.end != null ? loc.end : createDefaultPosition(),
},
range: range ?? [0, 0],
parent: parent ?? EMPTY_PARENT,
};
}
export function ident(name: string, info?: Etc): Identifier {
return {
type: 'Identifier',
name,
optional: false,
typeAnnotation: null,
...etc(info),
};
}
export function stringLiteral(value: string, info?: Etc): StringLiteral {
return {
type: 'Literal',
value,
raw: `"${value}"`,
literalType: 'string',
...etc(info),
};
}
export function numberLiteral(value: number, info?: Etc): NumericLiteral {
return {
type: 'Literal',
value,
raw: String(value),
literalType: 'numeric',
...etc(info),
};
}
export function nullLiteral(info?: Etc): NullLiteral {
return {
type: 'Literal',
value: null,
raw: 'null',
literalType: 'null',
...etc(info),
};
}
export function conjunction(tests: $ReadOnlyArray<Expression>): Expression {
if (tests.length === 0) {
throw new Error('Must have at least one test.');
}
return tests.reduce((acc, test): LogicalExpression => ({
type: 'LogicalExpression',
left: acc,
right: test,
operator: '&&',
...etc(),
}));
}
export function disjunction(tests: $ReadOnlyArray<Expression>): Expression {
if (tests.length === 0) {
throw new Error('Must have at least one test.');
}
return tests.reduce((acc, test): LogicalExpression => ({
type: 'LogicalExpression',
left: acc,
right: test,
operator: '||',
...etc(),
}));
}
export function variableDeclaration(
kind: VariableDeclaration['kind'],
id: BindingName,
init: Expression,
info?: Etc,
): VariableDeclaration {
return {
type: 'VariableDeclaration',
kind,
declarations: [
{
type: 'VariableDeclarator',
init,
id,
...etc(),
parent: EMPTY_PARENT,
},
],
...etc(info),
};
}
export function callExpression(
callee: Expression | Super,
args: $ReadOnlyArray<Expression | SpreadElement>,
info?: Etc,
): CallExpression {
return {
type: 'CallExpression',
callee,
arguments: args,
typeArguments: null,
optional: false,
...etc(info),
};
}
export function throwStatement(arg: Expression, info?: Etc): ThrowStatement {
return {
type: 'ThrowStatement',
argument: callExpression(ident('Error'), [arg]),
...etc(info),
};
}
export function iife(
statements: $ReadOnlyArray<Statement>,
params: $ReadOnlyArray<BindingName> = [],
args: $ReadOnlyArray<Expression> = [],
): CallExpression {
const callee: ArrowFunctionExpression = {
type: 'ArrowFunctionExpression',
params,
expression: false,
async: false,
predicate: null,
returnType: null,
typeParameters: null,
id: null,
body: {
type: 'BlockStatement',
body: statements,
...etc(),
},
...etc(),
};
return callExpression(callee, args);
}
export function typeofExpression(
arg: Expression,
kind: string,
): BinaryExpression {
return {
type: 'BinaryExpression',
left: {
type: 'UnaryExpression',
operator: 'typeof',
argument: arg,
prefix: true,
...etc(),
},
right: stringLiteral(kind),
operator: '===',
...etc(),
};
}

41
node_modules/hermes-parser/dist/utils/GenID.js generated vendored Normal file
View File

@@ -0,0 +1,41 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createGenID = createGenID;
const genPrefix = '$$gen$';
function createGenID(uniqueTransformPrefix) {
let genN = 0;
const used = new Set();
return {
genID() {
let name;
do {
name = `${genPrefix}${uniqueTransformPrefix}${genN}`;
genN++;
} while (used.has(name));
used.add(name);
return name;
},
addUsage(name) {
if (name.startsWith(genPrefix)) {
used.add(name);
}
}
};
}

38
node_modules/hermes-parser/dist/utils/GenID.js.flow generated vendored Normal file
View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/
'use strict';
const genPrefix = '$$gen$';
export function createGenID(uniqueTransformPrefix: string): {
genID(): string,
addUsage(string): void,
} {
let genN: number = 0;
const used = new Set<string>();
return {
genID(): string {
let name;
do {
name = `${genPrefix}${uniqueTransformPrefix}${genN}`;
genN++;
} while (used.has(name));
used.add(name);
return name;
},
addUsage(name: string): void {
if (name.startsWith(genPrefix)) {
used.add(name);
}
},
};
}

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createSyntaxError = createSyntaxError;
function createSyntaxError(node, err) {
const syntaxError = new SyntaxError(err); // $FlowExpectedError[prop-missing]
syntaxError.loc = {
line: node.loc.start.line,
column: node.loc.start.column
};
return syntaxError;
}

View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/
'use strict';
import type {ESNode} from 'hermes-estree';
export function createSyntaxError(node: ESNode, err: string): SyntaxError {
const syntaxError = new SyntaxError(err);
// $FlowExpectedError[prop-missing]
syntaxError.loc = {
line: node.loc.start.line,
column: node.loc.start.column,
};
return syntaxError;
}

View File

@@ -0,0 +1,127 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = mutate;
var _SimpleTransform = require("../transform/SimpleTransform");
// https://github.com/prettier/prettier/blob/d962466a828f8ef51435e3e8840178d90b7ec6cd/src/language-js/parse/postprocess/index.js#L161-L182
function transformChainExpression(node, comments) {
if (comments != null) {
var _node$comments;
// $FlowExpectedError[prop-missing]
const joinedComments = comments.concat((_node$comments = node.comments) != null ? _node$comments : []); // $FlowExpectedError[prop-missing]
// $FlowFixMe[cannot-write]
node.comments = joinedComments;
}
switch (node.type) {
case 'CallExpression':
// $FlowExpectedError[cannot-spread-interface]
return { ...node,
type: 'OptionalCallExpression',
callee: transformChainExpression(node.callee)
};
case 'MemberExpression':
// $FlowExpectedError[cannot-spread-interface]
return { ...node,
type: 'OptionalMemberExpression',
object: transformChainExpression(node.object)
};
// No default
}
return node;
}
function mutate(rootNode, visitorKeys) {
// Since we don't return the result of `transform` we need to be careful not to replace the Program root node.
_SimpleTransform.SimpleTransform.transform(rootNode, {
transform(node) {
// prettier fully expects the parent pointers are NOT set and
// certain cases can crash due to prettier infinite-looping
// whilst naively traversing the parent property
// https://github.com/prettier/prettier/issues/11793
// Note: Only needed for prettier V2, this is supported in V3
if (node.parent) {
// $FlowExpectedError[cannot-write]
delete node.parent;
} // prettier currently relies on the AST being in the old-school, deprecated AST format for optional chaining
// so we have to apply their transform to our AST so it can actually format it.
// Note: Only needed for prettier V2, this is supported in V3
if (node.type === 'ChainExpression') {
// $FlowFixMe[prop-missing]
return transformChainExpression(node.expression, node == null ? void 0 : node.comments);
} // Prettier currently relies on comparing the `node` vs `node.value` start positions to know if an
// `ObjectTypeProperty` is a method or not (instead of using the `node.method` boolean). To correctly print
// the node when its not a method we need the start position to be different from the `node.value`s start
// position.
if (node.type === 'ObjectTypeProperty') {
if (node.method === false && node.kind === 'init' && node.range[0] === 1 && node.value.range[0] === 1) {
// $FlowExpectedError[cannot-write]
// $FlowExpectedError[cannot-spread-interface]
node.value = { ...node.value,
range: [2, node.value.range[1]]
};
}
return node;
} // Prettier currently relies on comparing the the start positions to know if the import/export specifier should have a
// rename (eg `Name` vs `Name as Name`) when the name is exactly the same
// So we need to ensure that the range is always the same to avoid the useless code printing
if (node.type === 'ImportSpecifier') {
if (node.local.name === node.imported.name) {
if (node.local.range == null) {
// for our TS-ast printing which has no locs
// $FlowExpectedError[cannot-write]
node.local.range = [0, 0];
} // $FlowExpectedError[cannot-write]
node.imported.range = [...node.local.range];
}
return node;
}
if (node.type === 'ExportSpecifier') {
if (node.local.name === node.exported.name) {
if (node.local.range == null) {
// for our TS-ast printing which has no locs
// $FlowExpectedError[cannot-write]
node.local.range = [0, 0];
} // $FlowExpectedError[cannot-write]
node.exported.range = [...node.local.range];
}
return node;
}
return node;
},
visitorKeys
});
}

View File

@@ -0,0 +1,130 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/
'use strict';
import type {ESNode, Program, Comment} from 'hermes-estree';
import type {VisitorKeysType} from '../traverse/getVisitorKeys';
import {SimpleTransform} from '../transform/SimpleTransform';
// https://github.com/prettier/prettier/blob/d962466a828f8ef51435e3e8840178d90b7ec6cd/src/language-js/parse/postprocess/index.js#L161-L182
function transformChainExpression(
node: ESNode,
comments: ?$ReadOnlyArray<Comment>,
): ESNode {
if (comments != null) {
// $FlowExpectedError[prop-missing]
const joinedComments = comments.concat(node.comments ?? []);
// $FlowExpectedError[prop-missing]
// $FlowFixMe[cannot-write]
node.comments = joinedComments;
}
switch (node.type) {
case 'CallExpression':
// $FlowExpectedError[cannot-spread-interface]
return {
...node,
type: 'OptionalCallExpression',
callee: transformChainExpression(node.callee),
};
case 'MemberExpression':
// $FlowExpectedError[cannot-spread-interface]
return {
...node,
type: 'OptionalMemberExpression',
object: transformChainExpression(node.object),
};
// No default
}
return node;
}
export default function mutate(
rootNode: Program,
visitorKeys: ?VisitorKeysType,
): void {
// Since we don't return the result of `transform` we need to be careful not to replace the Program root node.
SimpleTransform.transform(rootNode, {
transform(node): ESNode | null {
// prettier fully expects the parent pointers are NOT set and
// certain cases can crash due to prettier infinite-looping
// whilst naively traversing the parent property
// https://github.com/prettier/prettier/issues/11793
// Note: Only needed for prettier V2, this is supported in V3
if (node.parent) {
// $FlowExpectedError[cannot-write]
delete node.parent;
}
// prettier currently relies on the AST being in the old-school, deprecated AST format for optional chaining
// so we have to apply their transform to our AST so it can actually format it.
// Note: Only needed for prettier V2, this is supported in V3
if (node.type === 'ChainExpression') {
// $FlowFixMe[prop-missing]
return transformChainExpression(node.expression, node?.comments);
}
// Prettier currently relies on comparing the `node` vs `node.value` start positions to know if an
// `ObjectTypeProperty` is a method or not (instead of using the `node.method` boolean). To correctly print
// the node when its not a method we need the start position to be different from the `node.value`s start
// position.
if (node.type === 'ObjectTypeProperty') {
if (
node.method === false &&
node.kind === 'init' &&
node.range[0] === 1 &&
node.value.range[0] === 1
) {
// $FlowExpectedError[cannot-write]
// $FlowExpectedError[cannot-spread-interface]
node.value = {
...node.value,
range: [2, node.value.range[1]],
};
}
return node;
}
// Prettier currently relies on comparing the the start positions to know if the import/export specifier should have a
// rename (eg `Name` vs `Name as Name`) when the name is exactly the same
// So we need to ensure that the range is always the same to avoid the useless code printing
if (node.type === 'ImportSpecifier') {
if (node.local.name === node.imported.name) {
if (node.local.range == null) {
// for our TS-ast printing which has no locs
// $FlowExpectedError[cannot-write]
node.local.range = [0, 0];
}
// $FlowExpectedError[cannot-write]
node.imported.range = [...node.local.range];
}
return node;
}
if (node.type === 'ExportSpecifier') {
if (node.local.name === node.exported.name) {
if (node.local.range == null) {
// for our TS-ast printing which has no locs
// $FlowExpectedError[cannot-write]
node.local.range = [0, 0];
}
// $FlowExpectedError[cannot-write]
node.exported.range = [...node.local.range];
}
return node;
}
return node;
},
visitorKeys,
});
}